国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

外星人入侵游戲-(創(chuàng)新版)

這篇具有很好參考價(jià)值的文章主要介紹了外星人入侵游戲-(創(chuàng)新版)。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

??write in front??
??大家好,我是Aileen??.希望你看完之后,能對(duì)你有所幫助,不足請(qǐng)指正!共同學(xué)習(xí)交流.
??本文由Aileen_0v0?? 原創(chuàng) CSDN首發(fā)?? 如需轉(zhuǎn)載還請(qǐng)通知??
??個(gè)人主頁:Aileen_0v0??—CSDN博客
??歡迎各位→點(diǎn)贊?? + 收藏?? + 留言???
??系列專欄:Aileen_0v0??的PYTHON學(xué)習(xí)系列專欄——CSDN博客
??我的格言:"沒有羅馬,那就自己創(chuàng)造羅馬~"?

外星人入侵游戲-(創(chuàng)新版),python,游戲,pygame,學(xué)習(xí),算法,開發(fā)語言,windows

目錄

首先,在python上 安裝pygame

然后,創(chuàng)建文件夾?要注意分級(jí)別?

?插入的圖片

主函數(shù) Aileen_invasion的文件

創(chuàng)建外星人aileen的文件

子彈bullet的文件

按鈕button的文件

?游戲數(shù)據(jù)game_stats的文件

游戲分?jǐn)?shù)scoreboard的文件

游戲設(shè)置settings的文件?

游戲飛船ship的文件

?編輯?全屏模式下的游戲

?編輯

小窗口下的游戲


首先,在python上 安裝pygame

資源--->https://download.csdn.net/download/Aileenvov/88301424?spm=1001.2014.3001.5503

然后轉(zhuǎn)到228頁,根據(jù)步驟進(jìn)行安裝

然后,創(chuàng)建文件夾?要注意分級(jí)別

?插入的圖片

插入圖片:需要注意圖片的大小比例,否則可能顯示不出來,這需要根據(jù)系統(tǒng)屏幕大小進(jìn)行設(shè)置,

將所需要的圖片和音樂拖到對(duì)應(yīng)的文件夾,這是我的圖片

外星人入侵游戲-(創(chuàng)新版),python,游戲,pygame,學(xué)習(xí),算法,開發(fā)語言,windows

外星人入侵游戲-(創(chuàng)新版),python,游戲,pygame,學(xué)習(xí),算法,開發(fā)語言,windows外星人入侵游戲-(創(chuàng)新版),python,游戲,pygame,學(xué)習(xí),算法,開發(fā)語言,windows外星人入侵游戲-(創(chuàng)新版),python,游戲,pygame,學(xué)習(xí),算法,開發(fā)語言,windows外星人入侵游戲-(創(chuàng)新版),python,游戲,pygame,學(xué)習(xí),算法,開發(fā)語言,windows外星人入侵游戲-(創(chuàng)新版),python,游戲,pygame,學(xué)習(xí),算法,開發(fā)語言,windows

主函數(shù) Aileen_invasion的文件

