2 This is a template for livecoding.
4 It is required() by the main.lua.
6 One wants to code the global_update(), global_draw(), and global_collide() routines
7 Put any new variables after the "declare variables here" line
10 --use the axis-aligned collision code (significantly faster)
11 require
"base/aabb_collision"
12 require
"scripts/Sparkle"
15 require
"scripts/Darkle"
16 require
"scripts/DarkLine"
17 require
"scripts/Phazon"
18 require
"scripts/PhazonBlast"
19 require
"scripts/Player"
20 require
"scripts/OrangeSpark"
21 require
"scripts/WhiteSpark"
23 bg_image
= get_image("images/bg.png")
24 dark_overlay
= get_image("images/dark_overlay.png")
27 --Set the FPS here (game speed depends on this)
30 --declare variables here
34 score_label
= Label
:new()
35 score_label
:set_font("VeraBd.ttf", 20)
36 score_label
:set_caption(score
.."")
39 score_label
.y
= 480 - score_label
.h
41 gameover_label
= Label
:new()
42 gameover_label
:set_font("VeraBd.ttf", 48)
43 gameover_label
:set_caption("GAME OVER")
44 gameover_label
:update()
45 gameover_label
.x
= 320
46 gameover_label
.y
= 240
47 gameover_label
.x_offset
= gameover_label
.w
/2
48 gameover_label
.y_offset
= gameover_label
.h
/2
53 darktangle
= Rectangle
:new({x
=0,y
=0,w
=640,h
=0,style
="filled"})
56 phazon_list
= ObjectList
:new()
57 bullet_list
= ObjectList
:new()
59 Sun_psys
= ParticleSystem
:new()
60 Sun_psys
.object
= Sparkle
61 Sun_psys
.angle_min
= 180
62 Sun_psys
.angle_max
= 360
63 Sun_psys
.speed_min
= 0.75
64 Sun_psys
.speed_max
= 2.0
65 Sun_psys
.life_min
= 100
66 Sun_psys
.life_max
= 200
67 Sun_psys
.update_delay
= 8
70 Dark_psys
= ParticleSystem
:new()
71 Dark_psys
.object
= Darkle
72 Dark_psys
.type ="rect"
73 Dark_psys
.rect
= Rect
:new({x
=0,y
=480-32,w
=640,h
=32})
74 Dark_psys
.angle_min
= 80
75 Dark_psys
.angle_max
= 100
76 Dark_psys
.speed_min
= 0.1
77 Dark_psys
.speed_max
= 0.35
78 Dark_psys
.life_min
= 100
79 Dark_psys
.life_max
= 200
80 Dark_psys
.update_delay
= 3
83 Dark_psys2
= ParticleSystem
:new()
84 Dark_psys2
.object
= DarkLine
85 Dark_psys2
.type ="rect"
86 Dark_psys2
.rect
= Rect
:new({x
=0,y
=480-32,w
=640,h
=32})
87 Dark_psys2
.angle_min
= 90
88 Dark_psys2
.angle_max
= 90
89 Dark_psys2
.speed_min
= 0.2
90 Dark_psys2
.speed_max
= 0.6
91 Dark_psys2
.particles_per_update_min
= 1
92 Dark_psys2
.particles_per_update_max
= 5
93 Dark_psys2
.life_min
= 50
94 Dark_psys2
.life_max
= 200
98 beam_psys_o
= ParticleSystem
:new()
99 beam_psys_o
.object
= OrangeSpark
100 beam_psys_o
.type ="rect"
101 beam_psys_o
.rect
= Rect
:new({x
=0,y
=0,w
=64,h
=32})
102 beam_psys_o
.angle_min
= 0
103 beam_psys_o
.angle_max
= 180
104 beam_psys_o
.speed_min
= 4
105 beam_psys_o
.speed_max
= 7.0
106 beam_psys_o
.life_min
= 2
107 beam_psys_o
.life_max
= 8
108 beam_psys_o
.particles_per_update_min
= 5
109 beam_psys_o
.particles_per_update_max
= 25
110 beam_psys_o
.on
= false
112 beam_psys_w
= ParticleSystem
:new()
113 beam_psys_w
.object
= WhiteSpark
114 beam_psys_w
.type ="rect"
115 beam_psys_w
.rect
= Rect
:new({x
=0,y
=0,w
=64,h
=32})
116 beam_psys_w
.angle_min
= 180
117 beam_psys_w
.angle_max
= 360
118 beam_psys_w
.speed_min
= 4
119 beam_psys_w
.speed_max
= 7.0
120 beam_psys_w
.life_min
= 2
121 beam_psys_w
.life_max
= 8
122 beam_psys_w
.particles_per_update_min
= 5
123 beam_psys_w
.particles_per_update_max
= 25
124 beam_psys_w
.on
= false
127 --set up the events here: evman variable
128 evman
.keyboard
.pressed
[Keys
.LEFT
] = function() player
.left
= true end
129 evman
.keyboard
.released
[Keys
.LEFT
] = function() player
.left
= false end
131 evman
.keyboard
.pressed
[Keys
.RIGHT
] = function() player
.right
= true end
132 evman
.keyboard
.released
[Keys
.RIGHT
] = function() player
.right
= false end
134 evman
.keyboard
.pressed
[Keys
.SPACE
] = function() player
:shoot() end
135 evman
.keyboard
.pressed
[Keys
.RETURN
] = function() title
= false end
137 --updating stuff goes here
138 function global_update()
139 if gameover
~= true then
140 player
.y
= 430 - dark_height
145 instr_begin("update_psys")
149 beam_psys_o
.rect
.x
= thesun
.x
- 40
150 beam_psys_w
.rect
.x
= thesun
.x
- 40
151 beam_psys_o
.rect
.y
= 432-dark_height
152 beam_psys_w
.rect
.y
= 448-dark_height
155 instr_track("psys", Dark_psys2
.object_list
.size
)
156 instr_end("update_psys")
157 dark_height
= dark_height
+ 0.05
158 darktangle
.y
= 480 - dark_height
159 darktangle
.h
= dark_height
160 Dark_psys
.rect
.y
= 448 - dark_height
161 Dark_psys2
.rect
.y
= 448 - dark_height
162 score_label
:set_caption(score
.."")
164 if dark_height
>= 480-128-32 then gameover
= true end
165 if thesun
.beam_on
== true then
166 dark_height
= dark_height
- 0.4
173 score_label
.x_offset
= score_label
.w
/2
174 score_label
.y
= 240 + 64
179 --drawing stuff goes here
180 function global_draw()
181 if gameover
~= true then
183 blit(bg_image
,0,0,0,1,1)
184 instr_begin("draw_psys")
188 instr_end("draw_psys")
193 blit(dark_overlay
,0,448-dark_height
,0,1,1)
200 gameover_label
:draw()
206 --collision stuff goes here
207 function global_collide()
208 if gameover
~= true then
209 instr_begin("collisions")
210 check_collisions_lists(Sun_psys
.object_list
, Dark_psys
.object_list
)
211 check_collisions_obj_list(darktangle
, phazon_list
)
212 check_collisions_obj_list(player
, phazon_list
)
213 check_collisions_obj_list(thesun
, bullet_list
)
214 check_collisions_obj_list(darktangle
, Sun_psys
.object_list
)
215 instr_end("collisions")