diff --git a/asset/img/background.jpg b/asset/img/background.jpg deleted file mode 100644 index e20b960..0000000 Binary files a/asset/img/background.jpg and /dev/null differ diff --git a/levels/001.json b/levels/001.json index daf9bce..51b967f 100644 --- a/levels/001.json +++ b/levels/001.json @@ -1,13 +1,13 @@ { "time_to_play": 300, - "playground_size_w":100, - "playground_size_h":200, + "playground_size_w":300, + "playground_size_h":300, "score_to_pass": 10, "good_food_count": [0,0,0], "bad_food_count": [0,0,0], "food_1": 3, - "food_2": 0, - "food_3": 0, + "food_2": 1, + "food_3": 1, "garbage_1": 3, "garbage_2": 0, "garbage_3": 0 diff --git a/src/env.py b/src/env.py index 6d850c1..0c79f63 100644 --- a/src/env.py +++ b/src/env.py @@ -3,21 +3,21 @@ from os import path from mlgame.utils.enum import StringEnum # game -WIDTH = 800 +WIDTH = 900 HEIGHT = 600 -BG_COLOR = "#111111" +BG_COLOR = "#2B2B49" PG_COLOR = "#B3E5FC" # ball BALL_COLOR = "#FFEB3B" BALL_VEL = 10 -BALL_H = 30 -BALL_W = 30 +BALL_H = 50 +BALL_W = 50 BALL_GROWTH_SCORE_STEP = 15 BALL_GROWTH_SIZE_STEP=10 BALL_GROWTH_VEL_STEP=3 -BALL_SIZE_MAX = 100 -BALL_SIZE_MIN = 10 +BALL_SIZE_MAX = 125 +BALL_SIZE_MIN = 20 BALL_VEL_MAX = 25 BALL_VEL_MIN = 10 @@ -39,9 +39,9 @@ FOOD_COLOR_MAP = { FoodTypeEnum.BAD_2: "#FF1744", FoodTypeEnum.BAD_3: "#FF1744" } -FOOD_LV1_SIZE = 20 -FOOD_LV2_SIZE = 12 -FOOD_LV3_SIZE = 16 +FOOD_LV1_SIZE = 30 +FOOD_LV2_SIZE = 40 +FOOD_LV3_SIZE = 50 # path of assets ASSET_PATH = path.join(path.dirname(__file__), "..", "asset") diff --git a/src/game.py b/src/game.py index e63781c..3d6bcde 100644 --- a/src/game.py +++ b/src/game.py @@ -3,7 +3,6 @@ import json import os.path import pygame -from orjson import orjson from mlgame.game.paia_game import PaiaGame, GameResultState, GameStatus from mlgame.utils.enum import get_ai_name @@ -52,7 +51,6 @@ class EasyGame(PaiaGame): self._init_game() - @timeit_in_perf def _init_game_by_file(self, level_file_path: str): try: @@ -71,8 +69,8 @@ class EasyGame(PaiaGame): # set game params self.playground = pygame.Rect( 0, 0, - game_params.playground_w, - game_params.playground_h + game_params.playground_size_h, + game_params.playground_size_w ) self._good_food_count = game_params.good_food_count self._bad_food_count = game_params.bad_food_count @@ -84,8 +82,9 @@ class EasyGame(PaiaGame): self.ball = Ball() self.foods.empty() - if not isinstance(self._good_food_count,list) or len(self._good_food_count)<3: - raise Exception("你的關卡檔案格式有誤,請在'good_food_count' 欄位後面填入一個長度為3的陣列,舉例: [1,2,3]") + if not isinstance(self._good_food_count, list) or len(self._good_food_count) < 3: + raise Exception( + "你的關卡檔案格式有誤,請在'good_food_count' 欄位後面填入一個長度為3的陣列,舉例: [1,2,3]") elif not isinstance(self._bad_food_count, list) or len(self._bad_food_count) < 3: raise Exception("你的關卡檔案格式有誤,請在'bad_food_count' 欄位後面填入一個長度為3的陣列,舉例: [1,2,3]") @@ -102,8 +101,6 @@ class EasyGame(PaiaGame): self._frame_count_down = self._frame_limit self.sound_controller.play_music() - - def update(self, commands): # handle command ai_1p_cmd = commands[get_ai_name(0)] @@ -115,7 +112,7 @@ class EasyGame(PaiaGame): self.ball.update(action) revise_ball(self.ball, self.playground) # update sprite - self.foods.update(playground=self.playground,squid=self.ball) + self.foods.update(playground=self.playground, squid=self.ball) # handle collision @@ -135,11 +132,11 @@ class EasyGame(PaiaGame): 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.ball.eat_food_and_change_level_and_play_sound(food, self.sound_controller) self._create_foods(food.__class__, 1) - if isinstance(food, (GoodFoodLv1,GoodFoodLv2,GoodFoodLv3,)): + if isinstance(food, (GoodFoodLv1, GoodFoodLv2, GoodFoodLv3,)): self.sound_controller.play_eating_good() - elif isinstance(food, (BadFoodLv1,BadFoodLv2,BadFoodLv3,)): + elif isinstance(food, (BadFoodLv1, BadFoodLv2, BadFoodLv3,)): self.sound_controller.play_eating_bad() def get_data_from_game_to_player(self): @@ -158,12 +155,12 @@ class EasyGame(PaiaGame): # 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_size": self.ball.rect.width, + "player_vel": self.ball.vel, "foods": foods_data, "score": self.ball.score, - "score_to_pass":self._score_to_pass, + "score_to_pass": self._score_to_pass, "status": self.get_game_status() } @@ -192,8 +189,6 @@ class EasyGame(PaiaGame): self.sound_controller.play_fail() self._init_game() - - pass def _init_game(self): @@ -221,14 +216,25 @@ class EasyGame(PaiaGame): # background = create_asset_init_data( # "background", WIDTH, HEIGHT, bg_path, # github_raw_url="https://raw.githubusercontent.com/PAIA-Playful-AI-Arena/easy_game/main/asset/img/background.jpg") + bg_path = path.join(ASSET_IMAGE_DIR, "background.png") food01_path = path.join(ASSET_IMAGE_DIR, "food_01.png") + # TODO food01_url = food01_path - scene_init_data = {"scene": self.scene.__dict__, - "assets": [ - create_asset_init_data("food01", 20, 20, food01_path,food01_url) - ], - # "audios": {} - } + bg_url = bg_path + + scene_init_data = { + "scene": self.scene.__dict__, + "assets": [ + create_asset_init_data("bg", 1000, 1000, bg_path, bg_url), + create_asset_init_data("food01", 20, 20, food01_path, food01_url) + ], + "background": [ + create_image_view_data( + 'bg', self.playground.x, self.playground.y, + self.playground.w, self.playground.h) + ] + # "audios": {} + } return scene_init_data @check_game_progress @@ -243,9 +249,9 @@ class EasyGame(PaiaGame): game_obj_list.extend(foods_data) backgrounds = [ # create_image_view_data("background", 0, 0, WIDTH, HEIGHT), - create_rect_view_data( - "playground", self.playground.x, self.playground.y, - self.playground.w, self.playground.h, PG_COLOR) + # create_rect_view_data( + # "playground", self.playground.x, self.playground.y, + # self.playground.w, self.playground.h, PG_COLOR) ] foregrounds = [ diff --git a/src/game_object.py b/src/game_object.py index 4bdb154..edd01ed 100644 --- a/src/game_object.py +++ b/src/game_object.py @@ -12,15 +12,16 @@ from mlgame.view.view_model import create_rect_view_data class LevelParams(pydantic.BaseModel): - playground_w: int = 100 - playground_h: int = 200 + # TODO max and min + playground_size_w: int = 300 + playground_size_h: int = 300 score_to_pass: int = 10 time_to_play: int = 300 good_food_count: List[int] = [] bad_food_count: List[int] = [] - food_1: int = 0 + food_1: int = 3 food_2: int = 0 food_3: int = 0 garbage_1: int = 0