diff --git a/game/gamemode.lua b/game/gamemode.lua index 50ba8dc..6f3d443 100644 --- a/game/gamemode.lua +++ b/game/gamemode.lua @@ -4,16 +4,14 @@ local lualzw = require 'libs.lualzw' local bitser = require 'libs.bitser' local playedReadySE = false -local playedGoSE = false local Grid = require 'game.grid' local Randomizer = require 'game.randomizer' -local Piece = require 'game.piece' local GameMode = Object:extend() function GameMode:new(player_name, input_file, replay_grade) - VCTRL.toggle(true) + VCTRL.toggle(MOBILE and not input_file) if player_name == nil then self.training = true else self.training = false end if input_file ~= nil then @@ -507,10 +505,10 @@ function GameMode:detectHoles(x, y) table.insert(self.visited, x..'.'..y) end if cell.colour ~= "" or cell.oob then return false end - if self:detectHoles(x+1, y, attempt_num) then return true end - if self:detectHoles(x-1, y, attempt_num) then return true end - if self:detectHoles(x, y+1, attempt_num) then return true end - if self:detectHoles(x, y-1, attempt_num) then return true end + if self:detectHoles(x+1, y) then return true end + if self:detectHoles(x-1, y) then return true end + if self:detectHoles(x, y+1) then return true end + if self:detectHoles(x, y-1) then return true end return false end @@ -520,7 +518,7 @@ function GameMode:stackQualityCheck() for x=1, 10 do for y = 1, 20 do if self.grid:getCell(x, y).colour == "" and not table.contains(self.visited, x..'.'..y) then - stack_clean = self:detectHoles(x, y) + local stack_clean = self:detectHoles(x, y) if not stack_clean then hole_num = hole_num + 1 end @@ -993,7 +991,7 @@ function GameMode:drawScoringInfo() love.graphics.rectangle("fill", 68, 270, 140, 190, 10, 10) love.graphics.setColor(0.05,0.05,0.05,1) love.graphics.rectangle("fill", 65, 267, 140, 190, 10, 10) - drawText(string.format("Replay in progress\nRotate Left:\n Pause/Frame Step\nRotate Right:\n Unpause\nLeft:\n Rewind 5 sec\nRight:\n FF 10 secs\n%s", formatTime(self.frames)), 70, 275, 1000, "left") + drawText(string.format("Replay in progress\n\n\n\n\n\n\n\n\n%s", formatTime(self.frames)), 70, 275, 1000, "left") drawBigText(string.format("%s", self.grade), 100, 143, 1000, "left") self:drawInputDisplay(103,185) elseif not PENTO_MODE then @@ -1069,11 +1067,7 @@ function GameMode:drawBackground() end if bg == 0 or bg == 8 or bg == 9 or bg == 3 then brightness = 0.7 end love.graphics.setColor(brightness, brightness, brightness, 1) - love.graphics.draw( - BACKGROUNDS[bg], - 0, 0, 0, - 1,1 - ) + love.graphics.draw(BACKGROUNDS[bg]) end function GameMode:drawFrame() diff --git a/libs/simple-button.lua b/libs/simple-button.lua index 94b4b37..9dfd84e 100644 --- a/libs/simple-button.lua +++ b/libs/simple-button.lua @@ -122,6 +122,7 @@ function button:press(x, y, touchID) self._touchID = touchID self._pressed = true + self:draw() return true end diff --git a/main.lua b/main.lua index fdd7efd..7bcfc3a 100644 --- a/main.lua +++ b/main.lua @@ -15,6 +15,9 @@ end CONFIG_FILE = 'config.sav' HIscoreFILE = 'hiscores.sav' +CURRENT_OS = love.system.getOS() +MOBILE = CURRENT_OS == "Android" or CURRENT_OS == "iOS" + LOADING_IMAGE_FILE = love.graphics.newImage('res/loading.png') --- Show the loading text while we are loading resources
--- **WARNING**: should only be used while loading the game! diff --git a/scene/game.lua b/scene/game.lua index 6fdb16f..5eb6de8 100644 --- a/scene/game.lua +++ b/scene/game.lua @@ -3,10 +3,59 @@ GameScene.title = "Game" local tas = false -function GameScene:new(player_name, replay_file, replay_grade) - game_mode = require 'game.gamemode' +-- 70 295 +local buttonList = { + BUTTON.new{ + text = "Rotate Left\n Pause/Frame Step", + x = 67, y = 289, h = 40, w = 140, + backgroundColor = {0, 0, 0, 0}, + borderColor = {0, 0, 0, 0}, + hoverColor = { 1, 1, 1, 0.2}, + textOrientation = "left", + codeWhenPressed = function() SCENE:onInputPress{input = "rotate_left"} end + }, + BUTTON.new{ + text = "Rotate Right\n Unpause", + x = 67, y = 323, h = 40, w = 140, + backgroundColor = {0, 0, 0, 0}, + borderColor = {0, 0, 0, 0}, + hoverColor = { 1, 1, 1, 0.2}, + textOrientation = "left", + codeWhenPressed = function() SCENE:onInputPress{input = "rotate_right"} end + }, + BUTTON.new{ + text = "Left\n Rewind 5 sec", + x = 67, y = 357, h = 40, w = 140, + backgroundColor = {0, 0, 0, 0}, + borderColor = {0, 0, 0, 0}, + hoverColor = { 1, 1, 1, 0.2}, + textOrientation = "left", + codeWhenPressed = function() SCENE:onInputPress{input = "left"} end + }, + BUTTON.new{ + text = "Right\n FF 10 sec", + x = 67, y = 391, h = 40, w = 140, + backgroundColor = {0, 0, 0, 0}, + borderColor = {0, 0, 0, 0}, + hoverColor = { 1, 1, 1, 0.2}, + textOrientation = "left", + codeWhenPressed = function() SCENE:onInputPress{input = "right"} end + }, +} +local menuKey -- MENU key used to go main menu XD - VCTRL[9].show = false; VCTRL[10].show = false -- Hide SELECT and QUIT button +function GameScene:new(player_name, replay_file, replay_grade) + menuKey = BUTTON.new{ + text = "MENU", + x = 270, y = 5, w = 50, h = 20, + codeWhenReleased = function() + if self.game.input_playback or self.game.game_over or self.game.completed then + SCENE = TitleScene() + end + end + } + + game_mode = require 'game.gamemode' if PENTO_MODE then ruleset = require 'game.rotation_pent' else @@ -46,7 +95,7 @@ function GameScene:update(nosound, tas_update) for input, value in pairs(self.inputs) do inputs[input] = value end - if tas and tas_update then + if tas and tas_update then self.paused = false self.game:update(inputs, self.ruleset) self.paused = true @@ -62,19 +111,25 @@ function GameScene:update(nosound, tas_update) if not self.paused then self.game:update(inputs, self.ruleset) end - if self.game.input_playback or self.game.game_over or self.game.game_completed then - VCTRL[9].show = true; VCTRL[10].show = true - end + -- if self.game.input_playback or self.game.game_over or self.game.game_completed then + -- VCTRL[9].show = true; VCTRL[10].show = true + -- end end function GameScene:render() self.game:draw(self.paused) - VCTRL.draw() + if self.game.input_playback then + BUTTON.draw(buttonList) + end + if self.game.input_playback or self.game.game_over or self.game.completed then + menuKey:draw() + end end function GameScene:onInputPress(e) - if e.type == "touch" then VCTRL.press(e.x, e.y, e.id) - + if e.type == "mouse" or (e.type == "touch" and not VCTRL.press(e.x, e.y, e.id)) then + BUTTON.press(buttonList, e.x, e.y, e.id) + menuKey:press(e.x, e.y, e.id) elseif (self.game.game_over or self.game.completed) and (e.input == "menu_decide" or e.input == "menu_back" or e.input == "rotate_right") and self.game.game_over_frames > 50 then SCENE = TitleScene() elseif tas and e.input == "menu_decide" then @@ -113,11 +168,17 @@ function GameScene:onInputPress(e) end function GameScene:onInputRelease(e) - if e.type == "touch" then - VCTRL.release(e.id) + if e.type == "touch" or (e.type == "mouse" and not VCTRL.release(e.id)) then + BUTTON.release(buttonList, e.x, e.y, e.id) + menuKey:release(e.x, e.y, e.id) elseif e.input and string.sub(e.input, 1, 5) ~= "menu_" then self.inputs[e.input] = false end end +function GameScene:onInputMove(e) + if e.type == "mouse" then BUTTON.checkHovering(buttonList, e.x, e.y) end + menuKey._hovering = menuKey:isHovering(e.x, e.y) +end + return GameScene diff --git a/scene/name_entry.lua b/scene/name_entry.lua index c098e09..369004c 100644 --- a/scene/name_entry.lua +++ b/scene/name_entry.lua @@ -46,8 +46,6 @@ function NameEntryScene:new() self.grade = 0 self.wins = 0 self.plays = 0 - self.delete_confirm = false - self.delete_input_count = 0 self.gradeNames = { "19k", "18k", "17k", "16k", "15k", "14k", "13k", "12k", "11k", "10k", "9k", "8k", "7k", "6k", "5k", "4k", "3k", "2k", "1k", @@ -110,11 +108,6 @@ function NameEntryScene:render() if self.grade > 0 then drawText(string.format('Games: %s', self.plays), 255, 250, 1000) drawText(string.format('Grade: %s', self.gradeNames[self.grade]), 255, 270, 1000) - --if not self.delete_confirm then - -- drawText('Press up\nthree times\nto delete', 255, 330, 1000) - --else - -- drawText('Are you sure?\nPress down\nthree times\nto confirm', 255, 330, 1000) - --end end end @@ -149,8 +142,6 @@ function NameEntryScene:onInputPress(e) if e.type == "mouse" or e.type == "touch" then BUTTON.press(buttonList, e.x, e.y, e.id) elseif e.input == "menu_decide" or e.input == "rotate_left" or e.scancode == "return" then - self.delete_confirm = false - self.delete_input_count = 0 if self.entry_pos == 4 then BUTTON.release(buttonList, e.x, e.y, e.id) SETTINGS['last_entry'] = name:upper() @@ -172,16 +163,10 @@ function NameEntryScene:onInputPress(e) self.entry_pos = self.entry_pos + 1 end elseif e.input == "left" or e.scancode == "left" then - self.delete_confirm = false - self.delete_input_count = 0 self.direction = "left" elseif e.input == "right" or e.scancode == "right" then - self.delete_confirm = false - self.delete_input_count = 0 self.direction = "right" elseif e.input == "menu_back" or e.input == "rotate_right" or e.scancode == "delete" or e.scancode == "backspace" then - self.delete_confirm = false - self.delete_input_count = 0 if self.entry_pos == 1 then BUTTON.release(buttonList, true) SCENE = TitleScene() @@ -193,28 +178,6 @@ function NameEntryScene:onInputPress(e) self.grade = 0 end end - --elseif e.input == "up" or e.scancode == "up" then - -- if self.delete_confirm then - -- self.delete_confirm = false - -- self.delete_input_count = 0 - -- end - -- if self.entry_pos == 4 and self.grade > 0 and not self.delete_confirm then - -- self.delete_input_count = self.delete_input_count + 1 - -- if self.delete_input_count >= 3 then - -- self.delete_input_count = 0 - -- self.delete_confirm = true - -- end - -- end - --elseif e.input == "down" or e.scancode == "down" then - -- if not self.delete_confirm then self.delete_input_count = 0 end - -- if self.entry_pos == 4 and self.delete_confirm then - -- self.delete_input_count = self.delete_input_count + 1 - -- if self.delete_input_count >= 3 then - -- love.filesystem.remove(string.lower(self.name_entry[1]..self.name_entry[2]..self.name_entry[3]).."_grade_history.sav") - -- scene = TitleScene() - -- end - -- end - --end end function NameEntryScene:onInputRelease(e) diff --git a/scene/training.lua b/scene/training.lua index 2a7044c..257d798 100644 --- a/scene/training.lua +++ b/scene/training.lua @@ -1,7 +1,15 @@ local TrainingScene = SCENE:extend() TrainingScene.title = "20G Training" +local menuKey + function TrainingScene:new() + menuKey = BUTTON.new{ + text = "MENU", + x = 270, y = 5, w = 50, h = 20, + codeWhenReleased = function() SCENE = TitleScene() end + } + game_mode = require 'game.gamemode' if PENTO_MODE then ruleset = require 'game.rotation_pent' @@ -38,11 +46,13 @@ end function TrainingScene:render() self.game:draw(self.paused) + menuKey:draw() VCTRL.draw() end function TrainingScene:onInputPress(e) - if e.type == "touch" then VCTRL.press(e.x, e.y, e.id) + if e.type == "mouse" or (e.type == "touch" and not VCTRL.press(e.x, e.y, e.id)) then + menuKey:press(e.x, e.y, e.id) elseif (self.game.game_over or self.game.completed) and (e.input == "menu_decide" or e.input == "menu_back" or e.input == "rotate_right") and self.game.game_over_frames > 50 then SCENE = TitleScene() elseif (e.input == "menu_back") then @@ -53,10 +63,15 @@ function TrainingScene:onInputPress(e) end function TrainingScene:onInputRelease(e) - if e.type == "touch" then VCTRL.release(e.id) + if e.type == "mouse" or (e.type == "touch" and not VCTRL.release(e.id)) then + menuKey:release(e.x, e.y, e.id) elseif e.input and string.sub(e.input, 1, 5) ~= "menu_" then self.inputs[e.input] = false end end +function TrainingScene:onInputMove(e) + menuKey._hovering = menuKey:isHovering(e.x, e.y) +end + return TrainingScene