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

#1 2012-04-26 14:28:56

Borrego6165
Scratcher
Registered: 2011-03-10
Posts: 1000+

Evil Rayman- Trying to make it follow Rayman's every move

Rayman 4

The shadow can copy his moves, it's just his X and Y positions that need sorting out. By the way, it is meant to be delayed by a few steps, so if real Rayman jumps the evil Rayman will jump after around 2 seconds.

What I need is the X and Y positions matching. If it was non-scrolling, this would be really easy, but because Rayman never moves, only the background scrolls, it's really hard to detect his position on the screen.

Remember: Real Rayman never moves, but the "shadow" must move on screen, and only when real Rayman stops for too long will the "shadow" catch up with him and kill him. I will program the killing script later, for now the "shadow" just needs to keep up with him.

If you have played Candy Chateax (yes it's spelt like that) in Rayman 1 than you will know what I mean.


Generation:4001 Build a beautiful city, with over 50 objects and over 10000 tiles per city! This simulates traffic, pollution, tourism, crime and more!

Offline

 

#2 2012-04-26 16:48:02

amcerbu
Scratcher
Registered: 2009-07-21
Posts: 500+

Re: Evil Rayman- Trying to make it follow Rayman's every move

The easiest way is to create x and y variables for the Rayman sprite, and adjust those when you use the arrow keys.  ScrollX and ScrollY are then set based on those. 

I guess we'll just say that Rayman_Shadow is 20 frames behind Rayman.  So...

For the Rayman sprite:

when gf clicked
set [numberFramesBehind v] to (20)
set [ListIndex v] to (1)
delete (all v) of [previousXPositions v]
delete (all v) of [previousYPositions v]
repeat (numberFramesBehind)
  add [0] to [previousXPositions v]
  add [0] to [previousYPositions v]
end
forever
  if <key [right arrow v] pressed?>
    do something to [PositionX v]
  end
  if <key [left arrow v] pressed?>
    do something to [PositionX v]
  end
  if <key [up arrow v] pressed?>
    do something to [PositionY v]
  end
  set [ScrollX v] to (PositionX) // Maybe PositionX * -1, depending on config.
  set [ScrollY v] to (PositionY) // Again, don't know how you have it set up.  
  replace item (ListIndex) of [previousXPositions v] with (PositionX)
  replace item (ListIndex) of [previousYPositions v] with (PositionY)
  broadcast [ShadowUpdate v] and wait
  change [ListIndex v] by (1)
  if <(ListIndex) > (numberFramesBehind)>
    set [ListIndex v] to (1)
  end
end
Now, put this script in Rayman_Shadow
when I receive [ShadowUpdate v]
set x to ( item ( ((ListIndex) mod (numberFramesBehind)) + (1) ) of [PreviousXPositions v] )
set y to ( item ( ((ListIndex) mod (numberFramesBehind)) + (1) ) of [PreviousYPositions v] )
That should work.  I still have to test the shadow script sometime, I'll edit it and fix if it doesn't work.

Last edited by amcerbu (2012-04-27 16:25:33)

Offline

 

#3 2012-04-27 02:36:46

Borrego6165
Scratcher
Registered: 2011-03-10
Posts: 1000+

Re: Evil Rayman- Trying to make it follow Rayman's every move

amcerbu wrote:

The easiest way is to create x and y variables for the Rayman sprite, and adjust those when you use the arrow keys.  ScrollX and ScrollY are then set based on those. 

I guess we'll just say that Rayman_Shadow is 20 frames behind Rayman.  So...

For the Rayman sprite:

when gf clicked
set [numberFramesBehind v] to (20)
set [ListIndex v] to (1)
delete (all v) of [previousXPositions v]
delete (all v) of [previousYPositions v]
repeat (numberFramesBehind)
  add [0] to [previousXPositions v]
  add [0] to [previousYPositions v]
end
forever
  if <key [right arrow v] pressed?>
    do something to [PositionX v]
  end
  if <key [left arrow v] pressed?>
    do something to [PositionX v]
  end
  if <key [up arrow v] pressed?>
    do something to [PositionY v]
  set [ScrollX v] to (PositionX) // Maybe PositionX * -1, depending on config.
  set [ScrollY v] to (PositionY) // Again, don't know how you have it set up.  
  replace item (ListIndex) of [previousXPositions v] with (PositionX)
  replace item (ListIndex) of [previousYPositions v] with (PositionY)
  broadcast [ShadowUpdate v] and wait
  change [ListIndex v] by (1)
  if <(ListIndex) > (numberFramesBehind)>
    set [ListIndex v] to (1)
  end
end
Now, put this script in Rayman_Shadow
when I receive [ShadowUpdate v]
set x to ( item ( ((ListIndex) mod (numberFramesBehind)) + (1) ) of [PreviousXPositions v] )
set y to ( item ( ((ListIndex) mod (numberFramesBehind)) + (1) ) of [PreviousYPositions v] )
That should work.  I still have to test the shadow script sometime, I'll edit it and fix if it doesn't work.

i'll give it a try- thanks  big_smile


Generation:4001 Build a beautiful city, with over 50 objects and over 10000 tiles per city! This simulates traffic, pollution, tourism, crime and more!

Offline

 

#4 2012-04-27 16:30:30

amcerbu
Scratcher
Registered: 2009-07-21
Posts: 500+

Re: Evil Rayman- Trying to make it follow Rayman's every move

Borrego6165 wrote:

hey- you know on the forums? well you told me to make some changes to my Rayman 4 game for the shadow, and I was wondering if you could help me out. It mostly works, but with jumping the shadow over does it, and I was wondering how I could calculate it perfectly to match the correct jump.

Borrego6165,

If you could upload the project as it is, I'll take a look at it.  I'm not sure how you have scrolling and all the rest set up. 

From the description of the bug, it looks like there are other scripts also acting on Rayman_Shadow.  Make sure you don't have any other code running at the same time.  Make sure as well that the sensing scripts for movement and the scripts for recording velocity are all under one loop, or that they run one at a time.  Anything will work, as long as you don't have two forever loops running. 

Example:
All under one loop:

when gf clicked
initialize list
forever
  move Rayman based on keyboard input
  record Rayman's positions, broadcast to Rayman_Shadow
end
... or if you want to use separate scripts
when gf clicked
initialize list
forever
  move Rayman based on keyboard input.
  broadcast [recordPositions v] and wait
end

when I receive [recordPositions v]
record Rayman's positions, broadcast to Rayman_Shadow
The key to all these scripts is that you're using broadcast and wait.  The waiting makes sure that you don't end up with multiple scripts running at the same time and affecting eachother in ways you don't want.

Last edited by amcerbu (2012-04-27 16:31:04)

Offline

 

#5 2012-04-27 17:07:27

Borrego6165
Scratcher
Registered: 2011-03-10
Posts: 1000+

Re: Evil Rayman- Trying to make it follow Rayman's every move

but i have uploaded the project, that was what the link was for a couple of messages above. And what I used was already quite similar to the second example.


Generation:4001 Build a beautiful city, with over 50 objects and over 10000 tiles per city! This simulates traffic, pollution, tourism, crime and more!

Offline

 

#6 2012-04-27 17:11:22

amcerbu
Scratcher
Registered: 2009-07-21
Posts: 500+

Re: Evil Rayman- Trying to make it follow Rayman's every move

Whoops, sorry about that.  Give me a second to check it out.  I played the first level.  Where does the shadow come in?

Last edited by amcerbu (2012-04-27 17:11:37)

Offline

 

#7 2012-04-27 17:23:23

Borrego6165
Scratcher
Registered: 2011-03-10
Posts: 1000+

Re: Evil Rayman- Trying to make it follow Rayman's every move

amcerbu wrote:

Whoops, sorry about that.  Give me a second to check it out.  I played the first level.  Where does the shadow come in?

Load Game One, it;s saved on level 5 when the evil shadow comes in


Generation:4001 Build a beautiful city, with over 50 objects and over 10000 tiles per city! This simulates traffic, pollution, tourism, crime and more!

Offline

 

#8 2012-04-28 14:40:30

amcerbu
Scratcher
Registered: 2009-07-21
Posts: 500+

Re: Evil Rayman- Trying to make it follow Rayman's every move

I've checked it out/downloaded, but I'm still trying to figure out why the shadow is off.  I'll get back to you later this weekend or sometime next week.

Offline

 

#9 2012-04-28 14:46:44

Borrego6165
Scratcher
Registered: 2011-03-10
Posts: 1000+

Re: Evil Rayman- Trying to make it follow Rayman's every move

amcerbu wrote:

I've checked it out/downloaded, but I'm still trying to figure out why the shadow is off.  I'll get back to you later this weekend or sometime next week.

oh sorry! but tomorrow is the April 29th celebrations day, and due to lack of time I had to delete the shadow and improvise new sections of the level. However, I would much appreciate it if you still carried out your investigation so that I can use it in my future games.

That means you'll have lots of extra time too!


Generation:4001 Build a beautiful city, with over 50 objects and over 10000 tiles per city! This simulates traffic, pollution, tourism, crime and more!

Offline

 

Board footer