Need help with my code (Read please)
Posted: Tue Oct 28, 2014 11:20 pm
Hello guys.
I need help with my code, I just have 3 questions by now.
I want that the "Defeat" sound, just plays once after "haValidoQueso". But I dont know how to do it.
I want that when "haValidoQueso", the player can't move anymore. But I dont know how, because when "haValidoQueso", the image "teemo" changes for the image "explosion", and thats ok, but I can still moving teemo.
This maybe is the most difficult thing in my script, but I want that "obstaculoUno" and "obstaculoDos" move constantly to the left, and dissapear when reaching the left part, and also that new "obstaculos" appear constantly, just like in "flappy bird", and if its not a hassle, I want that when "teemo" reach a "obstaculo", the game stop.
I leave the code that I have of all the game, thanks.
I need help with my code, I just have 3 questions by now.
I want that the "Defeat" sound, just plays once after "haValidoQueso". But I dont know how to do it.
I want that when "haValidoQueso", the player can't move anymore. But I dont know how, because when "haValidoQueso", the image "teemo" changes for the image "explosion", and thats ok, but I can still moving teemo.
This maybe is the most difficult thing in my script, but I want that "obstaculoUno" and "obstaculoDos" move constantly to the left, and dissapear when reaching the left part, and also that new "obstaculos" appear constantly, just like in "flappy bird", and if its not a hassle, I want that when "teemo" reach a "obstaculo", the game stop.
I leave the code that I have of all the game, thanks.
Code: Select all
-- main.lua
-- The Teemo's Fly
local posX = nil
local posY = nil
local speed = nil
local gravedad = nil
local avance = nil
local obstaculos = {}
local haValidoQueso = false
local haValidoChorizo = false
--Imagenes
local background = nil
local explosion = nil
local teemo = nil
local suelo = nil
local obstaculoUno = nil
local obstaculoDos = nil
--Sonidos
local defeat = nil
local Song = nil
-- El archivo de entrada a nuestra app.
function love.load()
--Imagenes
background = love.graphics.newImage("images/background.png")
explosion = love.graphics.newImage("images/explosion.png")
teemo = love.graphics.newImage("images/teemo.png")
suelo = love.graphics.newImage("images/groundDirt.png")
obstaculoUno = love.graphics.newImage("images/rockDown.png")
obstaculoDos = love.graphics.newImage("images/rock.png")
--Sonidos
defeat = love.audio.newSource("sounds/Defeat LOL.mp3")
Song = love.audio.newSource("sounds/teemo song.mp3")
--Otras cosas
posX = 100
posY = 240
speed = 300
gravedad = 150
end
function love.update(dt)
love.audio.play(Song)
if (haValidoQueso) then
love.audio.pause (Song)
end
--Avance!
--local avance = 480 - teemo:getHeight()
--posX = posX + (gravedad * dt)
-- Gravedad!
local piso = 480 - teemo:getHeight()
posY = posY + (gravedad * dt)
--Hacer que teemo se estrelle
if (posY > piso) then
posY = piso
--Avisar que ya perdimos
haValidoQueso = true
end
--Movimiento de Teemo
if love.keyboard.isDown("down") then
posY = posY + (speed * dt)
end
if love.keyboard.isDown("up") then
posY = posY - (speed * dt)
end
--Cerrar el juego
if love.keyboard.isDown("escape") then
love.event.quit()
end
--Sonido de defeat
if (haValidoQueso) then
love.audio.play(defeat)
end
end
function love.draw()
love.graphics.draw(background, 0, 0)
love.graphics.draw(obstaculoDos, 500, 480 - obstaculoDos:getHeight())
love.graphics.draw(obstaculoUno, 700, 0)
love.graphics.draw(suelo, 0, 480 - 70)
if (haValidoQueso) then
love.graphics.draw(explosion, posX, posY - 40)
else
love.graphics.draw(teemo, posX, posY)
end
end