Browse Source

1bit stuff

pixelbath 1 year ago
parent
commit
d969d2f4cb
2 changed files with 200 additions and 0 deletions
  1. 200 0
      1bit/main.lua
  2. BIN
      1bit/shmup.aseprite

+ 200 - 0
1bit/main.lua

@@ -0,0 +1,200 @@
+-- title:  1bit shmup
+-- author: pixelbath
+-- desc:   idk
+-- 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=257,
+	fire_t=0,
+	fire_held=false,
+	gun_type=1,
+	gun_level=1,
+}
+
+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
+
+-- TODO: various types
+function add_bullet()
+	sfx(0, 'D-6', 10, 0, 11, 4)
+	table.insert(player_bullets, {
+		x=player.x + 8,
+		y=player.y + 3,
+		vx = 0,
+		vy = 0,
+	})
+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
+
+	-- 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, 2)
+
+end
+
+function draw_bullets()
+	for key,val in ipairs(player_bullets) do
+		spr(291, val.x, val.y, 0, 1, 0, 0, 2, 1)
+	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()
+
+	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>
+-- 001:000000000000000000000ccc00cccccccccc00c000c00c000ccccccc0c0c0c0c
+-- 002:0000000000000000cc00000000000000000000000ccc0000ccccc000c000ccc0
+-- 003:0000000000000000000000cc000cccccccccc0c000c00c000ccccccc0ccccccc
+-- 004:0000000000000000cc00000000000000000000000ccc0000ccccc000cc00ccc0
+-- 005:00000000000000000000000000000ccc00cccccc0cc00c00cccccccc0ccccccc
+-- 006:000000000000000000000000cc000000000000000cc00000ccccc000ccc0ccc0
+-- 007:000000000000000000000000000000000000000000cccccc0c000000cccccccc
+-- 008:000000000000000000000000000000000000000000000000ccccc000ccccccc0
+-- 009:0000000000000000000000000000000000000ccc000cc0c0ccc00c000c00c000
+-- 010:00000000000000000000000000000000cc000000c00000000cccc0000000ccc0
+-- 011:00000000000000000000000000000ccc00ccc00cccc00c000c0000cc0cc0c000
+-- 012:000000000000000000000000cc000000000000000ccc0000c00cc0000000ccc0
+-- 013:0000000000000000000000cc000ccc0cccc000c000c00c000c0000cc0cc0c000
+-- 014:0000000000000000cc00000000000000000000000ccc0000c00cc0000000ccc0
+-- 017:0ccccccc00c00c00cccc00c000cccccc00000ccc000000000000000000000000
+-- 018:ccccc0000ccc00000000000000000000cc000000000000000000000000000000
+-- 019:0c0c0c0c00c00c00ccccc0c0000ccccc000000cc000000000000000000000000
+-- 020:c0ccc0000ccc00000000000000000000cc000000000000000000000000000000
+-- 021:cc0c0c0c0cc00c0000cccccc00000ccc00000000000000000000000000000000
+-- 022:c00cc0000cc0000000000000cc00000000000000000000000000000000000000
+-- 023:0ccccccc00cccccc000000000000000000000000000000000000000000000000
+-- 024:ccccc00000000000000000000000000000000000000000000000000000000000
+-- 025:ccc00c00000ccccc00000ccc0000000000000000000000000000000000000000
+-- 026:0ccc0000c0000000cc0000000000000000000000000000000000000000000000
+-- 027:0c0000ccccc00c0000ccc00c00000ccc00000000000000000000000000000000
+-- 028:c00cc0000ccc000000000000cc00000000000000000000000000000000000000
+-- 029:0c0000cc00c00c00ccc000c0000ccc0c000000cc000000000000000000000000
+-- 030:c00cc0000ccc00000000000000000000cc000000000000000000000000000000
+-- 033:000000000000000000000ccc00ccc00ccc0000c000c00c000c0000cc0cc0c000
+-- 034:0000000000000000cc00000000000000000000000ccc0000c00cc0000000ccc0
+-- 035:000000000c0c0ccc0000c0cc00000000000000000000c0cc0c0c0ccc00000000
+-- 036:00000000ccccccccccccccc00000000000000000ccccccc0cccccccc00000000
+-- 049:0c0000cc00c00c00cc0000c000ccc00c00000ccc000000000000000000000000
+-- 050:c00cc0000ccc00000000000000000000cc000000000000000000000000000000
+-- 051:0000c0c0000000000000000000000000000000000000000000000000000c0c0c
+-- 052:cc0cccc00000000cc0c0ccc000000000000000000c0cccc00000000cccccccc0
+-- </SPRITES>
+
+-- <WAVES>
+-- 000:123345667889abbcdeff1fedcba86642
+-- </WAVES>
+
+-- <SFX>
+-- 000:00d050808060c040d020e020f010f010f000f000f000f000f000f000f000f000f000f000f000f000f000f000f000f000f000f000f000f000f000f000502000000000
+-- </SFX>
+
+-- <PALETTE>
+-- 000:1a1c2c5d275db13e53ef7d57ffcd75a7f07038b76425717929366f3b5dc941a6f673eff7f4f4f494b0c2566c86333c57
+-- </PALETTE>
+

BIN
1bit/shmup.aseprite