Page 1 of 1

mousepressed vs. mouse.isDown PowerUp

Posted: Sun Dec 30, 2012 8:18 am
by TheDeskPop
Scenario Normal: When a user hits an entity:

Code: Select all

function love.mousepressed( x, y, button )
     if button == "l" then 
     ents.shoot(x, y)
end
Scenario wished for: For specific entity when killed or hit I wish to grant a power up.
I think this will come from love.mouse.isDown ("l") with a random number associated with dt in love.update and function Powerup
The random number associated with dt will be so that the Powerup does not last forever.

I have searched, tried, and have not been able to solve this. I hate asking for code but if anyone has any pointers I would be grateful!

Re: mousepressed vs. mouse.isDown PowerUp

Posted: Sun Dec 30, 2012 12:53 pm
by OmarShehata
I'm not sure what you mean by a random number and dt and all that, do you simply want that when an enemy is killed, the player gets a power that he can use whenever he wants?

If so, you just need to create a table called "Powerups" for example. And whenever you want to grant a power, do:

Code: Select all

--when enemy dies
Powerups["BigCannon"] = true;
And then

Code: Select all

function love.mousepressed( x, y, button )
     if(button == "l" and Powerups["BigCannon"] == true) then
     --fire big cannon
    Powerups["BigCannon"] = false;
end
So the BigCannon will only fire when you've gained the power up and press "l".

If you want the powerups to be cumulative (i.e you can gain several powerups) just store a number in the table instead of "true" or "false"

Did that make any sense? If you need any more help, or if that's not what you were asking for, feel free to ask again!

Re: mousepressed vs. mouse.isDown PowerUp

Posted: Sun Dec 30, 2012 4:39 pm
by TheDeskPop
That is close to what I need. However the numbers would be a number so that the PowerUp does not last forever. I need it to somehow go away after being used.

The reason I mentioned mouse.isDown is because I want the user to be able to hold the mouse button down for continuous fire after killing the PowerUp enemy.
So in other words after killing the PowerUp enemy it would then grant automatic fire rather than single shot fire.