refactor code structure
This commit is contained in:
23
module/player.py
Normal file
23
module/player.py
Normal 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
|
||||
Reference in New Issue
Block a user