Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require "player"
- require "SpriteAnimation"
- require "camera"
- require "menu"
- require "importantstuff"
- -- MASSIVE THANKS TO Sean Laurvick FOR THE BASE, THE TUTORIAL AND SUCH, WE COULD NOT HAE DONE IT WITHOUT YOU. YOU SHAL COME THIRD IN THE CREDITS, AND WE WILL LINK YOUR FORUM TUTORIAL.
- function love.load() --SET VARIABLES HERE PLZ THX BYE
- medium = love.graphics.newFont(25)
- gamestate = "menu"
- if gamestate == "playing" then
- loadgeneral()
- end
- love.graphics.setBackgroundColor(255,255,255)
- --buttons yay
- button_spawn(5,200,"Start","start")
- button_spawn(5,550,"Quit","quit")
- end
- function love.update(dt)
- -- The controls
- -- D - Right
- if love.keyboard.isDown("d") then
- if grid[math.floor(p.x/blocksize) + 2][math.floor(p.y/blocksize) + 1] == 0 or grid[math.floor(p.x/blocksize) + 2][math.floor(p.y/blocksize) + 1] == 3 then
- p:moveRight()
- else
- p:stop()
- end
- animation:flip(false, false)
- end
- -- A - Left
- if love.keyboard.isDown("a") then
- if p.x == 0 then
- p:stop()
- else if grid[math.ceil(p.x/blocksize)][math.floor(p.y/blocksize) + 1] == 0 or grid[math.ceil(p.x/blocksize)][math.floor(p.y/blocksize) + 1] == 3 then
- p:moveLeft()
- else
- p:stop()
- end
- end
- animation:flip(true, false)
- end
- -- W - Jump
- if love.keyboard.isDown("w") and not(hasJumped) then
- if grid[math.floor(p.x/blocksize) + 1][math.floor(p.y/blocksize) + 1] == 3 and grid[math.floor(p.x/blocksize) + 1][math.floor(p.y/blocksize)] == 0 or grid[math.floor(p.x/blocksize) + 1][math.floor(p.y/blocksize)] == 3 then
- p.y = p.y - 32
- else if grid[math.floor(p.x/blocksize) + 1][math.floor(p.y/blocksize)] == 0 or grid[math.floor(p.x/blocksize) + 1][math.floor(p.y/blocksize)] == 3 then
- p:jump()
- hasJumped = true
- else p:stop()
- end
- end
- end
- -- R - Reset to spawn
- if love.keyboard.isDown("r") then
- p.x = 0
- p.y = 0
- end
- --F - Place a ladder
- if love.keyboard.isDown("f") and grid[math.floor(p.x/blocksize) + 1][math.floor(p.y/blocksize) + 1] == 0 then
- grid[math.floor(p.x/blocksize) + 1][math.floor(p.y/blocksize) + 1] = 3
- end
- -- K - Place block on your right
- if love.keyboard.isDown("k") then
- if # inv > 0 then
- if grid[math.floor(p.x/blocksize) + 2][math.floor(p.y/blocksize) + 1] == 0 then
- grid[math.floor(p.x/blocksize) + 2][math.floor(p.y/blocksize) + 1] = inv[1]
- table.remove(inv, 1)
- end
- end
- end
- -- H - Place block on your left
- if love.keyboard.isDown("h") then
- if # inv > 0 then
- if math.floor(p.x/blocksize) > 0 then
- if grid[math.floor(p.x/blocksize)][math.floor(p.y/blocksize) + 1] == 0 then
- grid[math.floor(p.x/blocksize)][math.floor(p.y/blocksize) + 1] = inv[1]
- table.remove(inv, 1)
- end
- end
- end
- end
- -- J - Place blocks below you
- if love.keyboard.isDown("j") then
- if # inv > 0 then
- if grid[math.floor(p.x/blocksize) + 1][math.floor(p.y/blocksize) + 2] == 0 then
- grid[math.floor(p.x/blocksize) + 1][math.floor(p.y/blocksize) + 2] = inv[1]
- table.remove(inv, 1)
- end
- end
- end
- -- U - Place blocks above you
- if love.keyboard.isDown("u") then
- if # inv > 0 then
- if grid[math.floor(p.x/blocksize) + 1][math.floor(p.y/blocksize)] == 0 then
- grid[math.floor(p.x/blocksize) + 1][math.floor(p.y/blocksize)] = inv[1]
- table.remove(inv, 1)
- end
- end
- end
- -- E - Camera Rotate anti-clockwise
- if love.keyboard.isDown("e") then
- camera:rotate(0.1)
- -- update the player's position
- p:update(dt, gravity)
- -- stop the player when they hit the borders
- p.x = math.clamp(p.x, 0, width * 2 - p.width)
- if p.y < 0 then p.y = 0 end
- if grid[math.floor(p.x/blocksize) + 1][math.floor(p.y/blocksize) + 2] > 0 then
- p:hitFloor( (math.floor(p.y/blocksize) + 1 )* blocksize)
- end
- end
- -- update the sprite animation
- if (p.state == "stand") then
- animation:switch(1, 4, 200)
- end
- if (p.state == "moveRight") or (p.state == "moveLeft") then
- animation:switch(2, 4, 120)
- end
- if (p.state == "jump") or (p.state == "fall") then
- animation:reset()
- animation:switch(3, 1, 300)
- end
- animation:update(dt)
- -- center the camera on the player
- camera:setPosition(math.floor(p.x - width / 2), math.floor(p.y - height / 2))
- -- M - Dig right
- if love.keyboard.isDown("m") then
- if grid[math.floor(p.x/blocksize) + 2][math.floor(p.y/blocksize) + 1] > 0 then
- items[math.floor(p.x/blocksize) + 1][math.floor(p.y/blocksize) + 1] = grid[math.floor(p.x/blocksize) + 2][math.floor(p.y/blocksize) + 1]
- grid[math.floor(p.x/blocksize) + 2][math.floor(p.y/blocksize) + 1] = 0
- end
- end
- -- N - Dig left
- if love.keyboard.isDown("n") then
- if math.floor(p.x/blocksize) > 0 then
- if grid[math.floor(p.x/blocksize)][math.floor(p.y/blocksize) + 1] > 0 then
- items[math.floor(p.x/blocksize)][math.floor(p.y/blocksize) + 1] = grid[math.floor(p.x/blocksize)][math.floor(p.y/blocksize) + 1]
- grid[math.floor(p.x/blocksize)][math.floor(p.y/blocksize) + 1] = 0
- end
- end
- end
- -- B - Dig down
- if love.keyboard.isDown("b") then
- if grid[math.floor(p.x/blocksize) + 1][math.floor(p.y/blocksize) + 2] > 0 then
- items[math.floor(p.x/blocksize) + 1][math.floor(p.y/blocksize) + 1] = grid[math.floor(p.x/blocksize) + 1][math.floor(p.y/blocksize) + 2]
- grid[math.floor(p.x/blocksize) + 1][math.floor(p.y/blocksize) + 2] = 0
- end
- end
- -- Pick up items in your block
- if items[math.floor(p.x/blocksize) + 1][math.floor(p.y/blocksize) + 1] > 0 then
- table.insert(inv, items[math.floor(p.x/blocksize) + 1][math.floor(p.y/blocksize) + 1])
- items[math.floor(p.x/blocksize) + 1][math.floor(p.y/blocksize) + 1] = 0
- end
- function love.draw()
- camera:set()
- if gamestate == "menu" then
- button_draw()
- end
- -- round down our x, y values
- local x, y = math.floor(p.x), math.floor(p.y)
- -- draw the ground
- for i = 1, blockcount do
- for j = 1, blockcount do
- if grid[i][j] == 1 then
- g.setColor(groundColor)
- g.rectangle("fill", blocksize * (i - 1), blocksize * (j - 1), blocksize, blocksize)
- else if grid[i][j] == 2 then
- g.setColor(100, 100, 100)
- g.rectangle("fill", blocksize * (i - 1), blocksize * (j - 1), blocksize, blocksize)
- else if grid[i][j] == 3 then
- love.graphics.draw(Ladders, blocksize * (i - 1), blocksize * (j - 1))
- end
- end
- end
- end
- end
- -- draw the player
- g.setColor(255, 255, 255)
- animation:draw(x, y)
- camera:unset()
- -- debug information
- g.print("Player coordinates: ("..x..","..y..")", 5, 5)
- g.print("Current state: "..p.state, 5, 20)
- for i = 1, # inv do
- g.print(inv[i],5 + (i * 10),35)
- end
- g.print("Health = "..life, 5, 50)
- end
- end
- function love.keyreleased(key)
- if key == "escape" then
- love.event.push("quit") -- actually causes the app to quit
- end
- if (key == "d") or (key == "a") then
- p:stop()
- end
- if (key == "w") then
- hasJumped = false
- end
- if (key == "q") then
- invshuffle = inv[1]
- for i = 1, # inv - 1 do
- inv[i] = inv[i + 1]
- end
- inv[# inv] = invshuffle
- end
- if (key == "delete") then
- if # inv > 0 then
- table.remove(inv, 1)
- end
- end
- end
- function love.mousepressed(x,y)
- if gamestate == "menu" then
- button_click(x,y)
- end
- function math.clamp(x, min, max)
- return x < min and min or (x > max and max or x) --DAHECK?
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment