iT邦幫忙

鐵人檔案

2024 iThome 鐵人賽
回列表
Python

從Python入門到自製遊戲:30天鐵人挑戰之旅 系列

這次參賽將以Python程式語言為主軸,進行為期30天的學習與實作挑戰。內容從基礎語法、條件判斷、迴圈、函數等初學者必備概念,逐步深入到進階主題。最後,我將應用所學開發一個自製小型遊戲,作為挑戰的成果展示。每天的學習內容會搭配具體範例與程式碼解說,幫助讀者輕鬆理解,並實現程式從入門到實作的飛躍。

鐵人鍊成 | 共 30 篇文章 | 0 人訂閱 訂閱系列文 RSS系列文
DAY 21

遊戲設定與環境配置

今天開始慢慢做一個小遊戲,打算做簡易版打磚塊。 import pygame import random # 初始化 pygame pygame.init()...

2024-10-05 ‧ 由 cchung 分享
DAY 22

設定遊戲內的顏色與元素屬性

今天來做遊戲物件屬性,球、擋板、磚塊及顏色。 # 設定顏色 white = (255, 255, 255) black = (0, 0, 0) light_bl...

2024-10-06 ‧ 由 cchung 分享
DAY 23

建立磚塊矩形陣列

程式碼結構與邏輯 bricks = [] for row in range(brick_rows): for col in range(brick_co...

2024-10-07 ‧ 由 cchung 分享
DAY 24

遊戲主迴圈

今天來做遊戲中心。 running = True clock = pygame.time.Clock() while running: clock.t...

2024-10-08 ‧ 由 cchung 分享
DAY 25

玩家輸入與球的位置更新

今天來做擋板及球的移動。 keys = pygame.key.get_pressed() if keys[pygame.K_LEFT] and...

2024-10-09 ‧ 由 cchung 分享
DAY 26

碰撞檢測

今天來做碰撞檢測 if ball_x <= 0 or ball_x >= screen_width - ball_radius:...

2024-10-10 ‧ 由 cchung 分享
DAY 27

繪製遊戲畫面

今天來將每樣東西上色。 screen.fill(white) pygame.draw.circle(screen, black, (ball_x...

2024-10-11 ‧ 由 cchung 分享
DAY 28

遊戲的開始與結束

那今天來做開始結束按鈕。 font = pygame.font.SysFont(None, 55) def display_message(text, colo...

2024-10-12 ‧ 由 cchung 分享
DAY 29

增加關卡

今天來增加關卡。 level = 1 max_level = 3 if not bricks: if level == max_level:...

2024-10-13 ‧ 由 cchung 分享
DAY 30

總結與回顧

這30天的Python挑戰真的是一次滿滿收穫的經歷,讓我從入門一步步走到算是能夠自製遊戲的程度。前部分打好基礎,環境設置、基本語法、條件語句、迴圈等內容,讓我快...

2024-10-14 ‧ 由 cchung 分享