From 126df2943ce8c1963ca8175c562daba96e987fd5 Mon Sep 17 00:00:00 2001 From: BrentNewhall Date: Thu, 7 Apr 2022 15:38:31 -0400 Subject: [PATCH 1/2] Fix player ship to orient towards mouse pointer --- game.py | 2 +- step4.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/game.py b/game.py index caf9ab2..cb7af0e 100644 --- a/game.py +++ b/game.py @@ -59,7 +59,7 @@ # 6.1 - Set player position and rotation position = pygame.mouse.get_pos() angle = math.atan2(position[1]-(playerpos[1]+32),position[0]-(playerpos[0]+26)) - playerrot = pygame.transform.rotate(player, 360-angle*57) + playerrot = pygame.transform.rotate(player, 90-angle*57) playerpos1 = (playerpos[0]-playerrot.get_rect().width/2, playerpos[1]-playerrot.get_rect().height/2) screen.blit(playerrot, playerpos1) # 6.2 - Draw arrows diff --git a/step4.md b/step4.md index 0949b35..8f201e1 100644 --- a/step4.md +++ b/step4.md @@ -16,7 +16,7 @@ Then, replace the last line in section #6 (the player.blit line) with the follow # 6.1 - Set player position and rotation position = pygame.mouse.get_pos() angle = math.atan2(position[1]-(playerpos[1]+32),position[0]-(playerpos[0]+26)) - playerrot = pygame.transform.rotate(player, 360-angle*57.29) + playerrot = pygame.transform.rotate(player, 90-angle*57.29) playerpos1 = (playerpos[0]-playerrot.get_rect().width/2, playerpos[1]-playerrot.get_rect().height/2) screen.blit(playerrot, playerpos1) ``` From ecf5ff986530069079019d8c24362a5415f12fbe Mon Sep 17 00:00:00 2001 From: BrentNewhall Date: Thu, 7 Apr 2022 15:39:32 -0400 Subject: [PATCH 2/2] Start arrows at center of player ship --- game.py | 2 +- step5.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/game.py b/game.py index cb7af0e..a738989 100644 --- a/game.py +++ b/game.py @@ -153,7 +153,7 @@ #shoot.play() position = pygame.mouse.get_pos() acc[1] += 1 - arrows.append([math.atan2(position[1]-(playerpos1[1]+32),position[0]-(playerpos1[0]+26)),playerpos1[0]+32,playerpos1[1]+32]) + arrows.append([math.atan2(position[1]-(playerpos1[1]+64),position[0]-(playerpos1[0]+64)),playerpos1[0]+64,playerpos1[1]+64]) # 9 - Move player if keys[0]: playerpos[1] -= 5 diff --git a/step5.md b/step5.md index dee6423..ab98386 100644 --- a/step5.md +++ b/step5.md @@ -25,7 +25,7 @@ Now when a user clicks the mouse, an arrow needs to fire. Add the following to t if event.type==pygame.MOUSEBUTTONDOWN: position=pygame.mouse.get_pos() acc[1]+=1 - arrows.append([math.atan2(position[1]-(playerpos1[1]+32),position[0]-(playerpos1[0]+26)),playerpos1[0]+32,playerpos1[1]+32]) + arrows.append([math.atan2(position[1]-(playerpos1[1]+64),position[0]-(playerpos1[0]+64)),playerpos1[0]+64,playerpos1[1]+64]) ``` This code checks if the mouse was clicked and if it was, it gets the mouse position and calculates the arrow rotation based on the rotated player position and the cursor position. This rotation value is stored in the arrows array.