Help-Respawning at the top of the screen after touching bottom

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
zecky
Prole
Posts: 1
Joined: Mon Mar 30, 2020 1:26 am

Help-Respawning at the top of the screen after touching bottom

Post by zecky »

So I'm making a school activity and I want the square to appear at the top of the screen moving downwards and after touching a rectangle set at the bottom of the screen the score count goes up by one, right now what happens is that the square spawns at the bottom and moves slowly to the right.

Code: Select all

cuadro = {}
cuadro.x = 250
cuadro.y = 5
cuadro.vx = 10
cuadro.vy = 100
cuadro.width = 10
cuadro.height = 10

circulo = {}
circulo.x = 255
circulo.y = 400
circulo.size = 20

rect = {}
rect.x = 0
rect.y = 425
rect.width = 500
rect.height = 20

function love.load()
  score = 0
  time = 10
  speed = 300
  inicio = 1
  fuente = love.graphics.newFont("Fuentes/mama.ttf", 15)
end

function love.update(dt)---fucntion
  if inicio == 2 then---1
    if time > 0 then---2
      time = time - dt
    end---2
    if time < 0 then---3
      time = 0
      inicio = 1
    end---3
    Mover(dt)
    cuadro.x = cuadro.x + (cuadro.vx * dt)
    cuadro.y = cuadro.y + (cuadro.vy * dt)
    if Distancia(cuadro.y == rect.y) then---4
      Recolectar()
    end---4
  end---1
end---function

function love.draw()
  if inicio == 2 then
    love.graphics.setColor(235/255, 50/255, 50/255)
    love.graphics.circle("fill", circulo.x, circulo.y, circulo.size)

    love.graphics.setColor(50/255, 235/255, 50/255)
    love.graphics.rectangle("line", cuadro.x, cuadro.y, cuadro.width, cuadro.height)

    love.graphics.setColor(255/255, 255/255, 255/255)
    love.graphics.rectangle("fill", rect.x, rect.y, rect.width, rect.height)
  end

  love.graphics.setColor(1,1,1)
  love.graphics.setFont(fuente)
  love.graphics.print("Score: ".. score, 400, 465)
  love.graphics.print("Time: "..math.ceil(time), 30,465)

  if inicio == 1 then
    love.graphics.setFont(fuente)
    love.graphics.setColor(1, 1, 1)
    love.graphics.printf("Press spacebar to dodge", 0, love.graphics.getHeight()/2,love.graphics.getWidth(),"center")
  end
end

function Mover(d)
  if inicio == 2 then
    if love.keyboard.isDown("left") and circulo.x > 0 + circulo.size then
      circulo.x = circulo.x - speed * d
    end
    if love.keyboard.isDown("right") and circulo.x < love.graphics.getWidth() - circulo.size then
      circulo.x = circulo.x + speed * d
    end
  end
end

function love.keypressed(key)
  if key == "space" then
    inicio = 2
    time = 10
    score = 0
  end
end

function Recolectar()
  cuadro.x = math.random(100, love.graphics.getWidth())
  cuadro.y = math.random(100, love.graphics.getHeight())
  score = score + 1
end

function Distancia()
  cuadro.y = love.graphics.getHeight()
end
Post Reply

Who is online

Users browsing this forum: No registered users and 57 guests