forked from domgetter/battle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
55 lines (50 loc) · 1.67 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<!DOCTYPE html>
<head>
<title>Battle Sequence</title>
</head>
<body>
<canvas id="main"></canvas>
<div style="display:none;">
<img id="battle_cursor" src="./battle_cursor.png" width="5" height="7" />
</div>
<script>
var graphicsContext = document.getElementById("main").getContext("2d");
graphicsContext.font = "24px Consolas";
var battle_cursor = {
"image":document.getElementById("battle_cursor"),
"x":0,
"y":8,
"move_left": function(){this.x = 0;},
"move_right": function(){this.x = 100;},
"move_up": function(){this.y = 8;},
"move_down": function(){this.y = 40;}
};
function renderLoop() {
graphicsContext.clearRect(0,0,300,150);
graphicsContext.drawImage(battle_cursor.image, battle_cursor.x, battle_cursor.y);
graphicsContext.fillText("ATTACK", 10, 20);
graphicsContext.fillText("POKEMON", 110, 20);
graphicsContext.fillText("BAG", 10, 51);
graphicsContext.fillText("IGNORE", 110, 51);
window.requestAnimationFrame(renderLoop);
}
window.onload = (function() {
window.requestAnimationFrame(renderLoop);
});
window.onkeydown = function(event) {
if(event.keyCode === 37){
battle_cursor.move_left();
}else if(event.keyCode === 38){
battle_cursor.move_up();
}else if(event.keyCode === 39){
battle_cursor.move_right();
}else if(event.keyCode === 40){
battle_cursor.move_down();
}
if(event.keyCode === 13){
alert("Feature not supported");
}
}
</script>
</body>
</html>