aboutsummaryrefslogtreecommitdiff
path: root/projects/11/Pong/Bat.jack
diff options
context:
space:
mode:
authorYuchen Pei <me@ypei.me>2018-01-20 15:41:49 +0100
committerYuchen Pei <me@ypei.me>2018-01-20 15:41:49 +0100
commitd3a0cc3a8ba6dfeb64d3faeffdeb6845b60e5840 (patch)
treed58df9ec2480e2a9ec6240f9c797f83d1a0b1056 /projects/11/Pong/Bat.jack
parent3571f998b28fbc8d9250ba04c983935f10a16c15 (diff)
rearranged the dir for github
- removed tools and pdfs - rearranged the projects dirs - added md files - other minor changes
Diffstat (limited to 'projects/11/Pong/Bat.jack')
-rw-r--r--projects/11/Pong/Bat.jack103
1 files changed, 0 insertions, 103 deletions
diff --git a/projects/11/Pong/Bat.jack b/projects/11/Pong/Bat.jack
deleted file mode 100644
index 340760f..0000000
--- a/projects/11/Pong/Bat.jack
+++ /dev/null
@@ -1,103 +0,0 @@
-// This file is part of www.nand2tetris.org
-// and the book "The Elements of Computing Systems"
-// by Nisan and Schocken, MIT Press.
-// File name: projects/11/Pong/Bat.jack
-
-/**
- * A graphical Pong bat.
- * Displayed as a filled horizontal rectangle that has
- * a screen location, a width and a height.
- * Has methods for drawing, erasing, moving left and right,
- * and changing its width (to make the hitting action more challenging).
- * This class should have been called "paddle", following the
- * standard Pong terminology. But, unaware of this terminology,
- * we called it "bat", and then decided to stick to it.
- */
-class Bat {
-
- field int x, y; // the bat's screen location
- field int width, height; // the bat's width and height
- field int direction; // direction of the bat's movement (1 = left, 2 = right)
-
- /** Constructs a new bat with the given location and width. */
- constructor Bat new(int Ax, int Ay, int Awidth, int Aheight) {
- let x = Ax;
- let y = Ay;
- let width = Awidth;
- let height = Aheight;
- let direction = 2;
- do show();
- return this;
- }
-
- /** Deallocates the object's memory. */
- method void dispose() {
- do Memory.deAlloc(this);
- return;
- }
-
- /** Shows the bat. */
- method void show() {
- do Screen.setColor(true);
- do draw();
- return;
- }
-
- /** Hides the bat. */
- method void hide() {
- do Screen.setColor(false);
- do draw();
- return;
- }
-
- /** Draws the bat. */
- method void draw() {
- do Screen.drawRectangle(x, y, x + width, y + height);
- return;
- }
-
- /** Sets the bat's direction (0=stop, 1=left, 2=right). */
- method void setDirection(int Adirection) {
- let direction = Adirection;
- return;
- }
-
- /** Returns the bat's left edge. */
- method int getLeft() {
- return x;
- }
-
- /** Returns the bat's right edge. */
- method int getRight() {
- return x + width;
- }
-
- /** Sets the bat's width. */
- method void setWidth(int Awidth) {
- do hide();
- let width = Awidth;
- do show();
- return;
- }
-
- /** Moves the bat one step in the bat's direction. */
- method void move() {
- if (direction = 1) {
- let x = x - 4;
- if (x < 0) { let x = 0; }
- do Screen.setColor(false);
- do Screen.drawRectangle((x + width) + 1, y, (x + width) + 4, y + height);
- do Screen.setColor(true);
- do Screen.drawRectangle(x, y, x + 3, y + height);
- }
- else {
- let x = x + 4;
- if ((x + width) > 511) { let x = 511 - width; }
- do Screen.setColor(false);
- do Screen.drawRectangle(x - 4, y, x - 1, y + height);
- do Screen.setColor(true);
- do Screen.drawRectangle((x + width) - 3, y, x + width, y + height);
- }
- return;
- }
-}