steveyehtw commited on
Commit
8f48bbc
·
1 Parent(s): 0c25511

Style redesign to match telearn.best aesthetic, URL ID hashing, and share link generator

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. projects/.DS_Store +0 -0
  2. projects/2026project_class/.DS_Store +0 -0
  3. projects/2026project_class/examples/.DS_Store +0 -0
  4. projects/DEMO/Student1/MakeCode 跳舞機/link.txt +1 -0
  5. projects/DEMO/Student1/Pygame_Breakout/assets/ball_blue.png +3 -0
  6. projects/DEMO/Student1/Pygame_Breakout/assets/brick_blue.png +3 -0
  7. projects/DEMO/Student1/Pygame_Breakout/assets/brick_blue_cracked.png +3 -0
  8. projects/DEMO/Student1/Pygame_Breakout/assets/brick_brown.png +3 -0
  9. projects/DEMO/Student1/Pygame_Breakout/assets/brick_brown_cracked.png +3 -0
  10. projects/DEMO/Student1/Pygame_Breakout/assets/brick_cyan.png +3 -0
  11. projects/DEMO/Student1/Pygame_Breakout/assets/brick_cyan_cracked.png +3 -0
  12. projects/DEMO/Student1/Pygame_Breakout/assets/brick_dark_green.png +3 -0
  13. projects/DEMO/Student1/Pygame_Breakout/assets/brick_dark_green_cracked.png +3 -0
  14. projects/DEMO/Student1/Pygame_Breakout/assets/brick_green.png +3 -0
  15. projects/DEMO/Student1/Pygame_Breakout/assets/brick_green_cracked.png +3 -0
  16. projects/DEMO/Student1/Pygame_Breakout/assets/brick_grey.png +3 -0
  17. projects/DEMO/Student1/Pygame_Breakout/assets/brick_grey_cracked.png +3 -0
  18. projects/DEMO/Student1/Pygame_Breakout/assets/brick_orange.png +3 -0
  19. projects/DEMO/Student1/Pygame_Breakout/assets/brick_orange_cracked.png +3 -0
  20. projects/DEMO/Student1/Pygame_Breakout/assets/brick_purple.png +3 -0
  21. projects/DEMO/Student1/Pygame_Breakout/assets/brick_purple_cracked.png +3 -0
  22. projects/DEMO/Student1/Pygame_Breakout/assets/brick_red.png +3 -0
  23. projects/DEMO/Student1/Pygame_Breakout/assets/brick_red_cracked.png +3 -0
  24. projects/DEMO/Student1/Pygame_Breakout/assets/brick_yellow.png +3 -0
  25. projects/DEMO/Student1/Pygame_Breakout/assets/brick_yellow_cracked.png +3 -0
  26. projects/DEMO/Student1/Pygame_Breakout/assets/bullet.png +3 -0
  27. projects/DEMO/Student1/Pygame_Breakout/assets/heart.png +3 -0
  28. projects/DEMO/Student1/Pygame_Breakout/assets/paddle_1.png +3 -0
  29. projects/DEMO/Student1/Pygame_Breakout/assets/paddle_2.png +3 -0
  30. projects/DEMO/Student1/Pygame_Breakout/assets/paddle_3.png +3 -0
  31. projects/DEMO/Student1/Pygame_Breakout/assets/paddle_gun_1.png +3 -0
  32. projects/DEMO/Student1/Pygame_Breakout/assets/paddle_gun_2.png +3 -0
  33. projects/DEMO/Student1/Pygame_Breakout/assets/paddle_gun_3.png +3 -0
  34. projects/DEMO/Student1/Pygame_Breakout/assets/paddle_long.png +3 -0
  35. projects/DEMO/Student1/Pygame_Breakout/assets/powerup_acid_ball.png +3 -0
  36. projects/DEMO/Student1/Pygame_Breakout/assets/powerup_capsule_empty.png +3 -0
  37. projects/DEMO/Student1/Pygame_Breakout/assets/powerup_expand.png +3 -0
  38. projects/DEMO/Student1/Pygame_Breakout/assets/powerup_fast.png +3 -0
  39. projects/DEMO/Student1/Pygame_Breakout/assets/powerup_fireball.png +3 -0
  40. projects/DEMO/Student1/Pygame_Breakout/assets/powerup_laser.png +3 -0
  41. projects/DEMO/Student1/Pygame_Breakout/assets/powerup_multi_ball.png +3 -0
  42. projects/DEMO/Student1/Pygame_Breakout/assets/powerup_plus_100.png +3 -0
  43. projects/DEMO/Student1/Pygame_Breakout/assets/powerup_plus_250.png +3 -0
  44. projects/DEMO/Student1/Pygame_Breakout/assets/powerup_plus_50.png +3 -0
  45. projects/DEMO/Student1/Pygame_Breakout/assets/powerup_plus_500.png +3 -0
  46. projects/DEMO/Student1/Pygame_Breakout/assets/powerup_shrink.png +3 -0
  47. projects/DEMO/Student1/Pygame_Breakout/assets/powerup_slow.png +3 -0
  48. projects/DEMO/Student1/Pygame_Breakout/assets/star_yellow.png +3 -0
  49. projects/DEMO/Student1/Pygame_Breakout/main.py +257 -0
  50. projects/DEMO/Student1/Pygame乒乓/main.py +172 -0
