032第12章 A SHIP THAT FIRES BULLETS_續9_pygame.Rect() class
💛20230201 晨讀感言:
💔在 遊戲程式 所展現的畫面中,並不是所有元素 都來自 圖檔,有時候 是用 Code 刻畫出來的(像是 發射的 子彈),這時候,就會 用到 pygame.Rect() class 。
💔為了精確描繪 螢幕上 發射出來的子彈,書中在 bullet.py 中區分了三個分段來撰寫程式,分別是 子彈本身的大小設定、子彈的位置更新 和 將子彈繪製在螢幕上,而這三段程式 結合之後,就可以看到 當子彈發射 之後 的 位置 和 行經路徑。
💛晨讀摘要:
💚247 At 1, we create the bullet’s rect attribute. ==The bullet isn’t based on an image, so we have to build a rect from scratch using the pygame.Rect() class==. This class requires the x- and y-coordinates of the top-left corner of the rect, and the width and height of the rect. We initialize the rect at (0, 0), but we’ll move it to the correct location in the next line, because the bullet’s position depends on the ship’s position. We get the width and height of the bullet from the values stored in self.settings.
from:《python crash course》
Like my work? Don't forget to support and clap, let me know that you are with me on the road of creation. Keep this enthusiasm together!
- Author
- More