Game Maker's Garage Forum

Game Creation => SilverCreator => Topic started by: Connors on February 23, 2010, 10:22:30 PM

Title: Help With program
Post by: Connors 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
Title: Re: Help With program
Post by: Xiphos 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.
Title: Re: Help With program
Post by: EqwanoX 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
Title: Re: Help With program
Post by: Xiphos 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)
Title: Re: Help With program
Post by: EqwanoX 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
Title: Re: Help With program
Post by: Xiphos on February 24, 2010, 03:03:27 PM
Oh okay thanks!
Title: Re: Help With program
Post by: Connors 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?  ???
Title: Re: Help With program
Post by: Xiphos on February 24, 2010, 05:51:57 PM
I'm not sure of the order, but this happened to me also.
Title: Re: Help With program
Post by: EqwanoX 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