refactor code structure

This commit is contained in:
2025-01-31 19:35:09 +08:00
parent d74c866caf
commit 823158a8eb
4 changed files with 69 additions and 66 deletions

23
module/player.py Normal file
View File

@@ -0,0 +1,23 @@
# 玩家类
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