import sys
from time import sleep
import pygame
from settings import Settings
from game_starts import GameStats
from scoreboard import Scoreboard
from button import Button
from ship import Ship
from bullet import Bullet
from aileen import Aileen
class AileenInvasion:
    """Overall class to manage game assets and behavior.整體類來管理游戲資產(chǎn)和行為"""
    def __init__(self):#初始化
        """Initialize the game, and create game resources."""
        pygame.init()
        self.settings = Settings()
        self.screen = pygame.display.set_mode((0,0),pygame.FULLSCREEN)
        self.settings.screen_width = self.screen.get_rect().width
        self.settings.screen_height = self.screen.get_rect().height
        # self.screen = pygame.display.set_mode(
        #     (self.settings.screen_width,self.settings.screen_height))
        #類中變量前有self,說明該變量綁定在當(dāng)前實(shí)例化本身
        pygame.display.set_caption("Aileen Invasion")
        # Creation an instance to store game statistics.
        self.stats = GameStats(self)
        # Create an instance to store game statics,
        # and create a scoreboard.
        self.sb = Scoreboard(self)
        self.ship = Ship(self)
        self.bullets = pygame.sprite.Group()#Group可以批量使用的函數(shù)
        self.aileens = pygame.sprite.Group()
        self._create_fleet()
        #Make the play button.
        self.play_button = Button(self,"Play")
        self.bg_color =(0,0,225)  #代表紅 綠 藍(lán) 三顏色
    # def _create_fleet(self):
    #     """Create the fleet of aileens."""
    #     #Make a aileen
    #     aileen = Aileen(self)
    #     self.aileens.add(aileen)
    #     #set the background color.

    def run_game(self): #功能:1監(jiān)聽事件,2處理事件,3更新屏幕事件
        """Start the main loop for the game."""
        while True:
            # 1監(jiān)聽事件函數(shù)--監(jiān)聽和處理用戶的行為
            self._check_events()#將監(jiān)聽事件(封裝)外包給這個(gè)函數(shù),減輕run_game的工作量---這個(gè)過程叫重構(gòu)(refactory)
            if self.stats.game_active:
                # 2處理事件函數(shù)
                self.ship.update()
                #更新子彈
                self._update_bullets()
                self._update_aileens()
            # 3 屏幕更新函數(shù)
            self._update_screen()

    def _update_bullets(self):
            self.bullets.update()
            if not self.aileens:
            # Destory existing  bullets and create new fleet
                self.bullets.empty()
                self._create_fleet()

            # Get rid of the bullets that have disappeared.
            for bullet in self.bullets.copy():
                if bullet.rect.bottom <= 0:
                    self.bullets.remove(bullet)
            self._check_bullet_aileen_collisions()

    def _check_bullet_aileen_collisions(self):
        """Respond to bullet-aileen collisions."""
        """ Remove any bullets and aileens that have collided  """
        #??
        collisions = pygame.sprite.groupcollide(
            self.bullets, self.aileens,True,True)

        if collisions:  #collision是字典類型變量
            # for aileens in collisions.values():
            self.stats.score += self.settings.aileen_points  #* len(aileens)
            for aileens in collisions.values():
                self.stats.score += self.settings.aileen_points * len(aileens)
            self.sb.prep_score()
            self.sb.check_high_score()
            self.sb.prep_high_score()
        if not self.aileens:
                # Destory existing bullets and create new fleet.
                self.bullets.empty()
                self._create_fleet()
                self.settings.increase_speed()

                # Increase level
                self.stats.level += 1
                self.sb.prep_level()
            # print(len(self.bullets))

            # Watch for keyboard and mouse events.  監(jiān)聽用戶在做什么操作--這里設(shè)置游戲菜單欄
    def _check_events(self): #
        #--snip--
        """Respond to keypress and mouse events"""
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()
            elif event.type == pygame.KEYDOWN:
                self._check_keydown_events(event)
            elif event.type == pygame.KEYUP:
                self._check_keyup_events(event)
            elif event.type == pygame.MOUSEBUTTONDOWN:
                mouse_pos = pygame.mouse.get_pos()
                self._check_play_button(mouse_pos)

    def _check_play_button(self,mouse_pos):
        """Start a new game when the player clicks Play."""
        button_clicked = self.play_button.rect.collidepoint(mouse_pos)
        if button_clicked and not self.stats.game_active:
            # Hide the mouse cursor.
            pygame.mouse.set_visible(False)
            # Reset the game statistics.
            self.stats.reset_stats()
            self.stats.game_active = True
            # 確保分?jǐn)?shù)清0
            self.sb.prep_score()
            self.sb.prep_level()
            self.sb.prep_ships()
            # Get rid of any remaining aileens and bullets.
            self.aileens.empty()
            self.bullets.empty()
            #Create  A new fleet and center the ship.
            self._create_fleet()
            self.ship.center_ship()
            #Reset the game settings.
            self.settings.initialize_dynamic_settings()

            pygame.mixer.init()
            pygame.mixer.music.load("music/香香 - 豬之歌.mp3")
            # pygame.mixer.music.set_volume(2)
            pygame.mixer.music.play()

    def _check_keydown_events(self,event):
        """Respond to keypress"""
                #判斷右鍵
        if event.key == pygame.K_RIGHT:
                    #處理右鍵
            self.ship.moving_right = True
        elif event.key == pygame.K_LEFT:
            self.ship.moving_left = True
        elif event.key == pygame.K_UP:
            self.ship.moving_up = True
        elif event.key == pygame.K_DOWN:
            self.ship.moving_down = True
        elif event.key == pygame.K_q:#按q鍵退出游戲
            sys.exit()
        elif event.key == pygame.K_SPACE:
            self._fire_bullet()


    def _check_keyup_events(self,event):
        """Respond to key release."""
        if event.key == pygame.K_RIGHT:
            self.ship.moving_right = False

        elif event.key == pygame.K_LEFT:
            self.ship.moving_left = False
                     # Move the ship to the right.
            self.ship.rect.x += 1

        elif event.key == pygame.K_m:
            self.screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
            self.settings.screen_width =self.screen.get_rect().width
            self.settings.screen_height = self.screen.get_rect().height
            self.ship = Ship(self)
            self.aliens = pygame.sprite.Group()
            self._create_fleet()
        elif event.key == pygame.K_n:
            self.settings = Settings()
            self.screen = pygame.display.set_mode((self.settings.screen_width, self.settings.screen_height))
            self.ship = Ship(self)
            self.aliens = pygame.sprite.Group()
            self._create_fleet()
        elif event.key == pygame.K_UP:
            self.ship.moving_up = False
        elif event.key == pygame.K_DOWN:
            self.ship.moving_down = False

    def _fire_bullet(self):
        """create a new bullet and add it to the bullets group."""
        if len(self.bullets) < self.settings.bullets_allowed:
            new_bullet = Bullet(self)
            self.bullets.add(new_bullet)

    def _create_fleet(self):#self傳的也是ai
        """Create the fleet of aileens."""
        #Create an aileen  and find the number of aileens in a row
        #Spacing between each aileen is equal to one aileen width.
        aileen = Aileen(self)
        aileen_width, aileen_height  = aileen.rect.size
        available_space_x = self.settings.screen_width - (2 * aileen_width)
        print(available_space_x)
        print(self.settings.screen_width)
        print(2 * aileen_width)
        number_aileen_x = available_space_x // (2 * aileen_width)
        # Determine the number of rows of aileens that fit on the screen.
        ship_height =self.ship.rect.height
        available_space_y = (self.settings.screen_height -
                             (3 * aileen_height) - ship_height)
        number_rows = available_space_y // (2 * aileen_height)
        #Create the first row of aileens.
        for row_number in range(number_rows):
            for aileen_number in range(number_aileen_x):
                self._create_aileen(aileen_number, row_number)

    def _create_aileen(self,aileen_number, row_number):
            # Create an aileen and place it in row.
            # Make a aileen
            aileen = Aileen(self)
            aileen_width, aileen_height =aileen.rect.size
            aileen.x = aileen_width + 2 * aileen_width * aileen_number
            aileen.rect.x = aileen.x
            aileen.rect.y = aileen.rect.height + 2 * aileen.rect.height * row_number
            self.aileens.add(aileen)

    def _check_aileens_bottom(self):
        """Check if any aileens have reached the bottom of the screen."""
        screen_rect = self.screen.get_rect()
        for aileen in self.aileens.sprites():
            if aileen.rect.bottom >= screen_rect.bottom:
                #Treat this the same as if the ship got hit.
                self._ship_hit()
                break

             # Redraw the screen during each  pass through the loop.  更新畫布顏色
    def _update_aileens(self):
        """
        Check if the fleet is at an edge,
        then update the positions of all aliens in the fleet.
        """
        self._check_fleet_edges()
        """Update the positions of all aileens in the fleet."""
        self.aileens.update()

        # Look for aileen-ship collisions.
        if pygame.sprite.spritecollideany(self.ship, self.aileens):
            self._ship_hit()
            print("Ship hit!!!")

        # Look for aileens hitting the bottom of the screen
        self._check_aileens_bottom()

    def _check_fleet_edges(self):
        """Respond appropriately if any aileens have reached an edge."""
        for aileen in self.aileens.sprites():
            if aileen.check_edges():
                self._change_fleet_direction()
                break

    def _change_fleet_direction(self):
        """Drop the entire fleet and change the fleet's direction."""
        for aileen in self.aileens.sprites():
            aileen.rect.y += self.settings.fleet_drop_speed
        self.settings.fleet_direction *= -1

    def _ship_hit(self):
        """Respond to the ship being hit by an allien"""
        if self.stats.ships_left > 0:
            # Decrement ships_left.and update scoreboard
            self.stats.ships_left -= 1
            self.sb.prep_ships()
         # Get rid of any remaining aileens and bullets.
            self.aileens.empty()
            self.bullets.empty()
        # Create a new fleet and center the ship.
            self._create_fleet()
            self.ship.center_ship()
            # Pause
            sleep(0.5)
        else:
            self.stats.game_active = False
            pygame.mouse.set_visible(True)

    def _update_screen(self):
        """Update images on the screen , and flip to the new screen"""
        self.screen.fill(self.settings.bg_color)
        self.ship.blitme()
        for bullet in self.bullets.sprites():
            bullet.draw_bullet()
        self.aileens.draw(self.screen)
        #Draw the score information.
        self.sb.show_score()

        # Draw the play button if the games is inactive.
        if not self.stats.game_active:
            self.play_button.draw_button()
        self.bullets.draw(self.screen)

        pygame.display.flip()

    def check_high_score(self):
        """Check to see if there's a new high score."""
        if self.stats.score > self.stats.high_score:
            self.stats.high_score = self.stats.score
            self.prep_high_score()

if __name__ == '__main__':
        #  Make a game instance , and run the game.
    ai = AileenInvasion()#游戲本身的實(shí)例化,ai就是那個(gè)AileenInvasion
    ai.run_game()

創(chuàng)建外星人aileen的文件

import pygame
from pygame.sprite import Sprite

class Aileen(Sprite):
    """A class to represent a single alien in the fleet"""

    def __init__(self,ai_game):
        """Initilize the aileen and set its starting position."""
        super().__init__()
        self.screen = ai_game.screen
        self.settings = ai_game.settings

        # Load the aileen image and set its rect attribute.
        self.image = pygame.image.load("images/aileen.png")
        self.rect = self.image.get_rect()

        # Start each new aileen near the top left of the screen.
        self.rect.x = self.rect.width#將矩形左上角的值作為外星人的寬度
        self.rect.y = self.rect.height
        #通過飛船左上角的坐標(biāo)來控制其它圖片的位置
        #Store the aileen's exact horizontal position.
        self.x = float(self.rect.x)

    def check_edges(self):
        """Return True if aileen is at edge of screen"""
        screen_rect = self.screen.get_rect()
        if self.rect.right >= screen_rect.right or self.rect.left <= 0:
            return True

    def update(self):
        """Move the aileen to the right or left"""
        self.x += (self.settings.aileen_speed *
                        self.settings.fleet_direction)
        self.rect.x = self.x

子彈bullet的文件

import pygame
import random
from pygame.sprite import Sprite

class Bullet(Sprite):#子彈bullet繼承Sprite類--繼承
    """A class to manage bullets fired from the ship"""

    def __init__(self,ai_game):
        """Create a bullet object at the ship's current position"""
        super().__init__()#調(diào)用父類初始化函數(shù)
        self.screen = ai_game.screen
        self.settings = ai_game.settings
        self.color = self.settings.bullet_color
        # Load the aileen image and set its rect attribute.
        self.bullet_images = [pygame.image.load("images/heart.png"),pygame.image.load("images/banana.png"),pygame.image.load("images/cherry.png")]
        self.image = random.choice(self.bullet_images)
        self.rect = self.image.get_rect()
        #Create a bullet rect at(0,0) and then set correct position.
        self.rect =pygame.Rect(0,0,self.settings.bullet_width,
            self.settings.bullet_height)
        self.rect.midtop =ai_game.ship.rect.midtop#利用ai將船和子彈初始位置綁定,使得子彈在船中上方

        # Store the bullet's position as a decimal value.
        self.y = float(self.rect.y)

    def update(self):
        """move the bullet up the screen."""
        #update the decimal position of the bullet.
        self.y -= self.settings.bullet_speed
        #update the rect position.
        self.rect.y = self.y

    def draw_bullet(self):
        """draw the bullet to the screen"""
        self.screen.blit(self.image,self.rect)
        pygame.draw.rect(self.screen, self.color, self.rect)

按鈕button的文件

import  pygame.font

class Button:
    def __init__(self,ai_game,msg):
        """Initialize button attributes."""
        self.screen = ai_game.screen
        self.screen_rect = self.screen.get_rect()
        # Set the dimensions and properties(財(cái)產(chǎn),屬性==attributes) of the button
        self.width, self.height = 200, 50
        self.button_color = (0, 255, 0)
        self.text_color = (255,255,255)
        self.font = pygame.font.SysFont(None, 48)
        # Build the button's rect object and center it.
        self.rect = pygame.Rect(0,0,self.width,self.height)
        self.rect.center = self.screen_rect.center
        # The button message needs to be prepped(準(zhǔn)備) only once.
        self._prep_msg(msg)

    def _prep_msg(self,msg):
        """Turn msg into a rendered image and center and center text on the button."""
        self.msg_image = self.font.render(msg,True, self.text_color,
                                          self.button_color)
        self.msg_image_rect = self.msg_image.get_rect()
        self.msg_image_rect.center = self.rect.center

    def draw_button(self):
        # Draw blank button and then draw message.
        self.screen.fill(self.button_color,self.rect)
        self.screen.blit(self.msg_image,self.msg_image_rect)

?游戲數(shù)據(jù)game_stats的文件

class GameStats:
    """Track statics for Aileen Invasion."""
    def __init__(self,ai_game):
        # High score should never be reset.
        self.high_score = 0
        # Start Aileen Invasion in an active state.
        self.game_active = True
        """Initiallize statistics."""
        self.settings = ai_game.settings
        self.reset_stats()
        # Start game in an inactive state.
        self.game_active = False

    def reset_stats(self):
        """Initialize statistics that can change during the game."""
        self.ships_left = self.settings.ship_limit
        self.score = 0
        self.level=1

游戲分?jǐn)?shù)scoreboard的文件

import pygame.font
from pygame.sprite import Group
from ship import Ship

class Scoreboard:
    """A class to report scoring information."""

    def __init__(self,ai_game):
        """Initialize scorekeeping attributes."""
        self.ai_game = ai_game
        self.screen = ai_game.screen
        self.screen_rect = self.screen.get_rect()
        self.settings = ai_game.settings
        self.stats = ai_game.stats
        # Font settings for scoring information.
        self.text_color = (30,30,30)
        self.font = pygame.font.SysFont(None,48)
        #Prepare the initial score image.
        self.prep_score()
        self.prep_high_score()
        self.prep_level()
        self.prep_ships()

    def prep_ships(self):
        """Show how many ships are left."""
        self.ships = Group ()
        for ship_number in range(self.stats.ships_left):
            ship= Ship(self.ai_game)
            ship.rect.x = 10 + ship_number * ship.rect.width
            ship.rect.y = 10
            self.ships.add(ship)

    def prep_score(self):
        """Turn the score into a rendered image (將分?jǐn)?shù)轉(zhuǎn)換為渲染圖像)"""
        score_str = str(self.stats.score)
        """Turn the score into a rendered image."""
        rounded_score = round(self.stats.score,-1)
        score_str = "{:,}".format(rounded_score)  #round 取整
        self.score_image = self.font.render(score_str,True,
                    self.text_color,self.settings.bg_color)

        #Display the score at the top right of the screen.
        self.score_rect = self.score_image.get_rect()
        self.score_rect.right = self.screen_rect.right - 20
        self.score_rect.top = 20

    def prep_high_score(self):
        """Turn the high score into a rendered image"""
        high_score = round(self.stats.high_score,-1)
        high_score_str = "{:,}".format(high_score)
        self.high_score_image = self.font.render(high_score_str,True,
                                self.text_color,self.settings.bg_color)

    # Center the high score at the top of the screen.
        self.high_score_rect = self.high_score_image.get_rect()
        self.high_score_rect.centerx = self.screen_rect.centerx
        self.high_score_rect.top = self.score_rect.top

    def check_high_score(self):
        """Check to see if there's a new high score."""
        if self.stats.score > self.stats.high_score:
            self.stats.high_score = self.stats.score
            self.prep_high_score()

    def prep_level(self):
        """Turn the level into a rendered image."""
        level_str = str(self.stats.level)
        self.level_image = self.font.render(level_str,True,
                                            self.text_color,self.settings.bg_color)

        #Position the level below the score.
        self.level_rect = self.level_image.get_rect()
        self.level_rect.right = self.score_rect.right
        self.level_rect.top = self.score_rect.bottom + 10

    def show_score(self):
        """Draw score,level,and ships to the screen"""
        self.screen.blit(self.score_image,self.score_rect)
        self.screen.blit(self.high_score_image,self.high_score_rect)
        self.screen.blit(self.level_image,self.level_rect)
        self.ships.draw(self.screen)

游戲設(shè)置settings的文件?

class Settings:
    """A class store all settings for Aileen Invasion."""

    def __init__(self):
        """Initialize the game'settings """
        #Ship settings
        self.ship_speed = 1.5
        self.ship_limit = 3
        # Screen settings
        self.screen_width =1200
        self.screen_height=800
        self.bg_color =(255,255,255)

        # Bullet settings
        self.bullet_speed = 1
        self.bullet_width = 3
        self.bullet_height = 15
        self.bullet_color = (60,60,60)
        self.bullets_allowed = 3

        #Aileen settings
        self.aileen_speed = 1.0
        self.fleet_drop_speed = 10

        # How quickly the game speeds up
        self.speedup_scale = 2

        # How quickly the aileen point values increase
        self.score_scale =1.5
        self.initialize_dynamic_settings()

    def initialize_dynamic_settings(self):
        """Initialize speed settings"""
        self.ship_speed = 1.5
        self.bullet_speed = 1.5
        self.aileen_speed = 10
        # Scoring
        self.aileen_points =50

    # fleet_direction of 1 represents right ; -1 represents left.
        self.fleet_direction = 1

    def increase_speed(self):
        """Increase speed settings"""
        """Increase speed settings and aileen point values"""
        self.ship_speed *= self.speedup_scale
        self.bullet_speed *= self.speedup_scale
        self.aileen_speed *= self.speedup_scale
        self.aileen_points = int(self.aileen_points * self.score_scale)
        print(self.aileen_points)

游戲飛船ship的文件

import  pygame
from pygame.sprite import Sprite

class Ship(Sprite):
    """A class to manage the ship."""

    def __init__(self,ai_game):
        """Initialize the ship and set its starting position."""
        super().__init__()
        self.screen = ai_game.screen
        self.settings = ai_game.settings
        self.screen_rect = ai_game.screen.get_rect()#返回窗口矩形

        # Load the ship image and get its rect.
        self.image = pygame.image.load("images/ship.png")
        self.rect=self.image.get_rect()#取得屏幕的矩形 rect=rectangle 拿到圖片矩形

        # Start each new ship at the bottom center of the screen.
        self.rect.midbottom = self.screen_rect.midbottom
        #通過賦值:圖片的中下方的坐標(biāo),等于屏幕中下方的坐標(biāo)

        # Store a decimal value for the ship's horizontal position.
        self.x = float(self.rect.x)
        self.y = float(self.rect.y)

        # Movement flag
        self.moving_right =False
        self.moving_left =False
        self.moving_up =False
        self.moving_down =False
    def center_ship(self):
        """Center the ship on the screen"""
        self.rect.midbottom = self.screen_rect.midbottom
        self.x = float(self.rect.x)
    def update(self):
        """Update the ship's position based on the movement flag"""
        # Update the ship's value, not the rect.
        # if self.moving_right:
        if self.moving_right and self.rect.right < self.screen_rect.right:
            self.x += self.settings.ship_speed#不斷增加飛船左上角的橫坐標(biāo)帶動(dòng)圖片移動(dòng)
            self.rect.x += 1
        # if self.moving_left:
        if self.moving_left and self.rect.left > 0:
            self.x -= self.settings.ship_speed
            self.rect.x -= 1
        #top
        if self.moving_up and self.rect.top > 720 :
            self.y -= self.settings.ship_speed
            self.rect.y -= 1

        if self.moving_down and self.rect.bottom < self.screen_rect.bottom:
            self.y += self.settings.ship_speed
            self.rect.y += 1

    def blitme(self):#渲染函數(shù),讓圖片顯示出來
        """Draw the ship at its current location."""
        self.screen.blit(self.image,self.rect)

?全屏模式下的游戲

外星人入侵游戲-(創(chuàng)新版),python,游戲,pygame,學(xué)習(xí),算法,開發(fā)語言,windows

小窗口下的游戲

??今天的打豬游戲就分享到這里啦~??

??喜歡就一鍵三連支持一下吧?~??

??謝謝家人們!??

外星人入侵游戲-(創(chuàng)新版),python,游戲,pygame,學(xué)習(xí),算法,開發(fā)語言,windows文章來源地址http://www.zghlxwxcb.cn/news/detail-716602.html

到了這里,關(guān)于外星人入侵游戲-(創(chuàng)新版)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • Python游戲開發(fā)--外星人入侵(源代碼)

    Python游戲開發(fā)--外星人入侵(源代碼)

    最近學(xué)習(xí)的python第一個(gè)項(xiàng)目實(shí)戰(zhàn),《外星人入侵》,成功實(shí)現(xiàn)所有功能,給大家提供源代碼 環(huán)境安裝:python 3.7+ pygame 安裝 pygame 或者 先展示效果,消滅外星人,有三條命,按Q是退出全屏,空格鍵是子彈,按下play鍵開始游戲,擊敗外星人飛船會(huì)有積分加,三條命之后需要點(diǎn)擊

    2024年02月06日
    瀏覽(96)
  • python項(xiàng)目分享 - python外星人入侵小游戲

    python項(xiàng)目分享 - python外星人入侵小游戲

    ?? Hi,各位同學(xué)好呀,這里是L學(xué)長! ??今天向大家分享一個(gè)今年(2022)最新完成的畢業(yè)設(shè)計(jì)項(xiàng)目作品 外星人入侵小游戲設(shè)計(jì)與實(shí)現(xiàn) ?? 學(xué)長根據(jù)實(shí)現(xiàn)的難度和等級(jí)對(duì)項(xiàng)目進(jìn)行評(píng)分(最低0分,滿分5分) 難度系數(shù):3分 工作量:3分 創(chuàng)新點(diǎn):4分 項(xiàng)目獲取: https://gitee.com/sinonfin/s

    2024年02月03日
    瀏覽(18)
  • python畢設(shè)分享 python外星人入侵小游戲

    python畢設(shè)分享 python外星人入侵小游戲

    ?? Hi,各位同學(xué)好呀,這里是L學(xué)長! ??今天向大家分享一個(gè)今年(2022)最新完成的畢業(yè)設(shè)計(jì)項(xiàng)目作品 外星人入侵小游戲設(shè)計(jì)與實(shí)現(xiàn) ?? 學(xué)長根據(jù)實(shí)現(xiàn)的難度和等級(jí)對(duì)項(xiàng)目進(jìn)行評(píng)分(最低0分,滿分5分) 難度系數(shù):3分 工作量:3分 創(chuàng)新點(diǎn):4分 項(xiàng)目獲?。?https://gitee.com/sinonfin/s

    2024年02月04日
    瀏覽(23)
  • python項(xiàng)目分享 外星人入侵小游戲設(shè)計(jì)與實(shí)現(xiàn) (源碼)

    python項(xiàng)目分享 外星人入侵小游戲設(shè)計(jì)與實(shí)現(xiàn) (源碼)

    ?? Hi,各位同學(xué)好呀,這里是L學(xué)長! ??今天向大家分享一個(gè)今年(2022)最新完成的畢業(yè)設(shè)計(jì)項(xiàng)目作品 外星人入侵小游戲設(shè)計(jì)與實(shí)現(xiàn) ?? 學(xué)長根據(jù)實(shí)現(xiàn)的難度和等級(jí)對(duì)項(xiàng)目進(jìn)行評(píng)分(最低0分,滿分5分) 難度系數(shù):3分 工作量:3分 創(chuàng)新點(diǎn):4分 項(xiàng)目獲?。?https://gitee.com/sinonfin/s

    2024年01月18日
    瀏覽(16)
  • python畢設(shè)分享 外星人入侵小游戲設(shè)計(jì)與實(shí)現(xiàn) (源碼)

    python畢設(shè)分享 外星人入侵小游戲設(shè)計(jì)與實(shí)現(xiàn) (源碼)

    ?? Hi,各位同學(xué)好呀,這里是L學(xué)長! ??今天向大家分享一個(gè)今年(2022)最新完成的畢業(yè)設(shè)計(jì)項(xiàng)目作品 外星人入侵小游戲設(shè)計(jì)與實(shí)現(xiàn) ?? 學(xué)長根據(jù)實(shí)現(xiàn)的難度和等級(jí)對(duì)項(xiàng)目進(jìn)行評(píng)分(最低0分,滿分5分) 難度系數(shù):3分 工作量:3分 創(chuàng)新點(diǎn):4分 項(xiàng)目獲?。?https://gitee.com/sinonfin/s

    2024年02月05日
    瀏覽(27)
  • python實(shí)戰(zhàn)【外星人入侵】游戲并改編為【梅西vsC羅】(球迷整活)——搭建環(huán)境、源碼、讀取最高分及生成可執(zhí)行的.exe文件

    python實(shí)戰(zhàn)【外星人入侵】游戲并改編為【梅西vsC羅】(球迷整活)——搭建環(huán)境、源碼、讀取最高分及生成可執(zhí)行的.exe文件

    本篇文章將介紹python游戲【外星人入侵】代碼的 環(huán)境安裝 , 具體介紹如何將游戲的最高分寫入文件并在下次啟動(dòng)時(shí)讀取、生成 .exe可執(zhí)行文件 、如何 趣味性的改變游戲 。游戲相關(guān)的所有源碼已經(jīng)在文章 游戲?qū)崿F(xiàn)———————游戲源碼 部分。 ??游戲介紹: 玩家控制著一

    2024年02月11日
    瀏覽(20)
  • Python Project- Alien_invasion(外星人入侵)

    Python Project- Alien_invasion(外星人入侵)

    目錄 武裝飛船 開始游戲項(xiàng)目 創(chuàng)建pygame窗口以及相應(yīng)用戶輸入 ? 初始化程序 ? 創(chuàng)建surface對(duì)象 ? 事件監(jiān)聽 ? 游戲循環(huán) 設(shè)置背景色 創(chuàng)建設(shè)置類 添加飛船圖像 創(chuàng)建ship類 pygame.image ? get_rect( ) ? surface.blit( ) 在屏幕上繪制飛船 重構(gòu):模塊game_functions 函數(shù) check_events( ) 函數(shù) update_

    2024年02月09日
    瀏覽(49)
  • python 外星人入侵FileNotFoundError: No file ‘player.gif‘ found in working directory

    python 外星人入侵FileNotFoundError: No file ‘player.gif‘ found in working directory

    將相對(duì)路徑改為絕對(duì)路徑即可 例如 D:/AlienInvasion/ship/player.gif/

    2024年02月13日
    瀏覽(19)
  • 宇宙物演進(jìn)程——外星人去哪了游戲代碼(Python實(shí)現(xiàn))(1)

    宇宙物演進(jìn)程——外星人去哪了游戲代碼(Python實(shí)現(xiàn))(1)

    import os import sys import cfg import random import pygame from modules import * # 開始游戲 def startGame(screen): clock = pygame.time.Clock() font = pygame.font.SysFont(‘a(chǎn)rial’, 18) if not os.path.isfile(‘score’): f = open(‘score’, ‘w’) f.write(‘0’) f.close() with open(‘score’, ‘r’) as f: highest_score = int(f.read().strip()

    2024年04月26日
    瀏覽(19)
  • 外星人鼠標(biāo)如何設(shè)置宏定義

    外星人鼠標(biāo)如何設(shè)置宏定義

    適用于Alienware Wired/Wireless Gaming Mouse | AW610M的支持 | 驅(qū)動(dòng)程序和下載 | Dell 中國 下載應(yīng)用程序 下載到默認(rèn)位置 安裝程序 ? 與正常安裝程序一樣, ? 安裝第二個(gè)程序俗稱cmcc 我英文不好,知道這個(gè)干嘛的 打開安裝程序 第一次要點(diǎn)上面FX按鈕 ? ?點(diǎn)擊宏 ?點(diǎn)擊+ 創(chuàng)建自己的宏,

    2024年02月16日
    瀏覽(27)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包