-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCharacter.py
More file actions
69 lines (57 loc) · 2.6 KB
/
Character.py
File metadata and controls
69 lines (57 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# Character.py
import numpy as np
from PIL import Image
class Character:
def __init__(self, width, height):
self.width = width
self.height = height
self.base_size = 60 # 기본 크기 설정
self.current_size = self.base_size # 현재 크기
self.size_increment = 0.2 # 크기 증가율 조절
self.max_level = 5 # 커질 수 있는 최대 레벨 설정
self.position = np.array([width/2 - 30, height - 70, width/2 + 30, height - 10])
self.walk_speed = 5
self.run_speed = 10
self.walk_state = 0
self.run_state = 0
self.direction = "right"
self.is_running = False
self.is_moving = False
def resize(self, size_level):
level = min(size_level, self.max_level) # 최대 레벨 제한
old_center = (self.position[0] + self.current_size/2) # 이전 중심점 저장
# size_increment 변수 사용
self.current_size = self.base_size * (1 + (level - 1) * self.size_increment)
# 새로운 위치 계산 (중심점 기준으로)
new_left = max(0, min(old_center - self.current_size / 2, self.width - self.current_size))
self.position[0] = new_left
self.position[2] = new_left + self.current_size
self.position[1] = self.height - self.current_size - 10
self.position[3] = self.height - 10
def move(self, command):
move_speed = self.run_speed if self.is_running else self.walk_speed
# 이동 상태 초기화
self.is_moving = False
if command['left_pressed']:
self.is_moving = True
self.direction = "left"
self.position[0] = max(0, self.position[0] - move_speed)
self.position[2] = self.position[0] + self.current_size
if self.is_running:
self.run_state = (self.run_state + 1) % 8
else:
self.walk_state = (self.walk_state + 1) % 8
elif command['right_pressed']:
self.is_moving = True
self.direction = "right"
self.position[0] = min(self.width - self.current_size, self.position[0] + move_speed)
self.position[2] = self.position[0] + self.current_size
if self.is_running:
self.run_state = (self.run_state + 1) % 8
else:
self.walk_state = (self.walk_state + 1) % 8
else:
self.walk_state = 0
self.run_state = 0
def set_running(self, is_running):
self.is_running = is_running