-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.js
More file actions
166 lines (143 loc) · 3.73 KB
/
bootstrap.js
File metadata and controls
166 lines (143 loc) · 3.73 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
157
158
159
160
161
162
163
164
165
166
Resources =
{
// Backgrounds
bg_space : { file : "backgrounds/space.background" },
// Sprites
spr_ship : { file : "sprites/ship.sprite" },
spr_bullet : { file : "sprites/bullet.sprite" },
spr_asteroid : { file : "sprites/asteroid.sprite" },
// Sound effects
sfx_explosion : { file : "sfx/explosion.mp3" },
sfx_lazer_1 : { file : "sfx/lazer_1.mp3" },
sfx_lazer_2 : { file : "sfx/lazer_2.mp3" },
sfx_no_ammo : { file : "sfx/no_ammo.mp3" },
sfx_asteroid_hit : { file : "sfx/asteroid_hit.mp3" },
sfx_ammo_pickup : { file : "sfx/ammo_pickup.mp3" },
sfx_shield_pickup : { file : "sfx/shield_pickup.mp3" },
sfx_bounce : { file : "sfx/bounce.mp3" },
// Fonts
fnt_homenaje : { file : "fonts/homenaje.css" }
};
var g_info = null;
Scene = function()
{
$.extend(this, new Engine.Game2D.Scene(Resources["bg_space"]));
};
Entity = function(sprite_name)
{
$.extend(this, new Engine.Game2D.Entity(Resources[sprite_name]));
if(sprite_name == "spr_ship")
{
this.SetDepth(-1);
}
};
var g_using_input = false;
function KeyPressed(key)
{
g_using_input = true;
var is_tap = (key == "space");
return Engine.Keyboard.IsPressed(key, true) || (is_tap && ship && ship.IsTapped());
}
function KeyHeld(key)
{
g_using_input = true;
var is_tap = (key == "space");
return Engine.Keyboard.IsPressed(key) || (is_tap && ship && ship.IsTapped());
}
function Touched()
{
return Engine.Touch.IsPressed();
}
function Tapped()
{
return Engine.Touch.IsTapped();
}
function GetFingerX()
{
return Engine.Touch.GetPosition()[0];
}
function Chance(chance)
{
return Engine.Math.RandomInteger(0, chance) == 0;
}
function GetWidth()
{
return Engine.Canvas.GetWidth();
}
function GetHeight()
{
return Engine.Canvas.GetHeight();
}
function Random(x, y)
{
return Engine.Math.RandomInteger(x, y);
}
function Draw(scene)
{
scene.Render(g_info);
}
var text_boxes = {}; // Name --> Engine.Text2D.TextBox map
function DrawText(name, value)
{
if(name in text_boxes)
{
text_boxes[name].Set(value);
text_boxes[name].UpdateCSSPosition();
}
else
{
text_boxes[name] = new Engine.Text2D.TextBox(value,
{
prefix : name + ": ",
position : [10, GetHeight() - 60 - (50 * Object.keys(text_boxes).length)],
size : 50,
colour : "#48CAFF",
css : "font-family: Homenaje ;line-height: 1em;color: #ffbf00;font-size: 79px;text-shadow:0px 0px 0 #39a2cc,1px 1px 0 #2d82a3,2px 2px 0 #20607a,3px 3px 0 #144254,4px 4px 0 #0d2c38, 5px 5px 0 #0d2c38,6px 6px 5px rgba(0,0,0,0.25)}"
});
}
}
function HelperInit()
{
$("#loader").hide();
// Make sure canvas is visible and sized correctly
Engine.Canvas.Show();
if(!Engine.Device.IsMobile())
{
Engine.Device.SetAspectRatio(g_aspect_ratio);
}
Engine.Device.Maximise();
Init(); // game.js init
}
function HelperUpdate(info)
{
g_info = info;
if(typeof scene !== 'undefined')
{
// Remove off-screen asteroids
var asteroids = scene.FindByTag("asteroid");
for(var i = 0; i < asteroids.length; ++i)
{
var asteroid = asteroids[i];
if(asteroid.GetY() < -(asteroid.GetSize() / 2))
{
scene.Remove(asteroid);
}
}
// Remove off-screen bullets
var bullets = scene.FindByTag("bullet");
for(var i = 0; i < bullets.length; ++i)
{
var bullet = bullets[i];
if(bullet.GetY() > GetHeight() + (bullet.GetSize() / 2))
{
scene.Remove(bullet);
}
}
// If we detect they have setup input handling, automatically position the ship on touch devices
if(typeof ship !== 'undefined' && g_using_input && Engine.Touch.IsPressed())
{
ship.MoveTo([GetFingerX(), ship.GetY()]);
}
}
Update(); // game.js update
}