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

#1 2008-09-03 17:53:29

Bobby500
Scratcher
Registered: 2008-04-19
Posts: 1000+

Mouse Recorder Thing with Scrolling Capabilties?

I am trying to make a racing agme where you race through the course and then on the second lap, a ghost of you apears and does the exact same thing you did in the first lap. How would I make it so the ghost car changes its x by the scroll x thingy...I am getting confused writeing this. Any Ideas?

Offline

 

#2 2008-09-03 20:34:06

fullmoon
Retired Community Moderator
Registered: 2007-06-04
Posts: 1000+

Re: Mouse Recorder Thing with Scrolling Capabilties?

Try this, maybe? Let me know if it's too hard to understand (it is for me  tongue ) and I'll make a demo. In fact, I might just do one anyway...

//Code for the ghost
When I receive [newLap]
Set [ghost] effect to (50)
//Cause he's a ghost, right?
Show
Set [prevLap] to (thisLap-1)
repeatUntil not(thisLap=prevLap):
/*This is where it gets murky. Depending on the scrolling system you use, you may want to change the values in the following equation...*/
Set X to (item (i) of [lastLapX])
Set Y to (item (i) of [lastLapY])
//Instead, maybe try "set x to item (i) of [lastlapX] - 240"
If (touching edge?)
Hide
Else
Show
EndIF
Change i by 1
endRep

//Code for your car (or bus, or albatross, or whatever):
When I receive [newLap]
prevLap=thisLap
RepeatUntil(prevLap<thisLap)
/*Scratch doesn't support 2-dimensional arrays, and it doesn't handle data very fast. So you may have to create a new array for every lap.*/
//Code for recording into another array here, or for transferring data between arrays.
//maybe: add (scrollX) to [anotherListThatWillBeReadByTheGhostNextLap]
endRep


http://i302.photobucket.com/albums/nn100/fullmoon32/wow.jpg

Offline

 

#3 2008-09-03 20:42:59

Bobby500
Scratcher
Registered: 2008-04-19
Posts: 1000+

Re: Mouse Recorder Thing with Scrolling Capabilties?

Make a demo cause I am lost. Lists confuse me completely.

Offline

 

#4 2008-09-03 20:46:55

archmage
Scratcher
Registered: 2007-05-18
Posts: 1000+

Re: Mouse Recorder Thing with Scrolling Capabilties?

Ah I know how to go about doing this and it should work. Instead of recording the position of the car just record what keys were pressed.

I imagine the code would look something like this. The lists LEFT, RIGHT, and SPACE are recordings of the users previous key presses. If a value equals 1 then the key was down at the time otherwise it will equal 0.

//on the ghost car
//this has the variables X and Y
// j is the number of positions in the lists
set i to 1
repeat until (i=j)
if LEFT at (i) = 1
//whatever your rotation is, I have it at 10
turn -10
if RIGHT at (i) = 1
//whatever your rotation is, I have it at 10
turn 10
change X by sin of direction
change Y by cos of direction
set x to (X+scrollX) y to (Y+scrollY)
change i by 1

Something like that.


Hi, I am Archmage coder extraordinaire. I do Scratch,pascal,java,php,html, AS2 and AS3. Leave me a message if you want coding advice. Also check out my personal website, lots of good stuff about web development, Flash, and Scratch (v1 and v2) !

Offline

 

#5 2008-09-04 05:47:12

Bobby500
Scratcher
Registered: 2008-04-19
Posts: 1000+

Re: Mouse Recorder Thing with Scrolling Capabilties?

archmage wrote:

Ah I know how to go about doing this and it should work. Instead of recording the position of the car just record what keys were pressed.

I imagine the code would look something like this. The lists LEFT, RIGHT, and SPACE are recordings of the users previous key presses. If a value equals 1 then the key was down at the time otherwise it will equal 0.

//on the ghost car
//this has the variables X and Y
// j is the number of positions in the lists
set i to 1
repeat until (i=j)
if LEFT at (i) = 1
//whatever your rotation is, I have it at 10
turn -10
if RIGHT at (i) = 1
//whatever your rotation is, I have it at 10
turn 10
change X by sin of direction
change Y by cos of direction
set x to (X+scrollX) y to (Y+scrollY)
change i by 1

Something like that.

I will try it. This just seemed like a good game for 1.3

Offline

 

#6 2008-09-04 15:51:28

archmage
Scratcher
Registered: 2007-05-18
Posts: 1000+

Re: Mouse Recorder Thing with Scrolling Capabilties?

Bobby500, I made a project to demonstrate what I said. Unfortunately it doesn't work online. Try downloading to see the code.

http://scratch.mit.edu/projects/archmage/257300


Hi, I am Archmage coder extraordinaire. I do Scratch,pascal,java,php,html, AS2 and AS3. Leave me a message if you want coding advice. Also check out my personal website, lots of good stuff about web development, Flash, and Scratch (v1 and v2) !

Offline

 

Board footer