Tables atempt: Whats wrong with my code?

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
User avatar
BEANSFTW
Prole
Posts: 28
Joined: Sun Apr 15, 2012 2:58 pm

Tables atempt: Whats wrong with my code?

Post by BEANSFTW »

Love2d doesn't give me any signs that I did something wrong, but my screen keeps Going black!
My code:

Rock.lua

Code: Select all


	Rocks = {}
	
	function Rocks_spawn(x, y, rock)
		table.insert(Rocks, {x=  x, y = y, rock = rock})
	end
	
	function Rocks_draw()
		for i,v in ipairs(Rocks) do
			love.graphics.setColor(0, 0, 0)
			love.graphics.draw(v.rock, v.x, v.y)
		end	
	end
Main.lua

Code: Select all



function love.load()

	require ("Rock")
	require ("anal")
	
	RockMoveS = 200
	RockMoveX = 355
	RockMoveY = 255
	
	Boulder = love.graphics.newImage("Rock.png")
	Rockmonster = love.graphics.newImage("Rockmonster.png")
	backround = love.graphics.newImage("backround.png")

	spritesheet = love.graphics.newImage("spritesheet.png") 
	spritesheet:setFilter("nearest", "nearest")             
	animation = newAnimation(spritesheet, 45, 45, 0.1, 2)
	
	Rocks_spawn(5, 200, Boulder)
	
end

function love.update(dt)

	if love.keyboard.isDown("d") and love.keyboard.isDown("s") then
		RockMoveS = 210
	end	

	if love.keyboard.isDown("a") and love.keyboard.isDown("s") then
		RockMoveS = 210
	end
	
	if love.keyboard.isDown("a") and love.keyboard.isDown("w") then
		RockMoveS = 205
	end	
	
	if love.keyboard.isDown("d") and love.keyboard.isDown("w") then
		RockMoveS = 205
	end	

	if love.keyboard.isDown("w") then
		RockMoveY = RockMoveY - RockMoveS*dt
		animation:update(dt)
	end	
	
	if love.keyboard.isDown("s") then
		RockMoveY = RockMoveY + RockMoveS*dt
		animation:update(dt)
	end

	if love.keyboard.isDown("d") then
		RockMoveX = RockMoveX + RockMoveS*dt
		animation:update(dt)
	end

	if love.keyboard.isDown("a") then
		RockMoveX = RockMoveX - RockMoveS*dt
		animation:update(dt)
	end	
	

	
	if RockMoveY > 555 then
		RockMoveY = 555
	end
	
	if RockMoveX > 755 then
		RockMoveX = 755
	end	
	
	if RockMoveY < 0 then
		RockMoveY = 0
	end
	
	if RockMoveX < 0 then
		RockMoveX = 0
	end
	
end

function love.draw()



	love.graphics.draw(backround, 0, 0)
	
	Rocks_draw()
	
	animation:draw(RockMoveX, RockMoveY, 0, 1)

end
Last edited by BEANSFTW on Tue Sep 25, 2012 10:53 pm, edited 1 time in total.
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: How do you use tables?

Post by Nixola »

Did you try Programming in Lua?
http://www.lua.org/pil/2.5.html
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
User avatar
tv_user
Citizen
Posts: 57
Joined: Sun Aug 12, 2012 4:39 pm
Location: Portugal

Re: How do you use tables?

Post by tv_user »

Table is the name given to the sole structure in lua programming. If you honestly don't know what they are and how to use them, it means you don't understand what you've been doing until now and, as Nixola did, I fear I must recommend you to read on Lua programming (either the official book or a tutorial, just google it). However, if you have a more specific question, try to explain it better to us.
Either way, good luck.
Did my comment help/offended you? Use the Karma button!!
LÖVEing each day...
User avatar
Dola
Prole
Posts: 14
Joined: Sat Aug 11, 2012 2:45 am
Location: Brasil

Re: Tables atempt: Whats wrong with my code?

Post by Dola »

In the Rocks_draw() function you set the colors to (0,0,0), black, so nothing is showing up because (probably) your background is black.Just change it to (255,255,255) and it should draw correctly.
User avatar
tv_user
Citizen
Posts: 57
Joined: Sun Aug 12, 2012 4:39 pm
Location: Portugal

Re: Tables atempt: Whats wrong with my code?

Post by tv_user »

Nice way to entirely change the topic BEANSFTW, lol!!!!!
Now everyone who sees mine and Nixola's comment will think we are crazy. Okay, but for your current question, as Dola said, when you set the color to be black (0,0,0), your rocks will be drawn with the color you chose (in your case black), and therefore appear as black objects. Change it to (255,255,255 -- white) to maintain the original color of the image.
Did my comment help/offended you? Use the Karma button!!
LÖVEing each day...
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 3 guests