-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimplegame.html
118 lines (114 loc) · 3.74 KB
/
simplegame.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<title>Simple Game</title>
<script type="text/javascript" src="game.js"></script>
<script type="text/javascript">
var screenTimer, playerTimer, panel, player, bricks, boxes;
var brickCount = 0,monsterCount=0;
function main(){
var c = document.getElementById("panel");
panel = c.getContext("2d");
player = new Player(100,HEIGHT,"Kirito");
bricks = new Array();
boxes = new Array();
monsters = new Array();
bricks[brickCount++] = new Brick(0,FLOOR_HEIGHT,MAP_WIDTH,FLOOR_HEIGHT);
game1();
screenTimer = setInterval("updateScreen(panel,player,bricks,boxes,monsters);",30);
playerTimer = setInterval("Motions(player, monsters);",40);
}
function keyDownActions(e) {
if (e.keyCode==37){
//left
backwarding = true;
return false;
}
else if (e.keyCode==39){
//right
forwarding = true;
return false;
}
else if(e.keyCode==38){
if(!player.inAir)
upwarding = true;
return false;
}
}
function keyUpActions(e) {
if (e.keyCode==37){
//left
backwarding = false;
return false;
}
else if (e.keyCode==39){
//right
forwarding = false;
return false;
}
}
document.onkeydown=keyDownActions;
document.onkeyup=keyUpActions;
function addObject(){
var TYPE = document.getElementById('addType').value;
var x = parseInt(document.getElementById('x').value);
var y = parseInt(document.getElementById('y').value);
var v = parseInt(document.getElementById('vector').value);
var width = parseInt(document.getElementById('width').value);
var height = parseInt(document.getElementById('height').value);
if(TYPE == "monster"){
var minX = parseInt(document.getElementById('minX').value);
var maxX = parseInt(document.getElementById('maxX').value);
var name = document.getElementById('name').value;
var symbol = document.getElementById('symbol').value;
monsters[monsterCount++] = new Monster(x,FLOOR_HEIGHT+y,width,height,minX,maxX,name,symbol,v);
}
else{
bricks[brickCount++] = new Brick(x,FLOOR_HEIGHT+y,width,height);
}
}
function game1(){
bricks[brickCount++] = new Brick(200,FLOOR_HEIGHT+50,50,50);
bricks[brickCount++] = new Brick(250,FLOOR_HEIGHT+100,50,100);
bricks[brickCount++] = new Brick(300,FLOOR_HEIGHT+150,50,150);
bricks[brickCount++] = new Brick(350,FLOOR_HEIGHT+200,50,200);
monsters[monsterCount++] = new Monster(400,FLOOR_HEIGHT+230,50,50,400,700,"flyer","👼",2);
monsters[monsterCount++] = new Monster(400,FLOOR_HEIGHT+50,50,50,400,700,"背霸","🐨",1);
monsters[monsterCount++] = new Monster(470,FLOOR_HEIGHT+50,50,50,470,770,"背霸寵物","🐶",1);
monsters[monsterCount++] = new Monster(1070,FLOOR_HEIGHT+50,50,50,1070,1770,"內衣褲","👙",6);
}
</script>
</head>
<body onload="main();">
<div id="wrapper">
<div id="game_area" style="float:left;">
<canvas id="panel" width="1000" height="750" style="border:2px solid #666666;border-radius:10px;"></canvas>
<center><h2>尻猴大冒險</h2></center>
</div>
<div id="control_area" style="float:left;border:5px solid #666666;border-radius:10px;">
<p>x</p>
<input type="text" id="x">
<p>y(+floorHeight)</p>
<input type="text" id="y">
<p>width</p>
<input type="text" id="width">
<p>height</p>
<input type="text" id="height">
<p>minX</p>
<input type="text" id="minX">
<p>maxX</p>
<input type="text" id="maxX">
<p>name</p>
<input type="text" id="name">
<p>symbol</p>
<input type="text" id="symbol">
<p>vector</p>
<input type="text" id="vector">
<select id = "addType">
<option value="brick">Brick</option>
<option value="monster">Monster</option>
</select>
<button onclick="addObject();">add</button>
</div>
</div>
</body>