From 71bf683bf3cb9e34081d06afc18786d22f04eb4f Mon Sep 17 00:00:00 2001 From: Shulga Konstantin Date: Wed, 16 Sep 2020 16:25:47 +0300 Subject: [PATCH] feat: add a bounce of the sprite from the edges of the window --- Lab_1/Lab_1/Lab_1.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Lab_1/Lab_1/Lab_1.cpp b/Lab_1/Lab_1/Lab_1.cpp index 8144d60..8b0a543 100644 --- a/Lab_1/Lab_1/Lab_1.cpp +++ b/Lab_1/Lab_1/Lab_1.cpp @@ -93,21 +93,21 @@ COORD CreateNewSpritePosition(COORD spritePosition, COORD spriteSteps, HWND hWnd newSpritePosition.X = spritePosition.X + spriteSteps.X; if (newSpritePosition.X < 0) { - newSpritePosition.X = 0; + newSpritePosition.X = 0 + SPRITE_STEP + 90; } else if (newSpritePosition.X + spriteSize.cx > windowSize.cx) { - newSpritePosition.X = (SHORT)(windowSize.cx - spriteSize.cx); + newSpritePosition.X = (SHORT)(windowSize.cx - spriteSize.cx - SPRITE_STEP); } newSpritePosition.Y = spritePosition.Y + spriteSteps.Y; if (newSpritePosition.Y < 0) { - newSpritePosition.Y = 0; + newSpritePosition.Y = 0 + SPRITE_STEP; } else if (newSpritePosition.Y + spriteSize.cy > windowSize.cy) { - newSpritePosition.Y = (SHORT)(windowSize.cy - spriteSize.cy); + newSpritePosition.Y = (SHORT)(windowSize.cy - spriteSize.cy - SPRITE_STEP); } return newSpritePosition;