[SDL] Shooting and Hello World!

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

newbie1234
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 15
Joined: Fri May 15, 2009 9:01 am
Current Project: I'm currently making my own GUI
Favorite Gaming Platforms: Err... Linux?
Programming Language of Choice: C++
Location: St. Petersburg, Russian Federation

[SDL] Shooting and Hello World!

Post 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. ....:)
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Re: [SDL] Shooting and Hello World!

Post 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.
User avatar
eatcomics
ES Beta Backer
ES Beta Backer
Posts: 2528
Joined: Sat Mar 08, 2008 7:52 pm
Location: Illinois

Re: [SDL] Shooting and Hello World!

Post 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...
Image
User avatar
Kros
Chaos Rift Regular
Chaos Rift Regular
Posts: 136
Joined: Tue Feb 24, 2009 4:01 pm
Current Project: N/A
Favorite Gaming Platforms: PC, Playstation/2/3
Programming Language of Choice: C++
Location: Oregon,USA
Contact:

Re: [SDL] Shooting and Hello World!

Post by Kros »

eatcomics wrote:america...
What if hes not from America? =)
Isaac Asimov wrote:Part of the inhumanity of the computer is that, once it is competently programmed and working smoothly, it is completely honest.
YouTube Channel
User avatar
ultimatedragoon69
Chaos Rift Regular
Chaos Rift Regular
Posts: 122
Joined: Tue Oct 28, 2008 1:57 pm
Current Project: Pangea's quest (text ~tile~ based rpg)
Favorite Gaming Platforms: Dreamcast, PC, playstation 1, Virtual Boy, Snes
Programming Language of Choice: c++
Contact:

Re: [SDL] Shooting and Hello World!

Post 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.
User avatar
eatcomics
ES Beta Backer
ES Beta Backer
Posts: 2528
Joined: Sat Mar 08, 2008 7:52 pm
Location: Illinois

Re: [SDL] Shooting and Hello World!

Post by eatcomics »

Kros wrote:
eatcomics wrote:america...
What if hes not from America? =)
I'll bring him to america, anymore questions???
Image
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Re: [SDL] Shooting and Hello World!

Post by MarauderIIC »

eatcomics wrote:I'll bring him to america, anymore questions???
Yeah. What do you smoke, again?
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
User avatar
eatcomics
ES Beta Backer
ES Beta Backer
Posts: 2528
Joined: Sat Mar 08, 2008 7:52 pm
Location: Illinois

Re: [SDL] Shooting and Hello World!

Post 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....
Image
Martyj
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 20
Joined: Thu Apr 23, 2009 11:23 am
Location: Ogden Utah
Contact:

Re: [SDL] Shooting and Hello World!

Post 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.
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Re: [SDL] Shooting and Hello World!

Post 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
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Re: [SDL] Shooting and Hello World!

Post 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. ;)
User avatar
Innerscope
Chaos Rift Junior
Chaos Rift Junior
Posts: 200
Joined: Mon May 04, 2009 5:15 pm
Current Project: Gridbug
Favorite Gaming Platforms: NES, SNES
Programming Language of Choice: Obj-C, C++
Location: Emeryville, CA
Contact:

Re: [SDL] Shooting and Hello World!

Post by Innerscope »

I'm hoping newbie1234 didn't decide to bail when Falco told him to write his own "Update" function. :nono:
Current Project: Gridbug
Website (under construction) : http://www.timcool.me
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Re: [SDL] Shooting and Hello World!

Post by Falco Girgis »

Wow, this is why I don't help people.
newbie1234
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 15
Joined: Fri May 15, 2009 9:01 am
Current Project: I'm currently making my own GUI
Favorite Gaming Platforms: Err... Linux?
Programming Language of Choice: C++
Location: St. Petersburg, Russian Federation

Re: [SDL] Shooting and Hello World!

Post 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. ;)
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: [SDL] Shooting and Hello World!

Post 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. :)
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
Post Reply