話說在前面,我不是小黑子~
我是超級大黑子??
表弟大周末的跑來我家,沒事干天天騷擾我,搞得我都不能跟小姐姐好好聊天了,于是為了打發表弟,我決定用Python做一個小游戲來消耗一下他的精力,我思來想去,決定把他變成小黑子,于是做了一個坤坤打籃球的游戲,沒想到他還挺愛玩的~
終于解放了,于是我把游戲寫下來,也給大家分享一下吧~

好吧,其實并不是這樣的游戲,往下慢慢看吧,
準備作業
開發環境
Python版本:3.7.8
相關模塊:
requests模塊;
tqdm模塊;
pyfreeproxy模塊;
pyecharts模塊;
以及一些python自帶的模塊,
效果預覽
開始界面

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


結束游戲

代碼實作
匯入模塊
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(): #回圈播放背景音樂 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() #初始化游戲規則圖片并獲取圖片的矩形位置 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() #標志是否在主界面 is_ui = True #幀率 clock = pygame.time.Clock() #主界面回圈 while True: #獲取事件資訊 for event in pygame.event.get(): #如果點擊右上角退出 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) #檢測用戶的滑鼠操作 #如果用戶按下滑鼠左鍵 if pygame.mouse.get_pressed()[0]: #獲取滑鼠坐標 pos = pygame.mouse.get_pos() #如果用戶點擊”開始游戲“ 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: #呼叫主函式 main() #如果用戶點擊”退出游戲“ 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() #如果用戶點擊”游戲規則“ 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 # 代碼有點多,就沒有全部粘貼出來,直接在這個君羊708525271領取就好了
代碼有點多,就沒有全部粘貼出來,可以在文末名片自取哈~

轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/538803.html
標籤:Python
上一篇:Python中5大模塊的使用教程(collections模塊、time時間模塊、random模塊、os模塊、sys模塊)
