pygame 遊戲舞台搭建典型應用

2022-08-27 07:09:12 字數 1281 閱讀 4183

#兩個檔案要放在同一目錄中,包括

一、搭建遊戲舞台主程式

#!/usr/bin/env python3

#_*_coding:utf-8_*_ author ==$ vacyp

import sys

import pygame

from girl import girl

def build_pygwindows():

pygame.init()

screen =pygame.display.set_mode((1920,1080))                       #這裡可視螢幕大小修改windows 視窗大小

pygame.display.set_caption("pygame_playing_windows")

bg_color =(0,0,235)

girl = girl(screen)

while true:

for event in pygame.event.get():

if event.type ==pygame.quit:

sys.exit()

screen.fill(bg_color)

girl.blitme()

pygame.display.flip()

build_pygwindows()

二、建立第乙個角色

#!/sur/bin/env python3

#_*_ coding:utf-8 _*_ author == $vacyp

import pygame

class girl():

def __init__(self,screen):

self.screen =screen

self.image = pygame.image.load('horngirl.png')

self.rect = self.image.get_rect()

self.screen_rect = screen.get_rect()

self.rect.centerx =self.screen_rect.centerx

self.rect.centery =self.screen_rect.centery

def blitme(self):

self.screen.blit(self.image,self.rect)

三、舞台和角色(如下圖)

pygame遊戲 Pygame遊戲製作教程

pygame遊戲設計第一彈 pygame程式設計框架 www.bilibili.com pygame繪製圖形前,首先要建立乙個視窗 import pygame 使用pygame的第一步是將pygame庫匯入到python程式中 from pygame.locals import 然後需要引入pyga...

(五)通過pygame搭建遊戲框架

python飛機大戰系列文章 按順序 一 通過pygame 將自己的影象新增到遊戲中 二 通過pygame讓遊戲人物 動起來 三 通過pygame處理使用者的滑鼠鍵盤操作 事件和監聽 四 詳解pygame中的精靈和精靈組 五 通過pygame搭建遊戲框架 六 通過pygame讓遊戲背景影象實現交替滾...

pygame實現彈球遊戲

pygame彈球遊戲 寫的很簡陋 pip install pygame 安裝pygame模組 複製執行即可 import pygame import random pygame.init win pygame.display.set mode 600,600 畫布視窗的大小 pygame.displ...