WIP tile transition

This commit is contained in:
Simon Cambier 2022-07-12 21:47:10 +02:00
parent c5497d85d5
commit 57409bb7d6
14 changed files with 234 additions and 83 deletions

11
0hh1.p8
View File

@ -1,23 +1,28 @@
pico-8 cartridge // http://www.pico-8.com pico-8 cartridge // http://www.pico-8.com
version 36 version 36
__lua__ __lua__
-- enable mouse
poke(0x5F2D, 3)
-- Font M3X6 by daniel linssen -- Font M3X6 by daniel linssen
poke(0x5600, 4, 4, 7) poke(0x5600, 4, 4, 7)
poke4(0x5700,unpack(split"0x0000.0000,0x0000.0000,0x0202.0202,0x0000.0200,0x0000.0505,0x0000.0000,0x0505.0705,0x0000.0507,0x0407.0106,0x0000.0203,0x0204.0100,0x0000.0401,0x0102.0502,0x0000.0305,0x0000.0102,0x0000.0000,0x0101.0102,0x0000.0201,0x0202.0201,0x0000.0102,0x0205.0000,0x0000.0005,0x0702.0000,0x0000.0002,0x0000.0000,0x0000.0102,0x0700.0000,0x0000.0000,0x0000.0000,0x0000.0200,0x0202.0404,0x0000.0101,0x0505.0506,0x0000.0305,0x0202.0302,0x0000.0702,0x0204.0403,0x0000.0701,0x0403.0403,0x0000.0304,0x0406.0505,0x0000.0404,0x0403.0107,0x0000.0304,0x0503.0106,0x0000.0605,0x0204.0407,0x0000.0202,0x0502.0506,0x0000.0305,0x0605.0503,0x0000.0304,0x0002.0000,0x0000.0002,0x0002.0000,0x0000.0102,0x0102.0400,0x0000.0402,0x0007.0000,0x0000.0007,0x0402.0100,0x0000.0102,0x0204.0403,0x0000.0200,0x0505.0506,0x0000.0601,0x0604.0300,0x0000.0705,0x0505.0301,0x0000.0705,0x0101.0600,0x0000.0701,0x0505.0604,0x0000.0705,0x0705.0600,0x0000.0601,0x0702.0204,0x0000.0202,0x0705.0600,0x0000.0304,0x0505.0301,0x0000.0505,0x0202.0002,0x0000.0202,0x0202.0002,0x0000.0102,0x0305.0101,0x0000.0505,0x0202.0202,0x0000.0402,0x0707.0300,0x0000.0507,0x0505.0300,0x0000.0505,0x0505.0600,0x0000.0305,0x0305.0700,0x0000.0101,0x0705.0600,0x0000.0404,0x0101.0600,0x0000.0101,0x0701.0600,0x0000.0304,0x0207.0202,0x0000.0202,0x0505.0500,0x0000.0705,0x0505.0500,0x0000.0205,0x0705.0500,0x0000.0507,0x0205.0500,0x0000.0505,0x0605.0500,0x0000.0304,0x0204.0700,0x0000.0701,0x0101.0103,0x0000.0301,0x0202.0101,0x0000.0404,0x0202.0203,0x0000.0302,0x0000.0502,0x0000.0000,0x0000.0000,0x0000.0403,0x0000.0201,0x0000.0000,0x0507.0506,0x0000.0505,0x0507.0503,0x0000.0705,0x0101.0106,0x0000.0701,0x0505.0503,0x0000.0305,0x0103.0107,0x0000.0701,0x0301.0106,0x0000.0101,0x0501.0106,0x0000.0705,0x0507.0505,0x0000.0505,0x0202.0207,0x0000.0702,0x0404.0407,0x0000.0304,0x0503.0505,0x0000.0505,0x0101.0101,0x0000.0701,0x0507.0705,0x0000.0505,0x0505.0503,0x0000.0505,0x0505.0506,0x0000.0305,0x0103.0507,0x0000.0101,0x0505.0506,0x0000.0403,0x0503.0507,0x0000.0505,0x0407.0106,0x0000.0304,0x0202.0207,0x0000.0202,0x0505.0505,0x0000.0705,0x0505.0505,0x0000.0205,0x0705.0505,0x0000.0507,0x0202.0505,0x0000.0505,0x0205.0505,0x0000.0202,0x0202.0407,0x0000.0701,0x0302.0204,0x0000.0402,0x0202.0202,0x0000.0202,0x0602.0201,0x0000.0102,0x0704.0000,0x0000.0001,0x0205.0200,0x0000.0000")) poke4(0x5700,unpack(split"0x0000.0000,0x0000.0000,0x0202.0202,0x0000.0200,0x0000.0505,0x0000.0000,0x0505.0705,0x0000.0507,0x0407.0106,0x0000.0203,0x0204.0100,0x0000.0401,0x0102.0502,0x0000.0305,0x0000.0102,0x0000.0000,0x0101.0102,0x0000.0201,0x0202.0201,0x0000.0102,0x0205.0000,0x0000.0005,0x0702.0000,0x0000.0002,0x0000.0000,0x0000.0102,0x0700.0000,0x0000.0000,0x0000.0000,0x0000.0200,0x0202.0404,0x0000.0101,0x0505.0506,0x0000.0305,0x0202.0302,0x0000.0702,0x0204.0403,0x0000.0701,0x0403.0403,0x0000.0304,0x0406.0505,0x0000.0404,0x0403.0107,0x0000.0304,0x0503.0106,0x0000.0605,0x0204.0407,0x0000.0202,0x0502.0506,0x0000.0305,0x0605.0503,0x0000.0304,0x0002.0000,0x0000.0002,0x0002.0000,0x0000.0102,0x0102.0400,0x0000.0402,0x0007.0000,0x0000.0007,0x0402.0100,0x0000.0102,0x0204.0403,0x0000.0200,0x0505.0506,0x0000.0601,0x0604.0300,0x0000.0705,0x0505.0301,0x0000.0705,0x0101.0600,0x0000.0701,0x0505.0604,0x0000.0705,0x0705.0600,0x0000.0601,0x0702.0204,0x0000.0202,0x0705.0600,0x0000.0304,0x0505.0301,0x0000.0505,0x0202.0002,0x0000.0202,0x0202.0002,0x0000.0102,0x0305.0101,0x0000.0505,0x0202.0202,0x0000.0402,0x0707.0300,0x0000.0507,0x0505.0300,0x0000.0505,0x0505.0600,0x0000.0305,0x0305.0700,0x0000.0101,0x0705.0600,0x0000.0404,0x0101.0600,0x0000.0101,0x0701.0600,0x0000.0304,0x0207.0202,0x0000.0202,0x0505.0500,0x0000.0705,0x0505.0500,0x0000.0205,0x0705.0500,0x0000.0507,0x0205.0500,0x0000.0505,0x0605.0500,0x0000.0304,0x0204.0700,0x0000.0701,0x0101.0103,0x0000.0301,0x0202.0101,0x0000.0404,0x0202.0203,0x0000.0302,0x0000.0502,0x0000.0000,0x0000.0000,0x0000.0403,0x0000.0201,0x0000.0000,0x0507.0506,0x0000.0505,0x0507.0503,0x0000.0705,0x0101.0106,0x0000.0701,0x0505.0503,0x0000.0305,0x0103.0107,0x0000.0701,0x0301.0106,0x0000.0101,0x0501.0106,0x0000.0705,0x0507.0505,0x0000.0505,0x0202.0207,0x0000.0702,0x0404.0407,0x0000.0304,0x0503.0505,0x0000.0505,0x0101.0101,0x0000.0701,0x0507.0705,0x0000.0505,0x0505.0503,0x0000.0505,0x0505.0506,0x0000.0305,0x0103.0507,0x0000.0101,0x0505.0506,0x0000.0403,0x0503.0507,0x0000.0505,0x0407.0106,0x0000.0304,0x0202.0207,0x0000.0202,0x0505.0505,0x0000.0705,0x0505.0505,0x0000.0205,0x0705.0505,0x0000.0507,0x0202.0505,0x0000.0505,0x0205.0505,0x0000.0202,0x0202.0407,0x0000.0701,0x0302.0204,0x0000.0402,0x0202.0202,0x0000.0202,0x0602.0201,0x0000.0102,0x0704.0000,0x0000.0001,0x0205.0200,0x0000.0000"))
#include main.lua #include globals.lua
--
#include board.lua #include board.lua
#include coroutines.lua #include coroutines.lua
#include ui.lua #include ui.lua
#include utils.lua #include utils.lua
#include bg.lua #include bg.lua
#include visuals.lua
--
#include states/menu.lua #include states/menu.lua
#include states/loading.lua #include states/loading.lua
#include states/game.lua #include states/game.lua
#include states/rules.lua #include states/rules.lua
#include states/endgame.lua
--
#include main.lua
__gfx__ __gfx__
00000000110000000001110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000110000000001110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

4
bg.lua
View File

@ -29,3 +29,7 @@ function draw_animated_bg(startx)
color) color)
end end
end end
function draw_bg_menu()
end

View File

@ -2,7 +2,7 @@ local Board = {}
function Board.new() function Board.new()
local debug = false local debug = false
local width = 8 -- tiles local width = 4 -- tiles
local tile_width = 10 -- pixels local tile_width = 10 -- pixels
local padding = 1 local padding = 1
local tiles = {} local tiles = {}
@ -68,13 +68,21 @@ function Board.new()
end, end,
try_flip_tile = function(self, id) try_flip_tile = function(self, id)
local to_color = nil
if locked[id] then return end if locked[id] then return end
local from_color = tiles[id]
if tiles[id] == 0 then if tiles[id] == 0 then
tiles[id] = YELLOW to_color = YELLOW
elseif tiles[id] == YELLOW then elseif tiles[id] == YELLOW then
tiles[id] = BLUE to_color = BLUE
else tiles[id] = 0 else tiles[id] = 0
-- empty tile
end end
if to_color then
tiles[id] = to_color
end
local x,y = self:draw_coords(id)
spawn_tile_transition(x, y, tile_width-1, tile_width-1, from_color, to_color)
end, end,
get_rows = function(self) get_rows = function(self)
@ -420,14 +428,15 @@ function Board.new()
local v = tiles[idx] local v = tiles[idx]
if v > 0 then if v > 0 then
local x,y = self:draw_coords(idx) local x,y = self:draw_coords(idx)
local color = v == BLUE and 12 or 8 local color = get_main_color(v)
local shade = get_shade_color(v)
if color == 1 then fillp() else fillp() end if color == 1 then fillp() else fillp() end
if self:is_locked(idx) then if self:is_locked(idx) then
rectfill2(x, y, w, w, color) rectfill2(x, y, w, w, color)
else else
roundedrect(x, y, w, w, color) roundedrect(x, y, w, w, color)
line(x+1, y+w-1, x+w-2, y+w-1, color+1) line(x+1, y+w-1, x+w-2, y+w-1, shade)
line(x+w-1, y+1, x+w-1, y+w-2, color+1) line(x+w-1, y+1, x+w-1, y+w-2, shade)
end end
else else
fillp() fillp()

View File

@ -23,7 +23,7 @@ end
-- to be used inside a coroutine -- to be used inside a coroutine
function wait(seconds) function wait(seconds)
wait_frames(seconds*60) wait_frames(seconds*30)
end end
-- to be used inside a coroutine -- to be used inside a coroutine

View File

@ -1,3 +1,33 @@
local amplitude = 128 local amplitude = 128
local mouse_x = 0 local mouse_x = 0
local mouse_y = 0 local mouse_y = 0
--
-- constants
--
local BLUE = 1
local YELLOW = 2
-- 🅾️ Z[C]N ❎ [X]VM
-- X and C have the same position on QWERTY and AZERTY
local LEFT,RIGHT,UP,DOWN,BTN_O,BTN_X = 0,1,2,3,4,5
local patterns = {
0b1000000000000000,
0b1000000000100000,
0b1010000000100000,
0b1010000010100000,
0b1010010010100000,
0b1010010010100001,
0b1010010110100001,
0b1010010110100101,
0b1110010110100101,
0b1110010110110101,
0b1111010110110101,
0b1111010111110101,
0b1111110111110101,
0b1111110111110111,
0b1111111111110111,
0b1111111111111111,
}

View File

@ -1,14 +1,3 @@
--
-- constants
--
local BLUE = 1
local YELLOW = 2
-- 🅾️ Z[C]N ❎ [X]VM
-- X and C have the same position on QWERTY and AZERTY
local LEFT,RIGHT,UP,DOWN,BTN_O,BTN_X = 0,1,2,3,4,5
-- --
-- Utils -- Utils
-- --
@ -118,25 +107,30 @@ function _init()
states = { states = {
rules = state_rules(), rules = state_rules(),
menu = state_menu(), menu = state_menu(),
game = state_game(),
loading = state_loading(), loading = state_loading(),
game = state_game(),
endgame = state_endgame(),
} }
set_state(states.loading) set_state(states.menu)
end end
function _update60() function _update60()
frame_count += 1 frame_count += 1
_coresolve()
gs._update()
-- update mouse coords -- update mouse coords
mouse_x = stat(32) mouse_x = stat(32)
mouse_y = stat(33) mouse_y = stat(33)
_coresolve()
gs._update()
end end
function _draw() function _draw()
gs._draw() gs._draw()
for overlay in all(overlays) do
overlay:_draw()
end
spr(1, stat(32), stat(33)) spr(1, stat(32), stat(33))
end end

