Three questions.

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
Raylin
Prole
Posts: 30
Joined: Thu Dec 30, 2010 8:48 am
Location: Chicago
Contact:

Three questions.

Post by Raylin »

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?
User avatar
BlackBulletIV
Inner party member
Posts: 1261
Joined: Wed Dec 29, 2010 8:19 pm
Location: Queensland, Australia
Contact:

Re: Three questions.

Post by BlackBulletIV »

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:

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
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.

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
Again I recommend encapsulating the logic in a class.
User avatar
Raylin
Prole
Posts: 30
Joined: Thu Dec 30, 2010 8:48 am
Location: Chicago
Contact:

Re: Three questions.

Post by Raylin »

The player would fly back because I am using love.physics.

Does that change everything?
User avatar
BlackBulletIV
Inner party member
Posts: 1261
Joined: Wed Dec 29, 2010 8:19 pm
Location: Queensland, Australia
Contact:

Re: Three questions.

Post by BlackBulletIV »

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.
User avatar
Raylin
Prole
Posts: 30
Joined: Thu Dec 30, 2010 8:48 am
Location: Chicago
Contact:

Re: Three questions.

Post by Raylin »

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?
User avatar
BlackBulletIV
Inner party member
Posts: 1261
Joined: Wed Dec 29, 2010 8:19 pm
Location: Queensland, Australia
Contact:

Re: Three questions.

Post by BlackBulletIV »

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.
Post Reply

Who is online

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