Love.Draw problem

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
Aamer13
Prole
Posts: 10
Joined: Mon Jul 29, 2013 9:52 pm

Love.Draw problem

Post by Aamer13 »

--excuse the messy file name

What im currently working on is simplified version of bomberman (^_^ awesome game) and i cant figure out how to spawn a bomb

In my love.load i have 2 objects player.ball and player.bomb

Code: Select all

player = {}

player.ball= {}

player.ball.body = love.physics.newBody(world,650/2,1200/2,'dynamic') -- player Ball
player.ball.shape = love.physics.newCircleShape(20) --20 radius
player.ball.fixture = love.physics.newFixture(player.ball.body, player.ball.shape)

player.bomb = {}

player.bomb.body = player.ball.body
player.bomb.shape = love.physics.newCircleShape(10)
player.bomb.fixture = love.physics.newFixture(player.bomb.body, player.bomb.shape)
in my love.update i have controls for the player.ball and if space is pressed i change a state into true

Code: Select all

function love.update(dt)
world:update(dt)

if love.keyboard.isDown ('left') then
player.ball.body:applyForce(-400,0)
elseif love.keyboard.isDown ('right') then
player.ball.body:applyForce(400,0)
elseif love.keyboard.isDown ('up') then
player.ball.body:applyForce (0,-400)
elseif love.keyboard.isDown ('down') then
player.ball.body:applyForce (0,400)
elseif love.keyboard.isDown (' ') then
bombstate = yes
end
end
and finally in love.draw i want to make it so only when 'space' is down it will draw the player.bomb

Code: Select all

function love.draw()

love.graphics.setColor (0,255,0)
love.graphics.polygon('fill',wall.ground.body:getWorldPoints(wall.ground.shape:getPoints()))
if bombstate == yes then
love.graphics.circle('fill', player.bomb.body:getX(), player.bomb.body:getY(), player.bomb.shape:getRadius())
end
love.graphics.setColor (0,0,0)
love.graphics.polygon('fill',wall.roof.body:getWorldPoints(wall.roof.shape:getPoints()))
love.graphics.polygon('fill', wall.left.body:getWorldPoints(wall.left.shape:getPoints()))
love.graphics.polygon('fill', wall.right.body:getWorldPoints(wall.right.shape:getPoints()))

love.graphics.polygon('fill', objects.onepointone.body:getWorldPoints(objects.onepointone.shape:getPoints()))
love.graphics.polygon ('fill', objects.onepointtwo.body:getWorldPoints(objects.onepointtwo.shape:getPoints()))

love.graphics.setColor(255,0,0)

love.graphics.circle('fill', player.ball.body:getX(), player.ball.body:getY(), player.ball.shape:getRadius())

end
Attachments
main.lua
(3.49 KiB) Downloaded 91 times
fsadf.love
(921 Bytes) Downloaded 69 times
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Love.Draw problem

Post by raidho36 »

Get rid of physics. After that, it'll get obvious.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Love.Draw problem

Post by Robin »

In your code, the variable yes is undefined, which means it is nil. Just like bombstate.

Replace:

Code: Select all

elseif love.keyboard.isDown (' ') then
bombstate = yes
end
by:

Code: Select all

end
bombstate = love.keyboard.isDown (' ')
And replace:

Code: Select all

if bombstate == yes then
by:

Code: Select all

if bombstate then
Also: indentation.
Help us help you: attach a .love.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 0 guests