spinix-hive/devel/pong.spn

175 lines
3.3 KiB
Plaintext

CON
_clkmode = $62
_clkfreq = $4E495053 ' SPIN
height = 3
xmax = 78
xmin = 1
ymax = 23
ymin = 1
OBJ
p : "pongsubs"
c : "clibsd"
DAT
left long 0
right long 0
config long 0
x long 0
y long 0
xvel long 0
yvel long 0
score0 long 0
score1 long 0
center long 0
xold long 1
yold long 1
pub main(argc, argv) | time, deltat
c.enter(argc, argv)
p.splash
initialize
deltat := clkfreq/20
time := cnt
repeat
check_input
update_position
check_score
p.plotit(xold, yold, p.getval(xold, yold))
p.plotit(x, y, "@")
xold := x
yold := y
time += deltat
repeat while (cnt - time) < deltat
c.setconfig(config)
c.putchar(13)
c.exit(0)
pub initialize | i
c.putchar(0)
config := c.getconfig
c.setconfig(1)
center := (xmin + xmax)/2
p.updatevars(ymin, center, score0, score1)
x := 1
y := 10
xvel := 1
yvel := 1
left := (ymin + ymax)/2
right := left
p.moveto(xmin-1, ymin-1)
i := xmin-1
repeat while i++ =< xmax + 1
c.putchar("#")
p.moveto(xmin-1, ymax+1)
i := xmin-1
repeat while i++ =< xmax + 1
c.putchar("#")
i := ymin
repeat while i =< ymax
p.moveto(center, i)
c.putchar(".")
i++
p.plotpaddle(xmin-1, left, height)
p.plotpaddle(xmax+1, right, height)
p.putnum(center-8, ymin+1, 0)
p.putnum(center+3, ymin+1, 0)
p.moveto(xmin+1, ymin)
pub update_position
x += xvel
y += yvel
if y < ymin
y := ymin - y
yvel := 0 - yvel
c.putchar(7)
elseif y > ymax
y := 2 * ymax - y
yvel := 0 - yvel
c.putchar(7)
pub check_score
if x < xmin
if y =< left + height and y => left - height
x := xmin - x
xvel := 0 - xvel
c.putchar(7)
else
scoreit(1)
elseif x > xmax
if y =< right + height and y => right - height
x := 2 * xmax - x
xvel := 0 - xvel
c.putchar(7)
else
scoreit(0)
if y =< left + height and y => left - height
pub check_input | val
repeat while p.kbhit
val := c.getchar
if val == "x"
c.putchar(0)
c.setconfig(config)
c.exit(0)
if val == "q"
move_left_up
move_left_up
if val == "a"
move_left_down
move_left_down
if val == "p"
move_right_up
move_right_up
if val == "l"
move_right_down
move_right_down
pub move_left_up
if left > ymin + height
p.plotit(xmin-1, left + height, " ")
left--
p.plotit(xmin-1, left - height, "#")
pub move_left_down
if left < ymax - height
p.plotit(xmin-1, left - height, " ")
left++
p.plotit(xmin-1, left + height, "#")
pub move_right_up
if right > ymin + height
p.plotit(xmax+1, right + height, " ")
right--
p.plotit(xmax+1, right - height, "#")
pub move_right_down
if right < ymax - height
p.plotit(xmax+1, right - height, " ")
right++
p.plotit(xmax+1, right + height, "#")
pub scoreit(player)
if player
score1++
p.putnum(center+3, ymin+1, score1)
if right > (ymin+ymax)/2
y := right - height - 3
else
y := right + height + 3
x := xmax + 1
xvel := 0 - 1
else
score0++
p.putnum(center-8, ymin+1, score0)
if left > (ymin+ymax)/2
y := left - height - 3
else
y := left + height + 3
x := xmin - 1
xvel := 1
yvel := 1
p.updatevars(ymin, center, score0, score1)