Browse Source

basic jumping and moving mechanics

pixelbath 1 year ago
parent
commit
517fc96a5f
2 changed files with 71 additions and 18 deletions
  1. 71 18
      megamang/megamang.lua
  2. BIN
      megamang/sprites.aseprite

+ 71 - 18
megamang/megamang.lua

@@ -8,21 +8,28 @@
 
 
 t=0
 t=0
 
 
+local player_walk_speed = 1
+local player_slide_speed = 2
 local player_fire_cooldown = 3
 local player_fire_cooldown = 3
 local player_bullet_speed = 5
 local player_bullet_speed = 5
 
 
 local player = {
 local player = {
-	screenx=110,
-	screeny=80,
+	x=110,
+	y=80,
+	yvel=0,
 	spr=0,
 	spr=0,
 	spr_base=256,
 	spr_base=256,
 	flip=0,
 	flip=0,
 	cnt_run=0,
 	cnt_run=0,
 	cnt_fire=0,
 	cnt_fire=0,
 	cdn_fire=0,
 	cdn_fire=0,
+	cdn_auto_fire=0,
 	frames_run={258,260,262,260},
 	frames_run={258,260,262,260},
 	frame_slide=266,
 	frame_slide=266,
 	bullets={},
 	bullets={},
+	is_jumping=false,
+	jump_button_held=false,
+	cnt_slide=0,
 }
 }
 
 
 function BOOT()
 function BOOT()
@@ -32,26 +39,62 @@ end
 function update()
 function update()
 	local is_running = false
 	local is_running = false
 
 
+	if btn(1) and btn(5) then
+		if not player.is_jumping then
+			player.cnt_slide = 30
+		end
+	end
+
 	if btn(2) then
 	if btn(2) then
 		player.cnt_run = player.cnt_run + 1
 		player.cnt_run = player.cnt_run + 1
 		player.flip = 1
 		player.flip = 1
 		is_running = true
 		is_running = true
+		player.x = player.x - player_walk_speed
 	end
 	end
 	if btn(3) then
 	if btn(3) then
 		player.cnt_run = player.cnt_run + 1
 		player.cnt_run = player.cnt_run + 1
 		player.flip = 0
 		player.flip = 0
 		is_running = true
 		is_running = true
+		player.x = player.x + player_walk_speed
 	end
 	end
 	if btn(4) then
 	if btn(4) then
-		if player.cdn_fire <= 0 then
+		if player.cdn_fire <= 0 or player.cdn_auto_fire <= 0 then
 			player.cnt_fire = 10
 			player.cnt_fire = 10
 			player.cdn_fire = player_fire_cooldown
 			player.cdn_fire = player_fire_cooldown
+			player.cdn_auto_fire = player_fire_cooldown + 20
 			spawn_bullet()
 			spawn_bullet()
 		end
 		end
 	else
 	else
 		player.cnt_fire = player.cnt_fire - 1
 		player.cnt_fire = player.cnt_fire - 1
 		player.cdn_fire = player.cdn_fire - 1
 		player.cdn_fire = player.cdn_fire - 1
 	end
 	end
+	player.cdn_auto_fire = player.cdn_auto_fire - 1
+
+	if btn(5) then
+		if player.is_jumping == false and player.jump_button_held == false then
+			player.yvel = -4.4
+			player.is_jumping = true
+			player.jump_button_held = true
+		end
+	else
+		if player.is_jumping and player.yvel < -2.1 then
+			player.yvel = -1.2
+		end
+		player.jump_button_held = false
+	end
+
+	-- TODO: actual collision
+	player.y = player.y + player.yvel
+	if player.y < 80 then
+		if player.yvel < 12 then
+			player.yvel = player.yvel + 0.25
+		end
+	else
+		player.yvel = 0
+		player.y = 80
+		player.is_jumping = false
+	end
+
 
 
 	-- reset run counter if not pressing a button
 	-- reset run counter if not pressing a button
 	if not is_running then player.cnt_run = 0 end
 	if not is_running then player.cnt_run = 0 end
@@ -64,6 +107,10 @@ function update()
 		player.spr = player.spr_base
 		player.spr = player.spr_base
 	end
 	end
 
 
+	if player.is_jumping then
+		player.spr = 264
+	end
+
 	if player.cnt_fire > 0 then
 	if player.cnt_fire > 0 then
 		player.spr = player.spr + 32
 		player.spr = player.spr + 32
 	end
 	end
@@ -78,15 +125,15 @@ end
 
 
 function spawn_bullet()
 function spawn_bullet()
 	local bullet_speed = player_bullet_speed
 	local bullet_speed = player_bullet_speed
-	local bullet_x = player.screenx + 11
+	local bullet_x = player.x + 11
 	if player.flip == 1 then
 	if player.flip == 1 then
 		bullet_speed = bullet_speed * -1
 		bullet_speed = bullet_speed * -1
-		bullet_x = player.screenx
+		bullet_x = player.x
 	end
 	end
 
 
 	bullet = {
 	bullet = {
 		x = bullet_x,
 		x = bullet_x,
-		y = player.screeny+7,
+		y = player.y+7,
 		spd = bullet_speed,
 		spd = bullet_speed,
 		spr = 286,
 		spr = 286,
 	}
 	}
@@ -95,12 +142,16 @@ function spawn_bullet()
 end
 end
 
 
 function draw_player(colorkey)
 function draw_player(colorkey)
-	spr(player.spr, player.screenx, player.screeny, colorkey, 1, player.flip, 0, 2, 2)
+	spr(player.spr, player.x, player.y, colorkey, 1, player.flip, 0, 2, 2)
+	local flash_offset = 2
+	if player.spr == 290 or player.spr == 294 then
+		flash_offset = 3
+	end
 	if player.cnt_fire > 8 then
 	if player.cnt_fire > 8 then
 		if player.flip == 1 then
 		if player.flip == 1 then
-			spr(270, player.screenx, player.screeny+2, colorkey, 1, player.flip)
+			spr(270, player.x, player.y+flash_offset, colorkey, 1, player.flip)
 		else
 		else
-			spr(270, player.screenx+8, player.screeny+2, colorkey, 1, player.flip)
+			spr(270, player.x+8, player.y+flash_offset, colorkey, 1, player.flip)
 		end
 		end
 	end
 	end
 
 
@@ -114,10 +165,12 @@ function TIC()
 
 
 	update()
 	update()
 
 
-	cls(13)
+	cls(7)
 	draw_player(5)
 	draw_player(5)
 
 
-	print(player.spr)
+	line(0, 96, 240, 96, 0)
+	rect(0, 97, 240, 6, 4)
+	line(0, 103, 240, 103, 12)
 
 
 	t=t+1
 	t=t+1
 end
 end
@@ -147,7 +200,7 @@ end
 -- 020:55500bbb5550b0bb5550b99955509999555099bb555099995550909955500089
 -- 020:55500bbb5550b0bb5550b99955509999555099bb555099995550909955500089
 -- 021:b0555555b005555599055555b9055555a005555590555555900555559a055555
 -- 021:b0555555b005555599055555b9055555a005555590555555900555559a055555
 -- 022:5009bbb9509b0bbb509900bb50000b99009abb99099999000009900055000050
 -- 022:5009bbb9509b0bbb509900bb50000b99009abb99099999000009900055000050
--- 023:40055555b9905555b990555500055555bba055559990555599905555899a0555
+-- 023:40055555b9905555b990555500055555bba05555999055559990555589990555
 -- 024:55500bbb555500bb5555009955550b9955550bb055009ab05509990555099805
 -- 024:55500bbb555500bb5555009955550b9955550bb055009ab05509990555099805
 -- 025:bb005555b00555559bb005559bba055509990555099905550999a05500000055
 -- 025:bb005555b00555559bb005559bba055509990555099905550999a05500000055
 -- 026:5099999950b999bb50b994f4550b94445000994b509bbbbb00990bb909980099
 -- 026:5099999950b999bb50b994f4550b94445000994b509bbbbb00990bb909980099
@@ -156,15 +209,15 @@ end
 -- 029:bbb90555bb005555abba05559999055508890555089905555099055550000555
 -- 029:bbb90555bb005555abba05559999055508890555089905555099055550000555
 -- 030:5fff5555fcccf555fcccf5555fff555555555555555555555555555555555555
 -- 030:5fff5555fcccf555fcccf5555fff555555555555555555555555555555555555
 -- 031:55ffff555f5555f5f55ff55ff5fccf5ff5fccf5ff55ff55f5f5555f555ffff55
 -- 031:55ffff555f5555f5f55ff55ff5fccf5ff5fccf5ff55ff55f5f5555f555ffff55
--- 032:55555000555500bb55500999555099995550b9995550b99455500b9455509b99
+-- 032:55555000555500bb55500a99555099995550b9995550b99455500b9455509b99
 -- 033:00555555b0055555ab00555599905555bb905555f49055554400000540009a00
 -- 033:00555555b0055555ab00555599905555bb905555f49055554400000540009a00
--- 034:5555555555555000555500bb55500999555099995550b9995550b99450000b94
+-- 034:5555555555555000555500bb55500a99555099995550b9995550b99450000b94
 -- 035:5555555500555555b0055555ab00555599905555bb905555f490555544000005
 -- 035:5555555500555555b0055555ab00555599905555bb905555f490555544000005
--- 036:55555000555500bb55500999555099995550b9995550b99455500b9455550099
+-- 036:55555000555500bb55500a99555099995550b9995550b99455500b9455550099
 -- 037:00555555b0055555ab00555599905555bb905555f49055554400000540009a00
 -- 037:00555555b0055555ab00555599905555bb905555f49055554400000540009a00
--- 038:5555555555555000555500bb55500999555099995550b9995550b99455500b94
+-- 038:5555555555555000555500bb55500a99555099995550b9995550b99455500b94
 -- 039:5555555500555555b0055555ab00555599905555bb905555f490555544000005
 -- 039:5555555500555555b0055555ab00555599905555bb905555f490555544000005
--- 040:55555000555500bb5000099950990999509909995099b99450099b945500bb99
+-- 040:55555000555500bb50000a9950990999509909995099b99450099b945500bb99
 -- 041:00555555b0055555ab00555599905555bb905555f4905555440000054b009a00
 -- 041:00555555b0055555ab00555599905555bb905555f4905555440000054b009a00
 -- 042:55555000555500bb55500a99555099995550b9995550b99455500b9455550099
 -- 042:55555000555500bb55500a99555099995550b9995550b99455500b9455550099
 -- 043:00555555b0055555ab00555599a05555bb905555349055554400555540055555
 -- 043:00555555b0055555ab00555599a05555bb905555349055554400555540055555
@@ -179,7 +232,7 @@ end
 -- 052:55500bbb5550b0bb5550b99955509999555099bb555099995550909955500089
 -- 052:55500bbb5550b0bb5550b99955509999555099bb555099995550909955500089
 -- 053:bbb999a0b000990090550005b9055555a005555590555555900555559a055555
 -- 053:bbb999a0b000990090550005b9055555a005555590555555900555559a055555
 -- 054:55550bb955550bbb555550bb50000b99009abb99099999000009900055000050
 -- 054:55550bb955550bbb555550bb50000b99009abb99099999000009900055000050
--- 055:40009a00b99999a0b990990000050005bba055559990555599905555899a0555
+-- 055:40009a00b99999a0b990990000050005bba05555999055559990555589990555
 -- 056:55500bbb555500bb5555509955550b9955550bb055009ab05509990555099805
 -- 056:55500bbb555500bb5555509955550b9955550bb055009ab05509990555099805
 -- 057:bbb999a0b00099009bb000059bba055509990555099905550999a05500000055
 -- 057:bbb999a0b00099009bb000059bba055509990555099905550999a05500000055
 -- 058:55000bbb5509b0bb5509909955099b99550000bb555009995550999955509988
 -- 058:55000bbb5509b0bb5509909955099b99550000bb555009995550999955509988

BIN
megamang/sprites.aseprite