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

#1 2012-04-19 14:53:26

Rocket-Moon
New Scratcher
Registered: 2012-04-16
Posts: 14

Area Damage

You know when you throw a grenage or shoot a rocket in some sirst-person shooter games, they blow up right? I was wandering if this can be done in scratch witha simple 2d game, when you shoot a rocket it flies, touches something, and blows up while damaging the enemies around this. I have tried this but i don't know use. Any suggestions?

Offline

 

#2 2012-04-19 15:18:26

PhirripSyrrip
Scratcher
Registered: 2012-02-11
Posts: 100+

Re: Area Damage

How bout this?
For the Projectile:

forever
if <touching [object v]?>
repeat [length of animation]
next costume
end
end
and in another script
forever
if <touching [enemies v]?>
broadcast [kill v]
end
end
and then you'd programme the enemies do do something when they are killed. This method would work if you want to make a proper, fiery explosion. However, you'd have to make each frame of the explosion individually which can be annoying and time-consuming and tricky.

A simpler way would be to use a sort of "symbolic" explosion. For Example, if the game is from a bird's-eye (plan) view, the explosion could be symbolised with, say, a circle that grows out of the point of where the projectile hits something. Here would be the script for this:
For the projectile:
forever
if <touching [object v]?>
broadcast [explosion v]
end
end
for the explosion (this would be a separate sprite)
when i receive [explosion v]
show
set size to [10]%
go to [projectile v]
repeat [10]
change size by 10
if touching [enemies v]
broadcast [kill v]
end
hide


http://i46.tinypic.com/ao03lk.png

Offline

 

#3 2012-04-19 15:21:26

PhirripSyrrip
Scratcher
Registered: 2012-02-11
Posts: 100+

Re: Area Damage

meant to write:

if <touching [enemies v]?>
broadcast [kill v]
end


http://i46.tinypic.com/ao03lk.png

Offline

 

#4 2012-04-19 15:28:43

PhirripSyrrip
Scratcher
Registered: 2012-02-11
Posts: 100+

Re: Area Damage

and I do believe that that post was the 4000th in the "Help with Scripts" category!


http://i46.tinypic.com/ao03lk.png

Offline

 

#5 2012-04-19 15:39:31

joefarebrother
Scratcher
Registered: 2011-04-08
Posts: 1000+

Re: Area Damage

well broadcast sends a message to everything, so all the enemies will die at once!
But you could do

when i receive [explosion v]
set size to (0) %
go to [wherever the explosion is - usually a sprite v]
show
repeat (50)
change size by (2)%
wait [a short amount - probably 0.001] secs
end
hide


when i receive [spawn v] //Then in the enemy scripts
if <<(alive) = [yes]> and <(number of enemies) = [number indicating this enemy - start from 0 for the first one then add one for each new enemy you add]>>
set [alive v] to [yes] //make alive a "for this sprite only" variable
change [number of enemies v] by (1)
show
forever
do stuff
if <touching [explosion v]?>
hide
change [number of enemies v] by (-1)
set [alive v] to [no]
stop script
end

Last edited by joefarebrother (2012-04-19 15:40:31)


My latest project is called http://tinyurl.com/d2m8hne! It has http://tinyurl.com/d395ygk views, http://tinyurl.com/cnasmt7 love-its, and http://tinyurl.com/bwjy8xs comments.
http://tinyurl.com/756anbk   http://tinyurl.com/iplaychess

Offline

 

#6 2012-04-21 16:28:39

Noobie600
New Scratcher
Registered: 2012-04-21
Posts: 7

Re: Area Damage

thank you

Offline

 

Board footer