Collision Problem

Archives Forums/BlitzPlus Programming/Collision Problem

ShaunVonSuffern(Posted 2008) [#1]
In my game one, when one ship collides with a player ship, the player loses one hp and the enemy ship resets position randomly. This works perfectly when the enemy ship hits the left side of the ship, but when it hits the right side of the playership, nothing happens. What do i need to change?
Here the code snippet for collisions:
format_codebox('If player\x >= computer\x And player\x <= computer\x + StringWidth(computer\ship)
If player\y >= computer\y And player\y <= computer\y + 10 Then
computer\x = Rand(1,640)
computer\y = Rand(1,480)
player\hitpoints = player\hitpoints - 1
If player\hitpoints <= 0 Then
DeathScreen()
End If
End If
End If


If computer\x >= player\x And computer\x <= player\x + StringWidth(player\ship)
If computer\y >= player\y And computer\y <= player\y + 10 Then
computer\x = Rand(1,640)
computer\y = Rand(1,480)
player\hitpoints = player\hitpoints - 1
If player\hitpoints <= 0 Then
DeathScreen()
End If
End If
End If
')


Cp(Posted 2008) [#2]
Use images its easier
Text is too hard
format_code('
playerimage = LoadImage("player.bmp");load like that

If ImagesOverlap(player\pic,player\x,player\y,enemy\pic,enemy\x,enemy\y); this tests for collisions
enemy\x = Rand(1,640)
enemy\y = Rand(1,480)
player\hitpoints = player\hitpoints - 1
If player\hitpoints <= 0 Then DeathScreen()
EndIf ; Use that for collisions
')