Skip to content

Commit 889d0f3

Browse files
committed
Initial commit.
Achieved a basic animation of moving a square back and forth across a canvas.
0 parents  commit 889d0f3

File tree

6 files changed

+112
-0
lines changed

6 files changed

+112
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.idea/

backlog.txt

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
animate a player across the map.
3+
adjust framerate/movement speeds.
4+
use cursor keys to move the player.

game.css

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
canvas
2+
{
3+
border: 1px solid black;
4+
}

gameideas.txt

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Zombie game
2+
3+
player has to move from start position to end position without touching a zombie to win.
4+
5+
player can move in all eight directions.
6+
7+
zombies move slower than the player.
8+
zombies either (in order of priority):
9+
- towards the player
10+
- towards other zombies
11+
- move in random patterns
12+
13+
zombies have line of sight in a cone shape in front of them.
14+
zombies have short range hearing all round.
15+
hearing detects movement by the player or other zombies.

index.htm.html

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
2+
"http://www.w3.org/TR/html4/loose.dtd">
3+
<html>
4+
<head>
5+
<script language="javascript" src="main.js"></script>
6+
<link rel="stylesheet" href="game.css" text="text/css">
7+
<title></title>
8+
</head>
9+
<body>
10+
<button id="start" onclick="startGame()">Start Game</button>
11+
<br>
12+
<button id="pause" onclick="pauseGame()">Pause Game</button>
13+
<br>
14+
<button id="end" onclick="endGame()">End Game</button>
15+
<br>
16+
Player speed = <input id="playerSpeed" value="1">
17+
<br>
18+
FPS = <input id="fps" value="1">
19+
<br>
20+
<canvas id="gamefield" width="400" height="300"></canvas>
21+
</body>
22+
</html>

main.js

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/**
2+
* Created with JetBrains WebStorm.
3+
* User: Chris
4+
* Date: 22/07/12
5+
* Time: 02:06
6+
* To change this template use File | Settings | File Templates.
7+
*/
8+
9+
var player = {
10+
x: 20,
11+
y: 150,
12+
w: 20,
13+
h: 20,
14+
d: "e"
15+
}
16+
17+
var timer;
18+
19+
function startGame()
20+
{
21+
timer = setInterval("redrawGameField()", 33);
22+
}
23+
24+
function pauseGame()
25+
{
26+
clearInterval(timer);
27+
}
28+
29+
function endGame()
30+
{
31+
clearInterval(timer);
32+
}
33+
34+
function redrawGameField()
35+
{
36+
var gf = document.getElementById("gamefield");
37+
var ctx = gf.getContext("2d");
38+
ctx.clearRect(0, 0, gf.width, gf.height);
39+
40+
ctx.fillStyle = "rgba(255, 0, 0)";
41+
var playerSpeed = document.getElementById("playerSpeed");
42+
43+
// Handle player direction
44+
if (player.x >= gf.width - player.w)
45+
{
46+
player.d = "w";
47+
}
48+
else if (player.x < 0)
49+
{
50+
player.d = "e";
51+
}
52+
53+
// Increment x coordinate based on direction and speed.
54+
switch(player.d)
55+
{
56+
case "e":
57+
player.x += parseInt(playerSpeed.value);
58+
break;
59+
case "w":
60+
player.x -= parseInt(playerSpeed.value);
61+
break;
62+
}
63+
64+
// Render the player.
65+
ctx.fillRect(player.x, player.y, player.w, player.h);
66+
}

0 commit comments

Comments
 (0)