zuibaf
Member
- Joined
- Sep 29, 2017
- Messages
- 61
In the code below, the incorrect line is line 96, missing a parenthesis ")", however, CerberusX, reports that the incorrect line is line 95, although, such line 95 is correct.
I spent about 2 minutes trying to understand what was wrong on line 95, so when I went to check line 96, I found the error.
I spent about 2 minutes trying to understand what was wrong on line 95, so when I went to check line 96, I found the error.
Cerberus:
Import mojo
Class pongo Extends App
Field pX: Float = 630.0 ' X pos on the right side of canvas.
Field pY: Float = 240.0 ' Y pos in the middle of canvas.
Field bX: Float = 320.0 ' X pos of the ball in the middle of canvas.
Field bY: Float = 240.0 ' Y pos in the middle of the canvas.
Field bdX: Float = 3.5 ' X speed of the ball.
Field bdY: Float = 1.5 ' Y speed of the ball.
Field eX: Float[] = [5.0, 55.0] ' X pos of both paddles.
Field eY: Float[] = [240.0, 240.0] ' Y pos of both paddles.
Field edY: Float[] = [-10.0, 5.0] ' Y speed of both paddles.
Field pPoints: Int = 0 ' Player points.
Field ePoints: Int = 0 ' Enemy points.
Field gameMode: Int = 0 ' Gamemode 0 = Start game, 1 = Game, 2 = GameOver.
Field modeMessage: Int = 0 ' 0 = Message can be printed.
Method OnCreate:Int()
SetUpdateRate(60)
Return True
End
Method OnUpdate:Int()
UpdateGame()
Return True
End
Method OnRender:Int()
Cls ' Clear the canvas each frame.
DrawPlayField() ' this call draws the background.
DrawRect(pX, pY - 30, 5, 60) ' Draw the player paddle.
DrawRect(eX[0], eY[0] - 30, 5, 60) ' Draw the enemy paddle #1.
DrawRect(eX[1], eY[1] - 30, 5, 60) ' Draw the enemy paddle #2.
DrawCircle(bX, bY, 5)
Return True
End
Method DrawPlayField:Int ()
' Draw the top wall with a rectangle.
DrawRect(0, 0, 640, 5)
' Bottom wall.
DrawRect(0, 475, 640, 5)
' Middle line, 13 pieces, each 10 pixel long.
For Local i := 5 To 465 Step 20
DrawRect (318, i, 4, 10)
Next
Return True
End
Method ControlPlayer:Int()
If KeyDown(KEY_UP) Then
pY -= 5.0
' Check if it reaches the top wal.
If pY < 25.0 Then pY = 25.0
Endif
If KeyDown(KEY_DOWN) Then
pY += 5.0
' Check if it reaches the bottom wall.
If pY > 455.0 Then pY = 455.0
Endif
Return True
End
Method UpdateGame:Int()
ControlPlayer()
ControlEnemies()
UpdateBall()
If CheckPaddleCollP() = True And bdX > 0 Then
bdX *= -1
If ((bY - pY) > 7) Then bdY = 1.5
If ((bY - pY) < -7) Then bdY = -1.5
If ((bY - pY) <= 7) And ((bY - pY) >= -7) Then bdY = 0
Endif
Local ep:Int = CheckPaddleCollE()
If ep >= 0 And bdX < 0 Then
If ((bY - eY[ep]) > 7) Then bdY = 1.5
If ((bY - eY[ep]) < -7) Then bdY = -1.5 ' CerberusX report this line is incorrect.
If ((bY - eY[ep]) <= 7) And ((bY - eY[ep]) >= -7 Then bdY = 0 ' This line is incorrect.
Endif
Return True
End
Method ControlEnemies:Int()
For Local ep:Int = 0 To 1
'Update the paddles Y position.
eY[ep] += edY[ep]
' Check if paddles reaches top wall.
If eY[ep] < 25.0 Then
eY[ep] = 25.0
edY[ep] *= -1 ' Reverts its Y speed.
EndIf
' Check if paddles reaches bottom wall.
If eY[ep] > 455 Then
eY[ep] = 455.0
edY[ep] *= -1
Endif
Next
Return True
End
Method UpdateBall:Int()
bX += bdX ' Add the X speed of the ball to its X position.
bY += bdY ' Add the Y speed of the ball to its Y position.
If bY < 10.0 Then
bY = 10.0
bdY *= -1
Endif
If bY > 470.0 Then
bY = 470.0
bdY *= -1
Endif
If bX < 5.0 Then
bX = 5.0
bdX *= -1
pPoints += 1
If pPoints >= 10 Then gameMode = 2
Print (ePoints + ":" + pPoints)
Endif
If bX > 635.0 Then
bX = 635.0
bdX *= -1
ePoints += 1
If ePoints >= 10 Then gameMode = 2
Print (ePoints + ":" + pPoints)
Endif
End
Method CheckPaddleCollP:Bool()
If bX > 625.0 Then
If ((bY >= pY-25.0) And (bY <= pY + 25.0)) Then
Return True
Endif
Endif
Return False
End
Method CheckPaddleCollE:Int()
For Local ep:Int = 0 To 1
If (bX > (eX[ep]-5)) And (bX < (eX[ep]+5)) Then
If ((bY >= eY[ep] - 25.0) And (bY <= eY[ep] + 25.0)) Then
Return ep
Endif
Endif
Next
Return -1
End
End
Function Main:Int()
New pongo
Return True
End
Last edited: