Files
nand2tetris/Arkanoid/Ball.vm

201 lines
2.7 KiB
Plaintext

function Ball.new 0
push constant 5
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 argument 3
pop this 3
push argument 4
pop this 4
push pointer 0
return
function Ball.setPos 0
push argument 0
pop pointer 0
push pointer 0
call Ball.erase 1
pop temp 0
push argument 1
pop this 0
push argument 2
pop this 1
push constant 0
return
function Ball.setSpeed 0
push argument 0
pop pointer 0
push argument 1
pop this 3
push argument 2
pop this 4
push constant 0
return
function Ball.draw 0
push argument 0
pop pointer 0
push constant 0
not
call Screen.setColor 1
pop temp 0
push this 0
push this 1
push this 2
call Screen.drawCircle 3
pop temp 0
push constant 0
return
function Ball.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 2
call Screen.drawCircle 3
pop temp 0
push constant 0
return
function Ball.update 5
push argument 0
pop pointer 0
push pointer 0
call Ball.getLeft 1
pop local 1
push pointer 0
call Ball.getRight 1
pop local 2
push pointer 0
call Ball.getTop 1
pop local 3
push pointer 0
call Ball.getBottom 1
pop local 4
push pointer 0
call Ball.erase 1
pop temp 0
push local 1
push constant 2
lt
push this 3
and
push constant 0
lt
if-goto IF_TRUE0
goto IF_FALSE0
label IF_TRUE0
push pointer 0
call Ball.invertHspeed 1
pop temp 0
label IF_FALSE0
push local 2
push constant 508
gt
push this 3
and
push constant 0
gt
if-goto IF_TRUE1
goto IF_FALSE1
label IF_TRUE1
push pointer 0
call Ball.invertHspeed 1
pop temp 0
label IF_FALSE1
push local 3
push constant 2
lt
push this 4
and
push constant 0
lt
if-goto IF_TRUE2
goto IF_FALSE2
label IF_TRUE2
push pointer 0
call Ball.invertVspeed 1
pop temp 0
label IF_FALSE2
push local 4
push constant 250
gt
push this 4
and
push constant 0
gt
if-goto IF_TRUE3
goto IF_FALSE3
label IF_TRUE3
push pointer 0
call Ball.invertVspeed 1
pop temp 0
label IF_FALSE3
push this 0
push this 3
add
pop this 0
push this 1
push this 4
add
pop this 1
push pointer 0
call Ball.draw 1
pop temp 0
push constant 0
return
function Ball.invertVspeed 0
push argument 0
pop pointer 0
push this 4
neg
pop this 4
push constant 0
return
function Ball.invertHspeed 0
push argument 0
pop pointer 0
push this 3
neg
pop this 3
push constant 0
return
function Ball.getLeft 0
push argument 0
pop pointer 0
push this 0
push this 2
sub
return
function Ball.getRight 0
push argument 0
pop pointer 0
push this 0
push this 2
add
return
function Ball.getTop 0
push argument 0
pop pointer 0
push this 1
push this 2
sub
return
function Ball.getBottom 0
push argument 0
pop pointer 0
push this 1
push this 2
add
return
function Ball.getVspeed 0
push argument 0
pop pointer 0
push this 4
return