下载资源后端资源详情
PolandBallAttack Beta-1.0.zip
大小:3.97KB
价格:30积分
下载量:0
评分:
5.0
上传者:nmj9856
更新日期:2025-09-22

关于pygame跑酷游戏的示例

资源文件列表(大概)

文件名
大小
PolandBallAttack Beta-1.0/__pycache__/
-
PolandBallAttack Beta-1.0/__pycache__/player.cpython-310.pyc
1.73KB
PolandBallAttack Beta-1.0/countries/
-
PolandBallAttack Beta-1.0/countries/RUSSIA.png
283B
PolandBallAttack Beta-1.0/maps/
-
PolandBallAttack Beta-1.0/maps/index_map.map
41B
PolandBallAttack Beta-1.0/mapset.py
258B
PolandBallAttack Beta-1.0/player.py
1.15KB
PolandBallAttack Beta-1.0/PolandBallAttack Beta-1.0.py
2.15KB

资源内容介绍

关于pygame跑酷游戏的示例
import pygameimport sysimport jsonfrom player import PlayerWIDTH = 800HEIGHT = 600BG = (0, 221, 225)FPS=60class 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 mapsif __name__ == "__main__": Index()

用户评论 (0)

发表评论

captcha