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

#1 2007-09-20 12:50:51

EdnaC
Scratcher
Registered: 2007-08-28
Posts: 100+

Moon Lander Demo

Demo of a spaceship in a gravity field (that points straight down).  Instead of using trig to resolve the ship's velocity into X and Y, the velocity is tracked as magnitude and direction using two "helper" sprites.

http://scratch.mit.edu/projects/EdnaC/37711

How?
2d motion can be described by knowing where you are (easy) and where you are going.  Where the ship is going to go is determined by "how fast" and "what direction".  These are stored as variables so they can be "remembered" from one point in time to the next.

First: (and continuously), the ship gets user input (turning), and asks for updates from its helpers; (Broadcast "update" and wait)

Second: A Sprite called Result goes to the ship, then points in the direction of velocity (Vdir variable) and moves by the amount of velocity (Vmagnitude).  Now it is at the point where the ship will be going next.  It then points in the same direction as the ship (reading another variable), and checks to see if the user is pressing the Up arrow key.  If so, it moves by an amount that represents the "Thrust" of the rocket (in the direction that the ship is pointing).  Finally, Result moves by an amount that represents Gravity (moves in -Y).  Now it is at the place where the ship should go next.  Result broadcasts a request for the "Direction" and waits.

Third: A sprite called Pointer goes to the ship and points toward Result.  This is the direction that needs to be remembered, so it sets Vdirection to its current direction.  (I left Pointer visible, and its size is adjusted to represent the magnitude of the Velocity.)

Finally: The ship checks the distance to Result, and sets Vmagnitude to that distance, then moves to Result.  (Pointer could also set Vmagnitude).

The cycle continuously repeats.  Ship's "broadcast and wait" calls out to Result's "broadcast and wait", and once the Pointer does its job, the ship can move.

Offline

 

#2 2007-09-22 13:44:45

swordkirby9999
Scratcher
Registered: 2007-09-22
Posts: 3

Re: Moon Lander Demo

It was fun. good job

Offline

 

Board footer