projects/.DS_Store DELETED
Binary file (6.15 kB)
 
projects/2026project_class/.DS_Store DELETED
Binary file (6.15 kB)
 
projects/2026project_class/examples/.DS_Store DELETED
Binary file (6.15 kB)
 
projects/DEMO/Student1/MakeCode 跳舞機/link.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ https://makecode.com/_fcva84c8D5jD
projects/DEMO/Student1/Pygame_Breakout/assets/ball_blue.png ADDED

Git LFS Details

  • SHA256: 386c1d802b999b44dc23f7b664c5a83d9145d2a1998e10af4e1b5d1c573aff11
  • Pointer size: 130 Bytes
  • Size of remote file: 13.3 kB
projects/DEMO/Student1/Pygame_Breakout/assets/brick_blue.png ADDED

Git LFS Details

  • SHA256: be442525f1668f389cb2cb0872cb57bf1421c2576fbafba38df8f1b6ae8f88b4
  • Pointer size: 129 Bytes
  • Size of remote file: 1.83 kB
projects/DEMO/Student1/Pygame_Breakout/assets/brick_blue_cracked.png ADDED

Git LFS Details

  • SHA256: fb223c990af9fcc1377176a9f5323cadca54583253655d921b3ce9ddf6e4875c
  • Pointer size: 130 Bytes
  • Size of remote file: 10.9 kB
projects/DEMO/Student1/Pygame_Breakout/assets/brick_brown.png ADDED

Git LFS Details

  • SHA256: 37b33819b944c72ef1d0fda730969d98df370305d06a734cee76adaccb848000
  • Pointer size: 129 Bytes
  • Size of remote file: 1.88 kB
projects/DEMO/Student1/Pygame_Breakout/assets/brick_brown_cracked.png ADDED

Git LFS Details

  • SHA256: a92fa6903ae9c9bc9d4a9068e79dd0f6756c853c4409eabbe22f30115f4ccb9b
  • Pointer size: 130 Bytes
  • Size of remote file: 12.3 kB
projects/DEMO/Student1/Pygame_Breakout/assets/brick_cyan.png ADDED

Git LFS Details

  • SHA256: 76324575e57f6e7e1d68e553ac54707e2c447ad7860f11360d6159955e898145
  • Pointer size: 129 Bytes
  • Size of remote file: 1.86 kB
projects/DEMO/Student1/Pygame_Breakout/assets/brick_cyan_cracked.png ADDED

Git LFS Details

  • SHA256: a1213b25e949635bd84143144c1a9c6ae7832db6864a191ad39ff32428bdf694
  • Pointer size: 130 Bytes
  • Size of remote file: 13.4 kB
projects/DEMO/Student1/Pygame_Breakout/assets/brick_dark_green.png ADDED

Git LFS Details

  • SHA256: ea7e7b40d46961684f556d6aaa05ecc4691bfd01562f3ba892072339f6514c24
  • Pointer size: 129 Bytes
  • Size of remote file: 1.83 kB
projects/DEMO/Student1/Pygame_Breakout/assets/brick_dark_green_cracked.png ADDED

Git LFS Details

  • SHA256: c098a90154bc12dd1c0337b815caa88cb27b4d4afbc51b416136a23d8755a16e
  • Pointer size: 130 Bytes
  • Size of remote file: 11.2 kB
projects/DEMO/Student1/Pygame_Breakout/assets/brick_green.png ADDED

Git LFS Details

  • SHA256: 7ffad84b56cb3813a745080e477c2aff83e1f074ce2674b2a7a184543aa79c3b
  • Pointer size: 129 Bytes
  • Size of remote file: 1.82 kB
projects/DEMO/Student1/Pygame_Breakout/assets/brick_green_cracked.png ADDED

Git LFS Details

  • SHA256: d6d0bf4bcf004396af553c05812760e49b97ccefc4343eb8e9208c0a99a83a2e
  • Pointer size: 130 Bytes
  • Size of remote file: 14.4 kB
projects/DEMO/Student1/Pygame_Breakout/assets/brick_grey.png ADDED

Git LFS Details

  • SHA256: 2ad09acc38d4707113e49f995c98ece908698ec052b178b9cfdaa609f1b9d128
  • Pointer size: 129 Bytes
  • Size of remote file: 1.81 kB
projects/DEMO/Student1/Pygame_Breakout/assets/brick_grey_cracked.png ADDED

Git LFS Details

  • SHA256: d9c57fe577f1445fc777fc7957a26186e1e00d1a8ab9f3cb8d63ce4324c6c079
  • Pointer size: 130 Bytes
  • Size of remote file: 12.9 kB
projects/DEMO/Student1/Pygame_Breakout/assets/brick_orange.png ADDED

