wenwen
wenwen

探索網路世界和進入區塊鏈的過程或許很平凡,但我就是想分享給大家,若能幫助到有需要幫助的人,那就更好了。 有幫到你的話,記得按下方拍手圖,不需花你任何金錢,免費註冊Liker ID,就可對我化讚為賞:https://button.like.co/willie5068

032第12章 A SHIP THAT FIRES BULLETS_續9_pygame.Rect() class

用 code 刻圖 初體驗

💛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》

CC BY-NC-ND 2.0 版权声明

喜欢我的文章吗?
别忘了给点支持与赞赏,让我知道创作的路上有你陪伴。

加载中…
加载中…

发布评论