WIP tile transition

This commit is contained in:
2022-07-12 21:47:18 +02:00
parent c5497d85d5
commit 57409bb7d6
14 changed files with 234 additions and 83 deletions
+51
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
+48 -36
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,
-1
View File
@@ -114,7 +114,6 @@ function state_loading()
end
messages_str ..= "tHANK YOU FOR YOUR PATIENCE"
custom_font()
startcoroutine(create_board)
end
+14 -10
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
+9 -2
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