Topic:   Help With program   (Read 10014 times)


0 Members and 1 Guest are viewing this topic.

Connors


  • ^ This guy is amazing.

  • ****


  • Posts: 2374

  • It's a secret to everyone...
Help With program
« on: February 23, 2010, 10:22:30 PM »
I have finally decided I want to try using SC again... I've had an old shooter game project sitting on my computer for a long time, and I wanted some help continuing it.


So far I have the ship that can move around fine and some enemy sprites. What I'd like to know is if there is a way to make enemies appear with one piece of code that affects all of them at once. (I programmed 3 enemies separately)

(sprite 1 is background)

Code so far:

Open Card:
Code: [Select]
CREATESPRITE 1, "BG"
MOVESPRITE 1,0,0

CREATESPRITE 2, "Ship"
MOVESPRITE 2,100,

CREATESPRITE 3, "UFO"
MOVESPRITE 3, 700, random(300)

CREATESPRITE 4, "UFO"
MOVESPRITE 4, 700, random(300)

CREATESPRITE 5, "UFO"
MOVESPRITE 5, 700, random(300)

ON TIMER (3)
   PUSHSPRITE 1, -2,0
   PUSHSPRITE 3, -5,0
   PUSHSPRITE 4, -5,0
   PUSHSPRITE 5, -5,0
END TIMER

Key Down:

Code: [Select]
IF key$ = uparrow$ THEN
   PUSHSPRITE 2,0,-7
END IF

IF key$ = downarrow$ THEN
   PUSHSPRITE 2,0,7
END IF

IF key$ = leftarrow$ THEN
   PUSHSPRITE 2,-7,0
END IF

IF key$ = rightarrow$ THEN
   PUSHSPRITE 2,7,0
END IF
Warning: The above post may have been modified multiple times.

"In a great game, the character must never perfectly obey the user's command"
 - Tim Rogers

http://connorspuzzles.tumblr.com/

Xiphos


  • GMG-er

  • **


  • Posts: 676
Re: Help With program
« Reply #1 on: February 24, 2010, 07:32:36 AM »
Make sprite 5 your ship.

Code: [Select]
FOR x = 1 to 4
IF spritevalid(x) = TRUE THEN
Pushsprite x, -5, 0
END IF
NEXT

Not sure if arrays would but that would push them all.

EqwanoX


  • Administrator

  • GMG Extraordinaire

  • *****


  • Posts: 1180
Re: Help With program
« Reply #2 on: February 24, 2010, 09:59:42 AM »
and itll run much smoother if you add a "1" at the end of the pushsprite commnands and then "updatescreen" after all the sprites have been pushed

for x=1 to 4
pushsprite x, 5, 5, 1     //<---"1" here
next
updatescreen

Xiphos


  • GMG-er

  • **


  • Posts: 676
Re: Help With program
« Reply #3 on: February 24, 2010, 02:18:32 PM »
What does updatescreen do?

Update the screen right? And what does the "1" do?

(Sorry I'm a noob)
« Last Edit: February 24, 2010, 02:19:08 PM by Xiphos »

EqwanoX


  • Administrator

  • GMG Extraordinaire

  • *****


  • Posts: 1180
Re: Help With program
« Reply #4 on: February 24, 2010, 02:45:08 PM »
the 1 will hold the screen from being updated, other wise it will move each sprite individually rather than simultaniously

Xiphos


  • GMG-er

  • **


  • Posts: 676
Re: Help With program
« Reply #5 on: February 24, 2010, 03:03:27 PM »
Oh okay thanks!

Connors


  • ^ This guy is amazing.

  • ****


  • Posts: 2374

  • It's a secret to everyone...
Re: Help With program
« Reply #6 on: February 24, 2010, 04:44:08 PM »
Code: [Select]
CREATESPRITE 1, "UFO"
CREATESPRITE 2, "UFO"
CREATESPRITE 3, "UFO"
CREATESPRITE 4, "UFO"

CREATESPRITE 6, "BG"
MOVESPRITE 6,0,0

CREATESPRITE 5, "Ship"

MOVESPRITE 5, 50, 180

FOR x = 1 TO 4
   IF SPRITEVALID(x) = TRUE THEN
      MOVESPRITE x, 700, random(300)
   END IF
NEXT

ON TIMER (3)
   PUSHSPRITE 6, -2,0
END TIMER


I can understand that I probably did something odd with the enemies (1 through 4) but what about my ship!? All that is shown is the Back Ground...
Or could the background be in front of them?  ???
Warning: The above post may have been modified multiple times.

"In a great game, the character must never perfectly obey the user's command"
 - Tim Rogers

http://connorspuzzles.tumblr.com/

Xiphos


  • GMG-er

  • **


  • Posts: 676
Re: Help With program
« Reply #7 on: February 24, 2010, 05:51:57 PM »
I'm not sure of the order, but this happened to me also.

EqwanoX


  • Administrator

  • GMG Extraordinaire

  • *****


  • Posts: 1180
Re: Help With program
« Reply #8 on: February 24, 2010, 06:33:54 PM »
yup, the higher number sprites will overlap the lower number sprites, so you should make the back ground sprite 1