From 4b008d5fd69ded3c751ae2a04e3f0be5449781a2 Mon Sep 17 00:00:00 2001 From: 206530220 <19194089428@qq.com> Date: Thu, 17 Jun 2021 10:42:26 +0800 Subject: [PATCH 01/13] ship --- ship1.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 ship1.py diff --git a/ship1.py b/ship1.py new file mode 100644 index 0000000..56d5cfc --- /dev/null +++ b/ship1.py @@ -0,0 +1,10 @@ +import pygame +from pygame.sprite import Sprite + + +class Ship(Sprite): + def __init__(self, ai_settings, screen): + """初始化飞船并设置其初始位置""" + super(Ship, self).__init__() + self.screen = screen + self.ai_settings = ai_settings From dbcda72c68b7ccc8c71947076d89a3015666bfb2 Mon Sep 17 00:00:00 2001 From: 206530220 <19194089428@qq.com> Date: Thu, 17 Jun 2021 10:45:06 +0800 Subject: [PATCH 02/13] ship --- ship2.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 ship2.py diff --git a/ship2.py b/ship2.py new file mode 100644 index 0000000..d10db7e --- /dev/null +++ b/ship2.py @@ -0,0 +1,14 @@ +import pygame +from pygame.sprite import Sprite + + +class Ship(Sprite): + def __init__(self, ai_settings, screen): + """初始化飞船并设置其初始位置""" + super(Ship, self).__init__() + self.screen = screen + self.ai_settings = ai_settings + + self.image = pygame.image.load('images/ship.png') + self.rect = self.image.get_rect() + self.screen_rect = screen.get_rect() \ No newline at end of file From 9e7846df0849e8f6e6230ace0918b471b1aad225 Mon Sep 17 00:00:00 2001 From: 206530220 <19194089428@qq.com> Date: Thu, 17 Jun 2021 10:59:57 +0800 Subject: [PATCH 03/13] ship --- ship3.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 ship3.py diff --git a/ship3.py b/ship3.py new file mode 100644 index 0000000..38f33a9 --- /dev/null +++ b/ship3.py @@ -0,0 +1,20 @@ +import pygame +from pygame.sprite import Sprite + + +class Ship(Sprite): + def __init__(self, ai_settings, screen): + """初始化飞船并设置其初始位置""" + super(Ship, self).__init__() + self.screen = screen + self.ai_settings = ai_settings + + self.image = pygame.image.load('images/ship.png') + self.rect = self.image.get_rect() + self.screen_rect = screen.get_rect() + + # 将每艘新飞船放在屏幕底部中央 + self.rect.centerx = self.screen_rect.centerx + self.rect.bottom = self.screen_rect.bottom + + \ No newline at end of file From cd0e4d6d232502d0b8f824e40dca794fdfee0ff3 Mon Sep 17 00:00:00 2001 From: 206530219 <236845922@qq.com> Date: Thu, 17 Jun 2021 11:26:05 +0800 Subject: [PATCH 04/13] =?UTF-8?q?=E5=88=A0=E9=99=A4=20'ship1.py'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ship1.py | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 ship1.py diff --git a/ship1.py b/ship1.py deleted file mode 100644 index 56d5cfc..0000000 --- a/ship1.py +++ /dev/null @@ -1,10 +0,0 @@ -import pygame -from pygame.sprite import Sprite - - -class Ship(Sprite): - def __init__(self, ai_settings, screen): - """初始化飞船并设置其初始位置""" - super(Ship, self).__init__() - self.screen = screen - self.ai_settings = ai_settings From 9ca890738f57752762c25d10cc9045fbabb2b5e4 Mon Sep 17 00:00:00 2001 From: 206530219 <236845922@qq.com> Date: Thu, 17 Jun 2021 11:26:09 +0800 Subject: [PATCH 05/13] =?UTF-8?q?=E5=88=A0=E9=99=A4=20'ship2.py'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ship2.py | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 ship2.py diff --git a/ship2.py b/ship2.py deleted file mode 100644 index d10db7e..0000000 --- a/ship2.py +++ /dev/null @@ -1,14 +0,0 @@ -import pygame -from pygame.sprite import Sprite - - -class Ship(Sprite): - def __init__(self, ai_settings, screen): - """初始化飞船并设置其初始位置""" - super(Ship, self).__init__() - self.screen = screen - self.ai_settings = ai_settings - - self.image = pygame.image.load('images/ship.png') - self.rect = self.image.get_rect() - self.screen_rect = screen.get_rect() \ No newline at end of file From 1cd66cb7c9ec58de143af8f3ba45b401068e2061 Mon Sep 17 00:00:00 2001 From: 206530219 <236845922@qq.com> Date: Thu, 17 Jun 2021 11:26:14 +0800 Subject: [PATCH 06/13] =?UTF-8?q?=E5=88=A0=E9=99=A4=20'ship3.py'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ship3.py | 20 -------------------- 1 file changed, 20 deletions(-) delete mode 100644 ship3.py diff --git a/ship3.py b/ship3.py deleted file mode 100644 index 38f33a9..0000000 --- a/ship3.py +++ /dev/null @@ -1,20 +0,0 @@ -import pygame -from pygame.sprite import Sprite - - -class Ship(Sprite): - def __init__(self, ai_settings, screen): - """初始化飞船并设置其初始位置""" - super(Ship, self).__init__() - self.screen = screen - self.ai_settings = ai_settings - - self.image = pygame.image.load('images/ship.png') - self.rect = self.image.get_rect() - self.screen_rect = screen.get_rect() - - # 将每艘新飞船放在屏幕底部中央 - self.rect.centerx = self.screen_rect.centerx - self.rect.bottom = self.screen_rect.bottom - - \ No newline at end of file From 45286bb9ad6f3a1ce76b5d8088e070217e421f6e Mon Sep 17 00:00:00 2001 From: 206530220 <19194089428@qq.com> Date: Thu, 17 Jun 2021 11:33:18 +0800 Subject: [PATCH 07/13] ship --- ship.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 ship.py diff --git a/ship.py b/ship.py new file mode 100644 index 0000000..66d0f7a --- /dev/null +++ b/ship.py @@ -0,0 +1,12 @@ +import pygame +from pygame.sprite import Sprite + + +class Ship(Sprite): + def __init__(self, ai_settings, screen): + """初始化飞船并设置其初始位置""" + super(Ship, self).__init__() + self.screen = screen + self.ai_settings = ai_settings + + \ No newline at end of file From 441c81dcc31ebe9bf12447d170d7d361dee0727d Mon Sep 17 00:00:00 2001 From: 206530220 <19194089428@qq.com> Date: Fri, 18 Jun 2021 14:48:18 +0800 Subject: [PATCH 08/13] ship --- ship.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ship.py b/ship.py index 66d0f7a..d10db7e 100644 --- a/ship.py +++ b/ship.py @@ -9,4 +9,6 @@ class Ship(Sprite): self.screen = screen self.ai_settings = ai_settings - \ No newline at end of file + self.image = pygame.image.load('images/ship.png') + self.rect = self.image.get_rect() + self.screen_rect = screen.get_rect() \ No newline at end of file From fce4e234b067c47cc25150ff075c5de8055805be Mon Sep 17 00:00:00 2001 From: 206530220 <19194089428@qq.com> Date: Fri, 18 Jun 2021 14:55:13 +0800 Subject: [PATCH 09/13] ship --- ship.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/ship.py b/ship.py index d10db7e..e02ae43 100644 --- a/ship.py +++ b/ship.py @@ -11,4 +11,20 @@ class Ship(Sprite): self.image = pygame.image.load('images/ship.png') self.rect = self.image.get_rect() - self.screen_rect = screen.get_rect() \ No newline at end of file + self.screen_rect = screen.get_rect() + + # 将每艘新飞船放在屏幕底部中央 + self.rect.centerx = self.screen_rect.centerx + self.rect.bottom = self.screen_rect.bottom + + # 在飞船的属性center中存储小数值 + self.centerx = float(self.rect.centerx) + self.centery = float(self.rect.centery) + + # 移动标志 + self.moving_right = False + self.moving_left = False + self.moving_up = False + self.moving_down = False + + \ No newline at end of file From ed06427872b1135b2c4f9835ab956bec6644ece7 Mon Sep 17 00:00:00 2001 From: 206530220 <19194089428@qq.com> Date: Fri, 18 Jun 2021 14:56:05 +0800 Subject: [PATCH 10/13] ship --- ship.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/ship.py b/ship.py index e02ae43..9b32123 100644 --- a/ship.py +++ b/ship.py @@ -27,4 +27,19 @@ class Ship(Sprite): self.moving_up = False self.moving_down = False - \ No newline at end of file + def update(self): + """根据移动标志调整飞船的位置""" + # 更新飞船的center值,而不是rect + if self.moving_right and self.rect.right < self.screen_rect.right: + self.centerx += self.ai_settings.ship_speed_factor + if self.moving_left and self.rect.left > 0: + self.centerx -= self.ai_settings.ship_speed_factor + if self.moving_up and self.rect.top > 0: + self.centery -= self.ai_settings.ship_speed_factor + if self.moving_down and self.rect.bottom < self.screen_rect.bottom: + self.centery += self.ai_settings.ship_speed_factor + # 根据self.center更新rect对象 + self.rect.centerx = self.centerx + self.rect.centery = self.centery + + \ No newline at end of file From e455f416c70d6569a28ad0c6cae2953ada085f82 Mon Sep 17 00:00:00 2001 From: 206530220 <19194089428@qq.com> Date: Sat, 19 Jun 2021 11:46:36 +0800 Subject: [PATCH 11/13] ship --- ship.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ship.py b/ship.py index 9b32123..6638dad 100644 --- a/ship.py +++ b/ship.py @@ -42,4 +42,5 @@ class Ship(Sprite): self.rect.centerx = self.centerx self.rect.centery = self.centery - \ No newline at end of file + def blitme(self): + self.screen.blit(self.image, self.rect) \ No newline at end of file From 38519ba7f4558645ff39449ed83a8f5316c2b502 Mon Sep 17 00:00:00 2001 From: 206530220 <19194089428@qq.com> Date: Sat, 19 Jun 2021 11:57:34 +0800 Subject: [PATCH 12/13] ship --- ship.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ship.py b/ship.py index 6638dad..9ad7710 100644 --- a/ship.py +++ b/ship.py @@ -43,4 +43,8 @@ class Ship(Sprite): self.rect.centery = self.centery def blitme(self): - self.screen.blit(self.image, self.rect) \ No newline at end of file + self.screen.blit(self.image, self.rect) + + def center_ship(self): + """让飞船在屏幕上居中""" + self.center = self.screen_rect.centerx