-
Notifications
You must be signed in to change notification settings - Fork 0
/
devFire.html
159 lines (123 loc) · 3.71 KB
/
devFire.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<!doctype html>
<html lang="fr">
<head>
<meta charset="utf-8">
<script src="js/core/case.js"></script>
<script src="js/core/labyrinth.js"></script>
<script src="js/core/labyrinthFactory.js"></script>
<script src="js/core/actor.js"></script>
<script src="js/core/vector.js"></script>
<script src="js/core/action.js"></script>
<script src="js/core/movement.js"></script>
<script src="js/kdconf.js"></script>
<script src="libs/keydrown.min.js"></script>
<script src="js/core/sprite.js"></script>
<script src="js/graphics.js"></script>
<link rel="stylesheet" type="text/css" href="css/reset.min.css" />
<link rel="stylesheet" type="text/css" href="css/main.css" />
<title>Patate - GameJam 6</title>
</head>
<body>
<canvas id="map" width="800" height="600">
Mets à jour ton navigateur connard !
</canvas>
<canvas id="playersMap" width="800" height="600">
Mets à jour ton navigateur connard !
</canvas>
</body>
<p id="test">10
5
1111111111
1111111111
2111211111
1111111111
1111111111
1111111111
</p>
<script>
function sleep(milliseconds) {
var start = new Date().getTime();
for (var i = 0; i < 1e7; i++) {
if ((new Date().getTime() - start) > milliseconds){
break;
}
}
}
function p(x) { console.log(x); }
function nl(x) { p(""); }
//displayLab(lab);
// ***************************************************************************
function delTabElement(oldTab, element) {
var newTab = new Array();
for (i =0;i<oldTab.length; ++i) {
if (oldTab[i] != element) {
newTab.push(oldTab[i]);
}
}
return newTab;
}
var graphics = new Graphics(main_cb);
function main_cb() {
var lab=labyrinthFactory("test");
graphics.setLabyrinth(lab);
var player = new Actor();
player.setSpriteId(1);
var push_date=Date.now();
var ball_date=Date.now();
var action = function() { this.state = Action.IDLE; };
var entities = new Array();
entities[0] = player;
var monster = new Actor(); monster.setSpriteId(11);monster.setPosition(5,1);
entities[1] = monster;
var monster1 = new Actor(); monster1.setSpriteId(11);monster1.setPosition(2,3);
entities[2] = monster1;
var monster2 = new Actor(); monster2.setSpriteId(12);monster2.setPosition(7,4);
entities[3] = monster2;
initKdConf(action);
kd.run(function () {
kd.tick();
// prevent player to move super quickly
if (action.state != Action.IDLE) {
if (Date.now() > push_date + 150) {
push_date = Date.now();
doMovement(player, lab, action.state);
if (action.state >= Action.FIRE_U && action.state <= Action.FIRE_L) {
ball = new Actor();
ball.setPosition(player.getPosition().x, player.getPosition().y);
ball.setSpriteId(SpriteCode.FIRE_BALL);
ball.setDirection(action.state);
entities.push(ball);
}
}
}
if (Date.now() > ball_date + 100) {
ball_date = Date.now();
newEntities = entities.slice();
for (var i in entities) {
if(entities[i].getSpriteId() == SpriteCode.FIRE_BALL){
var ball = entities[i];
toRm = doMovementFireBall(ball, lab, ball.getDirection());
if (!toRm) {
for (var j in entities) {
if (i!=j) {
tmp_other = entities[j];
if (ball.getPosition().x == tmp_other.getPosition().x &&
ball.getPosition().y == tmp_other.getPosition().y) {
newEntities = delTabElement(newEntities, tmp_other);
toRm = true;
}
}
}
}
if (toRm) {
newEntities = delTabElement(newEntities, ball);
}
}
}
entities = newEntities;
}
graphics.refreshAll(entities);
});
}
</script>
</html>