wick-dodge.p8 (view raw)
1pico-8 cartridge // http://www.pico-8.com
2version 43
3__lua__
4start = false
5
6function _init()
7 if not start then
8 cartdata(0)
9 end
10 fire_balls = {}
11 game_over=false
12 player.sprite=17
13 player.timing=0.2
14 spawn_rate=0.05
15 score=0
16 high_score=dget(0)
17 palt(12, true)
18 palt(0, false)
19 music(0)
20end
21
22function _update()
23 if not start then
24 if btn(❎) then start=true end
25 return
26 end
27 if game_over then
28 animate_death()
29 if btn(❎) then _init() end
30 return
31 end
32 for fb in all(fire_balls) do
33 fb:update()
34 end
35 player_update()
36 update_score()
37 update_high_score()
38 add_fire_ball()
39end
40
41function _draw()
42 cls()
43 map()
44 spr(player.sprite,
45 player.posx-player.radius,
46 player.posy-player.radius)
47 for fb in all(fire_balls) do
48 fb:draw()
49 end
50 draw_score()
51 draw_highscore()
52 if not start or player.sprite>=player.death_sprite_end then
53 draw_start()
54 end
55end
56-->8
57player = {
58 posx = 45,
59 posy = 70,
60 velx = 0,
61 vely = 0,
62 vel_factor = 1,
63 vel_loose = 0.75,
64 timing = 0.20,
65 sprite = 17,
66 sprite_end = 20,
67 death_sprite = 21,
68 death_sprite_end = 28,
69 hitbox_radius = 2,
70 radius = 4,
71}
72
73function player_update()
74 input()
75 movement()
76 if collision_fire_balls() then
77 game_over=true
78 dset(0, high_score)
79 player.sprite=player.death_sprite
80 music(-1)
81 sfx(3)
82 end
83
84 animate()
85end
86
87function input()
88 if btn(0) then player.velx-=player.vel_factor end --left
89 if btn(1) then player.velx+=player.vel_factor end --right
90 if btn(2) then player.vely-=player.vel_factor end --up
91 if btn(3) then player.vely+=player.vel_factor end --down
92end
93
94function map_collision(x,y,flag)
95 return fget(mget(x,y),flag)
96end
97
98function collision_fire_balls()
99 local tolerance = 3
100 for fb in all(fire_balls) do
101 if abs(player.posx-fb.posx) < tolerance
102 and abs(player.posy-fb.posy) < tolerance
103 then
104 del(fire_balls, fb)
105 return true
106 end
107 end
108 return false
109end
110
111function border_collision()
112 if map_collision((player.posx-player.hitbox_radius)\8,
113 (player.posy-player.hitbox_radius)\8,0)
114 or map_collision((player.posx+player.hitbox_radius)\8,
115 (player.posy+player.hitbox_radius)\8,0)
116 then
117 player.posx-=player.velx
118 player.posy-=player.vely
119 player.velx*=-1
120 player.vely*=-1
121 end
122end
123
124function movement()
125 player.posx+=player.velx
126 player.posy+=player.vely
127 border_collision()
128 player.velx*=player.vel_loose
129 player.vely*=player.vel_loose
130end
131
132function animate()
133 if game_over then return end
134 player.sprite+=player.timing
135 if player.sprite >= player.sprite_end then player.sprite = 17 end
136end
137
138function animate_death()
139 player.sprite+=player.timing
140 if player.sprite >= player.death_sprite_end then player.timing = 0 end
141end
142-->8
143spawn_rate=0.05
144spawn_timer=0
145
146function get_spawn_position()
147 pos=rnd(128*4)
148 if pos < 128 then
149 return pos, 0-10
150 elseif pos < 256 then
151 return 128+10, pos-128
152 elseif pos < 384 then
153 return pos-256, 128+10
154 else return 0-10, pos-384
155 end
156end
157
158function get_direction(x,y)
159 local dx,dy=player.posx-x,player.posy-y
160 dist=sqrt(dx*dx + dy*dy)
161 if dist > 0 then
162 dx/=dist
163 dy/=dist
164 end
165 return dx,dy
166end
167
168function add_fire_ball()
169 spawn_timer+=spawn_rate
170 if spawn_timer < 1 then return end
171 spawn_rate*=1.005
172 spawn_timer=0
173 local x,y=get_spawn_position()
174 local dx,dy=get_direction(x,y)
175 add(fire_balls, {
176 posx=x,
177 posy=y,
178 velx=dx,
179 vely=dy,
180 radius=2,
181 draw=function(self)
182 spr(33,self.posx-self.radius,self.posy-self.radius)
183 end,
184 update=function(self)
185 self.posx+=self.velx
186 self.posy+=self.vely
187 end,
188 })
189end
190-->8
191score=0
192score_delta=1
193high_score=0
194
195function update_score()
196 score+=score_delta
197end
198
199function update_high_score()
200 if score>high_score then
201 high_score=score
202 end
203end
204
205function draw_score()
206 print(score,8,3,7)
207end
208
209function draw_highscore()
210 print(high_score,105,3,10)
211end
212
213function draw_start()
214 print("press ❎ to start",28,40,7)
215end
216__gfx__
217000000006665566666605666d0ddd0dd6566656655555515ddd2dd0000dd2ddddddd2ddd00000000dddd2d0000d2dddddddd2dddddd2ddddddd2dddd00000000
2180000000056666665560666650d000d005555555551155555ddd2dd0000dd2ddddddd2ddd00000000dddd2d0000d2dddddddd2dddddd2ddddddd2dddd00000000
219007007006655666666506666d0ddd0dd6665666555555115ddd2dd0000dd2dddddddd2ddddddd2ddddddd2dddd2dddddddddd2dddd2ddddddd2ddddd00000000
220000770006666665566dad6550d000d005555555555555555ddd2dd0000dd2ddd22dddd22ddddd2dddddddd2222dddddddddddd2222dddddd22dddddd00000000
221000770005566666655dad666d0ddd0dd6566656655155555ddd2dd0000dd2ddddd2ddddd22dddd2222dddddddddddd2222dddddddddddd22dddddd2200000000
2220070070066665566666d55660d000d005555555555551555ddd2dd0000dd2ddddd2ddddddd2ddddddd2dddddddddd2dddd2dddddddddd2ddddddd2dd00000000
223000000006556666665566666d0ddd0dd6665666515555551ddd2dd0000dd2ddd00000000ddd2ddddddd2dddddddd2ddd00d2dddddddd2d00dddd2ddd00000000
2240000000066666655666666550d000d005555555555511555ddd2dd0000dd2ddd00000000ddd2ddddddd2dddddddd2ddd00d2dddddddd2d00dddd2ddd00000000
22500000000cccccccccccccccccccccccc00000000ccccc9cccccccccccccccccccccccccccccccccccccccccccccccccccccccccc999999999999999900000000
22600000000cccc0cccccccccccccc0cccc00000000ccc98ccccccc9c9ccccccccccccccccccccccccccccccccccccccccccccccccc999996966969999900000000
22700000000ccccc0ccccc0cccccccc0ccc00000000ccccc0ccccccc8ccccc99cccccc9cccccccccccccccccccccccccccccccccccc99966d6dd6d6699900000000
22800000000ccc7776ccccc0cccccc776cc00000000ccc7776cccc7776ccccc8ccccccc9ccccccccccccccccccccccccccccccccccc996dddddddddd69900000000
22900000000cc77776cccc776cccc77776c00000000cc77776ccc77776ccc77776ccccc8cccccc9ccccccccc9cccccccccccccccccc996dddddddddd69900000000
23000000000cc7776cccc77776ccc77776c00000000cc7776cccc7776cccc7776ccccc776cccccc8cccccc98ccccccc99cccccccccc96dddddddddddd6900000000
23100000000cc7776cccc7776ccc77776cc00000000cc7776cccc7776cccc7776cccc7776cccc7776cccccc76cccccc8ccccccccccc96dddddddddddd6900000000
23200000000c777776cc777776cc777776c00000000c777776cc777776cc777776ccc77776ccc77776cccc7776cccc7776ccccccccc996ddd6666ddd69900000000
2330000000ccccccccc0000000000000000ddadaadadddd2ddd000000000000000996ddddd6888899996ddddd699988888888888888996ddd6666ddd69900000000
2340000000ccccccccc0000000000000000ddaaaa9adddd2ddd000000000000000996ddddd6888899996ddddd69999888888888888896dddddddddddd6900000000
2350000000cccc82ccc0000000000000000dddaaaadddadadad0000000000000009996ddd658899999956ddd699999888888888888896dddddddddddd6900000000
2360000000ccc8882cc0000000000000000dddddddd22aaa9a2000000000000000996ddddd6889999996ddddd699999988888888888996dddddddddd69900000000
2370000000ccc8888cc0000000000000000dddddddddd2aaadd000000000000000996ddddd6888899996ddddd699999998888888888996dddddddddd69900000000
2380000000cccc88ccc0000000000000000dddddddddd2ddddd0000000000000009996ddd658888889956ddd699988888888888888899966d6dd6d6699900000000
2390000000ccccccccc0000000000000000dddddddd00000000000000000000000996ddddd6888999996ddddd699888888888888888999996966969999900000000
2400000000ccccccccc0000000000000000dddddddd000000000000000000000009996ddd658888899956ddd6999998888888888888999999999999999900000000
24100000000000000000000000000000000999999995555551555555515000000006656656599999999999999998888888888888888000000000000000000000000
2420000000000000000000000000000000096696966511555555115555500000000dd6dd6d699999999966969668888888888888888000000000000000000000000
243000000000000000000000000000000006dd6d6dd555558155555511500000000dddddddd998899996dd6d6dd8888889888888888000000000000000000000000
24400000000000000000000000000000000dddddddd555545555555555500000000dddddddd98889989dddddddd8898889888888888000000000000000000000000
24500000000000000000000000000000000d44448dd551455555544448500000000dddddddd88889889dddddddd8998899988a8a8a8000000000000000000000000
24600000000000000000000000000000000dddddddd554515555555155500000000dd6dd6d688888888dddddddd9999999988aaa9a8000000000000000000000000
247000000000000000000000000000000006dd6d6dd15555551155555510000000066966969888888886dd6d6dd99999999888aaa88000000000000000000000000
24800000000000000000000000000000000566565665551155555511555000000009999999988888888566565669999999988888888000000000000000000000000
249__gff__
2500000000000000101010101010101010000000000000000000000000000010100000000000001000001000100000101000000000001000000010001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
2510000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
252__map__
2532c2c2c2c2c2c2c2c2c2c2c2c3c2c2c2c05050505050505050505050505050505050505050505050505050505050505050000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
2542c3b3b3b3b3b3b3b3b3b3b3b3b3b3b2c05050505050505050505050505050505050505050505050505050505050505050000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
255291d3a343a3a3a3a3a3a3a3a3a3a1e2b05050505050505050505050505050505050505050505050505050505050505050000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
25629280505050505050505050505052a2b05050505050505050505050505050505050505050505050505050505050505050000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
25729280505050505050505050505052a2b05050505050505050505050505050505050505050505050505050505050505050000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
25829280505050505050505050505052a2b05050505050505050505050505050505050505050505050505050505050505050000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
25929280505050505050505050505052a2b05050505050505050505050505050505050505050505050505050505050505050000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
26029280505050505050505050505052a2b05050505050505050505050505050505050505050505050505050505050505050000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
26129280505050505050505050505052a2b05050505050505050505050505050505050505050505050505050505050505050000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
26229280505050505050505050505052a2b05050505050505050505050505050505050505050505050505050505050505050000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
26329280505050505050505050505052a2b05050505050505050505050505050505050505050505050505050505050505050000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
26429280505050505050505050505052a2b05050505050505050505050505050505050505050505050505050505050505050000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
26529280505050505050505050505052a2b05050505050505050505050505050505050505050505050505050505050505050000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
26629280505050505050505050505052a2b05050505050505050505050505050505050505050505050505050505050505050000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
267292d3838383838383838383838382e2b05050505050505050505050505050505050505050505050505050505050505050000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
2682c39393939393939393939393939392c05050505050505050505050505050505050505050505050505050505050505050000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
2690505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
2700505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
2710505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
2720505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
2730505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
2740505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
2750505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
2760505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
2770505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
2780505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
2790505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
2800505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
2810505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
2820505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
2830505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
2840500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
285__sfx__
286011000200e775117750e775117750e775117750e775117750e775117750e775117750e775117750e7751177517775187751777518775177751877517775187751077513775107751377510775137751077513775
2870110000000073006003f6000060034673006000060000600000730060000600006003467300600006000060000073006000060000600346733460300600006000007300600006000060034673006000060000600
288011000001d3401d3311d3211d3111d3401d3311d3211d311213402133121321213111a3401a3311a3211a3111c3401c3311c3211c311243402433123340233312434024331243212431121340213312132121311
289011d00002665526645266352662526615266052660500005000050000500005000050000500005000050000500005000050000500005000050000500005000050000500005000050000500005000050000500005
2900110000000073006000000000073346730060000073000030c0030c00300073006003467300600006000060000073006000007300600346733460300600006000007300600006002460034673006000060000600
291011000002d4222d422294222942232422324222b4222b4222942229422284222842229422294222642228422244222442228422284222b4222b42228422284222642226422264222642224422244222442224422
292__music__
29301 00014244
29401 00010244
29500 00010244
29600 00040244
29700 00040244
29800 00010205
29900 00010205
30000 00040205
30102 00040205
302