This repository has been archived on 2025-02-14. You can view files and clone it, but cannot push or open issues or pull requests.
LXCsGame/module/player.py

23 lines
564 B
Python

# 玩家类
from module import WIDTH, HEIGHT, JUMP_FORCE
class Player:
def __init__(self):
self.x = WIDTH // 2
self.y = HEIGHT // 2
self.velocity = 0
self.on_ground = False
self.selected_block = "grass"
def move(self, dx, dy):
new_x = self.x + dx
new_y = self.y + dy
if 0 <= new_x < WIDTH and 0 <= new_y < HEIGHT:
self.x = new_x
self.y = new_y
def jump(self):
if self.on_ground:
self.velocity = JUMP_FORCE
self.on_ground = False