Git Product home page Git Product logo

Comments (1)

rafauke avatar rafauke commented on July 30, 2024

Hello @Rusbelito,

The problem is the naming that you are using in the code. Please have a look at your main.lua file.

function love.load()

Objecto = require "classic"
require "Jugador"
require "Enemigo"
require "Bala"

 Jugador = Jugador() -- oops, Jugador is no longer an extended Object :(
 Enemigo = Enemigo() -- oops, same goes here :(
 ListaDeBalas = {}
 
end


function love.update(dt)
Jugador:update(dt)
Enemigo:update(dt)

for i,v in ipairs(ListaDeBalas) do
v:update(dt)
v:collicionR_R(Enemigo)



 if v.dead then
 table.remove(ListaDeBalas,i)
end

end
end

function love.draw()
Jugador:draw()
Enemigo:draw()

for i,v in ipairs(ListaDeBalas) do
 v:draw()
end
end

function love.keypressed(key)
  Jugador:keypressed(key)
end

What happens is that you are overwriting Jugador and Enemigo classes with their instances, so you no longer have a blueprint/instruction how to create a player or enemy anymore. When the game starts, it tries to create new Player, but it won't be possible, since it's not a class that can be instantiated. Have a look at the fix:

function love.load()

Objecto = require "classic"
require "Jugador"
require "Enemigo"
require "Bala"

 jugador = Jugador() -- now the blueprint stays intact :)
 enemigo = Enemigo() -- enemy is also safe :)
 ListaDeBalas = {}
 
end


function love.update(dt)
jugador:update(dt) -- we are updating a player instance here, not Player class anymore
enemigo:update(dt) -- same goes for the enemy

for i,v in ipairs(ListaDeBalas) do
v:update(dt)
v:collicionR_R(enemigo) -- let's trigger collision for the `enemy`, which is an instance of `Enemy` class



 if v.dead then
 table.remove(ListaDeBalas,i)
end

end
end

function love.draw()
jugador:draw()
enemigo:draw()

for i,v in ipairs(ListaDeBalas) do
 v:draw()
end
end

function love.keypressed(key)
  jugador:keypressed(key)
end

So, right now you are updating the instances, not that classes that serve as your blueprints/recipes.

I hope that helps :)

from how-to-love.

Related Issues (10)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.