feat:remove some game arguments
This commit is contained in:
parent
af3fd41f00
commit
42adfd907a
|
@ -12,76 +12,13 @@
|
||||||
"max": 1
|
"max": 1
|
||||||
},
|
},
|
||||||
"game_params": [
|
"game_params": [
|
||||||
{
|
|
||||||
"name": "time_to_play",
|
|
||||||
"verbose": "遊戲總幀數",
|
|
||||||
"type": "int",
|
|
||||||
"max": 2000,
|
|
||||||
"min": 600,
|
|
||||||
"default": 600,
|
|
||||||
"help": "set the limit of frame count , actually time will be revised according to your FPS ."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "green_food_count",
|
|
||||||
"verbose": "綠色食物數量",
|
|
||||||
"type": "int",
|
|
||||||
"choices": [
|
|
||||||
5,
|
|
||||||
10,
|
|
||||||
15,
|
|
||||||
20,
|
|
||||||
25,
|
|
||||||
30,
|
|
||||||
35,
|
|
||||||
40,
|
|
||||||
45,
|
|
||||||
50
|
|
||||||
],
|
|
||||||
"help": "set the total number of points",
|
|
||||||
"default": 10
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "red_food_count",
|
|
||||||
"verbose": "紅色食物數量",
|
|
||||||
"type": "int",
|
|
||||||
"choices": [
|
|
||||||
5,
|
|
||||||
10,
|
|
||||||
15,
|
|
||||||
20,
|
|
||||||
25,
|
|
||||||
30,
|
|
||||||
35,
|
|
||||||
40,
|
|
||||||
45,
|
|
||||||
50
|
|
||||||
],
|
|
||||||
"help": "set the total number of points",
|
|
||||||
"default": 10
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "score_to_pass",
|
|
||||||
"verbose": "通關分數",
|
|
||||||
"type": "int",
|
|
||||||
"min": 1,
|
|
||||||
"max": 30,
|
|
||||||
"default": 10,
|
|
||||||
"help": "set the score to win this game "
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "playground_size",
|
|
||||||
"verbose": "場地尺寸",
|
|
||||||
"type": "list",
|
|
||||||
"default": "400,400",
|
|
||||||
"help": "set the size of playground "
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"name": "level",
|
"name": "level",
|
||||||
"verbose": "內建關卡編號",
|
"verbose": "內建關卡編號",
|
||||||
"type": "int",
|
"type": "int",
|
||||||
"min": -1,
|
"min": -1,
|
||||||
"max": 5,
|
"max": 100,
|
||||||
"default": "-1",
|
"default": -1,
|
||||||
"help": "選定內建關卡,請注意,使用此設定將會覆蓋掉其他關卡設定,預設為 -1 不選擇任何關卡。"
|
"help": "選定內建關卡,請注意,使用此設定將會覆蓋掉其他關卡設定,預設為 -1 不選擇任何關卡。"
|
||||||
}, {
|
}, {
|
||||||
"name": "level_file",
|
"name": "level_file",
|
||||||
|
|
|
@ -17,6 +17,7 @@ BALL_W = 30
|
||||||
|
|
||||||
# food
|
# food
|
||||||
class FoodTypeEnum(StringEnum):
|
class FoodTypeEnum(StringEnum):
|
||||||
|
# TODO add good_lv1~good_lv3
|
||||||
GREEN = auto()
|
GREEN = auto()
|
||||||
RED = auto()
|
RED = auto()
|
||||||
FOOD_COLOR_MAP = {FoodTypeEnum.GREEN: "#009688",
|
FOOD_COLOR_MAP = {FoodTypeEnum.GREEN: "#009688",
|
||||||
|
|
34
src/game.py
34
src/game.py
|
@ -20,19 +20,18 @@ class EasyGame(PaiaGame):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, time_to_play, score_to_pass, green_food_count, red_food_count,
|
self,
|
||||||
playground_size: list,
|
|
||||||
level: int = -1,
|
level: int = -1,
|
||||||
level_file: str = None,
|
level_file: str = None,
|
||||||
sound: str = "off",
|
sound: str = "off",
|
||||||
*args, **kwargs):
|
*args, **kwargs):
|
||||||
super().__init__(user_num=1)
|
super().__init__(user_num=1)
|
||||||
|
# TODO reduce game config and use level file
|
||||||
self.game_result_state = GameResultState.FAIL
|
self.game_result_state = GameResultState.FAIL
|
||||||
self.scene = Scene(width=WIDTH, height=HEIGHT, color=BG_COLOR, bias_x=0, bias_y=0)
|
self.scene = Scene(width=WIDTH, height=HEIGHT, color=BG_COLOR, bias_x=0, bias_y=0)
|
||||||
self._level = level
|
self._level = level
|
||||||
self._level_file = level_file
|
self._level_file = level_file
|
||||||
if self._level_file is not None or level == "":
|
if path.isfile(self._level_file) or self._level_file == "":
|
||||||
# set by injected file
|
# set by injected file
|
||||||
self.set_game_params_by_file(self._level_file)
|
self.set_game_params_by_file(self._level_file)
|
||||||
pass
|
pass
|
||||||
|
@ -41,25 +40,13 @@ class EasyGame(PaiaGame):
|
||||||
self.set_game_params_by_level(self._level)
|
self.set_game_params_by_level(self._level)
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
# set by game params
|
self.set_game_params_by_level(1)
|
||||||
self._playground_w = int(playground_size[0])
|
|
||||||
self._playground_h = int(playground_size[1])
|
|
||||||
self.playground = pygame.Rect(
|
|
||||||
0, 0,
|
|
||||||
self._playground_w,
|
|
||||||
self._playground_h
|
|
||||||
)
|
|
||||||
self._green_food_count = green_food_count
|
|
||||||
self._red_food_count = red_food_count
|
|
||||||
self._score_to_pass = score_to_pass
|
|
||||||
self._frame_limit = time_to_play
|
|
||||||
self.playground.center = (WIDTH / 2, HEIGHT / 2)
|
|
||||||
|
|
||||||
self.foods = pygame.sprite.Group()
|
self.foods = pygame.sprite.Group()
|
||||||
self.sound_controller = SoundController(sound)
|
self.sound_controller = SoundController(sound)
|
||||||
self.init_game()
|
self._init_game()
|
||||||
|
|
||||||
def set_game_params_by_level(self, level):
|
def set_game_params_by_level(self, level:int):
|
||||||
level_file_path = os.path.join(LEVEL_PATH, f"{level:03d}.json")
|
level_file_path = os.path.join(LEVEL_PATH, f"{level:03d}.json")
|
||||||
self.set_game_params_by_file(level_file_path)
|
self.set_game_params_by_file(level_file_path)
|
||||||
|
|
||||||
|
@ -92,7 +79,7 @@ class EasyGame(PaiaGame):
|
||||||
self._frame_limit = int(game_params["time_to_play"])
|
self._frame_limit = int(game_params["time_to_play"])
|
||||||
self.playground.center = (WIDTH / 2, HEIGHT / 2)
|
self.playground.center = (WIDTH / 2, HEIGHT / 2)
|
||||||
|
|
||||||
def init_game(self):
|
def _init_game(self):
|
||||||
self.ball = Ball()
|
self.ball = Ball()
|
||||||
self.foods.empty()
|
self.foods.empty()
|
||||||
self.score = 0
|
self.score = 0
|
||||||
|
@ -120,6 +107,7 @@ class EasyGame(PaiaGame):
|
||||||
if hits:
|
if hits:
|
||||||
|
|
||||||
for food in hits:
|
for food in hits:
|
||||||
|
# TODO add food score to function
|
||||||
if food.type == FoodTypeEnum.GREEN:
|
if food.type == FoodTypeEnum.GREEN:
|
||||||
self.sound_controller.play_eating_good()
|
self.sound_controller.play_eating_good()
|
||||||
self.score += 1
|
self.score += 1
|
||||||
|
@ -146,7 +134,9 @@ class EasyGame(PaiaGame):
|
||||||
to_players_data = {}
|
to_players_data = {}
|
||||||
foods_data = []
|
foods_data = []
|
||||||
for food in self.foods:
|
for food in self.foods:
|
||||||
foods_data.append({"x": food.rect.x, "y": food.rect.y})
|
# TODO add good food and bad food
|
||||||
|
|
||||||
|
foods_data.append({"x": food.rect.x, "y": food.rect.y,"type":food.type})
|
||||||
data_to_1p = {
|
data_to_1p = {
|
||||||
"frame": self.frame_count,
|
"frame": self.frame_count,
|
||||||
"ball_x": self.ball.rect.centerx,
|
"ball_x": self.ball.rect.centerx,
|
||||||
|
@ -183,7 +173,7 @@ class EasyGame(PaiaGame):
|
||||||
self._level += 1
|
self._level += 1
|
||||||
self.set_game_params_by_level(self._level)
|
self.set_game_params_by_level(self._level)
|
||||||
|
|
||||||
self.init_game()
|
self._init_game()
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue