最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

使用Python實現(xiàn)一個蔡徐坤大戰(zhàn)籃球的小游戲(推薦)

 更新時間:2022年12月08日 14:02:53   作者:輕松學(xué)Python  
這篇文章主要介紹了用Python實現(xiàn)一個蔡徐坤大戰(zhàn)籃球的小游戲,本文通過示例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下

序言

話說在前面,我不是小黑子~

我是超級大黑子??

表弟大周末的跑來我家,沒事干天天騷擾我,搞得我都不能跟小姐姐好好聊天了,于是為了打發(fā)表弟,我決定用Python做一個小游戲來消耗一下他的精力,我思來想去,決定把他變成小黑子,于是做了一個坤坤打籃球的游戲,沒想到他還挺愛玩的~

終于解放了,于是我把游戲?qū)懴聛恚步o大家分享一下吧~

好吧,其實并不是這樣的游戲,往下慢慢看吧。

準(zhǔn)備工作

開發(fā)環(huán)境

Python版本:3.7.8

相關(guān)模塊:
requests模塊;
tqdm模塊;
pyfreeproxy模塊;
pyecharts模塊;
以及一些python自帶的模塊。

效果預(yù)覽

開始界面

游戲規(guī)則

wasd 控制人物的移動,空格啟動律師函炸毀全部籃球。

結(jié)束游戲

兄弟們學(xué)習(xí)python,有時候不知道怎么學(xué),從哪里開始學(xué)。掌握了基本的一些語法或者做了兩個案例后,不知道下一步怎么走,不知道如何去學(xué)習(xí)更加高深的知識。
那么對于這些大兄弟們,我準(zhǔn)備了大量的免費(fèi)視頻教程,PDF電子書籍,以及源代碼!直接在文末名片自取即可!

代碼實現(xiàn)

導(dǎo)入模塊

import pygame
import sys
import traceback
import os
import CXK
import enemy
import bullet
import supply
from pygame.locals import *
from random import *

游戲主界面

#游戲主界面
def ui():
    #循環(huán)播放背景音樂
    pygame.mixer.music.play(-1)

    #初始化界面按鍵圖片并獲取圖片的矩形位置
    start_game_image = pygame.image.load("images/start_game.png").convert_alpha()
    start_game_image_rect = start_game_image.get_rect()
    game_rules_image = pygame.image.load("images/game_rules.png").convert_alpha()
    game_rules_image_rect = game_rules_image.get_rect()
    game_quit_image = pygame.image.load("images/game_quit.png").convert_alpha()
    game_quit_image_rect = game_quit_image.get_rect()

    #初始化游戲規(guī)則圖片并獲取圖片的矩形位置
    rules_image = pygame.image.load("images/游戲玩法.png").convert_alpha()
    back_image = pygame.image.load("images/back.png").convert_alpha()
    back_image_rect =  back_image.get_rect()

    #標(biāo)志是否在主界面
    is_ui = True

    #幀率
    clock = pygame.time.Clock()

    #主界面循環(huán)
    while True:
        #獲取事件信息
        for event in pygame.event.get():
            #如果點(diǎn)擊右上角退出
            if event.type == QUIT:
                #退出程序
                pygame.quit()
                sys.exit()

        #如果是主界面
        if is_ui:
            #繪制背景
            screen.blit(background,(0,0))

            #更改主界面按鍵圖片的矩形位置并繪制主界面按鍵
            start_game_image_rect.left,start_game_image_rect.top = (width - start_game_image_rect.width)//2,height - 500
            screen.blit(start_game_image,start_game_image_rect)

            game_rules_image_rect = game_rules_image.get_rect()
            game_rules_image_rect.left,game_rules_image_rect.top = (width - game_rules_image_rect.width)//2,start_game_image_rect.bottom+50
            screen.blit(game_rules_image,game_rules_image_rect)

            game_quit_image_rect.left,game_quit_image_rect.top = (width - game_quit_image_rect.width)//2, game_rules_image_rect.bottom+50
            screen.blit(game_quit_image,game_quit_image_rect)

            #檢測用戶的鼠標(biāo)操作
            #如果用戶按下鼠標(biāo)左鍵
            if pygame.mouse.get_pressed()[0]:
                #獲取鼠標(biāo)坐標(biāo)
                pos = pygame.mouse.get_pos()
                #如果用戶點(diǎn)擊”開始游戲“
                if start_game_image_rect.left < pos[0] < start_game_image_rect.right and start_game_image_rect.top < pos[1] < start_game_image_rect.bottom:
                    #調(diào)用主函數(shù)
                    main()
                #如果用戶點(diǎn)擊”退出游戲“
                if game_quit_image_rect.left < pos[0] < game_quit_image_rect.right and game_quit_image_rect.top < pos[1] < game_quit_image_rect.bottom:
                    pygame.quit()
                    sys.exit()
                #如果用戶點(diǎn)擊”游戲規(guī)則“
                if game_rules_image_rect.left < pos[0] < game_rules_image_rect.right and game_rules_image_rect.top < pos[1] < game_rules_image_rect.bottom:
                    #離開主界面
                    is_ui = False

到此這篇關(guān)于用Python實現(xiàn)一個蔡徐坤大戰(zhàn)籃球的小游戲的文章就介紹到這了,更多相關(guān)Python蔡徐坤大戰(zhàn)籃球的小游戲內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論

延安市| 广宁县| 沧州市| 仪陇县| 辰溪县| 岱山县| 邵阳县| 南昌市| 玛纳斯县| 巫山县| 梁河县| 正镶白旗| 信宜市| 改则县| 灌南县| 芦山县| 宣恩县| 靖边县| 晋州市| 长子县| 东阿县| 三都| 宜昌市| 保亭| 济阳县| 绵竹市| 郸城县| 兴安县| 勐海县| 中卫市| 杂多县| 旬阳县| 曲阜市| 郧西县| 闸北区| 忻州市| 浪卡子县| 宜都市| 通河县| 扶余县| 青州市|