Voici le code:Small Basic Comment puis-je faire "mourir" mes joueurs même si mon carré d'ennemis ne peut pas correspondre exactement?
'Player and Enemy Variables
PlayerX = 0
PlayerY = 339
EnemyX = Math.GetRandomNumber(590)
EnemyY = 339
'Just setting up
GraphicsWindow.Show()
GraphicsWindow.Width = "600"
GraphicsWindow.Height = "400"
GraphicsWindow.KeyDown = OnKeyDown
'Ground, Enemy, and Player Drawn
GraphicsWindow.FillRectangle(0,350,600,50)
GraphicsWindow.DrawRectangle(PlayerX,PlayerY,10,10)
GraphicsWindow.DrawRectangle(EnemyX,EnemyY,10,10)
GraphicsWindow.DrawBoundText(50,50,100,"WASD")
Sub OnKeyDown
'What button was pressed?
If (GraphicsWindow.LastKey = "W") Then
GraphicsWindow.Clear()
PlayerY = PlayerY - 10
GraphicsWindow.FillRectangle(0,350,600,50)
GraphicsWindow.DrawRectangle(PlayerX,PlayerY,10,10)
GraphicsWindow.DrawRectangle(EnemyX,EnemyY,10,10)
GraphicsWindow.DrawBoundText(50,50,100,"WASD")
EndIf
If (GraphicsWindow.LastKey = "S") Then
GraphicsWindow.Clear()
PlayerY = PlayerY + 10
GraphicsWindow.FillRectangle(0,350,600,50)
GraphicsWindow.DrawRectangle(PlayerX,PlayerY,10,10)
GraphicsWindow.DrawRectangle(EnemyX,EnemyY,10,10)
GraphicsWindow.DrawBoundText(50,50,100,"WASD")
EndIf
If (GraphicsWindow.LastKey = "A") Then
GraphicsWindow.Clear()
PlayerX = PlayerX - 10
GraphicsWindow.FillRectangle(0,350,600,50)
GraphicsWindow.DrawRectangle(PlayerX,PlayerY,10,10)
GraphicsWindow.DrawRectangle(EnemyX,EnemyY,10,10)
GraphicsWindow.DrawBoundText(50,50,100,"WASD")
EndIf
If (GraphicsWindow.LastKey = "D") Then
GraphicsWindow.Clear()
PlayerX = PlayerX + 10
GraphicsWindow.FillRectangle(0,350,600,50)
GraphicsWindow.DrawRectangle(PlayerX,PlayerY,10,10)
GraphicsWindow.DrawRectangle(EnemyX,EnemyY,10,10)
GraphicsWindow.DrawBoundText(50,50,100,"WASD")
EndIf
'Keep in the Graphics Window!
If (PlayerX < 10) Then
PlayerX = 10
EndIf
If (PlayerX > 590) Then
PlayerX = 590
EndIf
If (PlayerY < 10) Then
PlayerY = 10
EndIf
If (PlayerY > 339) Then
PlayerY = 339
EndIf
'Player and Enemy Collide.
If (PlayerX = EnemyX And PlayerY = EnemyY) Then
GraphicsWindow.DrawBoundText(100,50,100,"NO!")
EndIf
EndSub
Et voici le problème. Pour le rendre joli et ne pas être super lent, chaque fois que le joueur est déplacé, il est déplacé par multiples de 10. Cependant, l'axe X de l'ennemi est aléatoire, et pas toujours sur un multiple de 10. Ce que j'essaie de faire est Chaque fois que la case de mon joueur est dans la case de mon ennemi, elle affiche "NON!" dans la fenêtre graphique. Mais je ne peux pas, sauf si le nombre aléatoire que l'axe X de l'ennemi est sur un multiple de 10. Comment puis-je contourner cela?
enemyy et x [ennemi] est +10 pour accomider la surface du carré. Donc, s'il tombe n'importe où dans l'ennemi, il déclenchera le NON! programme. bon travail que je vais voir si je peux raccourcir votre code ou le rendre plus efficace – Matthew
vous pouvez utiliser des formes à la place. laissez-moi porivde le code. – Matthew
Je suis nouveau dans Small Basic, donc je ne me suis pas rendu compte que vous pouviez faire des formes et les déplacer sans avoir à effacer et redessiner l'écran graphique. Mais le nouveau code est plus propre et plus efficace – Auxhil