-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
156 lines (118 loc) · 3.92 KB
/
Copy pathindex.html
File metadata and controls
156 lines (118 loc) · 3.92 KB
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
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Making your first Phaser 3 Game - Part 1</title>
<script src="//cdn.jsdelivr.net/npm/phaser@3.1.1/dist/phaser.js"></script>
<style type="text/css">
body {
margin: 0;
}
</style>
</head>
<body>
<script type="text/javascript">
var platforms;
var player;
var cursors;
var stars;
var ball;
var marker = [];
var SceneA = {
key: 'SceneA',
preload: function preload() {
console.log(this);
this.load.image('sky', 'assets/sky.png');
this.load.image('ground', 'assets/platform.png');
this.load.spritesheet('dude','assets/dude.png', { frameWidth: 32, frameHeight: 48 });
this.load.image('ball', 'https://labs.phaser.io/assets/sprites/pangball.png');
this.load.image('block', 'https://labs.phaser.io/assets/sprites/block.png');
},
init: function init() {
console.info('SceneA init.');
},
create: function create() {
console.info('SceneB started.');
this.matter.world.setBounds(0, 0, 800, 600, 32, true, true, false, true);
this.add.image(400, 300, 'sky');
marker.push(this.add.image(500, 40, 'block'));
marker.push(this.add.image(100, 40, 'block'));
marker.push(this.add.image(300, 40, 'block'));
marker.push(this.add.image(700, 40, 'block'));
console.log(marker);
//don't understand why is it not working
for(var i=0;i<marker.length;i++){
createTween(this,marker[i]);
}
// Add in a stack of balls
for (var i = 0; i < 2; i++)
{
ball = this.matter.add.image(Phaser.Math.Between(100, 700), Phaser.Math.Between(-600, 0), 'ball');
ball.setCircle();
ball.setFriction(0.005);
ball.setBounce(1);
ball.setMass(0.5);
ball.body.ignorePointer = true;
}
player = this.matter.add.image(100, 150, 'dude');
player.setScale(1.5);
player.setCircle();
player.setFixedRotation();
player.setMass(500);
//Enable mouse
this.matter.add.mouseSpring();
cursors = this.input.keyboard.createCursorKeys();
},
update: function update() {
if (cursors.left.isDown){
player.setVelocityX(-3);
//player.anims.play('left', true);
}else if(cursors.right.isDown){
player.setVelocityX(3);
//player.anims.play('right', true);
}else{
player.setVelocityX(0);
//player.anims.play('turn');
}if (cursors.up.isDown){
player.setVelocityY(-3);
}
//why is it not working
for(var i=0;i<marker.length;i++){
if (Phaser.Geom.Intersects.RectangleToRectangle(player.getBounds(), marker[i].getBounds())) {
player.x = 10;
player.y = 10;
}
}
}
};
function createTween(obj,mark){
obj.tweens.add({
targets: mark,
y: 580,
duration: 3000,
ease: function (t) {
return Math.pow(Math.sin(t * 3), 3);
},
delay: 1000,
repeat: -1
});
}
var config = {
type: Phaser.AUTO,
width: 800,
height: 600,
physics: {
default: 'matter',
matter: {
debug: false,
gravity: {
y: 0.3
}
}
},
scene: [SceneA]
};
var game = new Phaser.Game(config);
</script>
</body>
</html>