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

#1 2012-07-02 12:35:24

paul2978
New Scratcher
Registered: 2012-05-31
Posts: 13

zombie game

I am trying to make a zombie type of scenario where a zombie heads towards another sprite, once it touches that sprite it then turns that sprite into a zombie and then moves on to the next.

Currently I have the zombie following the person1, but it always follows person1 if I create multiple copies of person1 eg person2, person3, it just follows person1.

I am unable to think of way to make the zombie to either

A follow them all or individual based on the distance they are from the zombie,

or

make the zombie follow the person2 once it has touched and infected person1.

Any suggestions help?

Paul

Offline

 

#2 2012-07-02 13:51:28

Prestige
Scratcher
Registered: 2008-12-15
Posts: 100+

Re: zombie game

Hey there Paul, I will try and help you - I am a big fan of AI Algorithms  big_smile

1) "Follow all people based on distance"
Construct a script like this. Any words in (brackets) are variables you'll need to make and those in [square brackets] are lists.
Set (counter) to 1
Delete all of [distances]
Repeat {number of people}
    Add {Distance to JOIN {person(counter)}} to [distances]
    change (counter) by 1

Note - this adds the distances to each person to memory, now you'll need an algorithm to determine the closest person to target

Set (target) to 0
Set (counter) to 1
Set (shortest distance) to 600 {just a large number >= 600}
Repeat {length of [distances]}
    if {item (counter) of [distances]} < (shortest distance)
              set (target) to (counter)
              set (shortest distance) to {item (counter) of [distances]}
    change counter by 1

Note - now the variable (shortest distance) will be the distance to the closest person and the number of that person is represented by the variable (target). Now we can go toward the target.

point towards JOIN {person(target)}
move {2} steps

Note - Change the speed to decide the pace of the zombie. Add this script to all zombies and execute it in a loop to always target the closest person.


2) Only target people, not infected people.
Create a variable on all people/zombies, (state). At the beginning, set the (state) of all starting zombies to "zombie" and all people to "people". Redo the script above but with one change which wont allow them to target (state) = "people".

Set (counter) to 1
Delete all of [distances]
Repeat {number of people}
    Add {Distance to JOIN {person(counter)}} to [distances]
    if (state) of JOIN {person(counter)} = zombie
                replace last of [distances] with 999
               
  change (counter) by 1

Set (target) to 0
Set (counter) to 1
Set (shortest distance) to 600 {just a large number >= 600}
Repeat {length of [distances]}
    if {item (counter) of [distances]} < (shortest distance)
              set (target) to (counter)
              set (shortest distance) to {item (counter) of [distances]}
    change counter by 1

point towards JOIN {person(target)}
move {2} steps

if (shortest distance) = 999
      Note - all people are zombies if the above statement is true, so the game is over.



_______________________


I hope this helps, let me know if you have any other questions I can help with  smile

Prestige

Last edited by Prestige (2012-07-02 13:53:30)


"Don't insult someone until you've walked a mile in their shoes. That way, if they don't like what you have to say, you'll be a mile away and still have their shoes  smile  "

Offline

 

#3 2012-07-02 13:58:59

SciTecCf
Scratcher
Registered: 2011-11-23
Posts: 1000+

Re: zombie game

Prestige was here. No further help is required.  lol


http://bit.ly/LCZEJRhttp://bit.ly/LSONcOhttp://bit.ly/LF3vIc
http://trinary.site40.net/images/scratchrank.php?username=SciTecCf&amp;display=small

Offline

 

#4 2012-07-02 15:57:55

paul2978
New Scratcher
Registered: 2012-05-31
Posts: 13

Re: zombie game

Hey prestige thanks for the script will need to sit down and see what I can sort.

Is your YouTube channel kamiprestige? Great work:)

Offline

 

#5 2012-07-02 17:31:53

Prestige
Scratcher
Registered: 2008-12-15
Posts: 100+

Re: zombie game

On this particular topic SciTecCf  tongue  On all the others I can sit back and let you and amcerbu help out!  smile 

@Paul2978 Good luck scripting that, wouldn't want to be you! Its a toughie if you're new to scratch, and welcome also if you are new!  big_smile  Indeed, kamiprestige is my channel, though 'mostly' non-scratch related  smile  Btw, if I don't reply to a forum post in a while just drop me a comment on a project so i get a notification and know to check it back - wish forums gave you notifications  tongue

Prestige


"Don't insult someone until you've walked a mile in their shoes. That way, if they don't like what you have to say, you'll be a mile away and still have their shoes  smile  "

Offline

 

#6 2012-07-02 17:42:31

Prestige
Scratcher
Registered: 2008-12-15
Posts: 100+

Re: zombie game

Just to clarify also, to make the explanation a little better for the numbers:

" Set (shortest distance) to 600 {just a large number >= 600} "
600 is the maximum possible distance 2 sprites on a stage could be apart. The stage is 480x360, so using pythagoras' sqrt(480^2 + 360^2) = 600. In other words the hypotenuse on the stage is 600 pixels long and is therefore the maximum distance 2 sprites on a stage could be apart. This means every distance value from the list MUST be shorter than 600 so the script won't ever break. You could set the value to 208832852 but as long as it is equal or greater ( >= ) than 600 it will work!

" replace last of [distances] with 999 "
No mathematical rubbish here, its the largest 3 digit integer  wink
Also it must be bigger than 600. If it was 580, then ( incredibly infrequently ) a non-infected person could be 600 pixels away and the zombies would instead auto-track a nearby zombie. So again, this number can be anything as long as its greater than the number you chose before ( ie the 600 )


"Don't insult someone until you've walked a mile in their shoes. That way, if they don't like what you have to say, you'll be a mile away and still have their shoes  smile  "

Offline

 

Board footer