Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -------------------------NOTES TO SELF------------------
- ------ TABLES-----|----- CTRL + ALT + , or \ (near ENTER) = {}
- -- X to shoot, arrow keys to move
- ------------------------ IMPORTANT FUNCTIONS TO LOAD -----------------------
- --------------------- and important tables ----------------------
- function love.load( ... )-- require love.load to create programs with Love2D
- player = {} --table for the player
- player.x = 0.0--Player x and y location variables
- player.y = 525.0
- -- shooting function, and bullets table for the shooting function
- player.bullets = {}--table for bullets
- player.cooldown = 20
- player.speed = 2.0
- player.speed_angle = '('player.speed_angle = math.sqrt(player.speed^2 / 2) --pytagore theorem - see "calculationFile.text"
- player.fire = function()--table for when the player shoots bullets
- if player.cooldown <= 0 then
- player.cooldown = 45
- bullet = {}
- bullet.x = player.x + 30
- bullet.y = player.y - 30
- table.insert(player.bullets, bullet)
- end
- end--if function ended
- player.speed_faster = 4.0
- player.speed_faster_angle = '('player.speed_faster_angle = math.sqrt(player.speed_faster^2 / 2) --pytagore theorem - see "calculationFile.text"
- end
- function love.update(dt)--always need to use love.update for player input in games
- -- (dt) is extremely important
- -- (dt) means deltatime variable - NEEDS TO DESCRIBE WHAT IT IS LATER
- --love.keyboard.isDown is a love"D function for checking if a key is pressed down upon
- --there are "on initially pressed" and "took the finger off" options as well
- --| https://love2d.org/wiki/love.keyboard |-- documentation
- player.cooldown = player.cooldown - 2 --cooldown for bullets
- ----------------------------------------------------------------------------
- if love.keyboard.isDown("z") then
- if love.keyboard.isDown("right") then
- if love.keyboard.isDown("up") then
- player.x = player.x + player.speed_faster_angle
- player.y = player.y - player.speed_faster_angle
- elseif love.keyboard.isDown("down") then
- player.x = player.x + player.speed_faster_angle
- player.y = player.y + player.speed_faster_angle
- else
- player.x = player.x + player.speed_faster
- end
- elseif love.keyboard.isDown("left") then
- if love.keyboard.isDown("up") then
- player.x = player.x - player.speed_faster_angle
- player.y = player.y - player.speed_faster_angle
- elseif love.keyboard.isDown("down") then
- player.x = player.x - player.speed_faster_angle
- player.y = player.y + player.speed_faster_angle
- else
- player.x = player.x - player.speed_faster
- end
- elseif love.keyboard.isDown("up") then
- player.y = player.y - player.speed_faster
- elseif love.keyboard.isDown("down") then
- player.y = player.y + player.speed_faster
- end
- else
- if love.keyboard.isDown("right") then
- if love.keyboard.isDown("up") then
- player.x = player.x + player.speed_angle
- player.y = player.y - player.speed_angle
- elseif love.keyboard.isDown("down") then
- player.x = player.x + player.speed_angle
- player.y = player.y + player.speed_angle
- else
- player.x = player.x + player.speed
- end
- elseif love.keyboard.isDown("left") then
- if love.keyboard.isDown("up") then
- player.x = player.x - player.speed_angle
- player.y = player.y - player.speed_angle
- elseif love.keyboard.isDown("down") then
- player.x = player.x - player.speed_angle
- player.y = player.y + player.speed_angle
- else
- player.x = player.x - player.speed
- end
- elseif love.keyboard.isDown("up") then
- player.y = player.y - player.speed
- elseif love.keyboard.isDown("down") then
- player.y = player.y + player.speed
- end
- end
- --------------------------------------------------------------------------------------------
- --------------------------------------------------------------
- --[[if love.keyboard.isDown("right") then
- player.x = player.x + player.speed--movement to the right, and to the left
- end
- if love.keyboard.isDown("left") then--| if multiple IF STATEMENTS are used, the player
- player.x = player.x - player.speed---------------------| will stop moving when pressing both keys
- end----------------------------otherwise, with if and elsif, the player will move one side if both are pressed
- --]]
- -- movement of the player
- if love.keyboard.isDown("x") then
- player.fire()
- end
- for i,b in ipairs(player.bullets) do
- if b.y < -10 then
- table.remove(player.bullets, i)
- end
- b.y = b.y - 12
- end
- end
- function love.draw( ... )-- this is used to draw images - x, y, width, height
- -- r g b
- love.graphics.setColor(140, 0, 140)
- love.graphics.rectangle("fill", player.x, player.y, 60, 40)
- -- 255, 255, 255 = white because it is the brightest a color can be
- -- 0, 0, 0, is black because it is the least amount of color it can have
- -- red | green | blue
- love.graphics.setColor(255, 255, 125)
- for i,b in ipairs(player.bullets) do
- love.graphics.rectangle("fill", b.x, b.y, 2, 30)
- end
- end
- ------------------------IMPORTANT FUNCTIONS LOADED-----------------------------------
Advertisement
Add Comment
Please, Sign In to add comment