Using 'My Blocks' can help make the code easier to understand and to reuse. Make a block and name it spawn.
Often games start in the lower left corner of the stage, but you can start anywhere you like. Your x and y coordinates might not match these.
when flag clicked
spawn
define spawn
go to x (-200) y (-140)
set rotation style [left-right v]
x velocity is how fast you are moving in the horizontal direction (left or right). y velocity is fast you are moving in the vertical direction (up or down).
set [x-velocity v] to (0)
set [y-velocity v] to (0)
On earth, gravity is a force of approximately 10 meters per second squared. Later, you can experiment with what it would be like if gravity changes in your game.
set [gravity v] to (-1)
when flag clicked
spawn
define spawn
go to x (-200) y (-140)
set rotation style [left-right v]
set [x-velocity v] to (0)
set [y-velocity v] to (0)
set [gravity v] to (-1)
when flag clicked
spawn
forever // add this block
Make a block called running? and add it to the game loop
when flag clicked
spawn
forever
running? // add this block
define running?
if < key [right arrow v] pressed? > then
change [x-velocity v] by (1)
end
What do you need to change to make the player go left?
The player should gradually slow down when you stop pressing a key.
set [x-velocity v] to ( (x-velocity) * (0.9) )
Finally we can move the player using the x velocity.
change x by (x-velocity)
define running?
if < key [right arrow v] pressed? > then
change [x-velocity v] by (1)
end
if < key [left arrow v] pressed? > then
change [x-velocity v] by (-1)
end
set [x-velocity v] to ( (x-velocity) * (0.9) )
change x by (x-velocity)
when flag clicked
spawn
forever
running?
Create a 'My Block' called falling?
when flag clicked
spawn
forever
running?
falling? // add this block
define falling?
change [y-velocity v] by (gravity)
change y by (y-velocity)
if < touching color (#000000) > then
change y by ( (0) - (y-velocity) )
set [y-velocity v] to (0)
define falling?
change [y-velocity v] by (gravity)
change y by (y-velocity)
if < touching color (#000000) > then
change y by ( (0) - (y-velocity) )
set [y-velocity v] to (0)
when flag clicked
spawn
forever
running?
falling?
when flag clicked
spawn
forever
running?
falling?
wall? // add this block
define wall?
if < touching color (#000000) > then
change x by ((0) - (x-velocity)
set [x-velocity v] to (0)
when flag clicked
spawn
forever
running?
falling?
wall?
define wall?
if < touching color (#000000) > then
change x by ((0) - (x-velocity)
set [x-velocity v] to (0)
define falling?
change [y-velocity v] by (gravity)
change y by (y-velocity)
if < touching color (#000000) > then
change y by ( (0) - (y-velocity) )
set [y-velocity v] to (0)
jump? // add this block
define jump?
if < key [up arrow v] pressed? > then
change [y-velocity v] by (12)
define falling?
change [y-velocity v] by (gravity)
change y by (y-velocity)
if < touching color (#000000) > then
change y by ( (0) - (y-velocity) )
set [y-velocity v] to (0)
jump? // add this block
define jump?
if < key [up arrow v] pressed? > then
change [y-velocity v] by (12)
when flag clicked
spawn
forever
running?
falling?
ramp? // add this block
wall?
define ramp?
if < touching color (#000000) > then
change y by (2)
if < touching color (#000000) > then
change y by (-2)
when flag clicked
spawn
forever
running?
falling?
ramp?
wall?
win? // add this block
define win?Use the eyedrop color picker to select the exact color of the goal. Or use this if you chose a sprite for the goal:
if < touching color () > then
touching [Giga v] ?
say [You won!] for (2) seconds
define win?
if < touching color (#fffb19) > then
say [You won!] for (2) seconds
end
when flag clicked
spawn
forever
running?
falling?
ramp?
wall?
win? // add this block
define win?
if < touching color (#fffb19) > then
say [You won!] for (2) seconds
spawn // add this block
end
define win?
if < touching color (#fffb19) > then
say [You won!] for (2) seconds
next backdrop // add this block
spawn
when flag clicked
switch backdrop to [backdrop1 v] // add this block
spawn
forever
running?
falling?
ramp?
wall?
win?
when backdrop switches to [backdrop1 v]
hide
when backdrop switches to [backdrop2 v]
show
when backdrop switches to [backdrop2 v]
show
forever // add this block
glide (3) secs to x (200) y(-130)
when backdrop switches to [backdrop2 v]
show
forever
glide (3) secs to x (200) y(-130)
glide (3) secs to x (35) y (-130) // add this block
when backdrop switches to [backdrop1 v]
hide
when backdrop switches to [backdrop2 v]
show
forever
glide (3) secs to x (200) y(-130)
glide (3) secs to x (35) y (-130)
define baddy?
when flag clicked
switch backdrop to [backdrop1 v]
spawn
forever
running?
falling?
ramp?
wall?
win?
baddy? // add this block
if < > then
touching [Frank v] ?
if < touching [Frank v] ? > then
spawn
define baddy?
if < touching [Frank v] ? > then
spawn
when flag clicked
switch backdrop to [backdrop1 v]
spawn
forever
running?
falling?
ramp?
wall?
win?
baddy?
if < touching color [#ff0000] > then
when backdrop switches to [backdrop1 v]
hide
when backdrop switches to [backdrop2 v]
show
forever
turn right (1) degrees