[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

Re: [SDL] Shooting and Hello World!

Post by newbie1234 »

Hmm, I imagine that the code for Update() function should look like something like this:

Code: Select all

Bullet::Update()
{
      if( direction == 1 )
      {
           x++;
      }
      
      if( direction == 0 )
      {
           x--;
      }
}
What do you guys think?
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 »

newbie1234 wrote:Hmm, I imagine that the code for Update() function should look like something like this:

Code: Select all

Bullet::Update()
{
      if( direction == 1 )
      {
           x++;
      }
      
      if( direction == 0 )
      {
           x--;
      }
}
What do you guys think?
Yeah, that'll do the trick.
User avatar
trufun202
Game Developer
Game Developer
Posts: 1105
Joined: Sun Sep 21, 2008 12:27 am
Location: Dallas, TX
Contact:

Re: [SDL] Shooting and Hello World!

Post by trufun202 »

I'm a fan of having Direction being 1 and -1, then you can do this:

Code: Select all

Bullet::Update()
{
     x += 1 * direction;
}
Either way works, of course. ;)
-Chris

YouTube | Twitter | Rad Raygun

“REAL ARTISTS SHIP” - Steve Jobs
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 »

trufun202 wrote:I'm a fan of having Direction being 1 and -1, then you can do this:

Code: Select all

Bullet::Update()
{
     x += 1 * direction;
}
Either way works, of course. ;)
oOoOo, clevar!
User avatar
trufun202
Game Developer
Game Developer
Posts: 1105
Joined: Sun Sep 21, 2008 12:27 am
Location: Dallas, TX
Contact:

Re: [SDL] Shooting and Hello World!

Post by trufun202 »

GyroVorbis wrote:
trufun202 wrote:I'm a fan of having Direction being 1 and -1, then you can do this:

Code: Select all

Bullet::Update()
{
     x += 1 * direction;
}
Either way works, of course. ;)
oOoOo, clevar!
This also allows you to switch directions easily:

Code: Select all

direction *= -1;
/flex
-Chris

YouTube | Twitter | Rad Raygun

“REAL ARTISTS SHIP” - Steve Jobs
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 »

Code: Select all

direction *= -1;

/flex
Nice invert, been hitting the gym lately?


I'm thinking you might need a constant for the speed as well...
and lets not forget up and down: -2,2 :twisted:

Code: Select all

	if((direction % 2)==0) {
			y += speed * direction/2;
	}else{
			x += speed * direction;
	}

:lol: just kidding
Current Project: Gridbug
Website (under construction) : http://www.timcool.me
fingerfry
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 34
Joined: Tue Sep 01, 2009 6:31 pm
Favorite Gaming Platforms: Xbox 360, PC, Gameboy Advance SP
Location: Palm Desert, California
Contact:

Re: [SDL] Shooting and Hello World!

Post by fingerfry »

ultimatedragoon69 wrote: “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.
I believe THIS is the correct quote:
“Give a man a fish; you have fed him for today. Teach a man to fish; and you have fed him for a lifetime. Teach a man to sell fish and he eats steak.”

—Author unknown
;)
Image
User avatar
hurstshifter
ES Beta Backer
ES Beta Backer
Posts: 713
Joined: Mon Jun 08, 2009 8:33 pm
Favorite Gaming Platforms: SNES
Programming Language of Choice: C/++
Location: Boston, MA
Contact:

Re: [SDL] Shooting and Hello World!

Post by hurstshifter »

fingerfry wrote:
ultimatedragoon69 wrote: “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.
I believe THIS is the correct quote:
“Give a man a fish; you have fed him for today. Teach a man to fish; and you have fed him for a lifetime. Teach a man to sell fish and he eats steak.”

—Author unknown
;)

How dare you resurrect a 4 month old thread...
"Time is an illusion. Lunchtime, doubly so."
http://www.thenerdnight.com
fingerfry
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 34
Joined: Tue Sep 01, 2009 6:31 pm
Favorite Gaming Platforms: Xbox 360, PC, Gameboy Advance SP
Location: Palm Desert, California
Contact:

Re: [SDL] Shooting and Hello World!

Post by fingerfry »

hurstshifter wrote:
fingerfry wrote:
ultimatedragoon69 wrote: “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.
I believe THIS is the correct quote:
“Give a man a fish; you have fed him for today. Teach a man to fish; and you have fed him for a lifetime. Teach a man to sell fish and he eats steak.”

—Author unknown
;)

How dare you resurrect a 4 month old thread...

You got to start somewhere :roll:
Image
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 »

Actually, the correct one is: “Sell a man a fish, he eats for a day, teach a man how to fish, you ruin a wonderful business opportunity.” - Karl Marx.
User avatar
captjack
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 50
Joined: Fri Sep 18, 2009 4:23 pm
Current Project: engine framework
Favorite Gaming Platforms: PC, XBox 360, PS3
Programming Language of Choice: C, C++
Location: Northern Virginia

Re: [SDL] Shooting and Hello World!

Post by captjack »

trufun202 wrote:
GyroVorbis wrote:
trufun202 wrote:I'm a fan of having Direction being 1 and -1, then you can do this:

Code: Select all

Bullet::Update()
{
     x += 1 * direction;
}
Either way works, of course. ;)
oOoOo, clevar!
This also allows you to switch directions easily:

Code: Select all

direction *= -1;
/flex

Who said math isn't cool? :)
Post Reply