diff --git a/main.lua b/main.lua index 8f285e1..a192492 100644 --- a/main.lua +++ b/main.lua @@ -26,7 +26,9 @@ function love.load() love.graphics.setFont(font) + minesound = love.audio.newSource("mine.ogg", "static") + placesound = love.audio.newSource("place.ogg", "static") end diff --git a/menu.lua b/menu.lua index a542746..1346464 100644 --- a/menu.lua +++ b/menu.lua @@ -62,7 +62,22 @@ function menu.draw() love.graphics.setFont(fontmed) love.graphics.setColor(255,255,255,255) love.graphics.print("Score:"..tostring(math.random(0,20000000)), 400,110) + + --debug mining + if player.mining == true then + love.graphics.setColor(255,0,0,255) + love.graphics.print("Mining", 400,180) + love.graphics.setColor(128,128,128,255) + love.graphics.print("Placing", 560,180) + + elseif player.mining == false then + love.graphics.setColor(128,128,128,255) + love.graphics.print("Mining", 400,180) + love.graphics.setColor(255,0,0,255) + love.graphics.print("Placing", 560,180)love.graphics.print("PosX:"..player.playerx.." PosY:"..player.playery, 400,150) + end --debug player's pos + love.graphics.setColor(255,255,255,255) love.graphics.print("PosX:"..player.playerx.." PosY:"..player.playery, 400,150) end diff --git a/place.ogg b/place.ogg new file mode 100644 index 0000000..7a05e15 Binary files /dev/null and b/place.ogg differ diff --git a/player.lua b/player.lua index 557d649..9982de6 100644 --- a/player.lua +++ b/player.lua @@ -2,6 +2,8 @@ player = {} player.playerx,player.playery = 1,1 +player.mining = true + --controls function love.keypressed( key, scancode, isrepeat ) @@ -22,6 +24,10 @@ function love.keypressed( key, scancode, isrepeat ) end collision(oldposx,oldposy) + if key == "space" then + player.mining = not player.mining + end + mine(key) end @@ -47,13 +53,26 @@ function mine(key) y = 1 end end + --cancel if nothing + if x == 0 and y == 0 then + return + end --play sound and remove tile - if tiles[player.playerx+x][player.playery+y]["block"] ~= 0 then - minesound:setPitch(love.math.random(50,100)/100) - minesound:stop() - minesound:play() - tiles[player.playerx+x][player.playery+y]["block"] = 0 + if player.mining == true then + if tiles[player.playerx+x][player.playery+y]["block"] ~= 0 then + minesound:setPitch(love.math.random(50,100)/100) + minesound:stop() + minesound:play() + tiles[player.playerx+x][player.playery+y]["block"] = 0 + end + elseif player.mining == false then + if tiles[player.playerx+x][player.playery+y]["block"] == 0 then + placesound:setPitch(love.math.random(50,100)/100) + placesound:stop() + placesound:play() + tiles[player.playerx+x][player.playery+y]["block"] = 1 + end end end