Git LFS Details

  • SHA256: c5b5fffa1ca91a69297d1c7f95ee5420f13cd63a6b6ad583bf750c0bac0b7679
  • Pointer size: 129 Bytes
  • Size of remote file: 1.82 kB
projects/DEMO/Student1/Pygame_Breakout/assets/brick_orange_cracked.png ADDED

Git LFS Details

  • SHA256: 0f6bf0a75c0bd738c2c9d7ccab65d937d318daf2ab6968cff5bd9427b6c282bd
  • Pointer size: 130 Bytes
  • Size of remote file: 13.4 kB
projects/DEMO/Student1/Pygame_Breakout/assets/brick_purple.png ADDED

Git LFS Details

  • SHA256: 4dcab1021c0deb727497d093e60a3dedbdb998c39c42d01299c61ed8cbdd93c9
  • Pointer size: 129 Bytes
  • Size of remote file: 1.83 kB
projects/DEMO/Student1/Pygame_Breakout/assets/brick_purple_cracked.png ADDED

Git LFS Details

  • SHA256: 2a9f450218acc6dc6ae8f87a3a0259ae3c3ac621b4035f06ec36162921ece8bc
  • Pointer size: 130 Bytes
  • Size of remote file: 13.2 kB
projects/DEMO/Student1/Pygame_Breakout/assets/brick_red.png ADDED

Git LFS Details

  • SHA256: 400de5aa0ae64094f97abada5b1f4864d15c2a8757a34d7fceaa9d0a1ea7e5e9
  • Pointer size: 129 Bytes
  • Size of remote file: 1.88 kB
projects/DEMO/Student1/Pygame_Breakout/assets/brick_red_cracked.png ADDED

Git LFS Details

  • SHA256: acbc7771e1827b55bf468ab8fe8125ea86952aae8e6106ab02435e17837c8841
  • Pointer size: 130 Bytes
  • Size of remote file: 13.3 kB
projects/DEMO/Student1/Pygame_Breakout/assets/brick_yellow.png ADDED

Git LFS Details

  • SHA256: 0fa521d0403f8b02699a9929ae1a252b5ea02f863865a1900c634c6d091da6ba
  • Pointer size: 129 Bytes
  • Size of remote file: 1.82 kB
projects/DEMO/Student1/Pygame_Breakout/assets/brick_yellow_cracked.png ADDED

Git LFS Details

  • SHA256: 06b67fd88f869cbb84bd0fa032ef4d594788ab9cac51925a72b987cb3ca6f937
  • Pointer size: 130 Bytes
  • Size of remote file: 13.1 kB
projects/DEMO/Student1/Pygame_Breakout/assets/bullet.png ADDED

Git LFS Details

  • SHA256: 6e47b0124d969d6f91c87355cce1062918055a1cad37dd4f6b7be4edac75c413
  • Pointer size: 129 Bytes
  • Size of remote file: 4.04 kB
projects/DEMO/Student1/Pygame_Breakout/assets/heart.png ADDED

Git LFS Details

  • SHA256: c9ec55cc56ed5e734f995023093d43e89ed5dd6b22b560bd216bb6702c7558ac
  • Pointer size: 129 Bytes
  • Size of remote file: 8.2 kB
projects/DEMO/Student1/Pygame_Breakout/assets/paddle_1.png ADDED

Git LFS Details

  • SHA256: 311a19275961fb10ae1c39b88190a74ef6ff30fc0be0fe949b767eb9a21a44b5
  • Pointer size: 130 Bytes
  • Size of remote file: 12.5 kB
projects/DEMO/Student1/Pygame_Breakout/assets/paddle_2.png ADDED

Git LFS Details

  • SHA256: 5d28181d820ee9de7da61da52dd191bf8f8a273128cba11acea367921486eb8d
  • Pointer size: 130 Bytes
  • Size of remote file: 12.5 kB
projects/DEMO/Student1/Pygame_Breakout/assets/paddle_3.png ADDED

Git LFS Details

  • SHA256: 48cad734d91773b0863c647061cbe9e40adcd5707383dd98641f93d2fe296620
  • Pointer size: 130 Bytes
  • Size of remote file: 12.9 kB
projects/DEMO/Student1/Pygame_Breakout/assets/paddle_gun_1.png ADDED

Git LFS Details

  • SHA256: 320b963be985885b2d1696bfe0a26528b1263633731fadb249ac99e67cf19886
  • Pointer size: 130 Bytes
  • Size of remote file: 12.6 kB
projects/DEMO/Student1/Pygame_Breakout/assets/paddle_gun_2.png ADDED

Git LFS Details

  • SHA256: 551a9b4913d7b46732e1eb99fcd2ab10ce67d663bcd764e16f44950f947d7752
  • Pointer size: 130 Bytes
  • Size of remote file: 13.2 kB
projects/DEMO/Student1/Pygame_Breakout/assets/paddle_gun_3.png ADDED

Git LFS Details

  • SHA256: 038b48138609798647351d97afd45a3ea1a793258928a8d8763ceab1e8fc2b34
  • Pointer size: 130 Bytes
  • Size of remote file: 12.6 kB
projects/DEMO/Student1/Pygame_Breakout/assets/paddle_long.png ADDED

Git LFS Details

  • SHA256: e5bf31101b7fa6ee1b4105e40a4cb3dce2c893ee01e8b5bc6bfa5010f3d30e50
  • Pointer size: 130 Bytes
  • Size of remote file: 14.8 kB
projects/DEMO/Student1/Pygame_Breakout/assets/powerup_acid_ball.png ADDED

Git LFS Details

  • SHA256: 53d6e9098f25894ce90a67f6d42bb229721bda6985600e532faafac34a657a75
  • Pointer size: 130 Bytes
  • Size of remote file: 14.8 kB
projects/DEMO/Student1/Pygame_Breakout/assets/powerup_capsule_empty.png ADDED

Git LFS Details

  • SHA256: 99ab17ab5acf4e015993c7b2ceb46065e65c674a12830ab4e6d9385eabb26aab
  • Pointer size: 129 Bytes
  • Size of remote file: 9.07 kB
projects/DEMO/Student1/Pygame_Breakout/assets/powerup_expand.png ADDED

Git LFS Details

  • SHA256: c5fba1431ce34e2aca0c354a9b41049aed8ce61adb5ecdbf65b6558b1bc5af9b
  • Pointer size: 130 Bytes
  • Size of remote file: 10.5 kB
projects/DEMO/Student1/Pygame_Breakout/assets/powerup_fast.png ADDED

Git LFS Details

  • SHA256: 4a71f41b8df56be1bd35892ea6b2d5a755705c4b8b816f8804809b2f205e5ee9
  • Pointer size: 130 Bytes
  • Size of remote file: 11.8 kB
projects/DEMO/Student1/Pygame_Breakout/assets/powerup_fireball.png ADDED

Git LFS Details

  • SHA256: 5a3da7acab4203acbb32a9aa6a41898e06387e1b3749e9202058f98416a9affe
  • Pointer size: 130 Bytes
  • Size of remote file: 14 kB
projects/DEMO/Student1/Pygame_Breakout/assets/powerup_laser.png ADDED

Git LFS Details

  • SHA256: eae6cb052fc26d5732d967359e9d1671a27d9c6ffd6878c1db6903956e914269
  • Pointer size: 129 Bytes
  • Size of remote file: 9.94 kB
projects/DEMO/Student1/Pygame_Breakout/assets/powerup_multi_ball.png ADDED

Git LFS Details

  • SHA256: 6fea5e16ed04fb7fa1094d6f829518d64d9f2f38a046fa09f3c25000e377f2d4
  • Pointer size: 130 Bytes
  • Size of remote file: 12.7 kB
projects/DEMO/Student1/Pygame_Breakout/assets/powerup_plus_100.png ADDED

Git LFS Details

  • SHA256: ff7dd9a00be46b21ca9c99227511515e7d51ec67a3a6c0b21131bab6c2ab854c
  • Pointer size: 130 Bytes
  • Size of remote file: 12.2 kB
projects/DEMO/Student1/Pygame_Breakout/assets/powerup_plus_250.png ADDED

Git LFS Details

  • SHA256: 11828eccc18039a380a3d3fe6b8f6479a5cccd7f7b06fb72257a1caeefc0a587
  • Pointer size: 130 Bytes
  • Size of remote file: 12.5 kB
projects/DEMO/Student1/Pygame_Breakout/assets/powerup_plus_50.png ADDED

Git LFS Details

  • SHA256: b016855f0cbdb1e4991838c6c6729581d72b2b2e952cd52dc1857bb8adf4d31f
  • Pointer size: 130 Bytes
  • Size of remote file: 11.7 kB
projects/DEMO/Student1/Pygame_Breakout/assets/powerup_plus_500.png ADDED

Git LFS Details

  • SHA256: 6c8a5f4e926a67c23b0eca18b10c1e8bc110ddd7ea949f5f693385bc405ecb4c
  • Pointer size: 130 Bytes
  • Size of remote file: 12.7 kB
projects/DEMO/Student1/Pygame_Breakout/assets/powerup_shrink.png ADDED

Git LFS Details

  • SHA256: a988444810ccf68ae21b8f565a78d6dbd715f24763032422b77d37435b886d8f
  • Pointer size: 130 Bytes
  • Size of remote file: 10.4 kB
projects/DEMO/Student1/Pygame_Breakout/assets/powerup_slow.png ADDED

Git LFS Details

  • SHA256: e67a01d09ed3dec411ecc206840b6d88df26df102f1ec1e1955653a6d447b15c
  • Pointer size: 130 Bytes
  • Size of remote file: 13 kB
projects/DEMO/Student1/Pygame_Breakout/assets/star_yellow.png ADDED

Git LFS Details

  • SHA256: 7ff1a84ad38b9eb9bfb777e0e0d7ebc9ccbdde8db1f1faeba6dedd64c57af990
  • Pointer size: 129 Bytes
  • Size of remote file: 9.56 kB
