Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.8 kB
3
Indexable
Never
//counts up and down depending on encoder movement
IF EncoderInput1>0 THEN
	Counter1:=Counter1+1;
	ELSE IF 
		EncoderInput1<0 THEN 
		Counter1:=Counter1-1;
	END_IF
END_IF
// sets limit to where the padels can stop
IF Counter1<0 THEN
	Counter1:=0;
	ELSE IF
		Counter1>MAXCOUNTER THEN 
		Counter1:=MAXCOUNTER;
	END_IF
END_IF

//counts up and down depending on encoder movement
IF EncoderInput2>0 THEN
	Counter2:=Counter2+1;
	ELSE IF 
		EncoderInput2<0 THEN 
		Counter2:=Counter2-1;
	END_IF
END_IF
// sets limit to where the padels can stop
IF Counter2<0 THEN
	Counter2:=0;
	ELSE IF
		Counter2>MAXCOUNTER THEN 
		Counter2:=MAXCOUNTER;
	END_IF
END_IF

RacketPositionY1:=(Counter1/MAXCOUNTER)*RacketPositionY1; //only moves in y direction
RacketPositionY2:=(Counter2/MAXCOUNTER)*RacketPositionY2; //only moves in y direction

//Ball
BallX:=BallX+BallSpeedX;
BallY:=BallY+BallSpeedY;
//hitting roof
IF BallY<42 OR BallY>402 THEN 
	BallSpeedY:= -BallSpeedY;
END_IF
//hit left racket 
IF BallX<22 THEN 
	IF (BallY<=racketPositionY1 ) AND ((BallY-racketPositionY1)<10) THEN 
		BallSpeedX:=-BallSpeedX;
	END_IF
END_IF
//hit right racket 
IF BallX>686 THEN
	IF (BallY<=racketPositionY2 ) AND ((BallY-racketPositionY2)<10) THEN
		BallSpeedX:=-BallSpeedX;
	END_IF
END_IF
//point update if it hits walls
IF BallX<21 THEN 
	Point1:=Point1+1;
	PointWon1:=TRUE;
	ELSE IF 
		BallX>687 THEN 
		Point2:=Point2+1;
		PointWon2:=TRUE;
	END_IF
END_IF
//restarts game when someone gets to 15
IF Point1=15 OR Point2=15 THEN 
	Point1:=0;
	Point2:=0;
END_IF
IF PointWon1 THEN 
	BallX:=22 ; //served by player 1
	BallY:=194; // served by player 1
	ELSE IF PointWon2 THEN 
		BallX:=686; //served by player 2
		BallY:=194;// served by player 2
	END_IF
END_IF