123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252 |
- -- title: untitled shmup
- -- author: game developer
- -- desc: something like Gradius/Nemesis/Salamander/Life Force
- -- script: lua
- t=0
- local bullet_speed = 6
- local bullet_timer = 0
- local bullet_timer_start = 10
- -- props: x, y, vx, vy, type
- local player_bullets = {}
- local player = {
- x=20,y=60,
- vx=0,vy=0,
- speed=1.5,
- sp=256,
- fire_t=0,
- fire_held=false,
- gun_type=1,
- gun_level=1,
- gunpods={},
- }
- local grad_palettes = {
- { 1, 2, 3, 4, 12 },
- { 7, 6, 5, 4, 12 },
- { 8, 9, 10, 11, 12 },
- }
- local enemies = {}
- function add_enemy(en_type, xpos, ypos)
- table.insert(enemies, {
- x=xpos, y=ypos,
- type=en_type,
- t=0,
- })
- end
- function mod(a, b)
- return math.floor(a-(math.floor(a/b)*b))
- end
- function draw_gradient(xpos, ypos, width, height, startindex, gradient)
- local idx = startindex or 1
- local grad = gradient or 1
- local band_w = width / 5 --# of colors in each gradient
- local cur_band = 0
- for i=0,width-1 do
- if cur_band >= band_w then
- idx = idx + 1
- cur_band = 0
- end
- cur_band = cur_band + 1
- if idx > 5 then idx = 1 end
- line(xpos + i, ypos, xpos + i - height, ypos + height, grad_palettes[grad][idx])
- end
- end
- -- TODO: various types
- function add_bullet()
- sfx(0, 'D-6', 10, 0, 11, 4)
- table.insert(player_bullets, {
- x=player.x + 10,
- y=player.y,
- vx = 0,
- vy = 0,
- })
- if #player.gunpods > 0 then
- for _,pod in ipairs(player.gunpods) do
- table.insert(player_bullets, {
- x=pod.x + 4,
- y=pod.y,
- vx = 0,
- vy = 0,
- })
- end
- end
- end
- function add_gunpod()
- if #player.gunpods < 5 then
- table.insert(player.gunpods, {
- x=0,y=0,vx=0,vy=0,
- sprs={ 259,260,261,262,263 },
- fr=1,t=0,frametime=5,
- })
- end
- end
- function draw_player()
- local engine_spr = 274
- if player.vx > 0 then
- engine_spr = 306
- elseif player.vx < 0 then
- engine_spr = 290
- end
- if player.vy > 0 then
- player.sp = 272
- elseif player.vy < 0 then
- player.sp = 288
- else
- player.sp = 256
- end
- -- draw engine fire then player
- spr(engine_spr, player.x-8, player.y+1)
- spr(player.sp, player.x, player.y, 0, 1, 0, 0, 2, 1)
- -- draw gunpods
- if #player.gunpods > 0 then
- for key,pod in ipairs(player.gunpods) do
- pod.t = pod.t + 1
- if mod(pod.t, pod.frametime) == 0 then
- pod.fr = pod.fr + 1
- if pod.fr > #pod.sprs then pod.fr = 1 end
- end
- spr(pod.sprs[pod.fr], pod.x, pod.y)
- -- TODO: move this into an update
- local targx = player.x + 4 - pod.x
- local targy = player.y - 10 - pod.y
- pod.vx = targx / 3
- pod.vy = targy / 3
- pod.x = pod.x + pod.vx
- pod.y = pod.y + pod.vy
- end
- end
- end
- add_gunpod()
- function draw_bullets()
- for key,val in ipairs(player_bullets) do
- spr(258, val.x, val.y, 0)
- end
- end
- -- also handle powerups since they're colliders
- function draw_enemies()
- end
- function handle_input()
- player.vx = 0
- player.vy = 0
- if btn(0) then
- player.vy=-player.speed
- end
- if btn(1) then
- player.vy=player.speed
- end
- if btn(2) then
- player.vx=-player.speed
- end
- if btn(3) then
- player.vx=player.speed
- end
- -- slow down diagonal movements
- if player.vx * player.vy ~= 0 then
- player.vx = player.vx * 0.707
- player.vy = player.vy * 0.707
- end
- player.x = player.x + player.vx
- player.y = player.y + player.vy
- if player.x < 5 then player.x = 5 end
- if player.x > 220 then player.x = 220 end
- if player.y < 5 then player.y = 5 end
- if player.y > 128 then player.y = 128 end
- player.fire_held = false
- if btn(4) then
- if player.fire_t <= 0 then
- player.fire_t = bullet_timer_start
- add_bullet()
- else
- player.fire_t = player.fire_t - 1
- end
- player.fire_held = true
- else
- player.fire_t = 0
- end
- -- debug
- if btnp(5) then
- player.gun_type = mod(player.gun_type + 1, 3) + 1
- end
- end
- function TIC()
- handle_input()
- for key,val in ipairs(player_bullets) do
- val.x = val.x + bullet_speed
- if val.x > 240 then
- table.remove(player_bullets, key)
- end
- end
- cls(0)
- draw_player()
- draw_bullets()
- draw_gradient(10, 40, 10, 5, mod(t/3, 5) + 1, player.gun_type)
- dbg("type:"..tostring(player.gun_type), 0)
- dbg(tostring(player.fire_held), 1)
- dbg(tostring(mod(t/3, 5) + 1), 2)
- -- dbg(tostring(player.vy), 3)
- t=t+1
- end
- function dbg(msg, line_no)
- print(msg, 5, line_no * 7, 5, true, 1, true)
- end
- -- <SPRITES>
- -- 000:00000000eccef0000edddefa0fcccc8bcf9deededfb8cddd00db8cdd00008cce
- -- 001:000000000000000090000000aa9deecc99eedcddddcccdf0ccf0000000000000
- -- 002:0000000000000000000000004040440030303300000000000000000000000000
- -- 003:00dd00000eeedddd023eeee02344320023443200023eddd00feefeee00ff0000
- -- 004:000000000f1eeddd02331ee023443200234eddd00feefeee00f1000000000000
- -- 005:000000000022000002332eef23dd31f0231ddddd0fe1eee00022000000000000
- -- 006:000000000022000002dd2000231ddddd23e1eeee02ee20000022000000000000
- -- 007:0000000000de00000f1ddddd2341eee02344320002331ee00f1eeddd00000000
- -- 016:dccefeed0ddddefa0fcccc8acf9deededfbbcddd0000bcdd00008ccc00000dd0
- -- 017:d00000009eedd000aaaaeecc9aa9dccdddcccdf0ccd00000d000000000000000
- -- 018:0000000000000880000889ab08899abc000889ab000008800000000000000000
- -- 032:ecdf00000edddf0000edddc00bbcfeeddcc99feeee8888880bc99f99000bfeee
- -- 033:000000000000000009aa0000cdc99e00eeedddcc88888eef9eeeedd0df000000
- -- 034:00000000000000000000089a000089ab0000089a000000000000000000000000
- -- 050:00000000000099a000889abb8889accc00889abb000099a00000000000000000
- -- </SPRITES>
- -- <WAVES>
- -- 000:123345667889abbcdeff1fedcba86642
- -- </WAVES>
- -- <SFX>
- -- 000:00d050808060c040d020e020f010f010f000f000f000f000f000f000f000f000f000f000f000f000f000f000f000f000f000f000f000f000f000f000502000000000
- -- </SFX>
- -- <PALETTE>
- -- 000:1a1c2c5d275db13e53ef7d57ffcd75a7f07038b76425717929366f3b5dc941a6f673eff7f4f4f494b0c2566c86333c57
- -- </PALETTE>
|