首页 星云 工具 资源 星选 资讯 热门工具
:

PDF转图片 完全免费 小红书视频下载 无水印 抖音视频下载 无水印 数字星空

关于pygame跑酷游戏的示例

后端 3.97KB 28 需要积分: 1
立即下载

资源介绍:

关于pygame跑酷游戏的示例
import pygame import sys import json from player import Player WIDTH = 800 HEIGHT = 600 BG = (0, 221, 225) FPS=60 class Index: def __init__(self): pygame.init() self.screen = pygame.display.set_mode((WIDTH, HEIGHT)) self.screenrect = self.screen.get_rect() pygame.display.set_caption("PolandBall Attack Beta-1.0") self.map = self.map_open("index_map") self.run_game() def run_game(self): self.center_x, self.center_y = 0, 0 self.player = Player("RUSSIA", self) self.fpsclock=pygame.time.Clock() while True: self.screen.fill(BG) self.check_events() self.update() self.draw() pygame.display.flip() self.fpsclock.tick(FPS) def check_events(self): for event in pygame.event.get(): if event.type == pygame.QUIT: self.quit() def quit(self): pygame.quit() sys.exit() def update(self): self.player.update() # 更新中心点的位置,可以根据具体情况调整 self.center_x = self.player.rect.x - WIDTH // 2 self.center_y = self.player.rect.y - HEIGHT // 2 def draw(self): self.draw_map() self.player.draw() keys = pygame.key.get_pressed() if keys[pygame.K_LEFT]: self.player.move(-5, 0) if keys[pygame.K_RIGHT]: self.player.move(5, 0) if keys[pygame.K_UP]: self.player.jump() def draw_map(self): for item in self.map: self.draw_in_center_map(item, (0, 0, 0)) def draw_in_center_map(self, rect, color): rect = rect.copy() rect.x -= self.center_x rect.y -= self.center_y pygame.draw.rect(self.screen, color, rect) def map_open(self, mapname): with open(f"maps/{mapname}.map") as file: mapo = json.load(file) maps = [] for item in mapo: maps.append(pygame.Rect(item[0], item[1], item[2], item[3])) return maps if __name__ == "__main__": Index()

资源文件列表:

PolandBallAttack Beta-1.0.zip 大约有9个文件
  1. PolandBallAttack Beta-1.0/__pycache__/
  2. PolandBallAttack Beta-1.0/__pycache__/player.cpython-310.pyc 1.73KB
  3. PolandBallAttack Beta-1.0/countries/
  4. PolandBallAttack Beta-1.0/countries/RUSSIA.png 283B
  5. PolandBallAttack Beta-1.0/maps/
  6. PolandBallAttack Beta-1.0/maps/index_map.map 41B
  7. PolandBallAttack Beta-1.0/mapset.py 258B
  8. PolandBallAttack Beta-1.0/player.py 1.15KB
  9. PolandBallAttack Beta-1.0/PolandBallAttack Beta-1.0.py 2.15KB
0评论
提交 加载更多评论
其他资源 我的远程软件 客户端C 服务端python
入口为RunClientLoop函数
好用的excel工具包
好用的excel工具包
ISO 26262 2018 Published 2nd.zip
ISO 26262 2018 1-12
三菱mc4c开发Java代码Demo
详细参考博客https://blog.csdn.net/h4241778/article/details/140947315?csdn_share_tail=%7B%22type%22%3A%22blog%22%2C%22rType%22%3A%22article%22%2C%22rId%22%3A%22140947315%22%2C%22source%22%3A%22h4241778%22%7D 解压密码博客中
铁路数据SHP、DBF、SHX
铁路数据SHP、DBF、SHX
青橙商城,青橙商城,青橙商城,青橙商城
青橙商城,青橙商城,青橙商城,青橙商城
抖音视频矩阵PHP解密
抖音视频矩阵PHP解密
抖音矩阵混剪系统源码V2.30
带解密版本,可实用