Meeting 2020-03-10

Welcome to the first meeting of the Lowell coding class third term!

If you took the elective class last term, welcome back! Last term we tried to teach Python programming in the Minecraft environment using a Minecraft mod that let us run Python scripts from the Minecraft chat prompt. Unfortunately, most of the students only got as far as Minecraft and didn't focus on learning programming.

This term we may revisit Minecraft if we can get Microsoft's Minecraft for Education up and running, but in the mean time we will use the same MakeCode enviroment that Minecraft for Education uses to do some game programming using MakeCode Arcade. MakeCode Arcade is a visual block-based programming environment like Scratch that can compile programs to run on hand-held gaming boards - it's like writing your own Nintendo Gameboy games!

The MakeCode Arcade environment also supports programming in JavaScript and Python, but the visual MakeCode language is surprisingly capable for the kind of simple 2D games we will be attempting in this class. There are sprites, sprite maps, collisions, animations, scoreboards and life counters, and music. Programs for MakeCode arcade run on a simulator in the development environment but can also be downloaded to actual hardware like the Adafruit PyBadge and other boards. My goal is to teach the fundamentals of programming in with example projects in MakeCode Arcade, and then have everyone write a game of their own design at the end of the year.

MakeCode Arcade

MakeCode Arcade runs in a browser window so it is not necessary to install software on the computer. In fact, I am going to ask everyone to run it on their Lowell Chromebooks so we won't need to set up a bunch of PCs for each class, and you don't have to worry about getting the same computer each time.

To start, go to the MakeCode Arcade website: Click on the "New Project" panel with a plus sign. You should see a window with a bunch of regions open up:

At the left side is the simulated handheld game. The programs you write will run on this console. You can click on the controls or press keys on the keyboard to control the game. In the middle column are the software elements you can add to your program (click on the colored labels to see more). The elements are color coded so you can tell where to find them. At the right is the program window. Drag the software elements to this window and snap them together to write your program!

First Steps - Opening Programs

To get started, let's open a game, try it on the simulator, and then download it to our boards and play it there. From the code editor, click the "Home" button at top to return to the opening screen. Under "Blocks Games" (third row of screens) click on "Space Destroyer" to open it, and then click "Open Example". You can see the code for the game on the right side of the screen - not a lot of code for a complete game because a lot of game logic is built in to MakeCode Arcade. You can play the game on the simulator screen on the left side. You can click the buttons with the mouse or press keys WASD to move and <SpaceBar> to shoot.

First Steps - Saving to the PyBadge boards

Once you have tried it in the simulator window, we can download it to the handheld game board. Make sure the board you have is plugged in to a USB port on your Chromebook and turned on. Press the reset button on the top or back of your board until the LEDs are glowing green. Then click the "Download" button and select the type of board you have - PyBadge or PyGamer (the PyGamer has a black plastic case and analog joystick). It may take a little while for the driver to load but eventually you will get a window asking you where to save the .uf2 file. Pick the PYBADGEBOOT or PYGAMERBOOT drive on the left and save it in the root folder. The board should blink for a while and then reboot and start playing your game!

If the file just downloads without asking you where to put it, you should change a setting in your Chrome browser. Click on the three dots in the upper right of the Chrome window and select "Settings". Then click "Advanced" in the list of categories on the left and pick "Downloads". Under Downloads, look for a setting "Ask where to save each file before downloading" and turn the switch on (blue). Now Chrome will ask you where to save the files you download and you can tell it to write them to the PYBADGEBOOT folder in the "Save file as" window.

Next Steps - Try Other Games and Demos

Once you have successfully opened and downloaded the first game, try others to make sure you understand the process - getting good at this will allow us to more time to focus on learning about programming in future classes.