Comments (1)
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)
- Missing images in chapter 20 HOT 1
- Link to animation assets is broken in chapter 17
- [suggestion] Use Luarocks variable naming conventions HOT 3
- Chapter Idea - States
- Translate HOT 1
- Website 404 HOT 1
- Chapter 11 has some issue HOT 1
- Prefer `.luarc.json` over VS Code-specific configuration
- Chapter 21 - Saving and loading HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from how-to-love.