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

#1 2013-04-07 21:21:03

Jas0nta11
New Scratcher
Registered: 2013-04-07
Posts: 3

asteroids movement

how do i make my sprite move like the ship in asteroids?

Offline

 

#2 2013-04-08 12:41:41

PaulBrownMagic
New Scratcher
Registered: 2013-04-05
Posts: 15

Re: asteroids movement

Could try something like this, where movement is a variable:

when gf clicked
set [movement] to [0]
forever
  move [movement] steps
  if <[movement] > [0] >
    change [movement] by (-1)
  end
  if <[movement] < [0] >
    change [movement] by (1)
  end
  if <key [left arrow] pressed?>
    turn left [15] degrees
  end
  if <key [right arrow] pressed?>
    turn right [15] degrees
  end 
  if <key [up arrow] pressed?>
    move [10] steps
    if <[movement] < [10]>
    change [movement] by (1)
    end
  end
 if <key [down arrow] pressed?>
    move [-10] steps
    if <[movement] > [-10]>
    change [movement] by (-1)
    end
  end
end

Offline

 

#3 2013-04-08 12:53:40

PaulBrownMagic
New Scratcher
Registered: 2013-04-05
Posts: 15

Re: asteroids movement

Oops, sleight error above. When the up or down arrow key's are pressed the movement variable needs to be changed by more than the amount it's reduced each time the forever block loops round. So if you just change the last part to:

when gf clicked
set [movement] to [0]
forever
  move [movement] steps
  if <[movement] > [0] >
    change [movement] by (-1)
  end
  if <[movement] < [0] >
    change [movement] by (1)
  end
  if <key [left arrow] pressed?>
    turn left [15] degrees
  end
  if <key [right arrow] pressed?>
    turn right [15] degrees
  end 
  if <key [up arrow] pressed?>
    move [10] steps
    if <[movement] < [10]>
    change [movement] by (2)
    end
  end
 if <key [down arrow] pressed?>
    move [-10] steps
    if <[movement] > [-10]>
    change [movement] by (-2)
    end
  end
end
That'll work. The amount of steps taken, the amount the variable movement is changed by each time and what the variable movement is capped at will change how quickly it moves, accelerates and decelerates. I'll let you play with that.

Offline

 

#4 2013-04-08 12:57:11

topazdragonlord
Scratcher
Registered: 2013-02-22
Posts: 500+

Re: asteroids movement

PaulBrownMagic wrote:

Could try something like this, where movement is a variable:

when gf clicked
set [movement] to [0]
forever
  move [movement] steps
  if <[movement] > [0] >
    change [movement] by (-1)
  end
  if <[movement] < [0] >
    change [movement] by (1)
  end
  if <key [left arrow] pressed?>
    turn left [15] degrees
  end
  if <key [right arrow] pressed?>
    turn right [15] degrees
  end 
  if <key [up arrow] pressed?>
    move [10] steps
    if <[movement] < [10]>
    change [movement] by (1)
    end
  end
 if <key [down arrow] pressed?>
    move [-10] steps
    if <[movement] > [-10]>
    change [movement] by (-1)
    end
  end
end

Fixed  smile

when gf clicked
set (movement) to [0]
forever
  move (movement) steps
  if <(movement) > [0] >
    change (movement) by (-1)
  end
  if <(movement) < [0] >
    change (movement) by (1)
  end
  if <key [left arrow v] pressed?>
    turn left [15] degrees
  end
  if <key [right arrow v] pressed?>
    turn right [15] degrees
  end 
  if <key [up arrow v] pressed?>
    move [10] steps
    if <(movement) < [10]>
    change (movement) by (1)
    end
  end
 if <key [down arrow v] pressed?>
    move [-10] steps
    if <(movement) > [-10]>
    change (movement) by (-1)
    end
  end
end

Last edited by topazdragonlord (2013-04-08 12:59:23)


http://i45.tinypic.com/idumbk.png

Offline

 

#5 2013-04-09 14:35:03

Jas0nta11
New Scratcher
Registered: 2013-04-07
Posts: 3

Re: asteroids movement

Thank You!

Offline

 

Board footer