51
states/endgame.lua Normal file
View File

@ -0,0 +1,51 @@
function state_endgame()
local board
local message = "웃웃 yay! 웃웃"
local message_x = 0
local btn_back = make_button({x=1, y=118, h=7, text="🅾️/C bACK TO mENU", color=8,
on_click=function() go_to_menu() end,
on_hover=function(btn) btn.color = 7 end})
local function go_to_menu()
set_state(states.menu)
end
local function _enter(_board)
board = _board
message_x = (128 - print(message,0,-100))/2
end
local function _update()
btn_back:update()
if btnp(BTN_O) then
go_to_menu()
end
end
local function _draw()
cls()
board:draw()
-- wavy message
local offset=0
for i = 1, #message, 1 do -- loop through every letter
letter = sub(message, i, i) -- grab this letter
local st = t() + 0.125 * i -- create a modified time for this letter
print(letter, message_x + offset, 20 + sin(st*0.5)*10, 7) -- draw this letter
offset += print(letter,0,-100)
end
btn_back:draw()
end
local function _leave()
end
return {
_enter = _enter,
_update = _update,
_draw = _draw,
_leave = _leave
}
end

View File

@ -3,6 +3,7 @@ function state_game()
local board local board
local selected_id = 1 local selected_id = 1
local timer_clue = 0 local timer_clue = 0
local mx,mx = 0,0
local clues = {} local clues = {}
local function show_clues() local function show_clues()
@ -27,7 +28,6 @@ function state_game()
fillp() fillp()
end end
local mx,mx = 0,0
local function update_mouse() local function update_mouse()
-- update mouse position -- update mouse position
if mx == mouse_x and my == mouse_y then return end if mx == mouse_x and my == mouse_y then return end
@ -39,10 +39,19 @@ function state_game()
local x = mid(1, (mouse_x - board_x) \ tw + 1, bw) local x = mid(1, (mouse_x - board_x) \ tw + 1, bw)
local y = mid(1, (mouse_y - board_y) \ tw + 1, bw) local y = mid(1, (mouse_y - board_y) \ tw + 1, bw)
selected_id = board:xy_idx(x,y) selected_id = board:xy_idx(x,y)
printh("x: " .. x .. " y: " .. y .. " id: " .. selected_id) -- printh("x: " .. x .. " y: " .. y .. " id: " .. selected_id)
end
local function check_endgame()
if board:is_complete() and board:is_valid() then
set_state(states.endgame, board)
end
end end
local function _enter(_board) local function _enter(_board)
-- mouse bound to buttons
poke(0x5F2D, 3)
board = _board board = _board
-- lock the initial tiles -- lock the initial tiles
board:lock_tiles() board:lock_tiles()
@ -52,6 +61,43 @@ function state_game()
-- stopcoroutine(show_clues) -- stopcoroutine(show_clues)
end end
local function _update()
local size = board:get_size()
local x, y = board:idx_xy(selected_id)
local moved = false
if btnp(UP) then
moved = true
y -= 1
elseif btnp(DOWN) then
moved = true
y += 1
elseif btnp(LEFT) then
moved = true
x -= 1
elseif btnp(RIGHT) then
moved = true
x += 1
end
if moved then
selected_id = board:xy_idx(x, y)
end
if btnp(BTN_X) then
board:try_flip_tile(selected_id)
show_clues()
end
update_mouse()
if (x<1) x=size
if (x>size) x=1
if (y<1) y=size
if (y>size) y=1
check_endgame()
end
local function _draw() local function _draw()
cls() cls()
local x,y = board:draw_coords(1) local x,y = board:draw_coords(1)
@ -80,40 +126,6 @@ function state_game()
palt() palt()
end end
local function _update()
local size = board:get_size()
local x, y = board:idx_xy(selected_id)
local moved = false
if btnp(UP) then
moved = true
y -= 1
elseif btnp(DOWN) then
moved = true
y += 1
elseif btnp(LEFT) then
moved = true
x -= 1
elseif btnp(RIGHT) then
moved = true
x += 1
end
if moved then
selected_id = board:xy_idx(x, y)
end
if btnp(BTN_X) then
board:try_flip_tile(selected_id)
show_clues()
end
update_mouse()
if (x<1) x=size
if (x>size) x=1
if (y<1) y=size
if (y>size) y=1
end
return { return {
_enter = _enter, _enter = _enter,
_update = _update, _update = _update,

View File

@ -114,7 +114,6 @@ function state_loading()
end end
messages_str ..= "tHANK YOU FOR YOUR PATIENCE" messages_str ..= "tHANK YOU FOR YOUR PATIENCE"
custom_font()
startcoroutine(create_board) startcoroutine(create_board)
end end

View File

@ -8,18 +8,28 @@ function state_menu()
end end
local buttons = { local buttons = {
make_button({x=10, y=10, w=30, text="play", data={i=1}, make_button({x=10, y=10, w=30, text="pLAY", data={i=1},
on_click=function() set_state(states.loading) end, on_click=function() set_state(states.loading) end,
on_hover=function(btn) btn.color = 7 selected = 1 end, on_hover=function(btn) btn.color = 7 selected = 1 end,
on_draw=on_btn_draw}), on_draw=on_btn_draw}),
make_button({x=10, y=20, w=30, text="rules", data={i=2}, make_button({x=10, y=20, w=30, text="rULES", data={i=2},
on_click=function() set_state(states.rules) end, on_click=function() set_state(states.rules) end,
on_hover=function(btn) btn.color = 7 selected = 2 end, on_hover=function(btn) btn.color = 7 selected = 2 end,
on_draw=on_btn_draw}) on_draw=on_btn_draw})
} }
local function _enter() local function _enter()
-- mouse not bound to buttons
poke(0x5F2D, 1)
end
local function _draw()
cls()
draw_bg_menu()
for k,button in ipairs(buttons) do
button:draw(selected == k)
end
print("pRESS ❎/X TO CONTINUE", 8, 120, 7)
end end
return { return {
@ -34,19 +44,13 @@ function state_menu()
selected -= 1 selected -= 1
elseif btnp(DOWN) then elseif btnp(DOWN) then
selected += 1 selected += 1
elseif btnp(BTN_O) then elseif btnp(BTN_X) then
buttons[selected]:on_click() buttons[selected]:on_click()
end end
selected = mid(1, selected, #buttons) selected = mid(1, selected, #buttons)
end, end,
_draw = function() _draw = _draw
cls()
for k,button in ipairs(buttons) do
button:draw(selected == k)
end
print("press 🅾️/c to continue", 8, 120, 7)
end
} }
end end

View File

@ -11,11 +11,19 @@ function state_rules()
set_state(states.menu) set_state(states.menu)
end end
local btn_back = make_button({x=1, y=118, w=30, h=7, text="❎menu", color=8, local btn_back = make_button({x=1, y=118, w=30, h=7, text="🅾️/C mENU", color=8,
on_click=function() go_back() end, on_click=function() go_back() end,
on_hover=function(btn) btn.color = 7 end}) on_hover=function(btn) btn.color = 7 end})
return { return {
_enter = function()
custom_font()
end,
_exit = function()
standard_font()
end,
_update=function() _update=function()
if frame_count%8==0 then if frame_count%8==0 then
color += 1 color += 1
@ -34,7 +42,6 @@ function state_rules()
_draw=function() _draw=function()
cls() cls()
custom_font()
print("1) yOU CAN'T HAVE MORE THAN\n TWO (2) CONSECUTIVE TILES\n OF THE SAME COLOR", 2,2, 7) print("1) yOU CAN'T HAVE MORE THAN\n TWO (2) CONSECUTIVE TILES\n OF THE SAME COLOR", 2,2, 7)
local x = 14 local x = 14

8
ui.lua
View File

@ -1,9 +1,10 @@
function make_button(options) function make_button(options)
local state = 0 -- 0 = normal, 1 = hovered, 2 = pressed local state = 0 -- 0 = normal, 1 = hovered, 2 = pressed
local w = print(options.text, 0, -100)
return { return {
x = options.x, x = options.x,
y = options.y, y = options.y,
w = options.w, w = options.w or w,
h = options.h or 6, h = options.h or 6,
data = options.data, data = options.data,
text = options.text, text = options.text,
@ -39,8 +40,3 @@ function make_button(options)
end end
} }
end end
function print_shadow(text, x, y, color)
print(text, x+1, y+1, 0)
print(text, x, y, color)
end

View File

@ -7,7 +7,7 @@ function print(t,x,y,col1,col2)
end end
end end
end end
oldprint(t, x, y, col1) return oldprint(t, x, y, col1)
end end
function str_width(str) function str_width(str)

40
visuals.lua Normal file
View File

@ -0,0 +1,40 @@
local overlays = {}
function get_main_color(tint)
if tint == BLUE then
return 12
elseif tint == YELLOW then
return 8
else
return 1
end
end
function get_shade_color(tint)
if tint == BLUE then
return 13
elseif tint == YELLOW then
return 4
else
return 1
end
end
function spawn_tile_transition(x, y, w, h, from_tint, to_tint)
local p = #patterns
printh(patterns)
local from_color = get_main_color(from_tint)
local to_color = get_main_color(to_tint)
add(overlays, {
_draw = function(self)
fillp()
rectfill(x, y, x + w, y + h, from_color)
fillp(patterns[p]+0b0.1)
rectfill(x, y, x + w, y + h, to_color)
p -= 2
if p < 1 then
del(overlays, self)
end
end
})
end