Cross The Road

These steps are available at bit.ly/cross-the-road-steps.


πŸ”„ Step 1: Remix the Starter Pack

Follow the link: bit.ly/cross-the-road-starter.

Next tap Remix. When the project loads, give it a new name. Have a look around the project.


πŸ” Step 2: Position the player at the bottom of the screen

When the game starts, we want to position the player at the bottom of the screen, in the middle. Add this code to the player sprite.

when green flag clicked
go to x: [0] y: [-160]

πŸšΆβ€βž‘οΈ Step 3: Make the player walk to the right

Add a forever loop and inside check to see if the right arrow is being pressed. If it is, move the player to the right.

when green flag clicked
go to x: [0] y: [-160]
forever
    if <key (right arrow v) pressed?> then
        change x by [5]
    end
end

⬅️ ⬆️ ⬇️ Step 4: Make the player walk in the other directions

Now the player can walk right. Next let’s make them walk left, up and down.


πŸš— Step 5: Add a car

Instead of using the car sprite directly, we will clone it. That will let us have more than one car on the screen at the same time.

To do that, hide the sprite, then clone it and then when the clone is created, position it and show it. We’re going to put it on the left of the screen. Add this code to the car sprite.

when green flag clicked
hide
create clone of (myself v)

when I start as a clone
go to x: [-240] y: [-110]
show

πŸš™ Step 6: Make the car move

Next we will make the car move from left to right across the screen. We will use repeat until for this. Once it gets across the screen, we can hide the clone.

when I start as a clone
go to x: [-240] y: [-110]
show
repeat until <(x position) > (240)>
	change x by (5)
end
hide

πŸš— πŸš™ 🚌 Step 7: Add more cars

Instead of just creating one clone, add a forever loop and create a clone every 2 seconds.

when green flag clicked
hide
forever
	create clone of (myself v)
	wait (2) seconds
end

❗️ Step 8: Make the car squash the player

Right now, the cars will just keep driving even if the player is in the way. When the car touches the player, broadcast the message β€œgame over”.

when I start as a clone
go to x: [-240] y: [-110]
show
repeat until <(x position) > (240)>
	change x by (5)
	if <touching (player v) ?> then
		broadcast (game over v)
	end
end
hide

And in the player sprite, when you receive the message, switch the costume and stop the game.

when I receive [game over v]
switch costume to (chicken-flat v)
stop [all v]

Step 8 - Hit area 1 Step 8 - Hit area 2


πŸ’° Step 9: Add some coins

Go to the coin sprite and add this code to create 10 clones at random positions.

when green flag clicked
hide
repeat (10)
	create clone of (myself v)
end

when I start as a clone
go to (random position v)
show

πŸ€‘ Step 10: Let the player collect the coins

when I start as a clone
go to (random position v)
show
forever
    if <touching (player v)?> then
        hide
    end
end

πŸŽ‰ Step 11: Finish the game when the player reaches the top of the screen

Add this code to the forever loop in the player sprite.

if <(y position) > (160)> then
    broadcast (you win v)
end

And add this inside the you-win sprite.

when green flag clicked
hide

when I receive [you win v]
show
stop [all v]

πŸ€” Challenges