首页下载资源后端关于pygame跑酷游戏的示例

ZIP关于pygame跑酷游戏的示例

nmj98563.97KB需要积分:1

资源文件列表:

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

资源介绍:

关于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()
100+评论
captcha