The Grownup Guide to Bitsbox
Red Racer
This app lets you drive a car by dragging your cursor on the screen.
1 fill('parking lot') {
Line 1 puts a background image of a parking lot on the screen.
- 'parking lot' is the label of the graphic we want the app to use.
2 size = 150
Line 2 creates a new variable called "size" and assigns it the value 150.
- This variable will be used on line 4.
- This variable exists to make this app easier to modify.
3 speed = 500
Line 3 creates a new variable called "speed" and assigns it the value 500.
- This variable will be used on line 7.
- This variable exists to make this app easier to modify.
4 c = stamp('car8',size)
Line 4 stamps a car on the screen and assigns it the name "c".
- 'car8' is the label of the car graphic we want the app to use.
- The value of size is 150, so the size of the car is 150 pixels.
5
Line 5 is left blank to create visual spacing in the code.
6 function drag() {
Line 6 creates a new block of code called drag() which tells the app what to do when you drag your cursor on the screen.
- The drag() function is built into Bitsbox.
- A function is a block of code which only runs when it's called. In this case, the drag() function is called whenever someone drags on the screen.
7 c.move(x,y,speed)
Line 7 tells "c" (which is the car) to move.
- x and y refer to where you're touching the screen.
- The value of speed is 500, so the car takes 500 milliseconds (0.5 seconds) to move.
8 c.aim(x,y)
Line 8 tells "c" (which is the car) to rotate until it's aimed at the spot where you're touching the screen.
- x and y refer to where you're touching the screen.
9 }
Line 9 uses a curly bracket } to indicate that this is the end of the drag() function which started on line 6.