24 lines
599 B
Python
24 lines
599 B
Python
from module import WIDTH, HEIGHT, JUMP_FORCE
|
|
from module.block import AirBlock
|
|
|
|
|
|
# 玩家类
|
|
class Player:
|
|
def __init__(self):
|
|
self.x = WIDTH // 2
|
|
self.y = HEIGHT // 2
|
|
self.velocity = 0
|
|
self.on_ground = False
|
|
self.selected_block = AirBlock
|
|
|
|
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 |