TheGuardian163

Untitled

Dec 11th, 2015
302
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.21 KB | None | 0 0
  1.  
  2.  
  3. -------------------------NOTES TO SELF------------------
  4.  
  5. ------ TABLES-----|----- CTRL + ALT +  , or \   (near ENTER)  = {}
  6.  
  7. -- X to shoot, arrow keys to move
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14. ------------------------  IMPORTANT FUNCTIONS TO LOAD  -----------------------
  15. ---------------------         and important tables       ----------------------
  16.  
  17. function love.load( ... )-- require love.load to create programs with Love2D
  18.    
  19.     player = {} --table for the player
  20.     player.x = 0.0--Player x and y location variables
  21.     player.y = 525.0
  22.    
  23.  
  24. --  shooting function, and bullets table for the shooting function
  25.     player.bullets = {}--table for bullets
  26.     player.cooldown = 20
  27.     player.speed = 2.0
  28.     player.speed_angle = '('player.speed_angle = math.sqrt(player.speed^2 / 2) --pytagore theorem - see "calculationFile.text"
  29.     player.fire = function()--table for when the player shoots bullets
  30.         if player.cooldown <= 0 then
  31.             player.cooldown = 45
  32.             bullet = {}
  33.             bullet.x = player.x + 30
  34.             bullet.y = player.y - 30
  35.             table.insert(player.bullets, bullet)
  36.         end
  37.  
  38.     end--if function ended
  39.  
  40.     player.speed_faster = 4.0
  41.     player.speed_faster_angle = '('player.speed_faster_angle = math.sqrt(player.speed_faster^2 / 2) --pytagore theorem - see "calculationFile.text"
  42.  
  43.  
  44.  
  45. end
  46.  
  47.  
  48. function love.update(dt)--always need to use love.update for player input in games
  49. -- (dt) is extremely important
  50. -- (dt) means deltatime variable - NEEDS TO DESCRIBE WHAT IT IS LATER
  51.  
  52.  
  53.  
  54. --love.keyboard.isDown is a love"D function for checking if a key is pressed down upon
  55. --there are "on initially pressed" and "took the finger off" options as well
  56. --| https://love2d.org/wiki/love.keyboard |-- documentation
  57.  
  58.  
  59.     player.cooldown = player.cooldown - 2 --cooldown for bullets
  60.  
  61.  
  62. ----------------------------------------------------------------------------
  63.  
  64.  
  65.  
  66.  
  67.     if love.keyboard.isDown("z") then
  68.  
  69.         if love.keyboard.isDown("right") then
  70.  
  71.             if love.keyboard.isDown("up") then
  72.                 player.x = player.x + player.speed_faster_angle
  73.                 player.y = player.y - player.speed_faster_angle
  74.             elseif love.keyboard.isDown("down") then
  75.                 player.x = player.x + player.speed_faster_angle
  76.                 player.y = player.y + player.speed_faster_angle
  77.             else
  78.                 player.x = player.x + player.speed_faster
  79.  
  80.             end
  81.  
  82.         elseif love.keyboard.isDown("left") then
  83.  
  84.             if love.keyboard.isDown("up") then
  85.                 player.x = player.x - player.speed_faster_angle
  86.                 player.y = player.y - player.speed_faster_angle
  87.             elseif love.keyboard.isDown("down") then
  88.                 player.x = player.x - player.speed_faster_angle
  89.                 player.y = player.y + player.speed_faster_angle
  90.             else
  91.                 player.x = player.x - player.speed_faster
  92.  
  93.             end
  94.         elseif love.keyboard.isDown("up") then
  95.             player.y = player.y - player.speed_faster
  96.         elseif love.keyboard.isDown("down") then
  97.             player.y = player.y + player.speed_faster
  98.  
  99.         end
  100.  
  101.     else
  102.  
  103.         if love.keyboard.isDown("right") then
  104.  
  105.             if love.keyboard.isDown("up") then
  106.                 player.x = player.x + player.speed_angle
  107.                 player.y = player.y - player.speed_angle
  108.             elseif love.keyboard.isDown("down") then
  109.                 player.x = player.x + player.speed_angle
  110.                 player.y = player.y + player.speed_angle
  111.             else
  112.                 player.x = player.x + player.speed
  113.  
  114.             end
  115.  
  116.         elseif love.keyboard.isDown("left") then
  117.  
  118.             if love.keyboard.isDown("up") then
  119.                 player.x = player.x - player.speed_angle
  120.                 player.y = player.y - player.speed_angle
  121.             elseif love.keyboard.isDown("down") then
  122.                 player.x = player.x - player.speed_angle
  123.                 player.y = player.y + player.speed_angle
  124.             else
  125.                 player.x = player.x - player.speed
  126.  
  127.             end
  128.         elseif love.keyboard.isDown("up") then
  129.             player.y = player.y - player.speed
  130.         elseif love.keyboard.isDown("down") then
  131.             player.y = player.y + player.speed
  132.  
  133.         end
  134.     end
  135.  
  136.     --------------------------------------------------------------------------------------------
  137.  
  138.  
  139.  
  140. --------------------------------------------------------------
  141.  
  142.  
  143.     --[[if love.keyboard.isDown("right") then
  144.         player.x = player.x + player.speed--movement to the right, and to the left
  145.     end
  146.     if love.keyboard.isDown("left") then--| if multiple IF STATEMENTS are used, the player
  147.         player.x = player.x - player.speed---------------------| will stop moving when pressing both keys
  148.     end----------------------------otherwise, with if and elsif, the player will move one side if both are pressed
  149. --]]
  150.     -- movement of the player
  151.     if love.keyboard.isDown("x") then
  152.         player.fire()
  153.     end
  154.  
  155.  
  156.  
  157.  
  158.     for i,b in ipairs(player.bullets) do
  159.         if b.y < -10 then
  160.             table.remove(player.bullets, i)
  161.         end
  162.             b.y = b.y - 12
  163.     end
  164.  
  165. end
  166.  
  167.  
  168. function love.draw( ... )-- this is used to draw images - x, y, width, height
  169.     --                     r    g   b
  170.     love.graphics.setColor(140, 0, 140)
  171.     love.graphics.rectangle("fill", player.x, player.y, 60, 40)
  172.     -- 255, 255, 255 = white because it is the brightest a color can be
  173.     -- 0, 0, 0, is black because it is the least amount of color it can have
  174.    
  175. --                       red | green | blue
  176.     love.graphics.setColor(255, 255, 125)
  177.     for i,b in ipairs(player.bullets) do
  178.  
  179.         love.graphics.rectangle("fill", b.x, b.y, 2, 30)
  180.     end
  181.  
  182.  
  183.  
  184. end
  185.  
  186. ------------------------IMPORTANT FUNCTIONS LOADED-----------------------------------
Advertisement
Add Comment
Please, Sign In to add comment