From c5497d85d5aa0e26a71f256a73d5185c8c423996 Mon Sep 17 00:00:00 2001 From: Simon Cambier Date: Sun, 10 Jul 2022 16:39:11 +0200 Subject: [PATCH] Click to switch tiles --- 0hh1.p8 | 146 +++++++++++++++++++++++++++++++++++++++++++++--- board.lua | 6 +- globals.lua | 2 + main.lua | 10 +--- states/game.lua | 30 +++++++++- 5 files changed, 172 insertions(+), 22 deletions(-) diff --git a/0hh1.p8 b/0hh1.p8 index a671585..604d719 100644 --- a/0hh1.p8 +++ b/0hh1.p8 @@ -2,7 +2,7 @@ pico-8 cartridge // http://www.pico-8.com version 36 __lua__ -- enable mouse -poke(0x5F2D, 1) +poke(0x5F2D, 3) -- Font M3X6 by daniel linssen poke(0x5600, 4, 4, 7) @@ -21,13 +21,13 @@ poke4(0x5700,unpack(split"0x0000.0000,0x0000.0000,0x0202.0202,0x0000.0200,0x0000 __gfx__ 00000000110000000001110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 -00000000131000000001711000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 -00700700133100001111771100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 -00077000133310001777777100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 -00077000133331001777777100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 -00700700133310001111771100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 -00000000131331000001711000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 -00000000010131000001110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000171000000001711000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00700700177100001111771100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00077000177710001777777100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00077000177771001777777100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00700700177710001111771100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000171771000001711000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000010171000001110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 55505550505050505050505055555555000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 50555055050505050500050055555555000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 55505550505050500050505050555055000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 @@ -63,3 +63,133 @@ cc0cc01101100cc0cc08801100110110110110011011011011001101101101100880110110110088 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 110cc0cc01100880cc0cc0880011011088011001101108801100cc01101101100cc01101101100880cc0880cc00880cc0880cc00000000000000000000000000 110cc0cc01100880cc0cc0880011011088011001101108801100cc01101101100cc01101101100880cc0880cc00880cc0880cc00000000000000000000000000 +__label__ +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +000000000cccccccc000cccccccc00088888888000cccccccc0008888888800088888888000cccccccc00088888888000cccccccc00088888888000000000000 +00000000cccccccccd0cccccccccd088888888890cccccccccd08888888889088888888890cccccccccd088888888890cccccccccd0888888888900000000000 +00000000cccccccccd0cccccccccd088888888890cccccccccd08888888889088888888890cccccccccd088888888890cccccccccd0888888888900000000000 +00000000cccccccccd0cccccccccd088888888890cccccccccd08888888889088888888890cccccccccd088888888890cccccccccd0888888888900000000000 +00000000cccccccccd0cccccccccd088888888890cccccccccd08888888889088888888890cccccccccd088888888890cccccccccd0888888888900000000000 +00000000cccccccccd0cccccccccd088888888890cccccccccd08888888889088888888890cccccccccd088888888890cccccccccd0888888888900000000000 +00000000cccccccccd0cccccccccd088888888890cccccccccd08888888889088888888890cccccccccd088888888890cccccccccd0888888888900000000000 +00000000cccccccccd0cccccccccd088888888890cccccccccd08888888889088888888890cccccccccd088888888890cccccccccd0888888888900000000000 +00000000cccccccccd0cccccccccd088888888890cccccccccd08888888889088888888890cccccccccd088888888890cccccccccd0888888888900000000000 +000000000dddddddd000dddddddd00099999999000dddddddd0009999999900099999999000dddddddd00099999999000dddddddd00099999999000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +000000000888888880008888888800cccccccccc008888888800cccccccccc0cccccccccc0088888888000cccccccc0088888888880cccccccccc00000000000 +000000008888888889088888888890cccccccccc088888888890cccccccccc0cccccccccc088888888890cccccccccd088888888880cccccccccc00000000000 +000000008888888889088888888890cccccccccc088888888890cccccccccc0cccccccccc088888888890cccccccccd088888888880cccccccccc00000000000 +000000008888888889088888888890cccccccccc088888888890cccccccccc0cccccccccc088888888890cccccccccd088888888880cccccccccc00000000000 +000000008888888889088888888890cccccccccc088888888890cccccccccc0cccccccccc088888888890cccccccccd088888888880cccccccccc00000000000 +000000008888888889088888888890cccccccccc088888888890cccccccccc0cccccccccc088888888890cccccccccd088888888880cccccccccc00000000000 +000000008888888889088888888890cccccccccc088888888890cccccccccc0cccccccccc088888888890cccccccccd088888888880cccccccccc00000000000 +000000008888888889088888888890cccccccccc088888888890cccccccccc0cccccccccc088888888890cccccccccd088888888880cccccccccc00000000000 +000000008888888889088888888890cccccccccc088888888890cccccccccc0cccccccccc088888888890cccccccccd088888888880cccccccccc00000000000 +000000000999999990009999999900cccccccccc009999999900cccccccccc0cccccccccc0099999999000dddddddd0088888888880cccccccccc00000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +000000000cccccccc0008888888800088888888000cccccccc000cccccccc0008888888800088888888000cccccccc00088888888000cccccccc000000000000 +00000000cccccccccd08888888889088888888890cccccccccd0cccccccccd08888888889088888888890cccccccccd088888888890cccccccccd00000000000 +00000000cccccccccd08888888889088888888890cccccccccd0cccccccccd08888888889088888888890cccccccccd088888888890cccccccccd00000000000 +00000000cccccccccd08888888889088888888890cccccccccd0cccccccccd08888888889088888888890cccccccccd088888888890cccccccccd00000000000 +00000000cccccccccd08888888889088888888890cccccccccd0cccccccccd08888888889088888888890cccccccccd088888888890cccccccccd00000000000 +00000000cccccccccd08888888889088888888890cccccccccd0cccccccccd08888888889088888888890cccccccccd088888888890cccccccccd00000000000 +00000000cccccccccd08888888889088888888890cccccccccd0cccccccccd08888888889088888888890cccccccccd088888888890cccccccccd00000000000 +00000000cccccccccd08888888889088888888890cccccccccd0cccccccccd08888888889088888888890cccccccccd088888888890cccccccccd00000000000 +00000000cccccccccd08888888889088888888890cccccccccd0cccccccccd08888888889088888888890cccccccccd088888888890cccccccccd00000000000 +000000000dddddddd0009999999900099999999000dddddddd000dddddddd0009999999900099999999000dddddddd00099999999000dddddddd000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +0000000008888888800cccccccccc00cccccccc008888888888008888888800cccccccccc0cccccccccc0088888888000cccccccc00888888888800000000000 +0000000088888888890cccccccccc0cccccccccd08888888888088888888890cccccccccc0cccccccccc088888888890cccccccccd0888888888800000000000 +0000000088888888890cccccccccc0cccccccccd08888888888088888888890cccccccccc0cccccccccc088888888890cccccccccd0888888888800000000000 +0000000088888888890cccccccccc0cccccccccd08888888888088888888890cccccccccc0cccccccccc088888888890cccccccccd0888888888800000000000 +0000000088888888890cccccccccc0cccccccccd08888888888088888888890cccccccccc0cccccccccc088888888890cccccccccd0888888888800000000000 +0000000088888888890cccccccccc0cccccccccd08888888888088888888890cccccccccc0cccccccccc088888888890cccccccccd0888888888800000000000 +0000000088888888890cccccccccc0cccccccccd08888888888088888888890cccccccccc0cccccccccc088888888890cccccccccd0888888888800000000000 +0000000088888888890cccccccccc0cccccccccd08888888888088888888890cccccccccc0cccccccccc088888888890cccccccccd0888888888800000000000 +0000000088888888890cccccccccc0cccccccccd08888888888088888888890cccccccccc0cccccccccc088888888890cccccccccd0888888888800000000000 +0000000009999999900cccccccccc00dddddddd008888888888009999999900cccccccccc0cccccccccc0099999999000dddddddd00888888888800000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +000000000cccccccc00088888888000cccccccc00888888888800cccccccc0008888888800cccccccccc008888888800cccccccccc0888888888800000000000 +00000000cccccccccd088888888890cccccccccd088888888880cccccccccd088888888890cccccccccc088888888890cccccccccc0888888888800000000000 +00000000cccccccccd088888888890cccccccccd088888888880cccccccccd088888888890cccccccccc088888888890cccccccccc0888888888800000000000 +00000000cccccccccd088888888890cccccccccd088888888880cccccccccd088888888890cccccccccc088888888890cccccccccc0888888888800000000000 +00000000cccccccccd088888888890cccccccccd088888888880cccccccccd088888888890cccccccccc088888888890cccccccccc0888888888800000000000 +00000000cccccccccd088888888890cccccccccd088888888880cccccccccd088888888890cccccccccc088888888890cccccccccc0888888888800000000000 +00000000cccccccccd088888888890cccccccccd088888888880cccccccccd088888888890cccccccccc088888888890cccccccccc0888888888800000000000 +00000000cccccccccd088888888890cccccccccd088888888880cccccccccd088888888890cccccccccc088888888890cccccccccc0888888888800000000000 +00000000cccccccccd088888888890cccccccccd088888888880cccccccccd088888888890cccccccccc088888888890cccccccccc0888888888800000000000 +000000000dddddddd00099999999000dddddddd00888888888800dddddddd0009999999900cccccccccc009999999900cccccccccc0888888888800000000000 +00000000000000000000000000000000000000000000000000066666666666600000000000000000000000000000000000000000000000000000000000000000 +00000000888888888800cccccccc00888888888800cccccccc06088888888060cccccccc00088888888000cccccccc00088888888000cccccccc000000000000 +0000000088888888880cccccccccd088888888880cccccccccd688888888896cccccccccd088888888890cccccccccd088888888890cccccccccd00000000000 +0000000088888888880cccccccccd088888888880cccccccccd688888888896cccccccccd088888888890cccccccccd088888888890cccccccccd00000000000 +0000000088888888880cccccccccd088888888880cccccccccd688888888896cccccccccd088888888890cccccccccd088888888890cccccccccd00000000000 +0000000088888888880cccccccccd088888888880cccccccccd688888888896cccccccccd088888888890cccccccccd088888888890cccccccccd00000000000 +0000000088888888880cccccccccd088888888880cccccccccd688888888896cccccccccd088888888890cccccccccd088888888890cccccccccd00000000000 +0000000088888888880cccccccccd088888888880cccccccccd688888888896cccccccccd088888888890cccccccccd088888888890cccccccccd00000000000 +0000000088888888880cccccccccd088888888880cccccccccd688888888896cccccccccd088888888890cccccccccd088888888890cccccccccd00000000000 +0000000088888888880cccccccccd088888888880cccccccccd688888888896cccccccccd088888888890cccccccccd088888888890cccccccccd00000000000 +00000000888888888800dddddddd00888888888800dddddddd06099999999060dddddddd00099999999000dddddddd00099999999000dddddddd000000000000 +00000000000000000000000000000000000000000000000000066666666666600000000000000000000000000000000000000000000000000000000000000000 +00000000088888888000cccccccc0008888888800088888888000cccccccc00088888888000cccccccc00088888888000cccccccc000cccccccc000000000000 +0000000088888888890cccccccccd08888888889088888888890cccccccccd088888888890cccccccccd088888888890cccccccccd0cccccccccd00000000000 +0000000088888888890cccccccccd08888888889088888888890cccccccccd088888888890cccccccccd088888888890cccccccccd0cccccccccd00000000000 +0000000088888888890cccccccccd08888888889088888888890cccccccccd088888888890cccccccccd088888888890cccccccccd0cccccccccd00000000000 +0000000088888888890cccccccccd08888888889088888888890cccccccccd088888888890cccccccccd088888888890cccccccccd0cccccccccd00000000000 +0000000088888888890cccccccccd08888888889088888888890cccccccccd088888888890cccccccccd088888888890cccccccccd0cccccccccd00000000000 +0000000088888888890cccccccccd08888888889088888888890cccccccccd088888888890cccccccccd088888888890cccccccccd0cccccccccd00000000000 +0000000088888888890cccccccccd08888888889088888888890cccccccccd088888888890cccccccccd088888888890cccccccccd0cccccccccd00000000000 +0000000088888888890cccccccccd08888888889088888888890cccccccccd088888888890cccccccccd088888888890cccccccccd0cccccccccd00000000000 +00000000099999999000dddddddd0009999999900099999999000dddddddd00099999999000dddddddd00099999999000dddddddd000dddddddd000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +000000000cccccccc0008888888800cccccccccc0cccccccccc0088888888000cccccccc0088888888880088888888000cccccccc00888888888800000000000 +00000000cccccccccd088888888890cccccccccc0cccccccccc088888888890cccccccccd08888888888088888888890cccccccccd0888888888800000000000 +00000000cccccccccd088888888890cccccccccc0cccccccccc088888888890cccccccccd08888888888088888888890cccccccccd0888888888800000000000 +00000000cccccccccd088888888890cccccccccc0cccccccccc088888888890cccccccccd08888888888088888888890cccccccccd0888888888800000000000 +00000000cccccccccd088888888890cccccccccc0cccccccccc088888888890cccccccccd08888888888088888888890cccccccccd0888888888800000000000 +00000000cccccccccd088888888890cccccccccc0cccccccccc088888888890cccccccccd08888888888088888888890cccccccccd0888888888800000000000 +00000000cccccccccd088888888890cccccccccc0cccccccccc088888888890cccccccccd08888888888088888888890cccccccccd0888888888800000000000 +00000000cccccccccd088888888890cccccccccc0cccccccccc088888888890cccccccccd08888888888088888888890cccccccccd0888888888800000000000 +00000000cccccccccd088888888890cccccccccc0cccccccccc088888888890cccccccccd08888888888088888888890cccccccccd0888888888800000000000 +000000000dddddddd0009999999900cccccccccc0cccccccccc0099999999000dddddddd0088888888880099999999000dddddddd00888888888800000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000088888888000cccccccc00088888888000cccccccc0008888888800088888888000cccccccc000cccccccc00888888888800cccccccc000000000000 +0000000088888888890cccccccccd088888888890cccccccccd08888888889088888888890cccccccccd0cccccccccd088888888880cccccccccd00000000000 +0000000088888888890cccccccccd088888888890cccccccccd08888888889088888888890cccccccccd0cccccccccd088888888880cccccccccd00000000000 +0000000088888888890cccccccccd088888888890cccccccccd08888888889088888888890cccccccccd0cccccccccd088888888880cccccccccd00000000000 +0000000088888888890cccccccccd088888888890cccccccccd08888888889088888888890cccccccccd0cccccccccd088888888880cccccccccd00000000000 +0000000088888888890cccccccccd088888888890cccccccccd08888888889088888888890cccccccccd0cccccccccd088888888880cccccccccd00000000000 +0000000088888888890cccccccccd088888888890cccccccccd08888888889088888888890cccccccccd0cccccccccd088888888880cccccccccd00000000000 +0000000088888888890cccccccccd088888888890cccccccccd08888888889088888888890cccccccccd0cccccccccd088888888880cccccccccd00000000000 +0000000088888888890cccccccccd088888888890cccccccccd08888888889088888888890cccccccccd0cccccccccd088888888880cccccccccd00000000000 +00000000099999999000dddddddd00099999999000dddddddd0009999999900099999999000dddddddd000dddddddd00888888888800dddddddd000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +000000000cccccccc00888888888800cccccccc0008888888800cccccccccc0cccccccccc0088888888000cccccccc0088888888880088888888000000000000 +00000000cccccccccd088888888880cccccccccd088888888890cccccccccc0cccccccccc088888888890cccccccccd088888888880888888888900000000000 +00000000cccccccccd088888888880cccccccccd088888888890cccccccccc0cccccccccc088888888890cccccccccd088888888880888888888900000000000 +00000000cccccccccd088888888880cccccccccd088888888890cccccccccc0cccccccccc088888888890cccccccccd088888888880888888888900000000000 +00000000cccccccccd088888888880cccccccccd088888888890cccccccccc0cccccccccc088888888890cccccccccd088888888880888888888900000000000 +00000000cccccccccd088888888880cccccccccd088888888890cccccccccc0cccccccccc088888888890cccccccccd088888888880888888888900000000000 +00000000cccccccccd088888888880cccccccccd088888888890cccccccccc0cccccccccc088888888890cccccccccd088888888880888888888900000000000 +00000000cccccccccd088888888880cccccccccd088888888890cccccccccc0cccccccccc088888888890cccccccccd088888888880888888888900000000000 +00000000cccccccccd088888888880cccccccccd088888888890cccccccccc0cccccccccc088888888890cccccccccd088888888880888888888900000000000 +000000000dddddddd00888888888800dddddddd0009999999900cccccccccc0cccccccccc0099999999000dddddddd0088888888880099999999000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000110000000000000000000000000000000000000000000000000 + diff --git a/board.lua b/board.lua index 5700ee0..1253e5e 100644 --- a/board.lua +++ b/board.lua @@ -2,8 +2,8 @@ local Board = {} function Board.new() local debug = false - local width = 10 - local tile_width = 10 + local width = 8 -- tiles + local tile_width = 10 -- pixels local padding = 1 local tiles = {} local locked = {} -- list of indexes @@ -56,7 +56,7 @@ function Board.new() end, get_tile_width = function(self) - return tile_width + return tile_width + padding end, fill = function(self, idx, color, invert) diff --git a/globals.lua b/globals.lua index 5372268..c7ff0e8 100644 --- a/globals.lua +++ b/globals.lua @@ -1 +1,3 @@ local amplitude = 128 +local mouse_x = 0 +local mouse_y = 0 \ No newline at end of file diff --git a/main.lua b/main.lua index 2d1bab7..8805388 100644 --- a/main.lua +++ b/main.lua @@ -101,8 +101,6 @@ end -- main loop -- -local create = true - function _init() -- pal({[0]=0,128,132,7,136,8,14,137,9,10,131,3,11,1,140,12},1) -- poke(0x5f2e,1) --to keep colors @@ -113,8 +111,7 @@ function _init() local date = stat(80)..stat(81)..stat(82)..stat(84)..stat(85) srand(date) printh("seed " .. date) - mouse_x = 0 - mouse_y = 0 + frame_count = 0 @@ -133,11 +130,8 @@ function _update60() frame_count += 1 _coresolve() gs._update() - -- if not create then - -- board:solve_step() - -- end - -- mouse + -- update mouse coords mouse_x = stat(32) mouse_y = stat(33) end diff --git a/states/game.lua b/states/game.lua index 39096e0..941ba85 100644 --- a/states/game.lua +++ b/states/game.lua @@ -22,11 +22,26 @@ function state_game() local x, y = board:draw_coords(selected_id) local w = board:get_tile_width() -- fillp(▒) - rect2(x-1, y-1, w+1, w+1, 6) + rect2(x-1, y-1, w, w, 6) line() 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 + mx,my = mouse_x, mouse_y + local board_x, board_y = board:draw_coords(1) + local tw = board:get_tile_width() + local bw = board:get_size() + -- pixels coords to grid coords + 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) + end + local function _enter(_board) board = _board -- lock the initial tiles @@ -68,26 +83,35 @@ function state_game() 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_O) then + 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 - selected_id = board:xy_idx(x, y) end return {