Error message

BlitzPlus Forums/BlitzPlus Beginners Area/Error message

nyybaseball(Posted 2014) [#1]
Why is this program giving the error "Illegal Type Conversion" in the function testballwithpaddle?. I am using Blitz Plus.


Graphics 600,800

SetBuffer BackBuffer()

SeedRnd MilliSecs()

AutoMidHandle True

Global paddle1 = LoadImage("BPaddle.bmp")

Global paddle2 = LoadImage("Rpaddle.bmp")

Global puck = LoadImage("Puck.bmp")

ScaleImage paddle1, .5, .5
ScaleImage paddle2, .5, .5

Type puck
Field x,y
Field xv,yv
End Type

Global ball.puck = New puck
ball\x = 300
ball\y = 400
ball\xv = Rand(-8,8)
ball\yv = Rand(-8,8)

Type user
Field x,y
Field score
End Type

Global player.user = New user
player\x = 300
player\y = 750
player\score = 0

Type enemy
Field x,y
Field xv,yv
Field score
End Type

Global comp.enemy = New enemy
comp\x = 300
comp\y = 50
comp\score = 0

While Not KeyDown(16)

Cls

drawHUD()
testinput()
updateball()
testballwithwalls()
testballwithpaddle()
testAI()

DrawImage paddle1, player\x, player\y
DrawImage paddle2, comp\x, comp\y

Flip

Wend

;Thi function draws score
Function drawhud()

Text 10,10,"Player score: " + player\score
Text 10,15, "Computer Score: " + comp\score

Flip

End Function

Function testinput()

If KeyDown(203) Then
player\x = player\x - 5
ElseIf KeyDown(205) Then
player\x = player\x = 5
EndIf

If KeyDown(1) Then
Cls
Text 10,10,"Press Any Key To unpause"
WaitKey
EndIf

End Function

Function updateball()

ball\x = ball\x + xv
ball\y = ball\y + yv

DrawImage puck, ball\x, ball\y

End Function

Function testballwithwalls()

If ball\x < 0 Then
ball\xv = -ball\xv + Rand(-2,2)
ElseIf ball\y < 50 Then
player\score = player\score + 1
EndIf
If player\score >= 7 Then
Cls
Text 300,400,"Computer wins . press any key to quit"
WaitKey
EndIf

If ball\y > 750 Then

comp\score = comp\score + 1
If comp\score >= 7 Then
Cls
Text 300,400,"Player wins . press any key to quit"
WaitKey
EndIf
EndIf

If ball\x > 800 Then

ball\xv = -ball\xv + Rand(-2,2)

EndIf

End Function

Function testballwithpaddle()

If ImagesOverlap(ball, ball\x, ball\y, paddle1, player\x, player\y) Then

ball\yv = -ball\yv + Rand(-2,2)

ElseIf ImagesOverlap(ball, ball\x, ball\y, paddle2, comp\x, comp\y)

ball\yv = ball\yv + Rand(-2,2)

EndIf

End Function

Function testAI()

If comp\x < ball\x Then

comp\x = comp\x + 5

ElseIf comp\x > ball\x Then

comp\x = comp\x - 5

EndIf

End Function


Floyd(Posted 2014) [#2]
ImagesOverlap compares two images. ball is not an image, hence the type conflict.


Matty(Posted 2014) [#3]
Yes as Floyd says...try changing it to puck not ball....