Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- p={}
- platforms={}
- function love.load()
- p.x=310
- p.y=love.graphics.getHeight()-400
- p.speed=5
- p.face="right"
- p.cooldown=20
- p.onPlat=false
- p.dVel=0
- p.jump=true
- p.bullets={}
- p.shoot = function(face)
- if p.cooldown <= 0 then
- p.cooldown=10
- bullet = {}
- bullet.x=p.x + 10
- bullet.y=p.y + 20
- bullet.face=face
- table.insert(p.bullets, bullet)
- end
- end
- end
- function spawnPlat(x, y, h, w)
- plat={}
- plat.x=x
- plat.y=y
- plat.height=h
- plat.width=w
- table.insert(platforms, plat)
- end
- spawnPlat(0,love.graphics.getHeight()-20, 20, love.graphics.getWidth())
- spawnPlat(300, 450, 20, 100)
- spawnPlat(600, 550, 20, 100)
- spawnPlat(10, 350, 20, 100)
- spawnPlat(600, 350, 20, 100)
- spawnPlat(300, 250, 20, 100)
- function checkPlatCollisions(platforms)
- for _,v in pairs(platforms) do
- if p.y+50>=v.y and p.x+30>v.x and p.x<v.x+v.width then
- if v.y<p.y+45 then
- elseif p.dVel>0 then
- p.onPlat=true
- return
- end
- else
- p.onPlat=false
- end
- end
- end
- function calcFall()
- if p.onPlat==false then
- p.y=p.y+p.dVel
- p.dVel=p.dVel+0.1
- else
- p.jump=true
- if p.dVel>=0 then
- p.dVel=0
- else
- p.y=p.y+p.dVel
- p.dVel=p.dVel+6
- end
- end
- end
- function love.update ()
- p.cooldown=p.cooldown-1
- checkPlatCollisions(platforms)
- calcFall()
- --Player Control
- if love.keyboard.isDown("left") then
- if p.x>0 then
- p.x=p.x-p.speed
- end
- p.face="left"
- elseif love.keyboard.isDown("right") then
- if p.x<love.graphics.getWidth()-30 then
- p.x=p.x+p.speed
- end
- p.face="right"
- end
- if love.keyboard.isDown("space") then
- p.shoot(p.face)
- end
- if love.keyboard.isDown("up") then
- if p.jump then
- p.dVel=p.dVel-6
- p.jump=false
- end
- elseif love.keyboard.isDown("down") then
- if p.onPlat then
- p.onPlat=false
- p.y=p.y+5
- end
- end
- --Bullet Cleanup/Control
- for i,b in ipairs(p.bullets) do
- if b.x < -10 or b.x > 1000 then
- table.remove(p.bullets, i)
- end
- if b.face=="left" then
- b.x=b.x-10
- elseif b.face=="right" then
- b.x=b.x+10
- end
- end
- end
- function love.draw()
- --Draw Character
- love.graphics.setColor(255,0,0)
- love.graphics.rectangle('fill', p.x,p.y,30,50)
- --Draw Bullet
- love.graphics.setColor(255,255,255)
- for _,b in pairs(p.bullets) do
- love.graphics.rectangle('fill', b.x, b.y, 10, 10)
- end
- --Draw Platforms
- love.graphics.setColor(0,255,255)
- for i,p in ipairs(platforms) do
- love.graphics.rectangle('fill', p.x, p.y, p.width, p.height)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement