zoukankan      html  css  js  c++  java
  • underdoge.exe

     本来一个飞机大战的小游戏,被我换贴图+魔改变成了underdoge,算是致敬ut吧

    import math
    import random
    
    import pygame
    from pygame import mixer
    
    # Intialize the game
    pygame.init()
    
    # create the screen
    screen = pygame.display.set_mode((800, 600))
    
    # Background
    background = pygame.image.load(r'C:UsersASUSPicturesUplayuff doge.png')
    
    # Sound
    mixer.music.load(r'E:CloudMusicToby Fox - MEGALOVANIA.mp3')
    mixer.music.play(-1)
    
    # Caption and Icon
    pygame.display.set_caption("underdoge")
    icon = pygame.image.load(r'C:UsersASUSPicturesUplaydoge.png')
    pygame.display.set_icon(icon)
    
    # Sans
    playerImg = pygame.image.load(r'C:UsersASUSPicturesUplaysans.png')
    playerX = 370
    playerY = 480
    playerX_change = 0
    
    # Doge
    enemyImg = []
    enemyX = []
    enemyY = []
    enemyX_change = []
    enemyY_change = []
    num_of_enemies = 6
    
    for i in range(num_of_enemies):
        enemyImg.append(pygame.image.load(r'C:UsersASUSPicturesUplaydoge.png'))
        enemyX.append(random.randint(0, 736))
        enemyY.append(random.randint(50, 150))
        enemyX_change.append(4)
        enemyY_change.append(40)
    
    #Bone
    bulletImg = pygame.image.load(r'C:UsersASUSPicturesUplayone.png')
    bulletX = 0
    bulletY = 480
    bulletX_change = 0
    bulletY_change = 10
    bullet_state = "ready"
    
    # Love(Level Of Violence)
    
    score_value = 0
    font = pygame.font.Font('freesansbold.ttf', 32)
    
    textX = 10
    testY = 10
    
    # 这使你充满了决心
    over_font = pygame.font.Font('freesansbold.ttf', 64)
    
    
    def show_score(x, y):
        score = font.render("love : " + str(score_value), True, (255, 255, 255))
        screen.blit(score, (x, y))
    
    
    def game_over_text():
        over_text1 = over_font.render("You're filled with", True, (255, 255, 255))
        screen.blit(over_text1, (150, 100))
        over_text2 = over_font.render("DETERMINATION", True, (255, 255, 255))
        screen.blit(over_text2, (150, 250))
    
    
    def player(x, y):
        screen.blit(playerImg, (x, y))
    
    
    def enemy(x, y, i):
        screen.blit(enemyImg[i], (x, y))
    
    
    def fire_bullet(x, y):
        global bullet_state
        bullet_state = "fire"
        screen.blit(bulletImg, (x + 16, y + 10))
    
    
    def isCollision(enemyX, enemyY, bulletX, bulletY):
        distance = math.sqrt(math.pow(enemyX - bulletX, 2) + (math.pow(enemyY - bulletY, 2)))
        if distance < 27:
            return True
        else:
            return False
    
    
    # Game Loop
    running = True
    while running:
    
        # RGB = Red, Green, Blue
        screen.fill((0, 0, 0))
        # Background Image
        screen.blit(background, (220, 100))
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                running = False
    
            # if keystroke is pressed check whether its right or left
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_LEFT:
                    playerX_change = -5
                if event.key == pygame.K_RIGHT:
                    playerX_change = 5
                if event.key == pygame.K_SPACE:
                    if bullet_state is "ready":
                        bulletSound = mixer.Sound(r"E:CloudMusiclaser.wav")
                        bulletSound.set_volume(0.3)
                        bulletSound.play()
                        # Get the current x cordinate of the Doge
                        bulletX = playerX
                        fire_bullet(bulletX, bulletY)
    
            if event.type == pygame.KEYUP:
                if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT:
                    playerX_change = 0
    
        playerX += playerX_change
        if playerX <= 0:
            playerX = 0
        elif playerX >= 736:
            playerX = 736
    
        # Doge Movement
        for i in range(num_of_enemies):
    
            # 这使你充满了决心
            if enemyY[i] > 440:
                for j in range(num_of_enemies):
                    enemyY[j] = 2000
                game_over_text()
                break
    
            enemyX[i] += enemyX_change[i]
            if enemyX[i] <= 0:
                enemyX_change[i] = 2.5
                enemyY[i] += enemyY_change[i]
            elif enemyX[i] >= 736:
                enemyX_change[i] = -2.5
                enemyY[i] += enemyY_change[i]
    
            # Collision
            collision = isCollision(enemyX[i], enemyY[i], bulletX, bulletY)
            if collision:
                explosionSound = mixer.Sound(r"E:CloudMusicoom.wav")
                explosionSound.set_volume(1.0)
                explosionSound.play()
                bulletY = 480
                bullet_state = "ready"
                score_value += 1
                enemyX[i] = random.randint(0, 736)
                enemyY[i] = random.randint(50, 150)
    
            enemy(enemyX[i], enemyY[i], i)
    
        # Bone Movement
        if bulletY <= 0:
            bulletY = 480
            bullet_state = "ready"
    
        if bullet_state is "fire":
            fire_bullet(bulletX, bulletY)
            bulletY -= bulletY_change
    
        player(playerX, playerY)
        show_score(textX, testY)
        pygame.display.update()
  • 相关阅读:
    Java MQTT 客户端之 Paho
    Spring Security + JJWT 实现 JWT 认证和授权
    MinIO
    Spring Boot 实现看门狗功能 (调用 Shell 脚本)
    Canal Admin
    canal
    浅尝 Elastic Stack (五) Logstash + Beats + Kafka
    养鸡场下蛋记
    涛声依旧
    原创:矩阵论学习心得
  • 原文地址:https://www.cnblogs.com/xxxsans/p/13442750.html
Copyright © 2011-2022 走看看