Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --main.lua
- require 'Files/camera'
- require 'Files/player'
- require 'Files/map'
- require 'Files/Tiles'
- local inspect = require('Files/inspect')
- io.stdout:setvbuf("no")
- function love.load()
- playerload()
- mapload()
- mapcollision()
- image = love.graphics.newImage('Textures/bg.jpg')
- song = love.audio.newSource("Sounds/BackgroundSong.mp3")
- song:setLooping(true)
- song:play()
- end
- function love.update()
- playercollision(collision)
- playerupdate()
- end
- function love.draw()
- camera:set()
- love.graphics.draw(image)
- mapdraw()
- playerdraw()
- camera:unset()
- end
- function love.keypressed(k)
- if k == 'escape' then
- love.event.quit()
- end
- if k == 'p' then
- for row = 1,9 do
- print(inspect(collision[row]))
- end
- end
- playermovement(k)
- if k == 'space' then
- mapload()
- mapcollision()
- mapdraw()
- end
- end
- --end of main.lua
- -- Files/Tiles.lua
- Tiles = {}
- function tilesload()
- Tiles[1] = love.graphics.newImage("Textures/Tile1.png")
- Tiles[2] = love.graphics.newImage("Textures/Tile2.png")
- end
- --end of Tiles.lua
- --Files/camera.lua
- camera = {}
- camera.x = -(64 * 3)
- camera.y = -(64 * 3)
- camera.scaleX = 1
- camera.scaleY = 1
- camera.rotation = 0
- function camera:set()
- love.graphics.push()
- love.graphics.rotate(-self.rotation)
- love.graphics.scale(1 / self.scaleX, 1 / self.scaleY)
- love.graphics.translate(-self.x, -self.y)
- end
- function camera:unset()
- love.graphics.pop()
- end
- function camera:move(dx, dy)
- self.x = self.x + (dx or 0)
- self.y = self.y + (dy or 0)
- end
- function camera:rotate(dr)
- self.rotation = self.rotation + dr
- end
- function camera:scale(sx, sy)
- sx = sx or 1
- self.scaleX = self.scaleX * sx
- self.scaleY = self.scaleY * (sy or sx)
- end
- function camera:setPosition(x, y)
- self.x = x or self.x
- self.y = y or self.y
- end
- function camera:setScale(sx, sy)
- self.scaleX = sx or self.scaleX
- self.scaleY = sy or self.scaleY
- end
- --end of camera.lua
- --Files/conf.lua
- function love.conf(t)
- t.window.heigth = 640
- t.window.width = 640
- end
- --end of conf.lua
- --Files/map.lua
- require 'Files/Tiles'
- map = {}
- collision = {}
- function mapload()
- tilesload()
- end
- function mapcollision()
- collision[1] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
- for row = 2, 8 do
- collision[row] = {}
- for column = 2, 10 do
- collision[row][column] = love.math.random(2)
- end
- collision[row][1] = 1
- collision[row][11] = 1
- end
- collision[9] = collision[1]
- end
- function mapdraw()
- for row = 1, 9 do
- for column = 1, 11 do
- if collision[row][column] == 1 then
- love.graphics.draw(Tiles[1], (column-1)*64, (row-1)*64)
- elseif collision[row][column] == 2 then
- love.graphics.draw(Tiles[2], (column-1)*64, (row-1)*64)
- end
- end
- end
- end
- --end of map.lua
- --Files/player.lua
- require 'Files/map'
- player = {}
- move = {}
- text = {}
- text.x = 32
- text.y = - 64
- function moveload()
- move.up = true
- move.down = true
- move.left = true
- move.right = true
- end
- function playerload()
- tilesload()
- moveload()
- player.x = 64
- player.y = 64
- player.color = 0, 255, 255
- Male = love.graphics.newImage("Textures/test.png")
- Female = love.graphics.newImage("Textures/Playertest.png")
- end
- function playerupdate()
- if currenttile == 2 then
- playerimage = Female
- elseif currenttile == 1 then
- playerimage = Male
- end
- end
- function playermovement(k)
- if k == 'w' and move.up then
- player.y = player.y - 64
- camera.y = camera.y - 64
- text.y = text.y - 64
- elseif k == 's' and move.down then
- player.y = player.y + 64
- camera.y = camera.y + 64
- text.y = text.y + 64
- end
- if k == 'a' and move.left then
- player.x = player.x - 64
- camera.x = camera.x - 64
- text.x = text.x - 64
- elseif k == 'd' and move.right then
- player.x = player.x + 64
- camera.x = camera.x + 64
- text.x = text.x + 64
- end
- end
- function playercollision(collision)
- currenttile = collision[player.y / 64 + 1][player.x / 64 + 1]
- if collision[player.y / 64][player.x / 64 + 1] == 1 then
- move.up = false
- else
- move.up = true
- end
- if collision[player.y / 64 + 2][player.x / 64 + 1] == 1 then
- move.down = false
- else
- move.down = true
- end
- if collision[player.y / 64 + 1][player.x / 64 + 2] == 1 then
- move.right = false
- else
- move.right = true
- end
- if collision[player.y / 64 + 1][player.x / 64] == 1 then
- move.left = false
- else
- move.left = true
- end
- end
- function playerdraw()
- love.graphics.draw(playerimage, player.x, player.y)
- end
- --end of player.lua
- --https://github.com/Ohwrake/Random-Generated-tiles-love-lua
Advertisement
Add Comment
Please, Sign In to add comment