Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Icon and title
- Icon = love.image.newImageData("images/Monster.png")
- love.window.setTitle("Basic Platformer Prototype")
- love.window.setIcon(Icon)
- function love.load()
- -- Window
- WindowWidth = love.graphics.getWidth()
- WindowHeight = love.graphics.getHeight()
- -- Character
- Monster = love.graphics.newImage("images/Monster.png")
- MonsterWidth = (Monster):getWidth()
- MonsterHeight = (Monster):getHeight()
- MonsterX = love.graphics.getWidth() / 2
- MonsterY = love.graphics.getHeight() - 100
- MonsterSpeed = 400
- MonsterYVelocity = 0
- JumpHeight = - 500
- Gravity = - 700
- -- Ground
- GroundX = 0
- GroundY = MonsterY
- GroundWidth = WindowWidth
- GroundHeight = WindowHeight - GroundY
- -- Platform
- Platform = love.graphics.newImage("images/Platform.png")
- PlatformWidth = (Platform):getWidth()
- PlatformHeight = (Platform):getHeight()
- PlatformX = 450
- PlatformY = love.graphics.getHeight() - (100 + PlatformHeight)
- end
- function love.update(dt)
- if love.keyboard.isDown("right") and MonsterX < (WindowWidth - MonsterWidth) then
- MonsterX = MonsterX + (MonsterSpeed * dt)
- elseif love.keyboard.isDown("left") and MonsterX > 0 then
- MonsterX = MonsterX - (MonsterSpeed * dt)
- end
- if love.keyboard.isDown("space") then
- if MonsterYVelocity == 0 then
- MonsterYVelocity = JumpHeight
- end
- end
- if MonsterYVelocity ~= 0 then
- MonsterY = MonsterY + (MonsterYVelocity * dt)
- MonsterYVelocity = MonsterYVelocity - (Gravity * dt)
- end
- if MonsterY > GroundY then
- MonsterYVelocity = 0
- if MonsterY == PlatformY and MonsterX >= PlatformX and MonsterX <= (PlatformX + PlatformWidth) then
- MonsterY = PlatformY
- else
- MonsterY = GroundY
- end
- end
- end
- function love.draw()
- -- Character
- love.graphics.setColor(1,1,1)
- love.graphics.draw(Monster, MonsterX, MonsterY, 0, 1, 1, 0, 32)
- -- Background
- love.graphics.setBackgroundColor(.5,.5,.5)
- love.graphics.setColor(0,0,0)
- love.graphics.rectangle("fill", GroundX, GroundY, GroundWidth, GroundHeight)
- -- Platform
- love.graphics.setColor(1,1,1)
- love.graphics.draw(Platform, PlatformX, PlatformY)
- end
Add Comment
Please, Sign In to add comment