@ -1,21 +1,15 @@ | |||
<?php | |||
//5-19-17 | |||
//5-19-17 | |||
include 'includes/header.php'; | |||
include 'includes/header.php'; | |||
echo '<br><div class="w3-row"> | |||
<div class="w3-half w3-container ">'; | |||
//add stuff | |||
echo '<br><div class="w3-row"> | |||
<div class="w3-half w3-container ">'; | |||
echo '</div><div class="w3-half w3-container">'; | |||
include 'user/profile.php'; | |||
echo '</div><div class="w3-half w3-container">'; | |||
include 'user/profile.php'; | |||
echo '</div></div>'; | |||
echo '</div>'; | |||
echo '</div>'; | |||
include 'includes/footer.php'; | |||
?> | |||
include 'includes/footer.php'; |
@ -1,39 +1,31 @@ | |||
<?php | |||
//11-24-16 | |||
require('includes/header.php'); | |||
if($admin) | |||
{ | |||
echo '<div class="w3-row w3-padding-32">'; | |||
echo '<div class="w3-twothird w3-container">'; | |||
//users | |||
include('user/users.php'); | |||
echo '</div><div class="w3-third w3-container">'; | |||
//profile | |||
include('user/profile.php'); | |||
echo '</div></div>'; | |||
echo '<div class="w3-row w3-padding-32">'; | |||
echo '<div class="w3-twothird w3-container">'; | |||
//edit user | |||
include('user/editUser.php'); | |||
echo '</div><div class="w3-third w3-container">'; | |||
//new user | |||
include('user/newUser.php'); | |||
echo '</div></div>'; | |||
} | |||
else | |||
{ | |||
include('includes/profile.php'); | |||
} | |||
require('includes/footer.php'); | |||
?> | |||
//11-24-16 | |||
require('includes/header.php'); | |||
if($admin) | |||
{ | |||
echo '<div class="w3-row w3-padding-32">'; | |||
echo '<div class="w3-twothird w3-container">'; | |||
include('user/users.php'); | |||
echo '</div><div class="w3-third w3-container">'; | |||
include('user/profile.php'); | |||
echo '</div></div>'; | |||
echo '<div class="w3-row w3-padding-32">'; | |||
echo '<div class="w3-twothird w3-container">'; | |||
include('user/editUser.php'); | |||
echo '</div><div class="w3-third w3-container">'; | |||
include('user/newUser.php'); | |||
echo '</div></div>'; | |||
} | |||
else | |||
{ | |||
include('includes/profile.php'); | |||
} | |||
require('includes/footer.php'); |
@ -1,22 +1,18 @@ | |||
<?php | |||
//5-16-17 | |||
//5-16-17 | |||
//ini_set('display_errors', 1); | |||
include 'includes/header.php'; | |||
//ini_set('display_errors', 1); | |||
include 'includes/header.php'; | |||
echo '<br><div class="w3-row"> | |||
<div class="w3-half w3-container ">'; | |||
include('games/bamboofield.html'); | |||
echo '<br><div class="w3-row"> | |||
<div class="w3-half w3-container ">'; | |||
include('games/bamboofield.html'); | |||
echo '</div><div class="w3-half w3-container">'; | |||
include('games/zombiePanda.html'); | |||
echo '</div><div class="w3-half w3-container">'; | |||
include('games/zombiePanda.html'); | |||
echo '</div>'; | |||
echo '</div>'; | |||
echo '</div></div>'; | |||
include 'includes/footer.php'; | |||
?> | |||
include 'includes/footer.php'; |
@ -1,319 +1,276 @@ | |||
<script> | |||
window.addEventListener("keydown", function(e) | |||
window.addEventListener("keydown", function(e) | |||
{ | |||
// space and arrow keys | |||
if([32, 37, 38, 39, 40].indexOf(e.keyCode) > -1) | |||
{ | |||
// space and arrow keys | |||
if([32, 37, 38, 39, 40].indexOf(e.keyCode) > -1) | |||
{ | |||
e.preventDefault(); | |||
} | |||
}, false); | |||
window.onload = function() | |||
e.preventDefault(); | |||
} | |||
}, false); | |||
window.onload = function() | |||
{ | |||
var canvasBFc = document.getElementById("canvasBF"); | |||
var c = canvasBFc.getContext('2d'); | |||
c.fillStyle= "black"; | |||
c.fillRect(0,0, canvasBFc.width, canvasBFc.height); | |||
}; | |||
function playBF() | |||
{ | |||
var animate = window.requestAnimationFrame || | |||
window.webkitRequestAnimationFrame || | |||
window.mozRequestAnimationFrame || function (callback) | |||
{ | |||
var canvasBFc = document.getElementById("canvasBF"); | |||
var c = canvasBFc.getContext('2d'); | |||
c.fillStyle= "black"; | |||
c.fillRect(0,0, canvasBFc.width, canvasBFc.height); | |||
window.setTimeout(callback, 1000 / 60) | |||
}; | |||
//entire game | |||
function playBF() | |||
var canvasBFc = document.getElementById("canvasBF"); | |||
var width = 700; | |||
var height = 700; | |||
canvasBFc.style.textAligh = 'center'; | |||
var context = canvasBFc.getContext('2d'); | |||
var keysDown = {}; | |||
//player variables; | |||
var score = 0; | |||
var alive = true; | |||
function getRandomIntInclusive(min, max) | |||
{ | |||
var animate = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || function (callback) | |||
min = Math.ceil(min); | |||
max = Math.floor(max); | |||
return Math.floor(Math.random() * (max - min + 1)) + min; | |||
} | |||
var Player = function(x,y) | |||
{ | |||
this.x = 350 | |||
this.y = 650; | |||
this.width = 10; | |||
this.height = 10; | |||
this.speed = 4; | |||
this.facing = 40; | |||
this.updateDirection = function(key) | |||
{ | |||
window.setTimeout(callback, 1000 / 60) | |||
}; | |||
var canvasBFc = document.getElementById("canvasBF"); | |||
var width = 700; | |||
var height = 700; | |||
canvasBFc.style.textAligh = 'center'; | |||
var context = canvasBFc.getContext('2d'); | |||
var keysDown = {}; | |||
//player variables; | |||
var score = 0; | |||
var alive = true; | |||
//usefull function | |||
function getRandomIntInclusive(min, max) | |||
facing = key; | |||
} | |||
this.render = function() | |||
{ | |||
min = Math.ceil(min); | |||
max = Math.floor(max); | |||
return Math.floor(Math.random() * (max - min + 1)) + min; | |||
context.fillStyle = "rgba(255, 255, 255, 1)"; //white | |||
context.fillRect(this.x, this.y, this.width, this.height); | |||
} | |||
//objects | |||
var Player = function(x,y) | |||
this.move = function() | |||
{ | |||
this.x = 350 | |||
this.y = 650; | |||
this.width = 10; | |||
this.height = 10; | |||
this.speed = 4; | |||
this.facing = 40; | |||
this.updateDirection = function(key) | |||
{ | |||
facing = key; | |||
} | |||
this.render = function() | |||
for (var key in keysDown) | |||
{ | |||
context.fillStyle = "rgba(255, 255, 255, 1)"; //white | |||
context.fillRect(this.x, this.y, this.width, this.height); | |||
var value = Number(key); | |||
if(value == 37) //left | |||
this.x = this.x - this.speed; | |||
else if(value == 39) | |||
this.x = this.x + this.speed; | |||
} | |||
this.move = function() | |||
//collisions | |||
for(i = 0; i < bamboos.length; i++) | |||
{ | |||
for (var key in keysDown) | |||
{ | |||
var value = Number(key); | |||
if(value == 37) //left | |||
{ | |||
this.x = this.x - this.speed; | |||
} | |||
else if(value == 39) | |||
{ | |||
this.x = this.x + this.speed; | |||
} | |||
} | |||
//collisions | |||
for(i = 0; i < bamboos.length; i++) | |||
if(bamboos[i] != -1) | |||
{ | |||
if(bamboos[i] != -1) | |||
bb = bamboos[i]; | |||
//if(Math.abs(bb.x - p.x) <= bb.width) | |||
if(p.x > bb.x && p.x < bb.x + bb.width || | |||
p.x + p.width < bb.x + bb.width && p.x + | |||
p.width > bb.x) | |||
{ | |||
bb = bamboos[i]; | |||
//if(Math.abs(bb.x - p.x) <= bb.width) | |||
if(p.x > bb.x && p.x < bb.x + bb.width || p.x + p.width < bb.x + bb.width && p.x + p.width > bb.x) | |||
if(p.y > bb.y && p.y < bb.y + bb.height || | |||
p.y + p.height < bb.y + bb.height && | |||
p.y + p.height > bb.y) | |||
{ | |||
if(p.y > bb.y && p.y < bb.y + bb.height || p.y + p.height < bb.y + bb.height && p.y + p.height > bb.y) | |||
{ | |||
alive = false; | |||
bb = -1; | |||
} | |||
alive = false; | |||
bb = -1; | |||
} | |||
} | |||
} | |||
if(this.x < 0) | |||
{ | |||
this.x += this.speed; | |||
} | |||
else if(this.x > width) | |||
{ | |||
this.x -= this.speed; | |||
} | |||
} | |||
if(this.x < 0) | |||
this.x += this.speed; | |||
else if(this.x > width) | |||
this.x -= this.speed; | |||
} | |||
//player object | |||
var p = new Player(350, 850); | |||
//object that falls from the sky | |||
var Bamboo = function() | |||
} | |||
//player object | |||
var p = new Player(350, 850); | |||
//object that falls from the sky | |||
var Bamboo = function() | |||
{ | |||
this.width = 25; | |||
this.height = 75; | |||
this.x = getRandomIntInclusive(0, width); | |||
this.y = -this.height; | |||
this.speed = 4; | |||
this.render = function() | |||
{ | |||
this.width = 25; | |||
this.height = 75; | |||
this.x = getRandomIntInclusive(0, width); | |||
this.y = -this.height; | |||
this.speed = 4; | |||
this.render = function() | |||
{ | |||
context.fillStyle = "rgba(0, 255, 0 , 1)"; //green | |||
context.fillRect(this.x, this.y, this.width, this.height); | |||
} | |||
this.move = function() | |||
{ | |||
this.y += this.speed; | |||
if(this.y> height) | |||
{ | |||
//remove bamboo from array | |||
score++; | |||
return true; | |||
} | |||
} | |||
context.fillStyle = "rgba(0, 255, 0 , 1)"; //green | |||
context.fillRect(this.x, this.y, this.width, this.height); | |||
} | |||
var bamboos = []; | |||
//draws all the objects | |||
var render = function() | |||
this.move = function() | |||
{ | |||
context.fillStyle = "rgba(0, 0,0 ,1)"; | |||
context.fillRect(0,0, width, height); | |||
context.fillStyle = "rgba(255, 255,255 ,1)"; | |||
context.font = "20px Georgia"; | |||
context.fillText("Score: " + score, 10, 25); | |||
p.render(); | |||
for(i= 0; i < bamboos.length; i++) | |||
this.y += this.speed; | |||
if(this.y> height) | |||
{ | |||
if(bamboos[i] != -1) | |||
{ | |||
bamboos[i].render(); | |||
} | |||
//remove bamboo from array | |||
score++; | |||
return true; | |||
} | |||
//console.log('render was called'); | |||
//context.fillStyle = "rgba(0, 128, 0 ,1)"; //green | |||
//context.fillRect(0, 0, 700, 700); | |||
//console.log(context); | |||
} | |||
var update = function() | |||
} | |||
var bamboos = []; | |||
//draws all the objects | |||
var render = function() | |||
{ | |||
context.fillStyle = "rgba(0, 0,0 ,1)"; | |||
context.fillRect(0,0, width, height); | |||
context.fillStyle = "rgba(255, 255,255 ,1)"; | |||
context.font = "20px Georgia"; | |||
context.fillText("Score: " + score, 10, 25); | |||
p.render(); | |||
for(i= 0; i < bamboos.length; i++) | |||
if(bamboos[i] != -1) | |||
bamboos[i].render(); | |||
} | |||
var update = function() | |||
{ | |||
addBamboo(); | |||
p.move(); | |||
for (i = 0; i< bamboos.length; i++) | |||
if(bamboos[i] != -1) | |||
if(bamboos[i].move()) | |||
bamboos[i] = -1; | |||
addBamboo(); | |||
} | |||
var count = 0; | |||
var limit = 25; | |||
var addBamboo = function() | |||
{ | |||
count++; | |||
if(count == limit) | |||
{ | |||
addBamboo(); | |||
p.move(); | |||
for (i = 0; i< bamboos.length; i++) | |||
count = 0; | |||
var bnew = true; | |||
for(i = 0; i < bamboos.length; i++) | |||
{ | |||
if(bamboos[i] != -1) | |||
if(bamboos[i] == -1) | |||
{ | |||
if(bamboos[i].move()) | |||
{ | |||
bamboos[i] = -1; | |||
} | |||
bamboos[i] = new Bamboo(); | |||
bnew = false; | |||
} | |||
} | |||
addBamboo(); | |||
if(bnew) | |||
bamboos.push(new Bamboo()); | |||
if(limit > 10) | |||
limit --; | |||
} | |||
var count = 0; | |||
var limit = 25; | |||
var addBamboo = function() | |||
} | |||
var sent; | |||
var tic = function() | |||
{ | |||
if(alive) | |||
{ | |||
count++; | |||
if(count == limit) | |||
{ | |||
count = 0; | |||
var bnew = true; | |||
for(i = 0; i < bamboos.length; i++) | |||
{ | |||
if(bamboos[i] == -1) | |||
{ | |||
bamboos[i] = new Bamboo(); | |||
bnew = false; | |||
} | |||
} | |||
if(bnew) | |||
{ | |||
bamboos.push(new Bamboo()); | |||
} | |||
if(limit > 10) | |||
{ | |||
limit --; | |||
} | |||
} | |||
update(); | |||
render(); | |||
} | |||
var sent; | |||
var tic = function() | |||
else | |||
{ | |||
//console.log('tic was called'); | |||
if(alive) | |||
{ | |||
update(); | |||
render(); | |||
} | |||
else | |||
if(!sent) | |||
{ | |||
if(!sent) | |||
{ | |||
context.fillStyle = "rgba(0, 0,0 ,1)"; | |||
context.fillRect(0,0, width, height); | |||
context.fillStyle = "rgba(0, 0,0 ,1)"; | |||
context.fillRect(0,0, width, height); | |||
context.fillStyle = "rgba(255, 255,255 ,1)"; | |||
context.font = "20px Georgia"; | |||
context.fillText("You died with a score of: " + score, 250, 325); | |||
context.fillStyle = "rgba(255, 255,255 ,1)"; | |||
context.font = "20px Georgia"; | |||
context.fillText("You died with a score of: " + | |||
score, 250, 325); | |||
document.body.innerHTML += '<form id="dynForm" action="insertScore.php" method="post"><input type="hidden" name="game_new_score" value=true><input type="hidden" name="game" value=1><input type="hidden" name="user_id_score" value=<?php echo $_SESSION['user_id']; ?>><input type="hidden" name="score_validate" value=' + score + '></form>'; | |||
document.getElementById("dynForm").submit(); | |||
sent = true; | |||
} | |||
document.body.innerHTML += '<form id="dynForm" ' + | |||
'action="insertScore.php" method="post"><input ' + | |||
'type="hidden" name="game_new_score" value=true>' + | |||
'<input type="hidden" name="game" value=1><input ' + | |||
'type="hidden" name="user_id_score" ' + | |||
'value=<?php echo $_SESSION['user_id']; ?>><input ' + | |||
'type="hidden" name="score_validate" value=' + score + '></form>'; | |||
document.getElementById("dynForm").submit(); | |||
sent = true; | |||
} | |||
animate(tic); | |||
} | |||
window.addEventListener("keydown", function (event) | |||
{ | |||
if(event.keyCode >=37 && event.keyCode <=40) | |||
{ | |||
p.facing = event.keyCode; | |||
} | |||
keysDown[event.keyCode] = true; | |||
}); | |||
window.addEventListener("keyup", function (event) | |||
{ | |||
delete keysDown[event.keyCode]; | |||
}); | |||
//tic(); | |||
animate(tic); | |||
} | |||
window.addEventListener("keydown", function (event) | |||
{ | |||
if(event.keyCode >=37 && event.keyCode <=40) | |||
p.facing = event.keyCode; | |||
keysDown[event.keyCode] = true; | |||
}); | |||
window.addEventListener("keyup", function (event) | |||
{ | |||
delete keysDown[event.keyCode]; | |||
}); | |||
//tic(); | |||
animate(tic); | |||
} | |||
</script> | |||
<div><canvas id="canvasBF" width="700" height="700"></canvas></div> | |||
<div><input type="submit" name="play" value="Play Game" onclick="this.blur();playBF()"/></div> | |||
<div><input type="submit" name="play" value="Play Game" onclick="this.blur(); | |||
playBF()"/></div> |
@ -1,38 +1,35 @@ | |||
<?php | |||
$dir = 2; | |||
//used for high score | |||
$game_id = 1; | |||
$dir = 2; | |||
//ini_set('display_errors', 1); | |||
include '../includes/header.php'; | |||
//used for high score | |||
$game_id = 1; | |||
echo '<div class="w3-row w3-padding-32">'; | |||
echo '<div class="w3-half w3-container">'; | |||
include('bamboofield.html'); | |||
//ini_set('display_errors', 1); | |||
include '../includes/header.php'; | |||
echo '<div class="w3-row w3-padding-32">'; | |||
echo '<div class="w3-half w3-container">'; | |||
include('bamboofield.html'); | |||
echo '</div><div class="w3-half w3-container">'; | |||
//include('../includes/profile.php'); | |||
include('highscore.php'); | |||
echo '</div></div>'; | |||
echo '<div class="w3-row w3-padding-32">'; | |||
echo '<div class="w3-half w3-container">'; | |||
echo '</div><div class="w3-half w3-container">'; | |||
//include('../includes/profile.php'); | |||
include('highscore.php'); | |||
//edit user | |||
include('../user/profile.php'); | |||
echo '</div></div>'; | |||
echo '</div><div class="w3-half w3-container">'; | |||
include('userscores.php'); | |||
echo '</div></div>'; | |||
echo '<div class="w3-row w3-padding-32">'; | |||
echo '<div class="w3-half w3-container">'; | |||
//edit user | |||
include('../user/profile.php'); | |||
include '../includes/footer.php'; | |||
?> | |||
echo '</div><div class="w3-half w3-container">'; | |||
include('userscores.php'); | |||
echo '</div></div>'; | |||
include '../includes/footer.php'; |
@ -1,44 +1,41 @@ | |||
<?php | |||
//5-17-17 | |||
echo '<h1 class="w3-text-teal"><center>High Scores</center></h1>'; | |||
$q = "select * from scores where game = '$game_id' order by score desc limit 20"; | |||
$r = mysqli_query($dbc, $q); | |||
echo '<div class="w3-responsive w3-card-4"><table class="w3-table w3-striped w3-bordered"><thead>'; | |||
echo '<tr class="w3-theme"> | |||
<td>Rank</td> | |||
<td>User Name</td> | |||
<td>Score</td> | |||
</tr></thead><tbody>'; | |||
$rank = 0; | |||
while($row = mysqli_fetch_array($r)) | |||
{ | |||
$rank ++; | |||
echo '<tr>'; | |||
echo '<td>' . $rank . '</td>'; | |||
echo '<td>'; | |||
$q2 = "select user_name from users where user_id='". $row['user_id'] . "' limit 1"; | |||
$r2 = mysqli_query($dbc, $q2); | |||
while($row2 = mysqli_fetch_array($r2)) | |||
{ | |||
echo $row2['user_name']; | |||
} | |||
echo '</td>'; | |||
//score | |||
echo '<td>' . $row['score'] . '</td>'; | |||
echo '</tr>'; | |||
} | |||
echo '</tbody></table></div>'; | |||
?> | |||
//5-17-17 | |||
echo '<h1 class="w3-text-teal"><center>High Scores</center></h1>'; | |||
$q = "select * from scores where game = '$game_id' order by score desc limit 20"; | |||
$r = mysqli_query($dbc, $q); | |||
echo '<div class="w3-responsive w3-card-4"><table class="w3-table w3-striped | |||
w3-bordered"><thead>'; | |||
echo '<tr class="w3-theme"> | |||
<td>Rank</td> | |||
<td>User Name</td> | |||
<td>Score</td> | |||
</tr></thead><tbody>'; | |||
$rank = 0; | |||
while($row = mysqli_fetch_array($r)) | |||
{ | |||
$rank ++; | |||
echo '<tr>'; | |||
echo '<td>' . $rank . '</td>'; | |||
echo '<td>'; | |||
$q2 = "select user_name from users where user_id='". $row['user_id'] . | |||
"' limit 1"; | |||
$r2 = mysqli_query($dbc, $q2); | |||
while($row2 = mysqli_fetch_array($r2)) | |||
echo $row2['user_name']; | |||
echo '</td>'; | |||
//score | |||
echo '<td>' . $row['score'] . '</td>'; | |||
echo '</tr>'; | |||
} | |||
echo '</tbody></table></div>'; |
@ -1,42 +1,26 @@ | |||
<?php | |||
//5-16-17 | |||
include_once '../../club_connect.php'; | |||
if(isset($_POST['game_new_score'])) | |||
{ | |||
$i_game = mysqli_real_escape_string($dbc, trim($_POST['game'])); | |||
$i_user_id = mysqli_real_escape_string($dbc, trim($_POST['user_id_score'])); | |||
$i_score = mysqli_real_escape_string($dbc, trim($_POST['score_validate'])); | |||
// | |||
// foreach ($_POST as $key => $value) | |||
// { | |||
// echo $value . '<br>'; | |||
// } | |||
$q = "insert into scores(game, user_id, score) values('$i_game','$i_user_id','$i_score')"; | |||
if($i_user_id > 0) | |||
{ | |||
$r = mysqli_query($dbc, $q); | |||
} | |||
// | |||
// | |||
// echo '<h1>' . $q . '</h1>'; | |||
if($i_game == 1) | |||
{ | |||
header("Location: bamboofield.php"); | |||
} | |||
else if($i_game == 2) | |||
{ | |||
header("Location: zombiePanda.php"); | |||
} | |||
} | |||
//5-16-17 | |||
?> | |||
include_once '../../club_connect.php'; | |||
if(isset($_POST['game_new_score'])) | |||
{ | |||
$i_game = mysqli_real_escape_string($dbc, | |||
trim($_POST['game'])); | |||
$i_user_id = mysqli_real_escape_string($dbc, | |||
trim($_POST['user_id_score'])); | |||
$i_score = mysqli_real_escape_string($dbc, | |||
trim($_POST['score_validate'])); | |||
$q = "insert into scores(game, user_id, score) | |||
values('$i_game','$i_user_id','$i_score')"; | |||
if($i_user_id > 0) | |||
$r = mysqli_query($dbc, $q); | |||
if($i_game == 1) | |||
header("Location: bamboofield.php"); | |||
else if($i_game == 2) | |||
header("Location: zombiePanda.php"); | |||
} |
@ -1,44 +1,37 @@ | |||
<?php | |||
//5-17-17 | |||
if($loggedIn) | |||
{ | |||
echo '<h1 class="w3-text-teal"><center>User\'s Personal Records</center></h1>'; | |||
$q = "select * from scores where user_id='" . $_SESSION['user_id'] . "' and game='$game_id' order by score desc limit 20"; | |||
$r = mysqli_query($dbc, $q); | |||
echo '<div class="w3-responsive w3-card-4"><table class="w3-table w3-striped w3-bordered"><thead>'; | |||
echo '<tr class="w3-theme"> | |||
<td>User Name</td> | |||
<td>Score</td> | |||
</tr></thead><tbody>'; | |||
//5-17-17 | |||
while($row = mysqli_fetch_array($r)) | |||
{ | |||
echo '<tr>'; | |||
if($loggedIn) | |||
{ | |||
echo '<h1 class="w3-text-teal"><center>User\'s Personal Records | |||
</center></h1>'; | |||
$q = "select * from scores where user_id='" . $_SESSION['user_id'] | |||
. "' and game='$game_id' order by score desc limit 20"; | |||
$r = mysqli_query($dbc, $q); | |||
echo '<div class="w3-responsive w3-card-4"><table | |||
class="w3-table w3-striped w3-bordered"><thead>'; | |||
echo '<tr class="w3-theme"> | |||
<td>User Name</td> | |||
<td>Score</td> | |||
</tr></thead><tbody>'; | |||
echo '<td>'; | |||
$q2 = "select user_name from users where user_id='". $row['user_id'] . "' limit 1"; | |||
$r2 = mysqli_query($dbc, $q2); | |||
while($row = mysqli_fetch_array($r)) | |||
{ | |||
echo '<tr><td>'; | |||
while($row2 = mysqli_fetch_array($r2)) | |||
{ | |||
echo $row2['user_name']; | |||
} | |||
$q2 = "select user_name from users where user_id='" | |||
. $row['user_id'] . "' limit 1"; | |||
$r2 = mysqli_query($dbc, $q2); | |||
echo '</td>'; | |||
while($row2 = mysqli_fetch_array($r2)) | |||
echo $row2['user_name']; | |||
//score | |||
echo '<td>' . $row['score'] . '</td>'; | |||
echo '</td>'; | |||
echo '</tr>'; | |||
} | |||
echo '</tbody></table></div>'; | |||
//score | |||
echo '<td>' . $row['score'] . '</td></tr>'; | |||
} | |||
?> | |||
echo '</tbody></table></div>'; | |||
} |
@ -1,396 +1,391 @@ | |||
<script> | |||
window.addEventListener("keydown", function(e) | |||
window.addEventListener("keydown", function(e) | |||
{ | |||
// space and arrow keys | |||
if([32, 37, 38, 39, 40].indexOf(e.keyCode) > -1) | |||
{ | |||
// space and arrow keys | |||
if([32, 37, 38, 39, 40].indexOf(e.keyCode) > -1) | |||
{ | |||
e.preventDefault(); | |||
} | |||
}, false); | |||
window.onload = function() | |||
e.preventDefault(); | |||
} | |||
}, false); | |||
window.onload = function() | |||
{ | |||
var canvas = document.getElementById("canvasZP"); | |||
var c = canvas.getContext('2d'); | |||
c.fillStyle= "black"; | |||
c.fillRect(0,0,canvas.width,canvas.height); | |||
}; | |||
function playZP() | |||
{ | |||
var animate = window.requestAnimationFrame || | |||
window.webkitRequestAnimationFrame || | |||
window.mozRequestAnimationFrame || function (callback) | |||
{ | |||
var canvas = document.getElementById("canvasZP"); | |||
var c = canvas.getContext('2d'); | |||
c.fillStyle= "black"; | |||
c.fillRect(0,0,canvas.width,canvas.height); | |||
window.setTimeout(callback, 1000 / 60) | |||
}; | |||
function playZP() | |||
var canvas = document.getElementById("canvasZP"); | |||
var width = 700; | |||
var height = 700; | |||
canvas.style.textAlign = 'center'; | |||
var context = canvas.getContext('2d'); | |||
var keysDown = {}; | |||
var score = 0; | |||
var dead = false; | |||
//player | |||
var Player = function(x,y) | |||
{ | |||
this.x = x; | |||
this.y = y; | |||
this.width = 25; | |||
this.height = 25; | |||
var animate = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || function (callback) | |||
{ | |||
window.setTimeout(callback, 1000 / 60) | |||
}; | |||
var canvas = document.getElementById("canvasZP"); | |||
var width = 700; | |||
var height = 700; | |||
canvas.style.textAlign = 'center'; | |||
var context = canvas.getContext('2d'); | |||
var keysDown = {}; | |||
var score = 0; | |||
var dead = false; | |||
//player | |||
var Player = function(x,y) | |||
{ | |||
this.x = x; | |||
this.y = y; | |||
this.width = 25; | |||
this.height = 25; | |||
this.speed = 3; | |||
this.facing = 40; | |||
this.speed = 3; | |||
this.updateDirection = function(key) | |||
{ | |||
facing = key; | |||
} | |||
this.render = function() | |||
{ | |||
context.fillStyle = "rgba(0, 45, 160, 1)"; //green | |||
context.fillRect(this.x, this.y, this.width,this.height); | |||
} | |||
this.move = function() | |||
{ | |||
for (var key in keysDown) | |||
{ | |||
var value = Number(key); | |||
if (value == 37) //left | |||
{ | |||
this.x = this.x - this.speed; | |||
} | |||
else if (value == 39) //right | |||
{ | |||
this.x = this.x + this.speed | |||
} | |||
else if(value == 38) //up | |||
{ | |||
this.y = this.y - this.speed | |||
} | |||
else if(value == 40) //down | |||
{ | |||
this.y = this.y + this.speed | |||
} | |||
else if(value == 32) | |||
{ | |||
var added = false; | |||
for(i = 0; i< bullets.length; i++) | |||
{ | |||
if(bullets[i] == -1) | |||
{ | |||
bullets[i] = new Bullet(); | |||
added = true; | |||
break; | |||
} | |||
} | |||
if(added == false) | |||
{ | |||
bullets.push(new Bullet()); | |||
} | |||
} | |||
} | |||
} | |||
this.facing = 40; | |||
this.updateDirection = function(key) | |||
{ | |||
facing = key; | |||
} | |||
var p = new Player(350, 350); | |||
//bullet | |||
var Bullet = function() | |||
this.render = function() | |||
{ | |||
this.x = p.x; | |||
this.y = p.y; | |||
this.width = 10; | |||
this.height = 10; | |||
this.speed = 4; | |||
this.facing = p.facing; | |||
context.fillStyle = "rgba(0, 45, 160, 1)"; //green | |||
context.fillRect(this.x, this.y, this.width,this.height); | |||
} | |||
this.move = function() | |||
this.move = function() | |||
{ | |||
for (var key in keysDown) | |||
{ | |||
if (this.facing == 37) //left | |||
var value = Number(key); | |||
if (value == 37) //left | |||
{ | |||
this.x = this.x - this.speed; | |||
} | |||
else if (this.facing == 39) //right | |||
} | |||
else if (value == 39) //right | |||
{ | |||
this.x = this.x + this.speed | |||
} | |||
else if(this.facing == 38) //up | |||
else if(value == 38) //up | |||
{ | |||
this.y = this.y - this.speed | |||
} | |||
else if(this.facing == 40) //down | |||
else if(value == 40) //down | |||
{ | |||
this.y = this.y + this.speed | |||
} | |||
else if(value == 32) | |||
{ | |||
var added = false; | |||
} | |||
for(i = 0; i< bullets.length; i++) | |||
{ | |||
if(bullets[i] == -1) | |||
{ | |||
bullets[i] = new Bullet(); | |||
added = true; | |||
break; | |||
} | |||
} | |||
if(added == false) | |||
bullets.push(new Bullet()); | |||
this.render = function() | |||
{ | |||
context.fillStyle = "rgba(255, 0, 199, 1)"; //green | |||
context.fillRect(this.x, this.y, this.width,this.height); | |||
} | |||
} | |||
} | |||
var bullets = []; | |||
} | |||
var p = new Player(350, 350); | |||
function getRandomIntInclusive(min, max) { | |||
min = Math.ceil(min); | |||
max = Math.floor(max); | |||
return Math.floor(Math.random() * (max - min + 1)) + min; | |||
} | |||
//bullet | |||
var Bullet = function() | |||
{ | |||
this.x = p.x; | |||
this.y = p.y; | |||
this.width = 10; | |||
this.height = 10; | |||
this.speed = 4; | |||
this.facing = p.facing; | |||
//zombie | |||
var Zombie = function(x,y) | |||
this.move = function() | |||
{ | |||
this.x = x; | |||
this.y = y; | |||
this.width = 25; | |||
this.height = 25; | |||
this.speed = 3; | |||
var side = getRandomIntInclusive(0,3); | |||
var mid = getRandomIntInclusive(0,700); | |||
if(side === 1) | |||
{ | |||
this.x = mid; | |||
this.y = 0; | |||
} | |||
else if(side === 2) | |||
{ | |||
this.x = 700; | |||
this.y = mid; | |||
} | |||
else if(side === 3) | |||
{ | |||
this.y = 700; | |||
this.x = mid; | |||
} | |||
else | |||
{ | |||
this.x = 0; | |||
this.y = mid; | |||
} | |||
if (this.facing == 37) //left | |||
this.x = this.x - this.speed; | |||
else if (this.facing == 39) //right | |||
this.x = this.x + this.speed | |||
else if(this.facing == 38) //up | |||
this.y = this.y - this.speed | |||
else if(this.facing == 40) //down | |||
this.y = this.y + this.speed | |||
} | |||
this.render = function() | |||
{ | |||
context.fillStyle = "rgba(0, 160, 0, 1)"; //green | |||
context.fillRect(this.x, this.y, this.width,this.height); | |||
} | |||
this.render = function() | |||
{ | |||
context.fillStyle = "rgba(255, 0, 199, 1)"; //green | |||
context.fillRect(this.x, this.y, this.width,this.height); | |||
this.move = function() | |||
{ | |||
if(this.x > p.x + this.speed) | |||
this.x -= this.speed; | |||
else if(this.x + this.speed < p.x ) | |||
this.x += this.speed; | |||
} | |||
} | |||
var bullets = []; | |||
function getRandomIntInclusive(min, max) { | |||
min = Math.ceil(min); | |||
max = Math.floor(max); | |||
return Math.floor(Math.random() * (max - min + 1)) + min; | |||
} | |||
if(this.y > p.y + this.speed) | |||
this.y -= this.speed; | |||
else if(this.y + this.speed < p.y ) | |||
this.y += this.speed; | |||
} | |||
//zombie | |||
var Zombie = function(x,y) | |||
{ | |||
this.x = x; | |||
this.y = y; | |||
this.width = 25; | |||
this.height = 25; | |||
this.speed = 3; | |||
var side = getRandomIntInclusive(0,3); | |||
var mid = getRandomIntInclusive(0,700); | |||
if(side === 1) | |||
{ | |||
this.x = mid; | |||
this.y = 0; | |||
} | |||
else if(side === 2) | |||
{ | |||
this.x = 700; | |||
this.y = mid; | |||
} | |||
else if(side === 3) | |||
{ | |||
this.y = 700; | |||
this.x = mid; | |||
} | |||
else | |||
{ | |||
this.x = 0; | |||
this.y = mid; | |||
} | |||
var zombies = []; | |||
zombies.push(new Zombie()); | |||
this.render = function() | |||
{ | |||
context.fillStyle = "rgba(0, 160, 0, 1)"; //green | |||
context.fillRect(this.x, this.y, this.width,this.height); | |||
} | |||
var render = function() | |||
this.move = function() | |||
{ | |||
context.fillStyle = "#000000"; | |||
context.fillRect(0, 0, width, height); | |||
if(this.x > p.x + this.speed) | |||
this.x -= this.speed; | |||
else if(this.x + this.speed < p.x ) | |||
this.x += this.speed; | |||
context.fillStyle = "rgba(255, 255, 255, 1)"; | |||
context.font= "20px Georgia"; | |||
context.fillText("Score: " + score,10,25); | |||
for(i = 0; i< zombies.length; i++) | |||
{ | |||
if(zombies[i] != -1) | |||
{ | |||
zombies[i].render(); | |||
} | |||
if(this.y > p.y + this.speed) | |||
this.y -= this.speed; | |||
else if(this.y + this.speed < p.y ) | |||
this.y += this.speed; | |||
} | |||
} | |||
var zombies = []; | |||
zombies.push(new Zombie()); | |||
} | |||
for(i = 0; i< bullets.length; i++) | |||
var render = function() | |||
{ | |||
context.fillStyle = "#000000"; | |||
context.fillRect(0, 0, width, height); | |||
context.fillStyle = "rgba(255, 255, 255, 1)"; | |||
context.font= "20px Georgia"; | |||
context.fillText("Score: " + score,10,25); | |||
for(i = 0; i< zombies.length; i++) | |||
{ | |||
if(zombies[i] != -1) | |||
{ | |||
if(bullets[i] != -1) | |||
{ | |||
bullets[i].render(); | |||
} | |||
zombies[i].render(); | |||
} | |||
} | |||
for(i = 0; i< bullets.length; i++) | |||
{ | |||
if(bullets[i] != -1) | |||
{ | |||
bullets[i].render(); | |||
} | |||
p.render(); | |||
} | |||
var update = function() | |||
p.render(); | |||
} | |||
var update = function() | |||
{ | |||
addZombie(); | |||
p.move(); | |||
for(i = 0; i< zombies.length; i++) | |||
{ | |||
addZombie(); | |||
p.move(); | |||
for(i = 0; i< zombies.length; i++) | |||
for(z = 0;z < bullets.length; z++) | |||
{ | |||
for(z = 0;z < bullets.length; z++) | |||
if(zombies[i] != -1 && bullets[z] != -1) | |||
{ | |||
if(zombies[i] != -1 && bullets[z] != -1) | |||
if(Math.abs(zombies[i].x - bullets[z].x) < 25 && | |||
Math.abs(zombies[i].y - bullets[z].y) < 25) | |||
{ | |||
if(Math.abs(zombies[i].x - bullets[z].x) < 25 && Math.abs(zombies[i].y - bullets[z].y) < 25) | |||
{ | |||
score++; | |||
zombies[i] = -1; | |||
bullets[z] = -1; | |||
} | |||
score++; | |||
zombies[i] = -1; | |||
bullets[z] = -1; | |||
} | |||
} | |||
if(zombies[i] != -1) | |||
{ | |||
zombies[i].move(); | |||
} | |||
} | |||
for(i = 0; i< bullets.length; i++) | |||
if(zombies[i] != -1) | |||
{ | |||
//checks to see if goes out of bounds | |||
if(bullets[i].x < 0 || bullets[i].y < 0 || bullets[i].x > 700 || bullets[i].y > 700) | |||
{ | |||
bullets[i] = -1; | |||
} | |||
zombies[i].move(); | |||
} | |||
if(bullets[i] != -1) | |||
{ | |||
} | |||
for(i = 0; i< bullets.length; i++) | |||
{ | |||
//checks to see if goes out of bounds | |||
if(bullets[i].x < 0 || bullets[i].y < 0 || | |||
bullets[i].x > 700 || bullets[i].y > 700) | |||
{ | |||
bullets[i] = -1; | |||
} | |||
bullets[i].move(); | |||
} | |||
if(bullets[i] != -1) | |||
{ | |||
bullets[i].move(); | |||
} | |||
for(i=0; i<zombies.length; i++) | |||
} | |||
for(i=0; i<zombies.length; i++) | |||
{ | |||
if(zombies[i] != -1 && | |||
Math.abs(p.x - zombies[i].x) < 25 && | |||
Math.abs(p.y - zombies[i].y) < 25) | |||
{ | |||
if(zombies[i] != -1 && Math.abs(p.x - zombies[i].x) < 25 && Math.abs(p.y - zombies[i].y) < 25) | |||
{ | |||
dead = true; | |||
} | |||
dead = true; | |||
} | |||
} | |||
var counter2 = 0; | |||
var counter = 0; | |||
var rate = 180; | |||
var addZombie = function() | |||
} | |||
var counter2 = 0; | |||
var counter = 0; | |||
var rate = 180; | |||
var addZombie = function() | |||
{ | |||
counter2++; | |||
counter++; | |||
var added = false; | |||
if(counter >= rate) | |||
{ | |||
counter2++; | |||
counter++; | |||
var added = false; | |||
if(counter >= rate) | |||
for(i = 0; i< zombies.length; i++) | |||
{ | |||
for(i = 0; i< zombies.length; i++) | |||
if(zombies[i] == -1) | |||
{ | |||
if(zombies[i] == -1) | |||
{ | |||
zombies[i] = new Zombie(); | |||
added = true; | |||
break; | |||
} | |||
zombies[i] = new Zombie(); | |||
added = true; | |||
break; | |||
} | |||
if(added == false) | |||
{ | |||
zombies.push(new Zombie()); | |||
} | |||
} | |||
counter = 0; | |||
if(added == false) | |||
{ | |||
zombies.push(new Zombie()); | |||
} | |||
if(counter2 >= 60) | |||
counter = 0; | |||
} | |||
if(counter2 >= 60) | |||
{ | |||
if(rate > 30) | |||
{ | |||
if(rate > 30) | |||
{ | |||
rate = rate -5; | |||
} | |||
counter2 = 0; | |||
rate = rate -5; | |||
} | |||
counter2 = 0; | |||
} | |||
} | |||
var sent = false; | |||
var sent = false; | |||
var tic = function() | |||
var tic = function() | |||
{ | |||
if(dead) | |||
{ | |||
if(dead) | |||
{ | |||
context.fillStyle = "#000000"; | |||
context.fillRect(0, 0, width, height); | |||
context.fillStyle = "#000000"; | |||
context.fillRect(0, 0, width, height); | |||
context.fillStyle = "rgba(255, 255, 255, 1)"; //green | |||
context.font= "20px Georgia"; | |||
context.fillText("You died with a score of " + score,200,340); | |||
if(!sent) | |||
{ | |||
document.body.innerHTML += '<form id="dynForm" action="insertScore.php" method="post"><input type="hidden" name="game_new_score" value=true><input type="hidden" name="game" value=2><input type="hidden" name="user_id_score" value=<?php echo $_SESSION['user_id']; ?>><input type="hidden" name="score_validate" value=' + score + '></form>'; | |||
document.getElementById("dynForm").submit(); | |||