├── README.md ├── arts.py ├── bg_img ├── no.png ├── pingpang.png ├── pingpangGamePic.jpeg ├── pingpangGamePic2.jpeg ├── skierGame.jpeg ├── skierGamePic.jpeg ├── skier_crash.png ├── skier_down.png ├── skier_flag.png ├── skier_left1.png ├── skier_left2.png ├── skier_right1.png ├── skier_right2.png └── skier_tree.png ├── bg_music ├── bg_music.mp3 ├── game_over.wav ├── get_point.wav ├── hit_paddle.wav ├── hit_wall.wav ├── new_life.wav └── splat.wav ├── drawTree.py ├── eventsGames.py ├── mutiplPicMove.py ├── pingpangGames.py ├── sin.py ├── singlePicMove.py └── skierGames.py /README.md: -------------------------------------------------------------------------------- 1 |

1、乒乓球游戏(pingpangGames)


2 |

游戏规则:


3 |

a、用球拍击中一个来回反弹,速度不定的球,如果球碰到屏幕的顶端,则玩家得一分。如果球掉下屏幕的底端,则玩家少一条命。

4 |

b、玩家一共有三条命,如果全部用完则游戏结束.

5 |

游戏效果:

6 | 7 | ![pingpangGamesPic](https://github.com/Molly6943/pythonGames/blob/master/bg_img/pingpangGamePic.jpeg) 8 | 9 | 10 | ![pingpangGamesPic2](https://github.com/Molly6943/pythonGames/blob/master/bg_img/pingpangGamePic2.jpeg) 11 | 12 | 13 |

2、滑雪游戏(skierGames)


14 |

游戏规则:


15 |

a、玩家滑下小山,努力避开树,尽量捡到小旗。

16 |

b、如果碰到树就负100分,如果捡到小旗就加10分

17 |

游戏效果:

18 | 19 | 20 | ![skierGamePic](https://github.com/Molly6943/pythonGames/blob/master/bg_img/skierGame.jpeg) 21 | 22 | 23 | ![skierGamePic2](https://github.com/Molly6943/pythonGames/blob/master/bg_img/skierGamePic.jpeg) 24 | 25 | -------------------------------------------------------------------------------- /arts.py: -------------------------------------------------------------------------------- 1 | import pygame,sys,random,time 2 | from pygame.color import THECOLORS 3 | pygame.init() 4 | screen = pygame.display.set_mode([640,480]) 5 | screen.fill([255,255,255]) 6 | for i in range(100): 7 | width = random.randint(0,250) 8 | height = random.randint(0,100) 9 | top = random.randint(0,400) 10 | left = random.randint(0,500) 11 | color_name = random.choice(THECOLORS.keys()) 12 | color = THECOLORS[color_name] 13 | pygame.draw.rect(screen,color,[left,top,width,height],3) 14 | pygame.time.delay(80) 15 | pygame.display.flip() 16 | while True: 17 | for event in pygame.event.get(): 18 | if event.type == pygame.QUIT: 19 | sys.exit() 20 | -------------------------------------------------------------------------------- /bg_img/no.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Molly6943/pythonGames/8cd0aaf494b76cb9341f0acb8ec3d430dd0efa60/bg_img/no.png -------------------------------------------------------------------------------- /bg_img/pingpang.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Molly6943/pythonGames/8cd0aaf494b76cb9341f0acb8ec3d430dd0efa60/bg_img/pingpang.png -------------------------------------------------------------------------------- /bg_img/pingpangGamePic.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Molly6943/pythonGames/8cd0aaf494b76cb9341f0acb8ec3d430dd0efa60/bg_img/pingpangGamePic.jpeg -------------------------------------------------------------------------------- /bg_img/pingpangGamePic2.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Molly6943/pythonGames/8cd0aaf494b76cb9341f0acb8ec3d430dd0efa60/bg_img/pingpangGamePic2.jpeg -------------------------------------------------------------------------------- /bg_img/skierGame.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Molly6943/pythonGames/8cd0aaf494b76cb9341f0acb8ec3d430dd0efa60/bg_img/skierGame.jpeg -------------------------------------------------------------------------------- /bg_img/skierGamePic.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Molly6943/pythonGames/8cd0aaf494b76cb9341f0acb8ec3d430dd0efa60/bg_img/skierGamePic.jpeg -------------------------------------------------------------------------------- /bg_img/skier_crash.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Molly6943/pythonGames/8cd0aaf494b76cb9341f0acb8ec3d430dd0efa60/bg_img/skier_crash.png -------------------------------------------------------------------------------- /bg_img/skier_down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Molly6943/pythonGames/8cd0aaf494b76cb9341f0acb8ec3d430dd0efa60/bg_img/skier_down.png -------------------------------------------------------------------------------- /bg_img/skier_flag.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Molly6943/pythonGames/8cd0aaf494b76cb9341f0acb8ec3d430dd0efa60/bg_img/skier_flag.png -------------------------------------------------------------------------------- /bg_img/skier_left1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Molly6943/pythonGames/8cd0aaf494b76cb9341f0acb8ec3d430dd0efa60/bg_img/skier_left1.png -------------------------------------------------------------------------------- /bg_img/skier_left2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Molly6943/pythonGames/8cd0aaf494b76cb9341f0acb8ec3d430dd0efa60/bg_img/skier_left2.png -------------------------------------------------------------------------------- /bg_img/skier_right1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Molly6943/pythonGames/8cd0aaf494b76cb9341f0acb8ec3d430dd0efa60/bg_img/skier_right1.png -------------------------------------------------------------------------------- /bg_img/skier_right2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Molly6943/pythonGames/8cd0aaf494b76cb9341f0acb8ec3d430dd0efa60/bg_img/skier_right2.png -------------------------------------------------------------------------------- /bg_img/skier_tree.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Molly6943/pythonGames/8cd0aaf494b76cb9341f0acb8ec3d430dd0efa60/bg_img/skier_tree.png -------------------------------------------------------------------------------- /bg_music/bg_music.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Molly6943/pythonGames/8cd0aaf494b76cb9341f0acb8ec3d430dd0efa60/bg_music/bg_music.mp3 -------------------------------------------------------------------------------- /bg_music/game_over.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Molly6943/pythonGames/8cd0aaf494b76cb9341f0acb8ec3d430dd0efa60/bg_music/game_over.wav -------------------------------------------------------------------------------- /bg_music/get_point.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Molly6943/pythonGames/8cd0aaf494b76cb9341f0acb8ec3d430dd0efa60/bg_music/get_point.wav -------------------------------------------------------------------------------- /bg_music/hit_paddle.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Molly6943/pythonGames/8cd0aaf494b76cb9341f0acb8ec3d430dd0efa60/bg_music/hit_paddle.wav -------------------------------------------------------------------------------- /bg_music/hit_wall.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Molly6943/pythonGames/8cd0aaf494b76cb9341f0acb8ec3d430dd0efa60/bg_music/hit_wall.wav -------------------------------------------------------------------------------- /bg_music/new_life.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Molly6943/pythonGames/8cd0aaf494b76cb9341f0acb8ec3d430dd0efa60/bg_music/new_life.wav -------------------------------------------------------------------------------- /bg_music/splat.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Molly6943/pythonGames/8cd0aaf494b76cb9341f0acb8ec3d430dd0efa60/bg_music/splat.wav -------------------------------------------------------------------------------- /drawTree.py: -------------------------------------------------------------------------------- 1 | import pygame,sys 2 | pygame.init() 3 | dots = [[221, 432],[225, 331],[133, 342],[141, 310],[51, 230],[74,217],[58,153],[114,164],[123,135],[176,190],[159,77], 4 | [193,93],[230,28],[267,93],[301,77],[284,190],[327,135],[336,164],[402,153],[386,217],[409,230],[319,310],[327,342], 5 | [233,311],[237,432]] 6 | screen = pygame.display.set_mode([640,480]) 7 | screen.fill([225,225,225]) 8 | pygame.draw.lines(screen,[255,0,0],True,dots,2) 9 | pygame.display.flip() 10 | while True: 11 | for event in pygame.event.get(): 12 | if event.type == pygame.QUIT: 13 | sys.exit() 14 | -------------------------------------------------------------------------------- /eventsGames.py: -------------------------------------------------------------------------------- 1 | import pygame,sys 2 | pygame.init() 3 | screen = pygame.display.set_mode([640,480]) 4 | background = pygame.Surface(screen.get_size()) 5 | background.fill([255,255,255]) 6 | clock = pygame.time.Clock() 7 | delay = 100 8 | interval = 50 9 | pygame.key.set_repeat(delay,interval) 10 | class Ball(pygame.sprite.Sprite): 11 | def __init__(self,image_file,speed,location): 12 | pygame.sprite.Sprite.__init__(self) 13 | self.image = pygame.image.load(image_file) 14 | self.rect = self.image.get_rect() 15 | self.rect.left,self.rect.top = location 16 | self.speed = speed 17 | def move(self): 18 | if self.rect.left <= screen.get_rect().left or self.rect.right >= screen.get_rect().right: 19 | self.speed[0] = - self.speed[0] 20 | newpos = self.rect.move(self.speed) 21 | self.rect = newpos 22 | 23 | myball = Ball("./bg_img/no.png",[10,0],[20,20]) 24 | held_town = False 25 | while 1: 26 | for event in pygame.event.get(): 27 | if event.type == pygame.QUIT: 28 | sys.exit() 29 | elif event.type == pygame.KEYDOWN: 30 | if event.key == pygame.K_UP: 31 | myball.rect.top = myball.rect.top - 10 32 | elif event.key == pygame.K_DOWN: 33 | myball.rect.top = myball.rect.top + 10 34 | elif event.type == pygame.MOUSEBUTTONDOWN: 35 | held_town = True 36 | elif event.type == pygame.MOUSEBUTTONUP: 37 | held_town = False 38 | elif event.type == pygame.MOUSEMOTION: 39 | if held_town: 40 | myball.rect.center = event.pos 41 | clock.tick(10) 42 | screen.blit(background,[0,0]) 43 | myball.move() 44 | screen.blit(myball.image,myball.rect) 45 | pygame.display.flip() 46 | -------------------------------------------------------------------------------- /mutiplPicMove.py: -------------------------------------------------------------------------------- 1 | import pygame,sys 2 | from random import * 3 | class myBallClass(pygame.sprite.Sprite): 4 | def __init__(self,image_file,location,speed): 5 | pygame.sprite.Sprite.__init__(self) 6 | self.image = pygame.image.load(image_file) 7 | self.rect = self.image.get_rect() 8 | self.rect.left,self.rect.top = location 9 | self.speed = speed 10 | def move(self): 11 | self.rect = self.rect.move(self.speed) 12 | if self.rect.left < 0 or self.rect.right > width: 13 | self.speed[0] = - self.speed[0] 14 | if self.rect.top < 0 or self.rect.bottom > height: 15 | self.speed[1] = - self.speed[1] 16 | 17 | def animate(group): 18 | screen.fill([255,255,255]) 19 | for ball in group: 20 | ball.move() 21 | for ball in group: 22 | group.remove(ball) 23 | if pygame.sprite.spritecollide(ball,group,False): 24 | ball.speed[0] = - ball.speed[0] 25 | ball.speed[1] = - ball.speed[1] 26 | group.add(ball) 27 | screen.blit(ball.image,ball.rect) 28 | 29 | pygame.display.flip() 30 | # pygame.time.delay(20) 31 | 32 | 33 | size = width,height = 640,480 34 | screen = pygame.display.set_mode(size) 35 | screen.fill([255,255,255]) 36 | img_file = "./bg_img/no.png" 37 | clock = pygame.time.Clock() 38 | group = pygame.sprite.Group() 39 | for row in range(0,2): 40 | for column in range(0,2): 41 | location = [column * 180 + 10,row * 180 + 10] 42 | speed = [choice([-2,2]),choice([-2,2])] 43 | ball = myBallClass(img_file,location,speed) 44 | group.add(ball) 45 | while True: 46 | for event in pygame.event.get(): 47 | if event.type == pygame.QUIT: 48 | frame_rate = clock.get_fps() 49 | print "frame_rate = ",frame_rate 50 | sys.exit() 51 | animate(group) 52 | clock.tick(30) 53 | -------------------------------------------------------------------------------- /pingpangGames.py: -------------------------------------------------------------------------------- 1 | import pygame,sys,random 2 | from pygame.locals import * 3 | class MyBallClass(pygame.sprite.Sprite): 4 | def __init__(self,image_file,location,speed): 5 | pygame.sprite.Sprite.__init__(self) 6 | self.image = pygame.image.load(image_file) 7 | self.rect = self.image.get_rect() 8 | self.rect.left,self.rect.top = location 9 | self.speed = speed 10 | def move(self): 11 | global points,score_text 12 | self.rect = self.rect.move(self.speed) 13 | if self.rect.left < 0 or self.rect.right > screen.get_width(): 14 | self.speed[0] = - self.speed[0] 15 | hit_wall.play() 16 | if self.rect.top <= 0: 17 | points = points + 1 18 | if self.speed[1] < 0: 19 | self.speed[1] = random.randint(5,10) 20 | else: 21 | self.speed[1] = random.randint(-10,-5) 22 | 23 | score_text = font.render(str(points),1,(0,200,0)) 24 | get_point.play() 25 | if self.rect.top >= screen.get_rect().bottom: 26 | hit_wall.stop() 27 | 28 | 29 | class MyPaddleClass(pygame.sprite.Sprite): 30 | def __init__(self,location = [0,0]): 31 | pygame.sprite.Sprite.__init__(self) 32 | image_surface = pygame.surface.Surface([100,20]) 33 | image_surface.fill([0,0,0]) 34 | self.image = image_surface.convert() 35 | self.rect = self.image.get_rect() 36 | self.rect.left,self.rect.top = location 37 | 38 | 39 | pygame.init() 40 | pygame.mixer.init() 41 | pygame.mixer.music.load("./bg_music/bg_music.mp3") 42 | pygame.mixer.music.set_volume(0.3) 43 | pygame.mixer.music.play(-1) 44 | hit = pygame.mixer.Sound("./bg_music/hit_hanndel.wav") 45 | hit.set_volume(0.60) 46 | 47 | hit_wall = pygame.mixer.Sound("./bg_music/hit_wall.wav") 48 | hit_wall.set_volume(0.20) 49 | 50 | get_point = pygame.mixer.Sound("./bg_music/get_point.wav") 51 | get_point.set_volume(0.30) 52 | 53 | game_over = pygame.mixer.Sound("./bg_music/game_over.wav") 54 | game_over.set_volume(0.40) 55 | 56 | new_life = pygame.mixer.Sound("./bg_music/new_life.wav") 57 | new_life.set_volume(0.40) 58 | 59 | splat = pygame.mixer.Sound("./bg_music/splat.wav") 60 | splat.set_volume(0.40) 61 | 62 | screen = pygame.display.set_mode([640,480]) 63 | clock = pygame.time.Clock() 64 | ball_speed = [random.randint(-10,5),random.randint(-5,10)] 65 | myball = MyBallClass("./bg_img/pingpang.png",[50,50],ball_speed) 66 | ballGroup = pygame.sprite.Group(myball) 67 | paddle = MyPaddleClass([270,400]) 68 | lives = 3 69 | points = 0 70 | 71 | font = pygame.font.Font(None,50) 72 | score_text = font.render(str(points),1,(0,200,0)) 73 | textpos = [10,10] 74 | done = False 75 | 76 | while 1: 77 | clock.tick(30) 78 | screen.fill([255,255,255]) 79 | for event in pygame.event.get(): 80 | if event.type == QUIT: 81 | sys.exit() 82 | elif event.type == pygame.MOUSEMOTION: 83 | paddle.rect.centerx = event.pos[0] 84 | 85 | if pygame.sprite.spritecollide(paddle,ballGroup,False): 86 | myball.speed[1] = - myball.speed[1] 87 | hit.play() 88 | 89 | myball.move() 90 | 91 | if not done: 92 | screen.blit(myball.image,myball.rect) 93 | screen.blit(paddle.image,paddle.rect) 94 | screen.blit(score_text,textpos) 95 | for i in range(lives): 96 | width = screen.get_width() 97 | screen.blit(myball.image,[width - 40 * i,20]) 98 | pygame.display.flip() 99 | 100 | if myball.rect.top >= screen.get_rect().bottom: 101 | if not done: 102 | splat.play() 103 | lives = lives - 1 104 | if lives <= 0: 105 | if not done: 106 | pygame.time.delay(1000) 107 | game_over.play() 108 | final_text1 = "Game over!" 109 | final_text2 = "your final score is : " + str(points) 110 | ft1_font = pygame.font.Font(None,70) 111 | ft1_surf = font.render(final_text1,1,(200,0,0)) 112 | ft2_font = pygame.font.Font(None,50) 113 | ft2_surf = font.render(final_text2,1,(0,200,0)) 114 | screen.blit(ft1_surf,[screen.get_width() / 2 - ft1_surf.get_width() / 2,100]) 115 | screen.blit(ft2_surf,[screen.get_width() / 2 - ft2_surf.get_width() / 2,200]) 116 | pygame.display.flip() 117 | done = True 118 | pygame.mixer.music.fadeout(2000) 119 | else: 120 | pygame.time.delay(1000) 121 | new_life.play() 122 | myball.rect.topleft = [50,50] 123 | pygame.display.flip() 124 | pygame.time.delay(1000) 125 | -------------------------------------------------------------------------------- /sin.py: -------------------------------------------------------------------------------- 1 | import pygame,sys 2 | import math 3 | pygame.init() 4 | screen = pygame.display.set_mode([640,480]) 5 | screen.fill([249,204,226]) 6 | for x in range(0,640): 7 | y = int(math.sin(x/640.0*4*math.pi)*200+240) 8 | pygame.draw.rect(screen,[0,0,0],[x,y,1,1],1) 9 | pygame.display.flip() 10 | while True: 11 | for event in pygame.event.get(): 12 | if event.type == pygame.QUIT: 13 | sys.exit() 14 | -------------------------------------------------------------------------------- /singlePicMove.py: -------------------------------------------------------------------------------- 1 | import pygame,sys 2 | pygame.init() 3 | screen = pygame.display.set_mode([640,480]) 4 | screen.fill([225,225,225]) 5 | my_ball = pygame.image.load("./bg_img/no.png") 6 | x = 50 7 | y = 50 8 | x_speed = 5 9 | y_speed = 10 10 | 11 | while True: 12 | for event in pygame.event.get(): 13 | if event.type == pygame.QUIT: 14 | sys.exit() 15 | pygame.time.delay(80) 16 | pygame.draw.rect(screen,[225,225,225],[x,y,65,65],0) 17 | x = x + x_speed 18 | y = y + y_speed 19 | if x > screen.get_width() - 65 or x < 0: 20 | x_speed = - x_speed 21 | if y > screen.get_height() - 65 or y <0: 22 | y_speed = - y_speed 23 | if x > screen.get_width(): 24 | x = 0 25 | if y > screen.get_height(): 26 | y = 0 27 | screen.blit(my_ball,[x,y]) 28 | pygame.display.flip() 29 | -------------------------------------------------------------------------------- /skierGames.py: -------------------------------------------------------------------------------- 1 | import pygame, sys, random 2 | 3 | skier_images = ["./bg_img/skier_down.png", "./bg_img/skier_right1.png", "./bg_img/skier_right2.png", 4 | "./bg_img/skier_left2.png", "./bg_img/skier_left1.png"] 5 | 6 | class SkierClass(pygame.sprite.Sprite): 7 | def __init__(self): 8 | pygame.sprite.Sprite.__init__(self) 9 | self.image = pygame.image.load("./bg_img/skier_down.png") 10 | self.rect = self.image.get_rect() 11 | self.rect.center = [320, 100] 12 | self.angle = 0 13 | 14 | def turn(self, direction): 15 | self.angle = self.angle + direction 16 | if self.angle < -2: self.angle = -2 17 | if self.angle > 2: self.angle = 2 18 | center = self.rect.center 19 | self.image = pygame.image.load(skier_images[self.angle]) 20 | self.rect = self.image.get_rect() 21 | self.rect.center = center 22 | speed = [self.angle, 6 - abs(self.angle) * 2] 23 | return speed 24 | 25 | def move(self, speed): 26 | self.rect.centerx = self.rect.centerx + speed[0] 27 | if self.rect.centerx < 20: self.rect.centerx = 20 28 | if self.rect.centerx > 620: self.rect.centerx = 620 29 | 30 | class ObstacleClass(pygame.sprite.Sprite): 31 | def __init__(self, image_file, location, type): 32 | pygame.sprite.Sprite.__init__(self) 33 | self.image_file = image_file 34 | self.image = pygame.image.load(image_file) 35 | self.location = location 36 | self.rect = self.image.get_rect() 37 | self.rect.center = location 38 | self.type = type 39 | self.passed = False 40 | 41 | def scroll(self, terrainPos): 42 | self.rect.centery = self.location[1] - terrainPos 43 | 44 | def create_map(start, end): 45 | obstacles = pygame.sprite.Group() 46 | locations = [] 47 | gates = pygame.sprite.Group() 48 | for i in range(10): 49 | row = random.randint(start, end) 50 | col = random.randint(0, 9) 51 | location = [col * 64 + 20, row * 64 + 20] 52 | if not (location in locations): 53 | locations.append(location) 54 | type = random.choice(["tree", "flag"]) 55 | if type == "tree": img = "./bg_img/skier_tree.png" 56 | elif type == "flag": img = "./bg_img/skier_flag.png" 57 | obstacle = ObstacleClass(img, location, type) 58 | obstacles.add(obstacle) 59 | return obstacles 60 | 61 | def animate(): 62 | screen.fill([255, 255, 255]) 63 | pygame.display.update(obstacles.draw(screen)) 64 | screen.blit(skier.image, skier.rect) 65 | screen.blit(score_text, [10, 10]) 66 | pygame.display.flip() 67 | 68 | def updateObstacleGroup(map0, map1): 69 | obstacles = pygame.sprite.Group() 70 | for ob in map0: obstacles.add(ob) 71 | for ob in map1: obstacles.add(ob) 72 | return obstacles 73 | 74 | pygame.init() 75 | pygame.mixer.init() 76 | pygame.mixer.music.load("./bg_music/bg_music.mp3") 77 | pygame.mixer.music.set_volume(0.3) 78 | pygame.mixer.music.play(-1) 79 | screen = pygame.display.set_mode([640,640]) 80 | clock = pygame.time.Clock() 81 | skier = SkierClass() 82 | speed = [0, 6] 83 | map_position = 0 84 | points = 0 85 | map0 = create_map(20, 29) 86 | map1 = create_map(10, 19) 87 | activeMap = 0 88 | 89 | obstacles = updateObstacleGroup(map0, map1) 90 | 91 | font = pygame.font.Font(None, 50) 92 | 93 | while True: 94 | clock.tick(30) 95 | for event in pygame.event.get(): 96 | if event.type == pygame.QUIT: sys.exit() 97 | if event.type == pygame.KEYDOWN: 98 | if event.key == pygame.K_LEFT: 99 | speed = skier.turn(-1) 100 | elif event.key == pygame.K_RIGHT: 101 | speed = skier.turn(1) 102 | skier.move(speed) 103 | map_position += speed[1] 104 | 105 | if map_position >=640 and activeMap == 0: 106 | activeMap = 1 107 | map0 = create_map(20, 29) 108 | obstacles = updateObstacleGroup(map0, map1) 109 | if map_position >=1280 and activeMap == 1: 110 | activeMap = 0 111 | for ob in map0: 112 | ob.location[1] = ob.location[1] - 1280 113 | map_position = map_position - 1280 114 | map1 = create_map(10, 19) 115 | obstacles = updateObstacleGroup(map0, map1) 116 | 117 | for obstacle in obstacles: 118 | obstacle.scroll(map_position) 119 | 120 | hit = pygame.sprite.spritecollide(skier, obstacles, False) 121 | if hit: 122 | if hit[0].type == "tree" and not hit[0].passed: 123 | points = points - 100 124 | skier.image = pygame.image.load("./bg_img/skier_crash.png") 125 | animate() 126 | pygame.time.delay(1000) 127 | skier.image = pygame.image.load("./bg_img/skier_down.png") 128 | skier.angle = 0 129 | speed = [0, 6] 130 | hit[0].passed = True 131 | elif hit[0].type == "flag" and not hit[0].passed: 132 | points += 10 133 | obstacles.remove(hit[0]) 134 | 135 | score_text = font.render("Score: " +str(points), 1, (0, 0, 0)) 136 | animate() 137 | --------------------------------------------------------------------------------