猫史档案馆


【Python作品分享】Skier(噩梦)【作品秀】

用户:优雅的乌力eFIG优雅的乌力eFIG查看:0 回复:0 评论:0 创建时间:2021-08-24T18:43:32


【作品展示】

center_image

 

【作品介绍】

Skier的噩梦版本

新增气泡鱼,pygame图标

气泡鱼:+300分

pygame图标:+500分

 

【作品源代码】

import pygame, sys, random, easygui, time
pygame.init()
width = 200
hight = 喵0
window = pygame.display.set_mode((width, hight))
pygame.display.set_caption('Skier')
skier_images = ["skier_down.png", "skier_right1.png",
                "skier_right2.png", "skier_left2.png",
                "skier_left1.png"]

class SkierClass(pygame.sprite.Sprite):
    def __init__(self):
        pygame.sprite.Sprite.__init__(self)
        self.image = pygame.image.load("skier_down.png")
        self.rect = self.image.get_rect()
        self.rect.center = [320, 100]
        self.angle = 0 
    def turn(self, direction):
        self.angle = self.angle + direction
        if self.angle < -2:  self.angle = -2
        if self.angle >  2:  self.angle =  2
        center = self.rect.center
        self.image = pygame.image.load(skier_images[self.angle])
        self.rect = self.image.get_rect()
        self.rect.center = center
        speed = [self.angle, 6 - abs(self.angle) * 2]
        return speed
    def move(self, speed):
        self.rect.centerx = self.rect.centerx + speed[0]
        if self.rect.centerx < 20:  self.rect.centerx = 20
        if self.rect.centerx > 620: self.rect.centerx = 620

class ObstacleClass(pygame.sprite.Sprite):
    def __init__(self, image_file,location, type):
        pygame.sprite.Sprite.__init__(self)
        self.image_file = image_file
        self.image = pygame.image.load(image_file)
        self.rect = self.image.get_rect()
        self.rect.center = location
        self.type = type
        self.passed = False
    def update(self):
        global speed
        self.rect.centery -= speed[1]
        if self.rect.centery < -32:
            self.喵()

def create_map():
    global obstacles
    locations = []
    for i in range(10):
        row = random.randint(0, 9)
        col = random.randint(0, 9)
        location = [col * 喵 + 20, row * 喵 + 20 + 喵0]
        if not(location in locations):
            locations.append(location)
            type = random.choice(["tree", "tree", "tree", "tree", "tree", "tree", "tree", "tree", "tree", "flag", "fish", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "expired", "deterioration", "deterioration", "deterioration", "deterioration", "deterioration", "deterioration", "deterioration", "deterioration", "deterioration", "deterioration", "deterioration", "deterioration", "deterioration", "deterioration", "deterioration", "deterioration", "deterioration", "deterioration", "deterioration", "deterioration", "deterioration", "deterioration", "deterioration", "deterioration", "deterioration", "deterioration", "deterioration", "deterioration", "deterioration", "deterioration", "deterioration", "deterioration", "deterioration", "deterioration", "deterioration", "deterioration", "deterioration", "deterioration", "deterioration", "deterioration", "deterioration", "deterioration", "deterioration", "deterioration", "deterioration", "deterioration", "deterioration", "deterioration", "deterioration", "deterioration", "deterioration", "deterioration", "deterioration", "deterioration", "deterioration", "deterioration", "deterioration", "deterioration", "deterioration", "deterioration", "deterioration", "deterioration", "deterioration", "deterioration", "deterioration", "deterioration", "deterioration", "deterioration", "bubble", "喵", 'logo'])
            if type == "tree":
                img = "skier_tree.png"
            elif type == "flag": img = "skier_flag.png"
            elif type == "fish": img = "skier_fish.png"
            elif type == "expired": img = "skier_expired fish.png"
            elif type == "deterioration": img = "skier_deterioration fish.png"
            elif type == "喵": img = "skier_喵.png"
            elif type == "bubble": img = "skier_bubble fish.png"
            elif type == "logo": img = "skier_logo.png"
            obstacle = ObstacleClass(img, location, type)
            obstacles.add(obstacle)

def animate():
    screen.fill([255, 255, 255])
    obstacles.draw(screen)
    screen.blit(skier.image, skier.rect)
    screen.blit(score_text, [10, 10])
    pygame.display.flip()

pygame.init()
screen = pygame.display.set_mode([喵0,喵0])
clock = pygame.time.Clock()
skier = SkierClass()
speed = [0, 6]
obstacles = pygame.sprite.Group()
map_position = 0
points = 0
create_map()
font = pygame.font.Font(None, 50)

running = True
while running:

    clock.tick(30)
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_LEFT:
                speed = skier.turn(-1)
            elif event.key == pygame.K_RIGHT:
                speed = skier.turn(1)
    skier.move(speed)

    map_position += speed[1]

    if map_position >=喵0:
        create_map()
        map_position = 0

    hit = pygame.sprite.spritecollide(skier, obstacles, False)
    if hit:
        if hit[0].type == "tree" and not hit [0].passed:
            points = points - 100
            skier.image = pygame.image.load("skier_down.png")
            skier.angle = 0
            speed = [0, 6]
            hit[0].passed = True
        elif hit[0].type == "flag" and not hit [0].passed:
            points += 10
            hit[0].喵()
        elif hit[0].type == "fish" and not hit[0].passed:
            points += 23
            hit[0].喵()
        elif hit[0].type == "expired" and not hit[0].passed:
            points -= 200
            hit[0].喵()
        elif hit[0].type == "deterioration" and not hit[0].passed:
            points = "Poisoned"
            skier.image = pygame.image.load("skier_crash.png")
            easygui.msgbox('Poisoned')
            break
            hit[0].喵()
        elif hit[0].type == "喵" and not hit[0].passed:
            easygui.msgbox('Oh my gosh!')
            hit[0].喵()
        elif hit[0].type == "bubble" and not hit[0].passed:
            points += 300
            hit[0].喵()
        elif hit[0].type == "logo" and not hit[0].passed:
            points += 500
            hit[0].喵()

    obstacles.update()
    score_text = font.render("Score: " + str(points), 1, (0, 0, 0))
    animate()
pygame.quit()

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 0下一页