Our version of Dig Dug implemented moving, digging in the ground, and continuously updating tiles based on their surroundings: an air edge would have a different texture than a dirt edge. We accomplished all this with a fairly simple few classes, namely one each for controlling and drawing our character, one to control the tilemap that stores and analyzes what's dirt and air, and a few others to tie it together.
In the end, we ended up storing and using 32 unique sprites each made with an online bitmap editor that changed certain values in memory to update exact addresses on the screen. We could manipulate where these get drawn to change the character's location, as well as load different dirt sprites to update the tiles surrounding the character.
The full program is stored in the jack/digdug folder in this repository. If you'd like to run the program for yourself, go to the Online nand2tetris IDE and upload the full contents of the folder. Compile, run, and ensure it's run at the full speed available and your keyboard is enabled. Have fun!
My notes on how to use, syntax, and in-class examples.
To run HardwareSimulator: navigate to nand2tetris root, run ./HardwareSimulator
48 inputs, 16 outputs
CHIP Add3Way16{
IN first[16], second[16], third[16]
OUT out[16]
PARTS:
Add16(a=first, b=second, out = temp);
Add16(a=temp, b=third, out=out);
}
CHIP And4Way{
IN a[4];
OUT out;
PARTS:
And(a=a[0], b=a[1], out= t01);
And(a=t01, b=a[2], out= t02);
And(a=t02, b=a[3], out= out);
}
CHIP And4{
IN a[4], b[4];
OUT out[4];
PARTS:
And(a=a[0], b=b[0], out=out[0]);
And(a=a[1], b=b[1], out=out[1]);
And(a=a[2], b=b[2], out=out[2]);
And(a=a[3], b=b[3], out=out[3]);
}
Add16(a[0..7]=lsb, a[8..15]=msb, b=..., out=...);
Booleans can be used as buses of any width.
--- ``` word = RAM[16384 + (32*row) + col/16] set the (col % 16)th bit of word RAM[i] = word ``` Credit Stewart Thomas
