-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
178 lines (141 loc) · 4.3 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
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>ShinyGaem - Game "polish" and Phaser test</title>
<script type="text/javascript" src="js/phaser.min.js"></script>
<style type="text/css">
body {
margin: 0;
}
</style>
</head>
<body>
<script type="text/javascript">
var game = new Phaser.Game(960, 640, Phaser.AUTO, '', { preload: preload, create: create, update: update });
function preload() {
game.load.spritesheet('player', 'assets/player_sprite.png', 32, 37, 12, 0, 4);
game.load.tilemap('scene', 'assets/map_forArcade.json', null, Phaser.Tilemap.TILED_JSON);
game.load.image('open_tileset', 'assets/open_tileset.png');
game.load.bitmapFont('font', 'assets/font.png', 'assets/font.fnt');
game.load.audio('alarm', 'assets/alarm.ogg');
game.load.audio('pickup', 'assets/pickup.wav');
game.load.image('paper', 'assets/paper3.png');
}
//player
var player;
var cursors;
var lastPosition = 7;
//scene
var collisionLayer;
var layers = new Array(4);
//reloj
var timeText;
var scoreText;
var timer;
//papers
var papers;
var score = 0;
function create() {
//Agregando Fisicas (para manejo de colisiones)
game.physics.startSystem(Phaser.Physics.ARCADE);
game.stage.backgroundColor = '#000000';
//layer stuff:
map = this.add.tilemap('scene');
map.addTilesetImage('open_tileset');
collisionLayer = map.createLayer('Collisions');
collisionLayer.resizeWorld();
map.setCollisionBetween(0,10);
//collisionLayer.debug = true;
layers[0] = map.createLayer('Background');
layers[1] = map.createLayer('MiddleGround');
layers[2] = map.createLayer('Foreground');
//Agregando el sprite del jugador
player = game.add.sprite(32, game.world.height - 150, 'player');
//Elementos del mapa que se renderean sobre el personaje
layers[3] = map.createLayer('Top');
//Agregando fisicas del jugador
game.physics.arcade.enable(player);
player.body.setSize(17, 24, 8, 13);
//Animaciones jugador
player.animations.add('top', [0, 1, 2], 8, true);
player.animations.add('right', [3, 4, 5], 8, true);
player.animations.add('down', [6, 7, 8], 8, true);
player.animations.add('left', [9, 10, 11], 8, true);
//cursores
cursors = game.input.keyboard.createCursorKeys();
//reloj
timeText = game.add.bitmapText(30, 30, 'font','99', 50);
scoreText = game.add.bitmapText(800, 30, 'font','0', 50);
game.time.events.add(Phaser.Timer.SECOND * 99, timeUp, this);
alarm = game.add.audio('alarm');
pickupSound = game.add.audio('pickup')
//papers
papers = game.add.group();
papers.enableBody = true;
for (var i = 0; i < 10; i++){
papers.create(game.rnd.integerInRange(0, 960), game.rnd.integerInRange(0, 640), 'paper');
}
}
function update() {
//colisiones entre el jugador y la layer creada en el json
game.physics.arcade.collide(player, collisionLayer);
game.physics.arcade.overlap(player, papers, collectPaper);
playerMovement();
var tiempo = Math.round(game.time.events.duration/1000);
timeText.setText(tiempo);
scoreText.setText(score);
if (!alarm.isPlaying && tiempo < 10){
alarm.play();
}
}
function collectPaper(player, paper) {
pickupSound.play();
paper.kill();
score += 10;
}
function timeUp(){
game.paused = true;
}
function playerMovement (){
//FUNCIONES JUGADOR
player.body.velocity.x = 0;
player.body.velocity.y = 0;
if (cursors.left.isDown)
{
//Mover a la izquierda
player.body.velocity.x = -150;
player.animations.play('left');
lastPosition = 10;
}
else if (cursors.right.isDown)
{
// Mover a la derecha
player.body.velocity.x = 150;
player.animations.play('right');
lastPosition = 4;
}
else if (cursors.up.isDown)
{
//Mover Arriba
player.body.velocity.y = -150;
player.animations.play('top');
lastPosition = 1;
}
else if (cursors.down.isDown)
{
//Mover Abajo
player.body.velocity.y = 150;
player.animations.play('down');
lastPosition = 7;
}
else
{
// Stand still
player.animations.stop();
player.frame = lastPosition;
}
}
</script>
</body>
</html>