Page 1 of 2

[SDL] Shooting and Hello World!

Posted: Fri May 15, 2009 9:07 am
by newbie1234
First of all, I would like to say hello to everyone here on this forum.

I have a question: Can somebody tell me or give me some sort of example of how to implement shooting feature in 2D platformer?
To be more precise, I want that bullet appears on left/right side of the character( depends on how main character is turned ) and speeds up until he collides with wall tiles.( pretty much something like Falco had in his video about previous projects I think ( Tile Demo or whatever that thing is called ) )

Oh, and I am using C++ and SDL if that matters. ....:)

Re: [SDL] Shooting and Hello World!

Posted: Fri May 15, 2009 9:47 am
by Falco Girgis
Y'know what, I have read this post like three times, and I have written (and deleted) maybe two different responses.

I'm going to do something a little different with you. Implementing bullets (my tile demo style) is really easy. I know you could do it. Instead of me just telling you a way to do it, you will do it yourself (on these boards), and we will walk you through.

I'll get you started. What is a bullet? It's a little box/sprite/square on the screen that goes either from right to left or left to right depending on the direction you were facing when you shot it.

Okay, so lets make a simple bullet class containing necessary things:

Code: Select all

class Bullet {
public:
    int x, y;
    int direction; //We'll be simple and say like 0 is facing left and 1 is facing right
    void Update();  //Make the bullet move based on direction
};
Okay, now you can start off by defining your "Update()" function and telling us what you think the next step should be.

Re: [SDL] Shooting and Hello World!

Posted: Fri May 15, 2009 1:40 pm
by eatcomics
GyroVorbis wrote:Y'know what, I have read this post like three times, and I have written (and deleted) maybe two different responses.

I'm going to do something a little different with you. Implementing bullets (my tile demo style) is really easy. I know you could do it. Instead of me just telling you a way to do it, you will do it yourself (on these boards), and we will walk you through.

I'll get you started. What is a bullet? It's a little box/sprite/square on the screen that goes either from right to left or left to right depending on the direction you were facing when you shot it.

Okay, so lets make a simple bullet class containing necessary things:

Code: Select all

class Bullet {
public:
    int x, y;
    int direction; //We'll be simple and say like 0 is facing left and 1 is facing right
    void Update();  //Make the bullet move based on direction
};
Okay, now you can start off by defining your "Update()" function and telling us what you think the next step should be.
Good idear Gyro... We should do this more often to teach independent thought to the youth of america...

Re: [SDL] Shooting and Hello World!

Posted: Fri May 15, 2009 3:57 pm
by Kros
eatcomics wrote:america...
What if hes not from America? =)

Re: [SDL] Shooting and Hello World!

Posted: Fri May 15, 2009 4:21 pm
by ultimatedragoon69
it's nice to meet you, and great idea gyro.

---

“Give a man a fish; you have fed him for today. Teach a man to fish; and you have fed him for a lifetime”

-unkown person wrote this.

Re: [SDL] Shooting and Hello World!

Posted: Fri May 15, 2009 8:52 pm
by eatcomics
Kros wrote:
eatcomics wrote:america...
What if hes not from America? =)
I'll bring him to america, anymore questions???

Re: [SDL] Shooting and Hello World!

Posted: Fri May 15, 2009 10:25 pm
by MarauderIIC
eatcomics wrote:I'll bring him to america, anymore questions???
Yeah. What do you smoke, again?

Re: [SDL] Shooting and Hello World!

Posted: Sat May 16, 2009 1:24 am
by eatcomics
MarauderIIC wrote:
eatcomics wrote:I'll bring him to america, anymore questions???
Yeah. What do you smoke, again?
a LOOOOOOOOOOOOOT.... other than that I refuse to tell....

Edit: Everybody's goin to the party have a real good time....

Re: [SDL] Shooting and Hello World!

Posted: Sat May 16, 2009 2:58 am
by Martyj
Wouldn't you want your object's attributes to be private. That way you don't have someone setting a value that they cannot store into it. Like trying to get a long type (don't know if c++ has longs for data types) into an int. Then again, you probably won't be storing a long into a data type for positions.

Anyways this is a very great idea. Teach not tell. Get them to think of the answer and not give them.

Re: [SDL] Shooting and Hello World!

Posted: Sat May 16, 2009 9:58 am
by MarauderIIC
Falco's not a big fan of accessors. And you would use accessors to prevent returning NULL values or accessing arrays out-of-bounds, that sort of thing, not to avoid data conversion.
Hope OP replies soon :D

Re: [SDL] Shooting and Hello World!

Posted: Sat May 16, 2009 11:02 am
by Falco Girgis
Martyj wrote:Wouldn't you want your object's attributes to be private. That way you don't have someone setting a value that they cannot store into it. Like trying to get a long type (don't know if c++ has longs for data types) into an int. Then again, you probably won't be storing a long into a data type for positions.

Anyways this is a very great idea. Teach not tell. Get them to think of the answer and not give them.
Oh, god.

I don't use accessors that do absolutely nothing but return and set a value. I use them when they do things like check for debugging, update multiple things, or as Marauder said. Otherwise it's pointless to me. You're writing more, useless code, your code that utilizes these accessors becomes 10 times uglier, etc.

It's up to you, but I would rather not treat this like a first year CS class. I also didn't want to discourage or confuse him with all of the complete OO whore bullshit. ;)

Re: [SDL] Shooting and Hello World!

Posted: Sun May 17, 2009 1:52 pm
by Innerscope
I'm hoping newbie1234 didn't decide to bail when Falco told him to write his own "Update" function. :nono:

Re: [SDL] Shooting and Hello World!

Posted: Sun May 17, 2009 11:30 pm
by Falco Girgis
Wow, this is why I don't help people.

Re: [SDL] Shooting and Hello World!

Posted: Mon May 18, 2009 11:20 am
by newbie1234
Hello everyone!

Wow, I wasn't expecting that you all will reply to my question so quickly. Thanks!
Unfortunately, I wasn't been able to write my own update function due to the lack of time. Work was really pushing hard on me lately, but I will have some time after 20th May. ;)

Re: [SDL] Shooting and Hello World!

Posted: Mon May 18, 2009 3:00 pm
by dandymcgee
GyroVorbis wrote:Wow, this is why I don't help people.
newbie1234 wrote:Hello everyone!

Wow, I wasn't expecting that you all will reply to my question so quickly. Thanks!
Unfortunately, I wasn't been able to write my own update function due to the lack of time. Work was really pushing hard on me lately, but I will have some time after 20th May. ;)
Not all hope is lost! Hehe, he wasn't expecting the crazy reply speed that takes place here on the forums. Feel free to make an attempt whenever you get time, newbie1234, and we'll help you build off of your base code. :)