This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-08-25 14:40:40

mgrbarton
New Scratcher
Registered: 2012-05-11
Posts: 10

Endless Enemies?

Does anyone know how to make one sprite (an enemy) keep on reappearing after you kill him?

Offline

 

#2 2012-08-25 15:29:28

Scratcher456
Scratcher
Registered: 2010-12-04
Posts: 58

Re: Endless Enemies?

Um... I think I see what you mean. The same sprite can't be in two places at one time, but if you want the same sprite to reappear AFTER you kill it, that's not hard. Let's say you want the sprite to 'die' after being hit by the sprite 'bullet' and then reappear after between 2 and 10 seconds at the point X:-240, Y:0. You'd probably do something like this:

when gf clicked
 forever
  if <touching [bullet v]?>
   hide
   wait (pick random (2) to (10)) secs
   go to x: (-240) y: (0)
   show
  end
end

Last edited by Scratcher456 (2012-08-25 15:33:59)


Mining diamonds, mining diamonds, mining diamonds...

Offline

 

#3 2012-08-25 15:35:18

BirdByte
Scratcher
Registered: 2012-07-07
Posts: 1000+

Re: Endless Enemies?

Scratcher456 wrote:

The same sprite can't be in two places at one time, but if you want the same sprite to reappear AFTER you kill it, that's not hard.

Actually, it can. Stamping FTW.


http://i50.tinypic.com/312u714.jpg

Offline

 

#4 2012-08-25 17:31:31

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: Endless Enemies?

BirdByte wrote:

Scratcher456 wrote:

The same sprite can't be in two places at one time, but if you want the same sprite to reappear AFTER you kill it, that's not hard.

Actually, it can. Stamping FTW.

Stamping is one of the best tools Scratch offers.  Unfortunately it can be quite complex to program some really cool stamping techniques.

Anyway, the basic code is something like this:

when I receive [enemy_come_in v]
forever
set [enemy health v] to (10)
broadcast [start enemy AI v]
wait until <not<(enemy health) > (0)>>


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#5 2012-08-25 22:12:10

Scratcher456
Scratcher
Registered: 2010-12-04
Posts: 58

Re: Endless Enemies?

BirdByte wrote:

Scratcher456 wrote:

The same sprite can't be in two places at one time, but if you want the same sprite to reappear AFTER you kill it, that's not hard.

Actually, it can. Stamping FTW.

True, I hadn't thought of that. The problem is, stamping can get confusing. FAST. It also tends to slow things down when used too much. Theoretically, though, it's not hard to have one sprite be several sprites. I've never played with it, but I've seen some really cool stuff done with it.


Mining diamonds, mining diamonds, mining diamonds...

Offline

 

#6 2012-08-25 22:22:41

zammer990
Scratcher
Registered: 2012-01-22
Posts: 500+

Re: Endless Enemies?

Scratcher456 wrote:

BirdByte wrote:

Scratcher456 wrote:

The same sprite can't be in two places at one time, but if you want the same sprite to reappear AFTER you kill it, that's not hard.

Actually, it can. Stamping FTW.

True, I hadn't thought of that. The problem is, stamping can get confusing. FAST. It also tends to slow things down when used too much. Theoretically, though, it's not hard to have one sprite be several sprites. I've never played with it, but I've seen some really cool stuff done with it.

Turbo mode or single frame code makes it instant. And with an easy function for the sprite to perform, for example move until i die or hit the player. It's rather simple to implement:

when gf clicked
forever
set [counter v] to (1)
repeat (length of [x positions v])
go to x:(item (counter) of [x positions v]) y:(item (counter) of [y positions v])
move (speed) steps
stamp
if <touching [player v]?>
change [player health v] by (-10)
replace item (counter) of [x positions v] with (original x)//another list 
replace item (counter) of [y positions v] with (original y)//could go here
else
replace item (counter) of [x positions v] with (x position)
replace item (counter) of [y positions v] with (y position)
end
change [counter v] by (1)
With a list of original xs, ys, and two more for the mutable positions, you can easily have as any enemies as you want. And with changing "ifs" that use the counter variable, you can have them behave differently. I try to use as few sprites as possible in my projects, so I use this a lot.


http://i45.tinypic.com/2ynq7nn.jpg Play now!

Offline

 

Board footer