-
Notifications
You must be signed in to change notification settings - Fork 1
/
pacslay.htm
113 lines (90 loc) · 3.23 KB
/
pacslay.htm
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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Pac & Slay</title>
<meta name="description" content="Pac & Slay">
<meta name="author" content="Olaf Nowacki">
<script src="js/phaser-2.3.0/phaser.min.js" type="text/javascript"></script>
<script src="js/tools.js" type="text/javascript"></script>
<script src="js/init.js" type="text/javascript"></script>
<script src="js/assets.js" type="text/javascript"></script>
<script src="js/render.js" type="text/javascript"></script>
<script src="js/player.js" type="text/javascript"></script>
<script src="js/monsters.js" type="text/javascript"></script>
<script src="js/fight.js" type="text/javascript"></script>
<script src="js/levelup.js" type="text/javascript"></script>
<!--link rel="stylesheet" href="css/styles.css"-->
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body>
<script type="text/javascript">
var game = new Phaser.Game(576, 384, Phaser.AUTO, 'pacslay', {init: init, preload: preload, create: create, update: update, render: render }, false, false);
var monsters = 0;
var levelUp = false;
function update() {
monsters.forEach(moveMonsters, this, true);
game.physics.arcade.collide(player, layer);
game.physics.arcade.collide(monsters, layer, rndDirection);
game.physics.arcade.collide(monsters, monsters, rndDirection);
game.physics.arcade.overlap(player, dots, collectDot, null, this);
//game.physics.arcade.collide(player, monsters, tryAttack);
game.physics.arcade.collide(monsters, player, tryAttack);
//monsters.forEach(moveToPlayer, this, true);
//player.body.velocity.x = 0;
//player.body.velocity.y = 0;
if (cursors.left.isDown) {
move(player, "left", "left");
} else if (cursors.right.isDown) {
move(player, "right", "right");
} else if (cursors.up.isDown) {
move(player, "up", "up");
} else if (cursors.down.isDown) {
move(player, "down", "down");
} else {
player.animations.stop();
}
//group.sort('y', Phaser.Group.SORT_ASCENDING);
monsters.sort('y', Phaser.Group.SORT_ASCENDING);
}
function moveMonsters(sprite) {
sprite.body.velocity.x = 0;
sprite.body.velocity.y = 0;
move(sprite, sprite.direction);
}
function move(sprite, direction, anim) {
if (direction === "up") {
sprite.body.velocity.y = -sprite.speed;
} else if (direction === "down") {
sprite.body.velocity.y = sprite.speed;
} else if (direction === "left") {
sprite.body.velocity.x = -sprite.speed;
} else if (direction === "right") {
sprite.body.velocity.x = sprite.speed;
}
if (typeof anim != 'undefined') {
sprite.animations.play(anim);
}
}
function rndDirection (sprite) {
var directions = ["up", "down", "left", "right"];
var index = directions.indexOf(sprite.direction);
if (index > -1) {
directions.splice(index, 1);
}
sprite.direction = game.rnd.pick(directions);
}
function moveToPlayer(monster) {
game.physics.arcade.moveToObject(monster, player);
}
function collectDot(player, dot) {
fx.play("dot");
dot.destroy();
player.exp += 1;
//checkLevelUp();
}
</script>
</body>
</html>