Skip to content
Snippets Groups Projects
Commit b6a34f87 authored by @dion-tsang's avatar @dion-tsang
Browse files

Lesson 05

parent d491f0ec
Branches
No related tags found
No related merge requests found
Pipeline #501911 passed
docs/assignments/ISAGeekClub/20241113_150836-ezgif.com-video-to-gif-converter.gif

227 KiB

docs/assignments/ISAGeekClub/20241113_152010-ezgif.com-video-to-gif-converter.gif

113 KiB

# Lesson 05 - Moving the Cube! 🤓🤓
## 课前复习 Recap - Creat pygame window and add a cube
```python
import pygame
# Initialize pygame
pygame.init()
# Constants
WIDTH, HEIGHT = 800, 600
SAND = (255, 255, 255)
# Game setup
# window size
screen = pygame.display.set_mode((WIDTH, HEIGHT))
# window caption
pygame.display.set_caption("Chrome Dino Game")
# Create a Frame Rate object
clock = pygame.time.Clock()
# Game loop
running = True
while running:
screen.fill(SAND)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
# add a cube
pygame.draw.rect(screen, (255, 0, 0), (400, 300, 100, 100), 0)
pygame.display.flip()
clock.tick(30)
pygame.quit()
```
## Heroshot: Moving the cube - Horizontally!🌎🤫
```python
import pygame
# Initialize pygame
pygame.init()
# Constants
WIDTH, HEIGHT = 800, 600
SAND = (255, 255, 255)
# Game setup
# window size
screen = pygame.display.set_mode((WIDTH, HEIGHT))
# window caption
pygame.display.set_caption("Chrome Dino Game")
# Create a Frame Rate object
clock = pygame.time.Clock()
# Game loop
running = True
#Moving the cube - Horizontally 水平移动
x = 400
while running:
screen.fill(SAND)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
pygame.draw.rect(screen, (255, 0, 0), (x, 400, 100, 100), 0)
x = x + 4
pygame.display.flip()
clock.tick(30)
pygame.quit()
```
## Chanllenge:Rising Smoke!飘烟挑战
```python
import pygame
# Initialize pygame
pygame.init()
# Constants
WIDTH, HEIGHT = 800, 600
SAND = (255, 255, 255)
# Game setup
# window size
screen = pygame.display.set_mode((WIDTH, HEIGHT))
# window caption
pygame.display.set_caption("Chrome Dino Game")
# Create a Frame Rate object
clock = pygame.time.Clock()
# Game loop
running = True
while running:
screen.fill(SAND)
#背景图
#画矩形-地面
pygame.draw.rect(screen,(0,255,0),(0,500,800,300),0)
#画屋子墙体
pygame.draw.rect(screen,(255,150,100),(500,300,200,200),0)
pygame.draw.rect(screen, (255, 255, 255), (600, 350, 50, 50), 0)
#画月亮
pygame.draw.circle(screen,(200,200,250),(0,0),100)
#画屋顶
pygame.draw.polygon(screen,(255,180,100),[(450,300),(600,150),(750,300)])
pygame.draw.polygon(screen,(0,0,0),[(450,300),(600,150),(750,300)],3)
#画烟圈
pygame.draw.ellipse(screen,(180,180,255),[650,160,60,15],1)
pygame.draw.ellipse(screen,(180,180,255),[650,120,80,30],1)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
pygame.display.flip()
clock.tick(30)
pygame.quit()
```
## Heroshot
### 飘烟挑战
![alt text](20241113_152010-ezgif.com-video-to-gif-converter.gif)
### Running Man
![alt text](20241113_150836-ezgif.com-video-to-gif-converter.gif)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment