-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
169 lines (97 loc) · 3.96 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
<doctype html>
<html>
<head>
<meta charset="UTF-8" />
<title>Laliasprite V2.0.0 - Example</title>
<script src="js/phaser.js"></script>
<script src="dist/laliasprite-2.0.js"></script>
</head>
<body>
<style type="text/css">
body{margin: 0;}
#main
{
background-color: #ff0000;
}
</style>
<div id="main">
</div>
<script type="text/javascript">
var ground , hitter, jogoysprite1, jogoysprite2 /*Jogoy is the fat character's name*/;
var collideObjects = []; /*Array of sprites that gonna have collision with our actor */
function preload() {
//Load main player (mario) and (other assets)
game.load.spritesheet('mario', 'img/mario-spritesheet.png',50,50);
game.load.image('ground' , 'img/tileset.png');
//Create Lalia instance
Lalia = new Lalia();
//Load sprite atlases and spritesheet
/*load atlases*/
Lalia.atlas(game, "jogoy1", 'img/jogoyatlas.png', 'json/jogoyatlas.json', 'json/atlashitboxes.json' );
/*load sheet*/
Lalia.sheet(game, "jogoy2", 'img/jogoysheet.png', 'json/sheethitboxes.json', 180, 240);
///ATLAS LINE END///
}
function create() {
/*Start game physics*/
game.physics.startSystem(Phaser.Physics.ARCADE);
/*Adding some environment*/
ground = game.add.sprite(0, 400, 'ground');
/*Add jogoy to the scene*/
jogoysprite1 = game.add.sprite(game.world.centerX, 30, 'jogoy1');
/* jogoysprite1.frame = 1*/
/* jogoysprite1.scale.setTo(0.5)*/
jogoysprite2 = game.add.sprite(100, 30, 'jogoy2');
/* jogoysprite2.frame = 1*/
/* jogoysprite2.scale.setTo(0.5)*/
//Creating and adding animation to jogoy characters
/*atlas animation : identified by frame name*/
jogoysprite1.animations.add("atlasanim1", ["1" ,"2", "3"],1, false);
/*sheet animation : identified by frame index*/
jogoysprite2.animations.add('sheetanim1', [ 1 , 2 , 3 ],1, false);
hitter = game.add.sprite(130, 40, 'mario'); //this adds our player to the scene (xpos, ypos, cachekey)
/*collideObjects : Objects which will collide with jogoy characters (jogoysprite1 & jogoysprite2) */
collideObjects.push(hitter)
/*Setting jogoy hitboxes for both atlases and sheet*/;
Lalia.atlasboxes(jogoysprite1, 'atlasanim1');
Lalia.sheetboxes(jogoysprite2, 'sheetanim1');
cursors = game.input.keyboard.createCursorKeys(); // we need some cursor keys for our controls
}
/*Action to execute*/
function myActionCallback1()
{
console.log('action 1 triggered : @ALT')
}
function myActionCallback2()
{
console.log('action 2 triggered : @ALT')
}
function update() {
if (cursors.right.isDown)
{
/////// PLAY ANIMATION : Perform action on collision with provided objects/////////////////
jogoysprite1.animations.playaction('atlasanim1','hit', collideObjects, myActionCallback1);
//Tips : move hitter character to test collision with other hitboxes
}
///////////////////////////////////////////////////////////////////////////////////////
if (cursors.left.isDown)
{
/////// PLAY ANIMATION : Perform action on collision with provided objects/////////////////
jogoysprite2.animations.playaction('sheetanim1','both', collideObjects, myActionCallback2);
//Tips : move hitter character to test collision with other hitboxes
}
}
//Render func
function render()
{
}
//Setting the game environment
var windW = window.innerWidth;
var windH = window.innerHeight;
var mainCanvas = document.getElementById('main');
mainCanvas.style.width = windW + 'px';
mainCanvas.style.height = windH + 'px';
var game = new Phaser.Game(windW, windH, Phaser.CANVAS, 'main',{preload:preload, create:create, update:update, render : render});
</script>
</body>
</html>