Three questions.
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Three questions.
My game is currently a 2d platformer akin to Stick Soldiers. How would I make code that shoots a bullet at the mouse relative to world space and not pushing the player itself back from the force of the bullet? Also, how would you limit bullets to an absolute number? And, how do you limit the player to world space so he doesn't fly off in a direction?
- BlackBulletIV
- Inner party member
- Posts: 1261
- Joined: Wed Dec 29, 2010 8:19 pm
- Location: Queensland, Australia
- Contact:
Re: Three questions.
Why would be player go back from the force of the bullet? Wouldn't you have to do that on purpose for it to happen anyway?
Limiting the number of bullets is easy. Every time you create a bullet you increment a counter, and every time a bullet is destroyed (hits a wall, expires, and so on) you decrement a counter. If the counter is at the maximum level, then you just don't create bullets. For example:
Although I highly recommend not using global variable and encapsulated this sort of logic inside of a class (using middleclass or something similar).
Limiting player bounds is easy too. On every update just check whether the player x/y position is out of bounds and then push the player back.
Again I recommend encapsulating the logic in a class.
Limiting the number of bullets is easy. Every time you create a bullet you increment a counter, and every time a bullet is destroyed (hits a wall, expires, and so on) you decrement a counter. If the counter is at the maximum level, then you just don't create bullets. For example:
Code: Select all
counter = 0
max = 50 -- or something
-- bullet created
counter = counter + 1
-- bullet destroyed
counter = counter - 1
-- bullet creation
if counter < max then
-- create bullet
end
Limiting player bounds is easy too. On every update just check whether the player x/y position is out of bounds and then push the player back.
Code: Select all
function love.update(dt)
if player.x < minX then
player.x = minX
elseif player.x > maxX then
player.x = maxX
end
if player.y < minY then
player.y = minY
elseif player.y > maxY then
player.y = maxY
end
end
Re: Three questions.
The player would fly back because I am using love.physics.
Does that change everything?
Does that change everything?
- BlackBulletIV
- Inner party member
- Posts: 1261
- Joined: Wed Dec 29, 2010 8:19 pm
- Location: Queensland, Australia
- Contact:
Re: Three questions.
Um ok. I still don't get how the player flies back, maybe I don't know the physics system so well.
If you're meaning does that knowledge change everything I said, no. That code will still work.
EDIT: Wait, you'll have to set the position of the player's physical body in the out-of-bounds detection code.
If you're meaning does that knowledge change everything I said, no. That code will still work.
EDIT: Wait, you'll have to set the position of the player's physical body in the out-of-bounds detection code.
Re: Three questions.
Okay then.
But, what do I do about the rotation?
Also, how can I make a out-of-bounds function in regards to world space?
But, what do I do about the rotation?
Also, how can I make a out-of-bounds function in regards to world space?
- BlackBulletIV
- Inner party member
- Posts: 1261
- Joined: Wed Dec 29, 2010 8:19 pm
- Location: Queensland, Australia
- Contact:
Re: Three questions.
Rotation for which of your problems? Can please be more clear in your questions.
What do you mean "world space"? That function works with global coordinates.
What do you mean "world space"? That function works with global coordinates.
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 5 guests