在遊戲的整個遊玩中,程式在一個不斷循環偵測的處理過程
clock
:每秒畫面更新速率計時器pygame.display.update()
: 更新畫面__init__
: 初始化函式
self
: 我是哪個物件canvas
: 所在的畫布pos
: 所在的位置radius
: 球的半徑update()
要放在display.update()
前,因為要先繪製遊戲物件再更新畫面resetGame()
)if event.type == pygame.MOUSEMOTION:
paddle_x = pygame.mouse.get_pos()[0] - 50
當球碰到反彈板時,要進行碰撞偵測並處理
首先宣告碰撞偵測函數
def isCollision(Rect1, Rect2):
if(pygame.Rect.colliderect(Rect1, Rect2)):
return True
return False
並且在適當位置放入碰撞判斷
if(isCollision(ball.rect, paddle.rect)):
dy = -dy
or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Do you want to remove this version name and description?
Syncing