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
version 36
__lua__
-- enable mouse
poke(0x5F2D, 3)
-- Font M3X6 by daniel linssen
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"))
#include main.lua
#include globals.lua
--
#include board.lua
#include coroutines.lua
#include ui.lua
#include utils.lua
#include bg.lua
#include visuals.lua
--
#include states/menu.lua
#include states/loading.lua
#include states/game.lua
#include states/rules.lua
#include states/endgame.lua
--
#include main.lua
__gfx__
00000000110000000001110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

4
bg.lua
View File

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

View File

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

View File

@ -23,12 +23,12 @@ end
-- to be used inside a coroutine
function wait(seconds)
wait_frames(seconds*60)
wait_frames(seconds*30)
end
-- to be used inside a coroutine
function wait_frames(frames)
for i=1,frames do
yield()
yield()
end
end

View File

@ -1,3 +1,33 @@
local amplitude = 128
local mouse_x = 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
--
@ -118,25 +107,30 @@ function _init()
states = {
rules = state_rules(),
menu = state_menu(),
game = state_game(),
loading = state_loading(),
game = state_game(),
endgame = state_endgame(),
}
set_state(states.loading)
set_state(states.menu)
end
function _update60()
frame_count += 1
_coresolve()
gs._update()
-- update mouse coords
mouse_x = stat(32)
mouse_y = stat(33)
_coresolve()
gs._update()
end
function _draw()
gs._draw()
for overlay in all(overlays) do
overlay:_draw()
end
spr(1, stat(32), stat(33))
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 selected_id = 1
local timer_clue = 0
local mx,mx = 0,0
local clues = {}
local function show_clues()
@ -27,7 +28,6 @@ function state_game()
fillp()
end
local mx,mx = 0,0
local function update_mouse()
-- update mouse position
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 y = mid(1, (mouse_y - board_y) \ tw + 1, bw)
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
local function _enter(_board)
-- mouse bound to buttons
poke(0x5F2D, 3)
board = _board
-- lock the initial tiles
board:lock_tiles()
@ -52,6 +61,43 @@ function state_game()
-- stopcoroutine(show_clues)
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()
cls()
local x,y = board:draw_coords(1)
@ -80,40 +126,6 @@ function state_game()
palt()
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 {
_enter = _enter,
_update = _update,

View File

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

View File

@ -8,18 +8,28 @@ function state_menu()
end
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_hover=function(btn) btn.color = 7 selected = 1 end,
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_hover=function(btn) btn.color = 7 selected = 2 end,
on_draw=on_btn_draw})
}
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
return {
@ -34,19 +44,13 @@ function state_menu()
selected -= 1
elseif btnp(DOWN) then
selected += 1
elseif btnp(BTN_O) then
elseif btnp(BTN_X) then
buttons[selected]:on_click()
end
selected = mid(1, selected, #buttons)
end,
_draw = function()
cls()
for k,button in ipairs(buttons) do
button:draw(selected == k)
end
print("press 🅾️/c to continue", 8, 120, 7)
end
_draw = _draw
}
end

View File

@ -11,11 +11,19 @@ function state_rules()
set_state(states.menu)
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_hover=function(btn) btn.color = 7 end})
return {
_enter = function()
custom_font()
end,
_exit = function()
standard_font()
end,
_update=function()
if frame_count%8==0 then
color += 1
@ -34,7 +42,6 @@ function state_rules()
_draw=function()
cls()
custom_font()
print("1) yOU CAN'T HAVE MORE THAN\n TWO (2) CONSECUTIVE TILES\n OF THE SAME COLOR", 2,2, 7)
local x = 14

8
ui.lua
View File

@ -1,9 +1,10 @@
function make_button(options)
local state = 0 -- 0 = normal, 1 = hovered, 2 = pressed
local w = print(options.text, 0, -100)
return {
x = options.x,
y = options.y,
w = options.w,
w = options.w or w,
h = options.h or 6,
data = options.data,
text = options.text,
@ -39,8 +40,3 @@ function make_button(options)
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
oldprint(t, x, y, col1)
return oldprint(t, x, y, col1)
end
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