Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- game = {}
- function game.load()
- game.clock = 0
- game.player_size = img["player"]:getWidth()
- game.playerX = 1280 / 2
- game.playerY = 720 / 2 + 200
- game.playerVel = 280
- game.bullet_size = img["bullet"]:getWidth()
- game.bulletVel = 800
- game.bullets = {}
- game.bulletCooldown = 6
- cooldownRemaining = 0
- game.score = 0
- end
- function game.update(dt)
- --setting clock
- game.clock = game.clock + dt
- if joystick:isGamepadDown("dpleft") then
- game.playerX = game.playerX - game.playerVel * dt
- elseif joystick:isGamepadDown("dpright") then
- game.playerX = game.playerX + game.playerVel * dt
- end
- if joystick:isGamepadDown("dpup") then
- game.playerY = game.playerY - game.playerVel * dt
- elseif joystick:isGamepadDown("dpdown") then
- game.playerY = game.playerY + game.playerVel * dt
- end
- --keep player onscreen
- if game.playerY > 720 - game.player_size/2 then
- game.playerY = 720 - game.player_size/2
- end
- if game.playerY < 0 + game.player_size/2 then
- game.playerY = 0 + game.player_size/2
- end
- if game.playerX > 1000 - game.player_size/2 then
- game.playerX = 1000 - game.player_size/2
- end
- if game.playerX < 280 + game.player_size/2 then
- game.playerX = 280 + game.player_size/2
- end
- if cooldownRemaining > 0 then
- cooldownRemaining = cooldownRemaining - 1
- end
- if joystick:isGamepadDown("a") and cooldownRemaining <=0 then
- cooldownRemaining = game.bulletCooldown
- NewBullet(10)
- NewBullet(-10)
- NewBullet(0)
- end
- --update bullets
- for i, v in ipairs(game.bullets) do
- v.X = v.X + game.bulletVel * dt * math.sin(math.rad(v.angle))
- v.Y = v.Y - game.bulletVel * dt * math.cos(math.rad(v.angle))
- if v.Y < 0 or v.X < 280 or v.X > 1000 then
- table.remove(game.bullets, i)
- end
- end
- end
- function game.draw()
- love.graphics.draw(img["overlay"], 0, 0)
- love.graphics.draw(img["player"], game.playerX, game.playerY,
- 0, 1, 1, game.player_size/2, game.player_size/2)
- for i,v in ipairs(game.bullets) do
- love.graphics.draw(img["bullet"], v.X, v.Y, 0, 1, 1, game.bullet_size/2, game.bullet_size/2)
- end
- end
- function NewBullet(angle)
- local bullet = {}
- bullet.X = game.playerX
- bullet.Y = game.playerY - 16
- bullet.angle = angle
- table.insert(game.bullets, bullet)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement