Advertisement
Guest User

Untitled

a guest
Nov 21st, 2014
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.26 KB | None | 0 0
  1. game = {}
  2.  
  3. function game.load()
  4.     game.clock = 0
  5.  
  6.     game.player_size = img["player"]:getWidth()
  7.     game.playerX = 1280 / 2
  8.     game.playerY = 720 / 2 + 200
  9.     game.playerVel = 280
  10.  
  11.     game.bullet_size = img["bullet"]:getWidth()
  12.     game.bulletVel = 800
  13.     game.bullets = {}
  14.     game.bulletCooldown = 6
  15.  
  16.     cooldownRemaining = 0
  17.  
  18.     game.score = 0
  19.  
  20. end
  21.  
  22. function game.update(dt)
  23.  
  24.     --setting clock
  25.     game.clock = game.clock + dt
  26.  
  27.         if joystick:isGamepadDown("dpleft") then
  28.         game.playerX = game.playerX - game.playerVel * dt
  29.     elseif joystick:isGamepadDown("dpright") then
  30.         game.playerX = game.playerX + game.playerVel * dt
  31.     end
  32.  
  33.     if joystick:isGamepadDown("dpup") then
  34.         game.playerY = game.playerY - game.playerVel * dt
  35.     elseif joystick:isGamepadDown("dpdown") then
  36.         game.playerY = game.playerY + game.playerVel * dt
  37.     end
  38.  
  39.     --keep player onscreen
  40.     if game.playerY > 720 - game.player_size/2 then
  41.         game.playerY = 720 - game.player_size/2
  42.     end
  43.     if game.playerY < 0 + game.player_size/2 then
  44.         game.playerY = 0 + game.player_size/2
  45.     end
  46.     if game.playerX > 1000 - game.player_size/2 then
  47.         game.playerX = 1000 - game.player_size/2
  48.     end
  49.     if game.playerX < 280 + game.player_size/2 then
  50.         game.playerX = 280 + game.player_size/2
  51.     end
  52.  
  53.  
  54.     if cooldownRemaining > 0 then
  55.         cooldownRemaining = cooldownRemaining - 1
  56.     end
  57.  
  58.     if joystick:isGamepadDown("a") and cooldownRemaining <=0 then
  59.         cooldownRemaining = game.bulletCooldown
  60.         NewBullet(10)
  61.         NewBullet(-10)
  62.         NewBullet(0)
  63.     end
  64.  
  65.  
  66.     --update bullets
  67.     for i, v in ipairs(game.bullets) do
  68.         v.X = v.X + game.bulletVel * dt * math.sin(math.rad(v.angle))
  69.         v.Y = v.Y - game.bulletVel * dt * math.cos(math.rad(v.angle))
  70.         if v.Y < 0 or v.X < 280 or v.X > 1000 then
  71.             table.remove(game.bullets, i)
  72.         end
  73.     end
  74.  
  75. end
  76.  
  77. function game.draw()
  78.  
  79.     love.graphics.draw(img["overlay"], 0, 0)
  80.  
  81.     love.graphics.draw(img["player"], game.playerX, game.playerY,
  82.                                          0, 1, 1, game.player_size/2, game.player_size/2)
  83.  
  84.     for i,v in ipairs(game.bullets) do
  85.         love.graphics.draw(img["bullet"], v.X, v.Y, 0, 1, 1, game.bullet_size/2, game.bullet_size/2)
  86.     end
  87.  
  88. end
  89.  
  90. function NewBullet(angle)
  91.  
  92.     local bullet = {}
  93.     bullet.X = game.playerX
  94.     bullet.Y = game.playerY - 16
  95.     bullet.angle = angle
  96.     table.insert(game.bullets, bullet)
  97. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement