Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- io.stdout:setvbuf('no')
- player = {}
- platform = {}
- background = {}
- blocGrass = {}
- blocDirt = {}
- fireball = {}
- flag = {}
- function love.load()
- love.window.setMode(1920, 1080) -- Change les dimensions de la fenêtre
- love.window.setFullscreen( true)
- debug = false
- background.img = love.graphics.newImage("image/Background.png")
- platform.width = love.graphics.getWidth()
- platform.height = love.graphics.getHeight()
- platform.x = 0
- platform.y = platform.height / 2
- blocGrass.img = love.graphics.newImage("image/grass.png") -- Paramètre de l'herbe
- blocGrass.x = 0
- blocGrass.y = love.graphics.getHeight() - (love.graphics.getHeight() /5)
- blocGrass.width = 32
- blocGrass.height = 32
- nbGrass = 0
- blocDirt.img = love.graphics.newImage("image/dirt.png") -- Paramètre de la terre
- blocDirt.x = 0
- blocDirt.y = blocGrass.y + 32
- blocDirt.width = 32
- blocDirt.height = 32
- nbDirt = 0
- i = 0
- flag.img = love.graphics.newImage("image/flag.png")
- flag.x = 1000
- flag.y = blocGrass.y
- player.img = love.graphics.newImage("image/p1_front.png")
- player.x = 100
- player.y = blocGrass.y
- player.speed = 200
- player.y_velocity = 0
- player.ground = player.y
- player.jump_height = -300
- player.gravity = -500
- fireball.x = 0
- end
- function placeGrass() -- on place tout les blocs
- while nbGrass < 60 do
- nbGrass = nbGrass+1
- love.graphics.draw(blocGrass.img, blocGrass.x + (blocGrass.height * (nbGrass - 1)), blocGrass.y)
- end
- nbGrass = 0
- end
- function placeDirt()
- while nbDirt < 60 do
- nbDirt = nbDirt+1
- while i < 7 do
- love.graphics.draw(blocDirt.img, blocDirt.x + (blocDirt.height * (nbDirt - 1)), blocDirt.y + (blocDirt.width *(i-1)))
- i = i + 1
- end
- i = 1
- end
- nbDirt = 0
- end
- function toggleDebug()
- debug = not debug
- end
- function initializeFireball()
- resetFireball()
- fireball.affich = not fireball.affich
- fireball.deplace = true
- end
- function resetFireball()
- fireball.img = love.graphics.newImage("image/fireball.png")
- fireball.x = player.x + player.img:getWidth()
- fireball.y = player.y - player.img:getHeight()/2
- fireball.vitesse = 5
- fireball.rotation = 0
- fireball.affich = false
- fireball.deplace = false
- end
- function refreshFireball(pt)
- fireball.x = fireball.x + fireball.vitesse
- fireball.rotation = fireball.rotation + 0.2
- end
- function love.update(dt)
- if love.keyboard.isScancodeDown("d") then
- if player.x < (love.graphics.getWidth() - player.img:getWidth()) then
- player.x = player.x + (player.speed * dt)
- end
- end
- if love.keyboard.isScancodeDown("a") then
- if player.x > 0 then
- player.x = player.x - (player.speed * dt)
- end
- end
- if love.keyboard.isScancodeDown("space") then
- if player.y_velocity == 0 then
- player.y_velocity = player.jump_height
- end
- end
- if player.y_velocity ~= 0 then
- player.y = player.y + player.y_velocity * dt
- player.y_velocity = player.y_velocity - player.gravity * dt
- end
- if player.y > player.ground then
- player.y_velocity = 0
- player.y = player.ground
- end
- if player.x < 0.3 then
- player.x = 0
- end
- if player.x > 1854 then
- player.x = 1854
- end
- if fireball.deplace == true then
- refreshFireball(dt)
- end
- if fireball.x > flag.x then
- fireball.affich = false
- end
- fps = love.timer.getFPS()
- end
- function love.draw()
- love.graphics.draw(background.img)
- love.graphics.setColor(255,255,255)
- --love.graphics.rectangle("fill", platform.x, 520, platform.width, 50)
- love.graphics.draw(flag.img, flag.x, blocGrass.y, 0, 1, 1, 0, 70)
- love.graphics.draw(player.img, player.x, player.y, 0, 1, 1, 0, 92)
- if fireball.affich == true then
- love.graphics.draw(fireball.img, fireball.x, fireball.y, fireball.rotation, 1, 1, fireball.img:getWidth()/2, fireball.img:getHeight()/2)
- end
- if debug == true then
- love.graphics.setColor(255,0,0)
- love.graphics.print(player.y_velocity, 0, 0)
- love.graphics.circle("fill", player.x, player.y, 5)
- love.graphics.print(player.y, 0, 15)
- love.graphics.print(player.x, 0, 30)
- love.graphics.print("fps : ", 1850, 0)
- love.graphics.print(fps, 1900, 0)
- love.graphics.circle("fill", 1280, blocGrass.y, 5)
- if fireball.affich == true then
- love.graphics.setColor(0,0,255)
- love.graphics.print(fireball.x, 1850, 15)
- love.graphics.circle("fill", fireball.x, fireball.y,5)
- end
- love.graphics.setColor(255,255,255)
- end
- placeGrass()
- placeDirt()
- end
- function love.keypressed(key, scancode, isRepeat)
- if scancode == "f1" then
- toggleDebug()
- end
- if scancode == "g" then
- love.window.close()
- end
- if scancode == "e" then
- initializeFireball()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement