SHARE
TWEET

load problem

a guest Aug 25th, 2018 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. Player = {x = 180, y = 710, speed = 150, shotspeed = 300, shotdelay = 5, img = nil, srcTag = "player"}
  3. bullet = {x = 0, y = 0, speed = 300, img = nil, src = ""}
  4.  
  5. -- Global Tables
  6.  
  7. globalImages = {}
  8. bulletTable = {}
  9.  
  10. -- Other Shit
  11. shotDelay = 50
  12.  
  13.  
  14. function bullet:newBullet(x, y, speed, img, src)
  15.     self.__index = self
  16.    
  17.     return setmetatable(
  18.     { x = x,
  19.     y = y,
  20.     speed = speed,
  21.     img = img,
  22.     src = src,
  23.     }, self
  24.   )
  25.  
  26. end
  27.  
  28.  
  29.  
  30. function love.load(arg)
  31.   if arg[#arg] == "-debug" then require("mobdebug").start() end
  32.  
  33.     --Objects
  34.     Player.img = love.graphics.newImage('assets/Aircraft_01.png')
  35.  
  36.     globalImages.bulletPlayerImg = love.graphics.newImage('assets/bullet_2_blue.png')
  37.     globalImages.bulletPlayerImg2 = love.graphics.newImage('assets/bullet_2_blue.png')
  38.     globalImages.bulletEnemyImg = love.graphics.newImage('assets/bullet_2_orange.png')
  39.        
  40.    
  41.     table.insert(bulletTable, bullet:newBullet(Player.x + Player.img:getWidth()/2, Player.y, Player.shotspeed, globalImages.bulletPlayerImg, Player.srcTag))    table.insert(bulletTable, bullet:newBullet(Player.x + Player.img:getWidth()/2, Player.y, Player.shotspeed, globalImages.bulletPlayerImg, Player.srcTag))
  42.  
  43. end
  44.  
  45. function love.update(dt)
  46.    
  47.     -- Keyboard Responses
  48.  
  49.     if love.keyboard.isDown('escape') then
  50.     love.event.push('quit')
  51.     end
  52.  
  53.     if love.keyboard.isDown('left', 'a') then
  54.         if Player.x > 0 then
  55.             Player.x = Player.x - (Player.speed*dt)
  56.         end
  57.  
  58.     elseif love.keyboard.isDown('right', 'd') then
  59.         if Player.x < (love.graphics.getWidth() - Player.img:getWidth()) then
  60.         Player.x = Player.x + (Player.speed*dt)
  61.         end
  62.     end
  63.  
  64.     if shotDelay >= Player.shotdelay then
  65.         if love.keyboard.isDown('up') then
  66.             local bulletPlayer = bullet:newBullet(Player.x + Player.img:getWidth()/2, Player.y, Player.shotspeed, globalImages.bulletPlayerImg2, Player.srcTag)
  67.          
  68.             table.insert(bulletTable, bulletPlayer)
  69.             shotDelay = 0
  70.         end
  71.     else
  72.         shotDelay = shotDelay + dt*25
  73.     end
  74.  
  75.     -- Position updates
  76.     if bulletTable[0] ~= nil then
  77.         for i = 0, #bulletTable do
  78.            
  79.             if bulletTable[i].src == Player.srcTag then
  80.                 bulletTable[i].y = bulletTable[i].y - bulletTable[i].speed*dt
  81.             end
  82.         end
  83.     end
  84. end
  85.  
  86.  
  87. function love.draw()
  88.     love.graphics.draw(Player.img, Player.x, Player.y)
  89.     love.graphics.print(#bulletTable, 100, 100)
  90.  
  91.     if bulletTable[0] ~= nil then
  92.         for i = 0, #bulletTable do
  93.                 love.graphics.draw(bulletTable[i].img, bulletTable[i].x, bulletTable[i].y)
  94.         end
  95.     end  
  96.     --for i, bullet in ipairs(bulletTable) do
  97.       --  love.graphics.draw(bullet.img, bullet.x, bullet.y)
  98.     --end
  99. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top