Browse Source

Hello world

Eiyeron Fulmincendii 4 years ago
parent
commit
583a1b9e0f
1 changed files with 289 additions and 0 deletions
  1. 289 0
      drop_sokoban.p8

+ 289 - 0
drop_sokoban.p8

@@ -0,0 +1,289 @@
+pico-8 cartridge // http://www.pico-8.com
+version 32
+__lua__
+function _init()
+	u_state, d_state = u_waiting, d_waiting
+end
+
+
+function _update()
+	u_state()
+end
+
+function _draw()
+	d_state()
+end
+-->8
+-- waiting for a level
+
+-- 0x4300 - 0x5600
+function u_waiting()
+	if (not stat(120)) return
+	
+	-- resetting the player
+	player_x, player_y = nil, nil
+	
+	-- resetting the goal counter
+	remaining_goals = 0
+	
+	-- read header
+	
+	local end_of_header = false
+	local header_length = 0
+	repeat
+		local next_byte_addr = 0x4300 + header_length
+		serial(0x800, next_byte_addr, 1)
+		header_length += 1
+		-- stop at newline
+		end_of_header = @next_byte_addr == ord("\n")
+	until end_of_header
+	
+	-- parse the string
+	-- moved here for readability
+	-- but could be in the header loading code
+	local header_str = ""
+	for i=0,header_length-1 do
+		header_str ..= chr(@(i+0x4300))
+	end
+
+	-- map dimension extraction
+	-- let's say there is only one space between width and height
+	local map_width, map_height
+	for i=1,#header_str do
+		local c = sub(header_str,i,i)
+		if c == " " then
+			map_width = sub(header_str,1,i) + 0
+			map_height = sub(header_str,i+1) + 0
+			break
+		end
+	end
+	
+	-- map read
+	for y=0,map_height - 1 do
+		-- read a line
+		-- map_width + 1 to read the newline character
+		serial(0x800, 0x4300, map_width + 1)		
+		
+		-- parse the read data into the map data
+		
+		for x=0,map_width - 1 do
+			local val = @(0x4300 + x)
+			if val == ord("#") then
+				mset(x, y, 1)
+			-- goal
+			elseif val == ord(".") then
+				mset(x, y, 2)
+				remaining_goals += 1
+			-- box
+			elseif val == ord("$") then
+				mset(x, y, 3)
+			-- box on goal
+			elseif val == ord("*") then
+				mset(x, y, 4)
+			-- player
+			elseif val == ord("@") then
+				player_x, player_y = x, y
+			-- player on goal
+			elseif val == ord("+") then
+				player_x, player_y = x, y
+				remaining_goals += 1
+				mset(x, y, 4)
+			end
+		end
+	end
+	
+	u_state, d_state = u_game, d_game
+end
+
+function d_waiting()
+	cls()
+	print("waiting for a file to drop", 7)
+	local center_x, center_y = 64+32 * sin(t()/4), 96 + cos(t()/3)*16
+	circfill(center_x-1, center_y-1, 7.5, 1)
+	spr(t()%5, center_x-4, center_y-4)
+end
+-->8
+-- "game" state
+-- oh, you know what?
+-- let's do a sokoban
+function u_game()
+	local move_x, move_y = 0, 0
+	if(btnp(➡️)) move_x = 1
+	if(btnp(⬅️)) move_x = -1
+	if(btnp(⬇️)) move_y = 1
+	if(btnp(⬆️)) move_y = -1
+	
+	if remaining_goals == 0 then
+		u_state, d_state = u_waiting, d_waiting
+	end
+	
+	if move_x ~= 0 or move_y ~= 0 then
+		local next_x, next_y = player_x + move_x, player_y + move_y
+		local has_box = fget(mget(next_x, next_y), 1)
+		local has_wall = fget(mget(next_x, next_y), 2)
+		local has_goal = fget(mget(next_x, next_y), 0)
+		if has_box then
+			next_box_x, next_box_y = player_x + move_x*2, player_y + move_y*2
+			-- next box tile has box or wall? abort
+			if fget(mget(next_box_x, next_box_y), 1) or fget(mget(next_box_x, next_box_y), 2) then
+				return
+			end
+			mset(next_x, next_y, has_goal and 2 or 0)
+			local has_next_goal = fget(mget(next_box_x, next_box_y), 0)
+			mset(next_box_x, next_box_y, has_next_goal and 4 or 3)			
+			if(has_goal)remaining_goals += 1
+			if(has_next_goal)remaining_goals -= 1
+		end
+		if not has_wall then
+			player_x, player_y = next_x, next_y
+		end
+	end
+end
+
+function d_game()
+	cls()
+	map()
+	spr(0, player_x*8, player_y*8)
+end
+__gfx__
+0aaaaaa0666066665000000544444444dddddddd0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+aaaaaaaa666066665555555540044004dd0000dd0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+aa0aa0aa666066660005500044000044d00dd00d0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+aaaaaaaa000000000050050040044004dd0000dd0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+a000000a666660660500005044444444dddddddd0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+a000000a666660660500005040444404d0dddd0d0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+0a0000a0666660665050050540000004d000000d0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00aaaa00000000005555555540444404d0dddd0d0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+__label__
+88806666666066666660666666606666666066666660666666606666000000000000000000000000000000000000000000000000000000000000000000000000
+66806666666066666660666666606666666066666660666666606666000000000000000000000000000000000000000000000000000000000000000000000000
+88806666666066666660666666606666666066666660666666606666000000000000000000000000000000000000000000000000000000000000000000000000
+80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+88866066666660666666606666666066666660666666606666666066000000000000000000000000000000000000000000000000000000000000000000000000
+66666066666660666666606666666066666660666666606666666066000000000000000000000000000000000000000000000000000000000000000000000000
+66666066666660666666606666666066666660666666606666666066000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+66606666dddddddd0000000000000000666066660000000066606666000000000000000000000000000000000000000000000000000000000000000000000000
+66606666dd0000dd0000000000000000666066660000000066606666000000000000000000000000000000000000000000000000000000000000000000000000
+66606666d00dd00d0000000000000000666066660000000066606666000000000000000000000000000000000000000000000000000000000000000000000000
+00000000dd0000dd0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+66666066dddddddd0000000000000000666660660000000066666066000000000000000000000000000000000000000000000000000000000000000000000000
+66666066d0dddd0d0000000000000000666660660000000066666066000000000000000000000000000000000000000000000000000000000000000000000000
+66666066d000000d0000000000000000666660660000000066666066000000000000000000000000000000000000000000000000000000000000000000000000
+00000000d0dddd0d0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+6660666600000000dddddddd00000000444444440000000066606666000000000000000000000000000000000000000000000000000000000000000000000000
+6660666600000000dd0000dd00000000400440040000000066606666000000000000000000000000000000000000000000000000000000000000000000000000
+6660666600000000d00dd00d00000000440000440000000066606666000000000000000000000000000000000000000000000000000000000000000000000000
+0000000000000000dd0000dd00000000400440040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+6666606600000000dddddddd00000000444444440000000066666066000000000000000000000000000000000000000000000000000000000000000000000000
+6666606600000000d0dddd0d00000000404444040000000066666066000000000000000000000000000000000000000000000000000000000000000000000000
+6666606600000000d000000d00000000400000040000000066666066000000000000000000000000000000000000000000000000000000000000000000000000
+0000000000000000d0dddd0d00000000404444040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+6660666600000000000000000aaaaaa0444444440000000066606666000000000000000000000000000000000000000000000000000000000000000000000000
+666066660000000000000000aaaaaaaa400440040000000066606666000000000000000000000000000000000000000000000000000000000000000000000000
+666066660000000000000000aa0aa0aa440000440000000066606666000000000000000000000000000000000000000000000000000000000000000000000000
+000000000000000000000000aaaaaaaa400440040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+666660660000000000000000a000000a444444440000000066666066000000000000000000000000000000000000000000000000000000000000000000000000
+666660660000000000000000a000000a404444040000000066666066000000000000000000000000000000000000000000000000000000000000000000000000
+6666606600000000000000000a0000a0400000040000000066666066000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000aaaa00404444040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+66606666000000005000000550000005000000000000000066606666000000000000000000000000000000000000000000000000000000000000000000000000
+66606666000000005555555555555555000000000000000066606666000000000000000000000000000000000000000000000000000000000000000000000000
+66606666000000000005500000055000000000000000000066606666000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000050050000500500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+66666066000000000500005005000050000000000000000066666066000000000000000000000000000000000000000000000000000000000000000000000000
+66666066000000000500005005000050000000000000000066666066000000000000000000000000000000000000000000000000000000000000000000000000
+66666066000000005050050550500505000000000000000066666066000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000005555555555555555000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+666066660000000000000000dddddddd000000000000000066606666000000000000000000000000000000000000000000000000000000000000000000000000
+666066660000000000000000dd0000dd000000000000000066606666000000000000000000000000000000000000000000000000000000000000000000000000
+666066660000000000000000d00dd00d000000000000000066606666000000000000000000000000000000000000000000000000000000000000000000000000
+000000000000000000000000dd0000dd000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+666660660000000000000000dddddddd000000000000000066666066000000000000000000000000000000000000000000000000000000000000000000000000
+666660660000000000000000d0dddd0d000000000000000066666066000000000000000000000000000000000000000000000000000000000000000000000000
+666660660000000000000000d000000d000000000000000066666066000000000000000000000000000000000000000000000000000000000000000000000000
+000000000000000000000000d0dddd0d000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+66606666666066666660666666606666666066666660666666606666000000000000000000000000000000000000000000000000000000000000000000000000
+66606666666066666660666666606666666066666660666666606666000000000000000000000000000000000000000000000000000000000000000000000000
+66606666666066666660666666606666666066666660666666606666000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+66666066666660666666606666666066666660666666606666666066000000000000000000000000000000000000000000000000000000000000000000000000
+66666066666660666666606666666066666660666666606666666066000000000000000000000000000000000000000000000000000000000000000000000000
+66666066666660666666606666666066666660666666606666666066000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+
+__gff__
+0004010203000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000