projects/DEMO/Student1/Pygame_Breakout/main.py ADDED
@@ -0,0 +1,257 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pygame
2
+ import random
3
+
4
+ SCREEN_WIDTH = 800
5
+ SCREEN_HEIGHT = 600
6
+
7
+ BLACK = (0, 0, 0)
8
+ WHITE = (255, 255, 255)
9
+ YELLOW = (255, 255, 0)
10
+ RED = (255, 0, 0)
11
+
12
+ PADDLE_NEW_WIDTH = 110
13
+ PADDLE_NEW_HEIGHT = 22
14
+ BRICK_NEW_WIDTH = 80
15
+ BRICK_NEW_HEIGHT = 25
16
+
17
+ BALL_RADIUS = 10
18
+
19
+ def draw_text(surface, text, size, x, y):
20
+ font = pygame.font.Font(None, size)
21
+ text_surface = font.render(text, True, WHITE)
22
+ text_rect = text_surface.get_rect()
23
+ text_rect.midtop = (x, y)
24
+ surface.blit(text_surface, text_rect)
25
+
26
+ class Paddle(pygame.sprite.Sprite):
27
+ def __init__(self):
28
+ super().__init__()
29
+
30
+ self.animation_frames = [
31
+ pygame.transform.scale( pygame.image.load("assets/paddle_1.png").convert_alpha(), (PADDLE_NEW_WIDTH, PADDLE_NEW_HEIGHT) ),
32
+ pygame.transform.scale( pygame.image.load("assets/paddle_2.png").convert_alpha(), (PADDLE_NEW_WIDTH, PADDLE_NEW_HEIGHT) ),
33
+ pygame.transform.scale( pygame.image.load("assets/paddle_3.png").convert_alpha(), (PADDLE_NEW_WIDTH, PADDLE_NEW_HEIGHT) )
34
+ ]
35
+ self.current_frame = 0
36
+ self.image = self.animation_frames[self.current_frame]
37
+
38
+ self.rect = self.image.get_rect()
39
+ self.rect.x = (SCREEN_WIDTH - self.rect.width) // 2
40
+ self.rect.y = SCREEN_HEIGHT - self.rect.height - 10
41
+
42
+ self.last_update = pygame.time.get_ticks()
43
+ self.frame_rate = 100
44
+
45
+ def update(self):
46
+ now = pygame.time.get_ticks()
47
+ if now - self.last_update > self.frame_rate:
48
+ self.last_update = now
49
+ self.current_frame = (self.current_frame + 1) % len(self.animation_frames)
50
+ self.image = self.animation_frames[self.current_frame]
51
+
52
+ def move(self,keys):
53
+ if keys[pygame.K_LEFT]:
54
+ self.rect.x -= 7
55
+ if keys[pygame.K_RIGHT]:
56
+ self.rect.x += 7
57
+ if keys[pygame.K_UP]:
58
+ self.rect.y -= 7
59
+ if keys[pygame.K_DOWN]:
60
+ self.rect.y += 7
61
+ if self.rect.right >= SCREEN_WIDTH:
62
+ self.rect.right = SCREEN_WIDTH
63
+ if self.rect.left <= 0:
64
+ self.rect.left = 0
65
+ def widden(self):
66
+ print("球拍變寬了")
67
+ center = self.rect.x
68
+ new_width = int(PADDLE_NEW_WIDTH*1.5)
69
+ self.animation_frames = [
70
+ pygame.transform.scale(frame, (new_width, PADDLE_NEW_HEIGHT))
71
+ for frame in self.animation_frames
72
+ ]
73
+
74
+
75
+ class Ball(pygame.sprite.Sprite):
76
+ def __init__(self):
77
+ super().__init__()
78
+ self.image = pygame.image.load("assets/ball_blue.png").convert_alpha()
79
+ self.image = pygame.transform.scale(self.image, (BALL_RADIUS * 2, BALL_RADIUS * 2))
80
+ self.rect = self.image.get_rect()
81
+ self.reset()
82
+
83
+ def reset(self):
84
+ self.rect.x = SCREEN_WIDTH // 2
85
+ self.rect.y = SCREEN_HEIGHT // 2 + 100
86
+ self.speed_x = random.choice([4, -4])
87
+ self.speed_y = -4
88
+
89
+ def update(self):
90
+ self.rect.x += self.speed_x
91
+ self.rect.y += self.speed_y
92
+ if self.rect.left <= 0 or self.rect.right >= SCREEN_WIDTH:
93
+ self.speed_x *= -1
94
+
95
+ if self.rect.top <= 0:
96
+ self.speed_y *= -1
97
+
98
+ class PowerUp(pygame.sprite.Sprite):
99
+ def __init__(self, x, y, color):
100
+ super().__init__()
101
+ self.color = color
102
+ self.image = pygame.Surface((15,15))
103
+ self.image.fill(self.color)
104
+ self.rect = self.image.get_rect()
105
+ self.rect.centerx = x
106
+ self.rect.centery = y
107
+ self.speed_y = 3
108
+
109
+ def update(self):
110
+ self.rect.y += self.speed_y
111
+ if self.rect.top > SCREEN_HEIGHT:
112
+ self.kill()
113
+
114
+
115
+
116
+ class Brick(pygame.sprite.Sprite):
117
+ def __init__(self, x, y, color, points):
118
+ super().__init__()
119
+ self.points = points
120
+ self.color = color
121
+ self.image_normal = pygame.transform.scale(pygame.image.load(f"assets/brick_{self.color}.png").convert_alpha(), (BRICK_NEW_WIDTH, BRICK_NEW_HEIGHT))
122
+ self.image_cracked = pygame.transform.scale(pygame.image.load(f"assets/brick_{self.color}_cracked.png").convert_alpha(), (BRICK_NEW_WIDTH, BRICK_NEW_HEIGHT))
123
+
124
+ self.image = self.image_normal
125
+ self.rect = self.image.get_rect()
126
+ self.rect.x = x
127
+ self.rect.y = y
128
+ self.health = 2
129
+
130
+ self.all_sprites_group = None
131
+ self.powerups_group = None
132
+
133
+ def hit(self):
134
+ self.health -= 1
135
+ if self.health <= 0:
136
+ if random.randint(1,100) <= 20:
137
+ new_powerup = PowerUp(self.rect.x, self.rect.y, random.choice([YELLOW, RED]))
138
+ self.all_sprites_group.add(new_powerup)
139
+ self.powerups_group.add(new_powerup)
140
+ self.kill()
141
+ return self.points
142
+ else:
143
+ self.image = self.image_cracked
144
+ return 0
145
+
146
+ def game_loop():
147
+ pygame.init()
148
+ screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
149
+ pygame.display.set_caption("打磚塊遊戲")
150
+ clock = pygame.time.Clock()
151
+
152
+ game_state = "start"
153
+ score = 0
154
+
155
+ all_sprites = pygame.sprite.Group()
156
+ bricks = pygame.sprite.Group()
157
+ powerups = pygame.sprite.Group()
158
+ paddle = Paddle()
159
+ ball = Ball()
160
+
161
+ def create_brick_wall():
162
+ bricks.empty()
163
+ powerups.empty()
164
+ all_sprites.empty()
165
+ all_sprites.add(paddle)
166
+ all_sprites.add(ball)
167
+
168
+
169
+ BRICK_COLORS = ["red", "orange", "yellow", "green", "cyan", "blue", "purple"]
170
+ for row, color in enumerate(BRICK_COLORS):
171
+ points = (7 - row) * 10
172
+ for column in range(SCREEN_WIDTH // (BRICK_NEW_WIDTH + 5)):
173
+ brick = Brick(
174
+ column * (BRICK_NEW_WIDTH + 5) + 10,
175
+ row * (BRICK_NEW_HEIGHT + 10) + 50,
176
+ color,
177
+ points
178
+ )
179
+ all_sprites.add(brick)
180
+ bricks.add(brick)
181
+
182
+ brick.all_sprites_group = all_sprites
183
+ brick.powerups_group = powerups
184
+
185
+
186
+
187
+ running = True
188
+ while running:
189
+ clock.tick(60)
190
+
191
+ for event in pygame.event.get():
192
+ if event.type == pygame.QUIT:
193
+ running = False
194
+ if event.type == pygame.KEYDOWN:
195
+ if game_state == "start":
196
+ game_state = "playing"
197
+ score = 0
198
+ paddle.rect.x = (SCREEN_WIDTH - paddle.rect.width) // 2
199
+ paddle.rect.y = SCREEN_HEIGHT - paddle.rect.height - 10
200
+ ball.reset()
201
+ create_brick_wall()
202
+ elif game_state == "game_over":
203
+ game_state = "start"
204
+
205
+ if game_state == "start":
206
+ screen.fill(BLACK)
207
+ draw_text(screen, "BREAKOUT", 64, SCREEN_WIDTH / 2, SCREEN_HEIGHT / 4)
208
+ draw_text(screen, "Press any key to start", 40, SCREEN_WIDTH / 2, SCREEN_HEIGHT * 3 / 4)
209
+ pygame.display.flip()
210
+ elif game_state == "playing":
211
+ keys = pygame.key.get_pressed()
212
+ paddle.move(keys)
213
+ all_sprites.update()
214
+
215
+ if pygame.sprite.collide_rect(ball, paddle):
216
+ ball.speed_y *= -1
217
+ brick_hit_list = pygame.sprite.spritecollide(ball, bricks, False)
218
+ if brick_hit_list:
219
+ ball.speed_y *= -1
220
+ for brick in brick_hit_list:
221
+ score += brick.hit()
222
+ powerups_hit_list = pygame.sprite.spritecollide(paddle, powerups, False)
223
+ for _ in powerups_hit_list:
224
+ if _.color == YELLOW:
225
+ paddle.widden()
226
+ score += 50
227
+ elif _.color == RED:
228
+ ball.speed_y *= 0.3
229
+ ball.speed_x *= 3
230
+ score += 50
231
+ _.kill()
232
+
233
+
234
+ if ball.rect.top >= SCREEN_HEIGHT:
235
+ game_state = "game_over"
236
+ if not bricks:
237
+ game_state = "game_over"
238
+
239
+
240
+ screen.fill(BLACK)
241
+ all_sprites.draw(screen)
242
+ draw_text(screen, f"Score: {score}", 24, SCREEN_WIDTH / 2, 10)
243
+ pygame.display.flip()
244
+
245
+ elif game_state == "game_over":
246
+ screen.fill(BLACK)
247
+ draw_text(screen, "GAME OVER", 64, SCREEN_WIDTH / 2, SCREEN_HEIGHT / 4)
248
+ draw_text(screen, f"Final Score: {score}", 50, SCREEN_WIDTH / 2, SCREEN_HEIGHT / 4 - 50)
249
+ draw_text(screen, "Press any key to restart", 40, SCREEN_WIDTH / 2, SCREEN_HEIGHT * 3 / 4)
250
+ pygame.display.flip()
251
+
252
+ pygame.quit()
253
+
254
+ if __name__ == "__main__":
255
+ game_loop()
256
+ #| |
257
+ # ˇ
projects/DEMO/Student1/Pygame乒乓/main.py ADDED
@@ -0,0 +1,172 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pygame, sys, random
2
+
3
+ pygame.init()
4
+
5
+ SCREEN_WIDTH = 900
6
+ SCREEN_HEIGHT = 600
7
+ BG_COLOR = pygame.Color("#00D000")
8
+ PADDLE_COLOR = pygame.Color("#FF0000")
9
+ PADDLE_WIDTH = 10
10
+ PADDLE_HEIGHT = 100
11
+ BALL_COLOR = pygame.Color(255, 144, 0)
12
+ x = 144
13
+ BALL_SIZE = 15
14
+ LINE_COLOR = pygame.Color("#FFFFFF")
15
+ TEXT_COLOR = pygame.Color("#FFFFFF")
16
+
17
+
18
+ title_font = pygame.font.Font(None, 64)
19
+ game_font = pygame.font.Font(None, 48)
20
+ prompt_font = pygame.font.Font(None, 32)
21
+ paddle1 = pygame.Rect(20, SCREEN_HEIGHT // 2 - PADDLE_HEIGHT // 2, PADDLE_WIDTH, PADDLE_HEIGHT)
22
+ paddle2 = pygame.Rect(SCREEN_WIDTH - 20 - PADDLE_WIDTH, SCREEN_HEIGHT // 2 - PADDLE_HEIGHT // 2, PADDLE_WIDTH, PADDLE_HEIGHT)
23
+ ball = pygame.Rect(SCREEN_WIDTH // 2 - BALL_SIZE // 2, SCREEN_HEIGHT // 2 - BALL_SIZE // 2, BALL_SIZE, BALL_SIZE)
24
+ player_1_score = 0
25
+ player_2_score = 0
26
+
27
+ screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
28
+ pygame.display.set_caption("Pong by Pygame")
29
+ clock = pygame.time.Clock()
30
+
31
+ ball_moving = False
32
+ running = True
33
+ game_start = False
34
+ game_over = False
35
+ deuce = False
36
+ winner_text = ""
37
+
38
+
39
+ while running:
40
+ for event in pygame.event.get():
41
+ if event.type == pygame.QUIT:
42
+ running = False
43
+ if event.type == pygame.KEYDOWN and event.key == pygame.K_SPACE:
44
+ if not ball_moving and not game_over:
45
+ ball_moving = True
46
+ if not deuce :
47
+ if (player_1_score + player_2_score) % 4 == 0 or (player_1_score + player_2_score) % 4 == 1:
48
+ ball_speed_x = 7
49
+ else:
50
+ ball_speed_x = -7
51
+ else:
52
+ if (player_1_score + player_2_score) % 2 == 0:
53
+ ball_speed_x = 7
54
+ else:
55
+ ball_speed_x = -7
56
+ ball_speed_y = 7*random.choice((1, -1))
57
+
58
+ if game_over:
59
+ game_over = False
60
+ winner_text = ""
61
+ player_1_score = 0
62
+ player_2_score = 0
63
+ ball_moving = False
64
+ ball.center = (SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2)
65
+ if not game_start:
66
+ game_start = True
67
+
68
+ keys = pygame.key.get_pressed()
69
+ if keys[pygame.K_w]:
70
+ paddle1.y -= 10
71
+ if keys[pygame.K_s]:
72
+ paddle1.y += 10
73
+ if keys[pygame.K_UP]:
74
+ paddle2.y -= 10
75
+ if keys[pygame.K_DOWN]:
76
+ paddle2.y += 10
77
+ screen.fill(BG_COLOR)
78
+ pygame.draw.rect(screen, PADDLE_COLOR, paddle1)
79
+ pygame.draw.rect(screen, PADDLE_COLOR, paddle2)
80
+ pygame.draw.ellipse(screen, BALL_COLOR, ball)
81
+ pygame.draw.aaline(screen, LINE_COLOR, (SCREEN_WIDTH // 2, 0), (SCREEN_WIDTH // 2, SCREEN_HEIGHT))
82
+
83
+ text1 = game_font.render(f"{player_1_score}", True, TEXT_COLOR)
84
+ p1_rect = text1.get_rect(topright = (SCREEN_WIDTH // 2 - 60, 20))
85
+ screen.blit(text1, p1_rect)
86
+ text2 = game_font.render(f"{player_2_score}", True, TEXT_COLOR)
87
+ p2_rect = text2.get_rect(topleft = (SCREEN_WIDTH // 2 + 60, 20))
88
+ screen.blit(text2, p2_rect)
89
+
90
+ if not game_start:#開始畫面
91
+ title_surface = title_font.render("Pong Game", True, TEXT_COLOR)
92
+ title_rect = title_surface.get_rect(center = (SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2 - 100))
93
+
94
+ prompt_surface = prompt_font.render("Press Space to Start", True, TEXT_COLOR)
95
+ prompt_rect = prompt_rect = prompt_surface.get_rect(center = (SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2))
96
+
97
+ screen.blit(title_surface, title_rect)
98
+ screen.blit(prompt_surface, prompt_rect)
99
+
100
+ pong_img = pygame.image.load("pong.png")
101
+ pong_img = pygame.transform.scale(pong_img, (100, 100))
102
+ screen.blit(pong_img, (SCREEN_WIDTH // 2 - pong_img.get_width() // 2, SCREEN_HEIGHT//2+40))
103
+ if not ball_moving and game_start and not game_over:
104
+ prompt_surface = prompt_font.render("Press Space to Serve", True, TEXT_COLOR)
105
+ prompt_rect = prompt_surface.get_rect(center = (SCREEN_WIDTH // 2, SCREEN_HEIGHT - 50))
106
+ screen.blit(prompt_surface, prompt_rect)
107
+
108
+
109
+ if ball_moving:
110
+ ball.x += ball_speed_x
111
+ ball.y += ball_speed_y
112
+ if ball.top <= 0 or ball.bottom >= SCREEN_HEIGHT:
113
+ ball_speed_y *= -1
114
+ if ball.colliderect(paddle1) or ball.colliderect(paddle2):
115
+ ball_speed_x *= -1.05
116
+ ball_speed_y *= 1.05
117
+ if x > 0:
118
+ x -= x/10
119
+ BALL_COLOR = (255, x, 0)
120
+ if ball.left <= 0:
121
+ player_2_score += 1
122
+ x = 144
123
+ if deuce and player_2_score - player_1_score >= 2:
124
+ winner_text = "Player 2 Wins !"
125
+ game_over = True
126
+ deuce = False
127
+ if not deuce and player_2_score >= 11:
128
+ winner_text = "Player 2 Wins !"
129
+ game_over = True
130
+ deuce = False
131
+ if not deuce and player_1_score >= 10 and player_2_score >= 10:
132
+ deuce = True
133
+ ball.center = (SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2)
134
+ ball_moving = False
135
+ if ball.right >= SCREEN_WIDTH:
136
+ player_1_score += 1
137
+ x = 144
138
+ if deuce and player_1_score - player_2_score >= 2:
139
+ winner_text = "Player 1 Wins !"
140
+ game_over = True
141
+ deuce = False
142
+ if not deuce and player_1_score >= 11:
143
+ winner_text = "Player 1 Wins !"
144
+ game_over = True
145
+ if not deuce and player_1_score >= 10 and player_2_score >= 10:
146
+ deuce = True
147
+ deuce = False
148
+ ball.center = (SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2)
149
+ ball_moving = False
150
+ if game_over:
151
+ game_over_surface = title_font.render(winner_text, True, TEXT_COLOR)
152
+ game_over_rect = game_over_surface.get_rect(center = (SCREEN_WIDTH // 2 , SCREEN_HEIGHT // 2 -50))
153
+ screen.blit(game_over_surface, game_over_rect)
154
+
155
+ restart_surface = prompt_font.render("Press Space to Restart", True, TEXT_COLOR)
156
+ restart_rect = restart_surface.get_rect(center = (SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2 + 20))
157
+ screen.blit(restart_surface, restart_rect)
158
+
159
+
160
+ if paddle1.top <= 0:
161
+ paddle1.top = 0
162
+ if paddle1.bottom >= SCREEN_HEIGHT:
163
+ paddle1.bottom = SCREEN_HEIGHT
164
+ if paddle2.top <= 0:
165
+ paddle2.top = 0
166
+ if paddle2.bottom >= SCREEN_HEIGHT:
167
+ paddle2.bottom = SCREEN_HEIGHT
168
+ pygame.display.flip()
169
+ clock.tick(60)
170
+
171
+ pygame.quit()
172
+ sys.exit()