Mouse control for player one.
Gamepad or keys for player two.
Alternatively (by default) Player two is AI controlled.
.. AI controlled.!?!?! In a script!?! That I've written!!?!?
Sure does feel kinda empty without sound though, huh...?
Hmmm..
The code is more or less "standard", but I've had to do a few quirky things to get the ifs working properly.
You can Play it here. Simply copy the code below, shove it in the box, then click run!
// Table Tennis
// by Jayenkai
// Created 2021/5/3
Symbol 0,"2__0_0,O.MM0_0_0@OVVOOMM0_0_0/OVVOOMM0_0_0/OVVO,MM0_0_0!OVVO,MM0_0_0!OVVO,MM0_0_0!OVVO,MM0_0_0!OVVO,MM0_0_0!OVVO,MM0_0_0!OVVO,MM0_0_0!OVVO,MM0_0_0!OVVO,MM0_0_0!OVVO,MM0_0_0!OVVO,MM0_0_0!OVVO,MM0_0_0!OVVO,MM0_0_0!OVVO,MM0_0_0!OVVO,MM0_0_0!OVVO,MM0_0_0!OVVO,MM0_0_0!OVVO,MM0_0_0!OVVO,MM0_0_0!OVVO,MM0_0_0!OVVO,MM0_0_0!OVVO,MM0_0_0!OVVO,MM0_0_0!OVVO,MM0_0_0!OVVO,MM0_0_0!OVVO,MM0_0_0!OVVOOMM0_0_0/OVVOOMM0_0_0/O.MM";
Symbol 1,"2__0_0?MMO.0_0_0/MMOOBBO0_0_0/MMOOBBO0_0_0!MMO,BBO0_0_0!MMO,BBO0_0_0!MMO,BBO0_0_0!MMO,BBO0_0_0!MMO,BBO0_0_0!MMO,BBO0_0_0!MMO,BBO0_0_0!MMO,BBO0_0_0!MMO,BBO0_0_0!MMO,BBO0_0_0!MMO,BBO0_0_0!MMO,BBO0_0_0!MMO,BBO0_0_0!MMO,BBO0_0_0!MMO,BBO0_0_0!MMO,BBO0_0_0!MMO,BBO0_0_0!MMO,BBO0_0_0!MMO,BBO0_0_0!MMO,BBO0_0_0!MMO,BBO0_0_0!MMO,BBO0_0_0!MMO,BBO0_0_0!MMO,BBO0_0_0!MMO,BBO0_0_0!MMO,BBO0_0_0/MMOOBBO0_0_0/MMOOBBO0_0_0@MMO.";
Symbol 2,"2__0_0_0_0_0_0_0_0_0_0_0_0_0_0_0_0_0_0_0_0_0_0_0_0_0_0_0_0_0_0_0_0_0_0_0_0_0_0_0_0_0_0_0_0_00M.0_0_0_M,NNO0_0_0/M,N,OP0_0_0!MMN,OOP0_0_0!MN,OOPP0_0_0!MNNOOP,0_0_0/O,P,0_0_0_P.";
Players=1 // One player mode. Use mouse for player one
//Players=2 // Two player mode. Use gamepad/keys for player two
Graphics 1024,768,2
AA Off
reset=1
point=0;pointlit=0
y1=ScreenHeight()*0.5
y2=ScreenHeight()*0.5
yg2=0
Repeat
CLS;ResetDraw()
If reset==1
ballx=ScreenWidth()*0.5
bally=ScreenHeight()*0.5
ballgx=Rnd(0.8,1.2)
if Rnd(10)<5 then ballgx=Neg(ballgx)
ballgy=Rnd(0.8,1.2)
if Rnd(10)<5 then ballgy=Neg(ballgy)
speed=Neg(8)
maxspeed=8
reset=0
endif
if speed<maxspeed then speed=speed+0.1
size=24
SetCol 32,64,32
Rect ScreenWidth()*0.5,ScreenHeight()*0.5,4,ScreenHeight(),1
SetCol 100,255,100
SetSize 3
DrawImg size*2,y1,0
DrawImg jscrw-(size*2),y2,1
n=0
Repeat
n=n+1
if speed>0
ballx=ballx+((ballgx*speed)*0.25)
bally=bally+((ballgy*speed)*0.25)
endif
DrawImg ballx,bally,2
if bally<32 then bally=32;ballgy=jRnd(0.8,1.2)
if bally>(jscrh-32) then bally=(jscrh-32);ballgy=Neg(jRnd(0.8,1.2))
a=(Abs(ballx-(size*2))<(size))
b=(Abs(bally-(y1))<(48+(size*0.5)))
c=ballgx<0
if a and b and c then ballgx=jRnd(0.8,1.2); maxspeed=maxspeed+0.25
a=(Abs(ballx-(ScreenWidth()-(size*2)))<(size))
b=(Abs(bally-(y2))<(48+(size*0.5)))
c=ballgx>0
if a and b and c then ballgx=Neg(jRnd(0.8,1.2)); maxspeed=maxspeed+0.25
Until n>4
If ballx<Neg(size) then reset=1;Score2=Score2+1;point=2;pointlit=90
If ballx>(ScreenWidth()+size) then reset=1;Score1=Score1+1;point=1;pointlit=90
if MouseY>0 then y1=MouseY()
if Players!=1 then y2=y2+((Gamepad(ButtonDown)-Gamepad(ButtonUp))*16)
if Players==1
// Basic AI
if bally<(y2-24) then yg2=yg2+Neg(Rnd(0.5,2))
if bally>(y2+24) then yg2=yg2+Rnd(0.5,2)
if Abs(bally-y2)<24 then yg2=yg2*0.6
if yg2<Neg(16) then yg2=Neg(16)
if yg2>16 then yg2=16
y2=y2+yg2
endif
if y1<48 then y1=48
if y1>(ScreenHeight()-48) then y1=(ScreenHeight()-48)
if y2<48 then y2=48
if y2>(ScreenHeight()-48) then y2=(ScreenHeight()-48)
SetSize 4
SetCol 100,255,100
if ((point==1) and (pointlit%30>15)) then SetCol 255,100,255
Text ScreenWidth()*0.25,32,Score1,1
SetCol 100,255,100
if ((point==2) and (pointlit%30>15)) then SetCol 255,100,255
Text ScreenWidth()*0.75,32,Score2,1
pointlit=pointlit-1
if pointlit<1 then pointlit=0;point=0
Flip
fin=0
if Score1>9 then fin=1;GameOver="Left Wins"
if Score2>9 then fin=1;GameOver="Right Wins"
Until fin=1
Text ScreenWidth()*0.5,ScreenHeight()*0.5,GameOver,1
Flip
|update| Apologies if you copy+pasted this in the previous hour or so. Silly me forgot that browser's don't like <'s and >'s!! Had to do some code-converting in the AGameAWeek script! |update|
Views 225, Upvotes 12
Jse
New games every week!
Places
Archives
Site credits : Site built from the ground up, in php, using Programmer's Notepad 2, and a very bored Jayenkai.
(c) Jayenkai 2023 and onwards, RSS feed
6