aboutsummaryrefslogtreecommitdiff
path: root/projects/11/Square
diff options
context:
space:
mode:
authorYuchen Pei <me@ypei.me>2018-01-15 12:07:13 +0100
committerYuchen Pei <me@ypei.me>2018-01-15 12:07:13 +0100
commit09c40f135cb3f69599457a5b278d29bcb38fa6ef (patch)
treed92034782bafc958fe1077ba575534d7a7b7f587 /projects/11/Square
parent459776159903ab583c0791b1599ec4fc47da8f79 (diff)
checkpoint
Diffstat (limited to 'projects/11/Square')
-rw-r--r--projects/11/Square/Main.vm11
-rw-r--r--projects/11/Square/Square.vm298
-rw-r--r--projects/11/Square/SquareGame.vm168
3 files changed, 477 insertions, 0 deletions
diff --git a/projects/11/Square/Main.vm b/projects/11/Square/Main.vm
new file mode 100644
index 0000000..a3b355b
--- /dev/null
+++ b/projects/11/Square/Main.vm
@@ -0,0 +1,11 @@
+function Main.main 1
+call SquareGame.new 0
+pop local 0
+push local 0
+call SquareGame.run 1
+pop temp 0
+push local 0
+call SquareGame.dispose 1
+pop temp 0
+push constant 0
+return
diff --git a/projects/11/Square/Square.vm b/projects/11/Square/Square.vm
new file mode 100644
index 0000000..871ccf7
--- /dev/null
+++ b/projects/11/Square/Square.vm
@@ -0,0 +1,298 @@
+function Square.new 0
+push constant 3
+call Memory.alloc 1
+pop pointer 0
+push argument 0
+pop this 0
+push argument 1
+pop this 1
+push argument 2
+pop this 2
+push pointer 0
+call Square.draw 1
+pop temp 0
+push pointer 0
+return
+function Square.dispose 0
+push argument 0
+pop pointer 0
+push pointer 0
+call Memory.deAlloc 1
+pop temp 0
+push constant 0
+return
+function Square.draw 0
+push argument 0
+pop pointer 0
+push constant 1
+neg
+call Screen.setColor 1
+pop temp 0
+push this 0
+push this 1
+push this 0
+push this 2
+add
+push this 1
+push this 2
+add
+call Screen.drawRectangle 4
+pop temp 0
+push constant 0
+return
+function Square.erase 0
+push argument 0
+pop pointer 0
+push constant 0
+call Screen.setColor 1
+pop temp 0
+push this 0
+push this 1
+push this 0
+push this 2
+add
+push this 1
+push this 2
+add
+call Screen.drawRectangle 4
+pop temp 0
+push constant 0
+return
+function Square.incSize 0
+push argument 0
+pop pointer 0
+push this 1
+push this 2
+add
+push constant 254
+lt
+push this 0
+push this 2
+add
+push constant 510
+lt
+and
+not
+if-goto incSize.Else0
+push pointer 0
+call Square.erase 1
+pop temp 0
+push this 2
+push constant 2
+add
+pop this 2
+push pointer 0
+call Square.draw 1
+pop temp 0
+label incSize.Else0
+push constant 0
+return
+function Square.decSize 0
+push argument 0
+pop pointer 0
+push this 2
+push constant 2
+gt
+not
+if-goto decSize.Else0
+push pointer 0
+call Square.erase 1
+pop temp 0
+push this 2
+push constant 2
+sub
+pop this 2
+push pointer 0
+call Square.draw 1
+pop temp 0
+label decSize.Else0
+push constant 0
+return
+function Square.moveUp 0
+push argument 0
+pop pointer 0
+push this 1
+push constant 1
+gt
+not
+if-goto moveUp.Else0
+push constant 0
+call Screen.setColor 1
+pop temp 0
+push this 0
+push this 1
+push this 2
+add
+push constant 1
+sub
+push this 0
+push this 2
+add
+push this 1
+push this 2
+add
+call Screen.drawRectangle 4
+pop temp 0
+push this 1
+push constant 2
+sub
+pop this 1
+push constant 1
+neg
+call Screen.setColor 1
+pop temp 0
+push this 0
+push this 1
+push this 0
+push this 2
+add
+push this 1
+push constant 1
+add
+call Screen.drawRectangle 4
+pop temp 0
+label moveUp.Else0
+push constant 0
+return
+function Square.moveDown 0
+push argument 0
+pop pointer 0
+push this 1
+push this 2
+add
+push constant 254
+lt
+not
+if-goto moveDown.Else0
+push constant 0
+call Screen.setColor 1
+pop temp 0
+push this 0
+push this 1
+push this 0
+push this 2
+add
+push this 1
+push constant 1
+add
+call Screen.drawRectangle 4
+pop temp 0
+push this 1
+push constant 2
+add
+pop this 1
+push constant 1
+neg
+call Screen.setColor 1
+pop temp 0
+push this 0
+push this 1
+push this 2
+add
+push constant 1
+sub
+push this 0
+push this 2
+add
+push this 1
+push this 2
+add
+call Screen.drawRectangle 4
+pop temp 0
+label moveDown.Else0
+push constant 0
+return
+function Square.moveLeft 0
+push argument 0
+pop pointer 0
+push this 0
+push constant 1
+gt
+not
+if-goto moveLeft.Else0
+push constant 0
+call Screen.setColor 1
+pop temp 0
+push this 0
+push this 2
+add
+push constant 1
+sub
+push this 1
+push this 0
+push this 2
+add
+push this 1
+push this 2
+add
+call Screen.drawRectangle 4
+pop temp 0
+push this 0
+push constant 2
+sub
+pop this 0
+push constant 1
+neg
+call Screen.setColor 1
+pop temp 0
+push this 0
+push this 1
+push this 0
+push constant 1
+add
+push this 1
+push this 2
+add
+call Screen.drawRectangle 4
+pop temp 0
+label moveLeft.Else0
+push constant 0
+return
+function Square.moveRight 0
+push argument 0
+pop pointer 0
+push this 0
+push this 2
+add
+push constant 510
+lt
+not
+if-goto moveRight.Else0
+push constant 0
+call Screen.setColor 1
+pop temp 0
+push this 0
+push this 1
+push this 0
+push constant 1
+add
+push this 1
+push this 2
+add
+call Screen.drawRectangle 4
+pop temp 0
+push this 0
+push constant 2
+add
+pop this 0
+push constant 1
+neg
+call Screen.setColor 1
+pop temp 0
+push this 0
+push this 2
+add
+push constant 1
+sub
+push this 1
+push this 0
+push this 2
+add
+push this 1
+push this 2
+add
+call Screen.drawRectangle 4
+pop temp 0
+label moveRight.Else0
+push constant 0
+return
diff --git a/projects/11/Square/SquareGame.vm b/projects/11/Square/SquareGame.vm
new file mode 100644
index 0000000..f2dd542
--- /dev/null
+++ b/projects/11/Square/SquareGame.vm
@@ -0,0 +1,168 @@
+function SquareGame.new 0
+push constant 2
+call Memory.alloc 1
+pop pointer 0
+push constant 0
+push constant 0
+push constant 30
+call Square.new 3
+pop this 0
+push constant 0
+pop this 1
+push pointer 0
+return
+function SquareGame.dispose 0
+push argument 0
+pop pointer 0
+push this 0
+call Square.dispose 1
+pop temp 0
+push pointer 0
+call Memory.deAlloc 1
+pop temp 0
+push constant 0
+return
+function SquareGame.moveSquare 0
+push argument 0
+pop pointer 0
+push this 1
+push constant 1
+eq
+not
+if-goto moveSquare.Else0
+push this 0
+call Square.moveUp 1
+pop temp 0
+label moveSquare.Else0
+push this 1
+push constant 2
+eq
+not
+if-goto moveSquare.Else1
+push this 0
+call Square.moveDown 1
+pop temp 0
+label moveSquare.Else1
+push this 1
+push constant 3
+eq
+not
+if-goto moveSquare.Else2
+push this 0
+call Square.moveLeft 1
+pop temp 0
+label moveSquare.Else2
+push this 1
+push constant 4
+eq
+not
+if-goto moveSquare.Else3
+push this 0
+call Square.moveRight 1
+pop temp 0
+label moveSquare.Else3
+push constant 5
+call Sys.wait 1
+pop temp 0
+push constant 0
+return
+function SquareGame.run 2
+push argument 0
+pop pointer 0
+push constant 0
+pop local 1
+label run.While0
+push local 1
+not
+not
+if-goto run.EndWhile0
+label run.While0.While0
+push local 0
+push constant 0
+eq
+not
+if-goto run.While0.EndWhile0
+call Keyboard.keyPressed 0
+pop local 0
+push pointer 0
+call SquareGame.moveSquare 1
+pop temp 0
+goto run.While0.While0
+label run.While0.EndWhile0
+push local 0
+push constant 81
+eq
+not
+if-goto run.While0.Else1
+push constant 1
+neg
+pop local 1
+label run.While0.Else1
+push local 0
+push constant 90
+eq
+not
+if-goto run.While0.Else2
+push this 0
+call Square.decSize 1
+pop temp 0
+label run.While0.Else2
+push local 0
+push constant 88
+eq
+not
+if-goto run.While0.Else3
+push this 0
+call Square.incSize 1
+pop temp 0
+label run.While0.Else3
+push local 0
+push constant 131
+eq
+not
+if-goto run.While0.Else4
+push constant 1
+pop this 1
+label run.While0.Else4
+push local 0
+push constant 133
+eq
+not
+if-goto run.While0.Else5
+push constant 2
+pop this 1
+label run.While0.Else5
+push local 0
+push constant 130
+eq
+not
+if-goto run.While0.Else6
+push constant 3
+pop this 1
+label run.While0.Else6
+push local 0
+push constant 132
+eq
+not
+if-goto run.While0.Else7
+push constant 4
+pop this 1
+label run.While0.Else7
+label run.While0.While8
+push local 0
+push constant 0
+eq
+not
+not
+if-goto run.While0.EndWhile8
+call Keyboard.keyPressed 0
+pop local 0
+push pointer 0
+call SquareGame.moveSquare 1
+pop temp 0
+goto run.While0.While8
+label run.While0.EndWhile8
+goto run.While0
+label run.EndWhile0
+push constant 0
+return