Actually Using Your Raspberry Pi Part 2B: Coding the Knight Lightning Game

blog-raspberry-2b

04 May

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 - gameStart 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 lightningThis 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 dinosaurFirst, 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:

Actually Using Your Raspberry Pi: Part 1 Getting a Pi

Actually Using Your Raspberry Pi: Part 2A Programming with Scratch

James Demby
James Demby
jdemby@bandwidth.com

James studied Industrial Engineering at Georgia Tech, and loves going to GT Football Games. In his spare time he volunteers at Big Brother Big Sister in Raleigh, and spends time with his Fiancé exploring downtown. He also likes listening to podcasts, reading books (Michael Lewis rocks!), learning to code, and Raspberry Pi projects.

2 Comments

Post A Comment