fix:level error
This commit is contained in:
parent
3eb2a6cdb4
commit
2f470099b8
|
@ -12,7 +12,7 @@ PG_COLOR = "#B3E5FC"
|
|||
# BALL_COLOR = "#FFEB3B"
|
||||
SQUID_W = 40
|
||||
SQUID_H = 60
|
||||
LEVEL_THRESHOLDS = [10, 30, 60, 100, 150]
|
||||
LEVEL_THRESHOLDS = [10, 30, 60, 100, 150,200]
|
||||
LEVEL_PROPERTIES = {
|
||||
1: {'size_ratio': 1.0, 'vel': 10},
|
||||
2: {'size_ratio': 1.2, 'vel': 12},
|
||||
|
|
37
src/game.py
37
src/game.py
|
@ -77,7 +77,7 @@ class EasyGame(PaiaGame):
|
|||
self.playground.center = ((WIDTH-200) / 2, HEIGHT / 2)
|
||||
|
||||
# init game
|
||||
self.ball = Squid()
|
||||
self.squid = Squid()
|
||||
self.foods.empty()
|
||||
self._create_foods(Food1, game_params.food_1)
|
||||
self._create_foods(Food2, game_params.food_2)
|
||||
|
@ -98,10 +98,10 @@ class EasyGame(PaiaGame):
|
|||
else:
|
||||
action = "NONE"
|
||||
|
||||
self.ball.update(action)
|
||||
revise_ball(self.ball, self.playground)
|
||||
self.squid.update(action)
|
||||
revise_ball(self.squid, self.playground)
|
||||
# update sprite
|
||||
self.foods.update(playground=self.playground, squid=self.ball)
|
||||
self.foods.update(playground=self.playground, squid=self.squid)
|
||||
|
||||
# handle collision
|
||||
|
||||
|
@ -116,12 +116,12 @@ class EasyGame(PaiaGame):
|
|||
return "RESET"
|
||||
|
||||
def _check_foods_collision(self):
|
||||
hits = pygame.sprite.spritecollide(self.ball, self.foods, True)
|
||||
hits = pygame.sprite.spritecollide(self.squid, self.foods, True)
|
||||
if hits:
|
||||
for food in hits:
|
||||
# self.ball.score += food.score
|
||||
# growth play special sound
|
||||
self.ball.eat_food_and_change_level_and_play_sound(food, self.sound_controller)
|
||||
self.squid.eat_food_and_change_level_and_play_sound(food, self.sound_controller)
|
||||
self._create_foods(food.__class__, 1)
|
||||
if isinstance(food, (Food1, Food2, Food3,)):
|
||||
self.sound_controller.play_eating_good()
|
||||
|
@ -142,13 +142,13 @@ class EasyGame(PaiaGame):
|
|||
data_to_1p = {
|
||||
"frame": self.frame_count,
|
||||
# TODO 確認要提供中心點座標還是左上角座標。
|
||||
"player_x": self.ball.rect.centerx,
|
||||
"player_y": self.ball.rect.centery,
|
||||
"player_size": self.ball.rect.width,
|
||||
"player_vel": self.ball.vel,
|
||||
"player_x": self.squid.rect.centerx,
|
||||
"player_y": self.squid.rect.centery,
|
||||
"player_size": self.squid.rect.width,
|
||||
"player_vel": self.squid.vel,
|
||||
"foods": foods_data,
|
||||
|
||||
"score": self.ball.score,
|
||||
"score": self.squid.score,
|
||||
"score_to_pass": self._score_to_pass,
|
||||
"status": self.get_game_status()
|
||||
|
||||
|
@ -191,7 +191,7 @@ class EasyGame(PaiaGame):
|
|||
|
||||
@property
|
||||
def is_passed(self):
|
||||
return self.ball.score > self._score_to_pass
|
||||
return self.squid.score > self._score_to_pass
|
||||
|
||||
@property
|
||||
def is_running(self):
|
||||
|
@ -238,7 +238,7 @@ class EasyGame(PaiaGame):
|
|||
foods_data = []
|
||||
for food in self.foods:
|
||||
foods_data.append(food.game_object_data)
|
||||
game_obj_list = [self.ball.game_object_data]
|
||||
game_obj_list = [self.squid.game_object_data]
|
||||
game_obj_list.extend(foods_data)
|
||||
backgrounds = [
|
||||
# create_image_view_data("background", 0, 0, WIDTH, HEIGHT),
|
||||
|
@ -253,9 +253,12 @@ class EasyGame(PaiaGame):
|
|||
|
||||
]
|
||||
toggle_objs = [
|
||||
create_text_view_data(f"Score: {self.ball.score:04d}", 750, 50, "#EEEEEE", "24px Arial BOLD"),
|
||||
create_text_view_data(f"Next : {self._score_to_pass:04d}", 750, 100, "#EEEEEE", "24px Arial BOLD"),
|
||||
create_text_view_data(f"Time : {self._frame_count_down:04d}", 750, 150, "#EEEEEE", "24px Arial BOLD"),
|
||||
create_text_view_data(f"Lv : {self.squid.lv:4d}", 750, 50, "#EEEEEE", "24px Arial BOLD"),
|
||||
create_text_view_data(f"Vel : {self.squid.vel:4d}", 750, 80, "#EEEEEE", "24px Arial BOLD"),
|
||||
create_text_view_data(f"Score: {self.squid.score:04d}", 750, 110, "#EEEEEE", "24px Arial BOLD"),
|
||||
create_text_view_data(f"Lv_up: {LEVEL_THRESHOLDS[self.squid.lv-1]:4d}", 750, 140, "#EEEEEE", "24px Arial BOLD"),
|
||||
create_text_view_data(f"Time : {self._frame_count_down:04d}", 750, 200, "#EEEEEE", "24px Arial BOLD"),
|
||||
create_text_view_data(f"ToPass: {self._score_to_pass:04d}", 750, 230, "#EEEEEE", "24px Arial BOLD"),
|
||||
|
||||
]
|
||||
scene_progress = create_scene_progress_data(frame=self.frame_count, background=backgrounds,
|
||||
|
@ -276,7 +279,7 @@ class EasyGame(PaiaGame):
|
|||
{
|
||||
"player": get_ai_name(0),
|
||||
"rank": 1,
|
||||
"score": self.ball.score,
|
||||
"score": self.squid.score,
|
||||
"passed": self.is_passed
|
||||
}
|
||||
]
|
||||
|
|
|
@ -36,6 +36,7 @@ class Squid(pygame.sprite.Sprite):
|
|||
|
||||
def __init__(self):
|
||||
pygame.sprite.Sprite.__init__(self)
|
||||
|
||||
self.origin_image = pygame.Surface([SQUID_W, SQUID_H])
|
||||
self.image = self.origin_image
|
||||
self.rect = self.image.get_rect()
|
||||
|
@ -99,6 +100,9 @@ class Squid(pygame.sprite.Sprite):
|
|||
@property
|
||||
def vel(self):
|
||||
return self._vel
|
||||
@property
|
||||
def lv(self):
|
||||
return self._lv
|
||||
|
||||
|
||||
def get_current_level(score: int) -> int:
|
||||
|
@ -111,5 +115,5 @@ def get_current_level(score: int) -> int:
|
|||
|
||||
for level, threshold in enumerate(LEVEL_THRESHOLDS, start=1):
|
||||
if score < threshold:
|
||||
return level
|
||||
return len(LEVEL_THRESHOLDS) + 1 # Return the next level if score is beyond all thresholds
|
||||
return min(level,6)
|
||||
return len(LEVEL_THRESHOLDS) # Return the next level if score is beyond all thresholds
|
||||
|
|
Loading…
Reference in New Issue