require("PlayerShip")
require("Bullet")
function love.load()
love.graphics.setBlendMode('alpha')
love.graphics.toggleFullscreen()
PShip = PlayerShip.Create()
Bullets = {}
for i = 1, 1000 do
Bullets[i] = {}
end
BulletIndex = 1
end
function love.keypressed(k)
if k == 'escape' then
love.event.push('q') --Quits the game
end
--TODO: Create bullet instance and add to array!
if k == 'lctrl' then
Bullets[BulletIndex] = Bullet.Create()
BulletIndex = BulletIndex + 1
end
end
function love.update(dt)
if love.keyboard.isDown('up') then
PShip.Y = PShip.Y - 1
end
if love.keyboard.isDown('down') then
PShip.Y = PShip.Y + 1
end
if love.keyboard.isDown('left') then
PShip.X = PShip.X - 1
end
if love.keyboard.isDown('right') then
PShip.X = PShip.X + 1
end
--for i = 1, 1000 do
-- if not Bullets[i] == nil then
-- Bullets[i].Y = Bullets[i].Y - 1
-- end
--end
end
function love.draw()
love.graphics.draw(PShip.Image, PShip.X, PShip.Y)
for i = 1, 1000 do
if Bullets[i] == not nil then
love.graphics.draw(Bullets[i].Image, Bullets[i].X, Bullets[i].Y)
end
end
end
Bullet = {}
BulletMT = { Index = Bullet } --This metatable will be attached to every created class instance.
function Bullet:Create()
local NewInstance =
{
Image = love.graphics.newImage("Bullet.png"),
X = 350,
Y = 80
} --The new instance
setmetatable(NewInstance, BulletMT) --All instances share the same metatable.
return NewInstance
end
That is some bullshit right there. "== not" doesn't exist, what it does it checks if it is equal to "not nil", which is "true" (the boolean), you could use either
function Bullet:Create()
local NewInstance =
{
Image = love.graphics.newImage("Bullet.png"),
X = 350,
Y = 80
} --The new instance
setmetatable(NewInstance, BulletMT) --All instances share the same metatable.
return NewInstance
end
You might not want to make a new Image for every bullet you create -- it will eat up a lot of resources.
Bullet.Image = love.graphics.newImage("Bullet.png"),
function Bullet:Create()
local NewInstance =
{
X = 350,
Y = 80
} --The new instance
setmetatable(NewInstance, BulletMT) --All instances share the same metatable.
return NewInstance
end
Last but not least, Bullet:Create() is still overly verbose. This will work just as well:
Bullet = {}
BulletMT = { __index = Bullet } --This metatable will be attached to every created class instance.
Bullet.Image = love.graphics.newImage("Bullet.png")
function Bullet:Create()
local NewInstance =
{
X = 350,
Y = 90
} --The new instance
setmetatable(NewInstance, BulletMT) --All instances share the same metatable.
return NewInstance
end
require("PlayerShip")
require("Bullet")
function love.load()
love.graphics.setBlendMode('alpha')
love.graphics.toggleFullscreen()
PShip = PlayerShip.Create()
Bullets = {}
for i = 1, 1000 do
Bullets[i] = {}
end
BulletIndex = 1
end
function love.keypressed(k)
if k == 'escape' then
love.event.push('q') --Quits the game
end
--TODO: Create bullet instance and add to array!
if k == 'lctrl' then
Bullets[BulletIndex] = Bullet.Create()
BulletIndex = BulletIndex + 1
end
end
function love.update(dt)
if love.keyboard.isDown('up') then
PShip.Y = PShip.Y - 1
end
if love.keyboard.isDown('down') then
PShip.Y = PShip.Y + 1
end
if love.keyboard.isDown('left') then
PShip.X = PShip.X - 1
end
if love.keyboard.isDown('right') then
PShip.X = PShip.X + 1
end
--for i = 1, 1000 do
-- if not Bullets[i] == nil then
-- Bullets[i].Y = Bullets[i].Y - 1
-- end
--end
end
function love.draw()
love.graphics.draw(PShip.Image, PShip.X, PShip.Y)
for i = 1, 1000 do
if Bullets[i] then
love.graphics.draw(Bullets[i].Image, Bullets[i].X, Bullets[i].Y)
end
end
end
Now I get an error on the love.graphics.draw() call on line 59! 'Expected userdata'!
What does this mean?
Also... any plans to incorporate network support into Löve anytime soon?
Edit: Robin, I made a game a long time ago in Blitz Basic I called 'Space'. The game I'm kinda puzzling with now I was thinking of calling 'Space 2'. Hope you don't mind!
You see, empty tables are true. And when drawing those bullets, you only check whether they are true, not if they actually have an Image. If you remove those three lines, it will (hopefully ) work fine.
Afr0 wrote:Edit: Robin, I made a game a long time ago in Blitz Basic I called 'Space'. The game I'm kinda puzzling with now I was thinking of calling 'Space 2'. Hope you don't mind!
I am only disappointed -- that you are as bad as me in making original names.
bartbes wrote:we have an excellent networking library called LUBE