Skip to main content


Actually using your Raspberry Pi part 2b: coding the knight lightning game


May 4, 2016


March 28, 2023

Graphic code builder - Part 2B: Coding the Knight Game

I wanted to give you a few screenshots that you can take to make your own version of Knight Lightning, discussed in my blog post,  Actually Using Your Raspberry Pi Part 2A: Programming with Scratch.

A cool thing about scratch is that you really just need to assign blocks to sprites and hit go. One thing that you will need to work out on your own is the sizing of the sprites. You are creative though and you can probably come up with something cooler than me.

So here are the blocks I assigned to my sprites.

#1 Background.

No blocks. It just sits there 🙂

#2 The man himself Knight Lightning

image 1 - game

Start Flag: I move him to the left side of the screen.

Also Start Flag: Whenever I press the right arrow the night moves 10 steps to the right

Also Start Flag: Whenever I press the left arrow the knight goes left 10 steps. Notice the -10. This makes the knight move backwards.

Also Start Flag: >Whenever I press the spacebar the knight will glide up to 30 on the y access over .5 seconds. Then he glides back down to where he started over 1 second. In other words the knight jumps.

#3 The Lightning

image 2 game lightning

This one is kinda cool.

First when the start flag is pressed. The lightning is

  • pointed towards the right of the screen
  • Then it is constantly moved to be in front of the knight.

Then, this string of blocks starts by hiding the lightning behind the other layers. But, whenever (if) the spacebar is pressed the lightning will “show” for .25 seconds. This is what looks like the knight using his weapon! Then the lightning is hidden for .5 seconds. This means the knight can’t use it for half a second.

#4 The Dinosaur

image 3 - game dinosaur

First, at the green start flag, I set a counter to 0. This keeps track of the score.

Then I start the dinosaur on the right of the screen and have it glide to the left side of the screen. This makes the dinosaur look like it is coming for the knight!

Also, this string of blocks is constantly looking to see if the lightning is touching the dinosaur. If the knight brings it out then it will touch the dinosaur. This will cause the dinosaur to “hide” aka disappear, and will add 1 to the score.

Lastly, this string of blocks is constantly checking if the Dinosaur is touching the knight. So if it gets to the knight without hitting lightning the game stops.

That’s is! Go try it yourself.

Helpful Links: