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

#1 2012-03-09 15:37:13

OCE4point5
New Scratcher
Registered: 2012-01-08
Posts: 3

Attacks

I'm making game and I would like the enemies to shoot objects at the player if the player is within a certain range. Does anyone have any code that would do that, so far the code I've come up with doesn't work consistently?

Offline

 

#2 2012-03-09 19:27:15

GameCentral
Scratcher
Registered: 2011-10-05
Posts: 100+

Re: Attacks

when gf clicked
forever
if <(x of player) = [10]>
broadcast [shoot]
end
end

Last edited by GameCentral (2012-03-09 19:28:55)


http://i1237.photobucket.com/albums/ff468/sciteccf/gamecentral.gif
http://i.imgur.com/2RYxb.png

Offline

 

#3 2012-03-10 00:17:09

trinary
Scratcher
Registered: 2012-01-29
Posts: 1000+

Re: Attacks

Use these scripts.

In the enemies:

when gf clicked
forever
if <(distance to [player v]) < (50)> //or another distance
broadcast [shoot v] 
end
add movement scripts here
In the missiles:
when gf clicked
hide

when I receive [shoot v]
go to [enemy v]
show
glide (0.5) secs to x:([x position v] of [player v]) y:([y position v] of [player v]) //adjust for a faster/slower speed
hide
In the player:
when gf clicked
forever
if <touching [missile v]?>
change [health v] by (-1) //or another value
end
more scripts here
These scripts are very simple and rather inefficient but they should work.

Last edited by trinary (2012-03-10 00:18:45)


http://trinary.tk/images/signature_.php

Offline

 

#4 2012-03-12 18:00:24

GameCentral
Scratcher
Registered: 2011-10-05
Posts: 100+

Re: Attacks

trinary wrote:

Use these scripts.

In the enemies:

when gf clicked
forever
if <(distance to [player v]) < (50)> //or another distance
broadcast [shoot v] 
end
add movement scripts here
In the missiles:
when gf clicked
hide

when I receive [shoot v]
go to [enemy v]
show
glide (0.5) secs to x:([x position v] of [player v]) y:([y position v] of [player v]) //adjust for a faster/slower speed
hide
In the player:
when gf clicked
forever
if <touching [missile v]?>
change [health v] by (-1) //or another value
end
more scripts here
These scripts are very simple and rather inefficient but they should work.

that works better


http://i1237.photobucket.com/albums/ff468/sciteccf/gamecentral.gif
http://i.imgur.com/2RYxb.png

Offline

 

Board footer