(Solved) No objects are being drawn

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Torbaz
Prole
Posts: 2
Joined: Mon May 28, 2018 10:04 am

(Solved) No objects are being drawn

Post by Torbaz »

Code: Select all

	enemy = {}
	enemies_controller = {}
	enemies_controller.enemies = {}
	
function love.load()
	player = {}
	player.x = 0
	player.y = 575
	player.bullets = {}
	player.cooldown = 40
	player.speed = 5
	player.fire = function()
		if player.cooldown <= 0 then
			player.cooldown = 40
			bullet = {}
			bullet.x = player.x + 35
			bullet.y = player.y - 5
			table.insert(player.bullets, bullet)
		end
	end
	enemies_controller:spawnEnemy()
end

function enemies_controller:spawnEnemy()
	enemy = {}
	enemy.x = 0
	enemy.y = 0
	enemy.bullets = {}
	enemy.cooldown = 40
	enemy.speed = 5
	table.insert(self.enemies, enemy)
end

function enemy:fire()
	if self.cooldown <= 0 then
		self.cooldown = 40
		bullet = {}
		bullet.x = self.x + 35
		bullet.y = self.y - 5
		table.insert(player.bullets, bullet)
end

function love.draw()
	-- Draw the player
	love.graphics.setColor(0, 0, 255)
	love.graphics.rectangle("fill", player.x, player.y, 80, 20)
	-- Draw Bullets
	love.graphics.setColor(255, 255, 255)
	for _, b in pairs(player.bullets) do
		love.graphics.rectangle("fill", b.x, b.y, 10, 10)
	end
end

function love.update(dt)
	player.cooldown = player.cooldown - 1
	if love.keyboard.isDown("right") then
		player.x = player.x + player.speed
	end

	if love.keyboard.isDown("left") then
		player.x = player.x - player.speed
	end

	if love.keyboard.isDown("space") then
		player.fire()
	end

	for i, b in ipairs(player.bullets) do
		if b.y < -10 then
			table.remove(player.bullets, i)
		end
		b.y = b.y - 5
	end

end
end
Nothing is being drawn when I run the program
Last edited by Torbaz on Mon May 28, 2018 11:30 pm, edited 1 time in total.

Code: Select all

player.happiness = 100 - bugs.unsolved * 5
KayleMaster
Party member
Posts: 234
Joined: Mon Aug 29, 2016 8:51 am

Re: No objects are being drawn

Post by KayleMaster »

If this is 11+ version, you'd need the color values to be between 0-1, not 0-255.

edit: check bobbyjones answer
Last edited by KayleMaster on Mon May 28, 2018 10:58 am, edited 1 time in total.
bobbyjones
Party member
Posts: 730
Joined: Sat Apr 26, 2014 7:46 pm

Re: No objects are being drawn

Post by bobbyjones »

So maybe I'm just not pairing them up properly but you have a stray end at the end of the file. Is all of the code you shown wrapped in another function?

Edit: found it. Remove the end at the end of the file and add after the end for enemy:fire(). You ended the if statement but did not end the function. I'm assuming you ended up with an error and just threw an extra end at the end. I've done that when I first started. I recommend indenting the code properly. It will allow you see things that are missing really easily.
Torbaz
Prole
Posts: 2
Joined: Mon May 28, 2018 10:04 am

Re: No objects are being drawn

Post by Torbaz »

bobbyjones wrote: Mon May 28, 2018 10:43 am So maybe I'm just not pairing them up properly but you have a stray end at the end of the file. Is all of the code you shown wrapped in another function?

Edit: found it. Remove the end at the end of the file and add after the end for enemy:fire(). You ended the if statement but did not end the function. I'm assuming you ended up with an error and just threw an extra end at the end. I've done that when I first started. I recommend indenting the code properly. It will allow you see things that are missing really easily.
Thanks :)

Code: Select all

player.happiness = 100 - bugs.unsolved * 5
Post Reply

Who is online

Users browsing this forum: skagonTheIdiot and 82 guests