diff --git a/README.md b/README.md index 1ec4b60..1ed748c 100644 --- a/README.md +++ b/README.md @@ -101,8 +101,10 @@ class MLPlay: ```json { "frame": 25, - "ball_x": 425, - "ball_y": 306, + "player_x": 425, + "player_y": 306, + "player_size": 90, + "player_vel": 16, "foods": [ { "x": 656, @@ -125,8 +127,10 @@ class MLPlay: ``` - `frame`:遊戲畫面更新的編號 -- `ball_x`:主角方塊的X座標,表示方塊的左邊座標值。 -- `ball_y`:主角方塊的Y座標,表示方塊的上方座標值。 +- `player_x`:主角方塊的X座標,表示方塊的`中心點`座標值,單位 pixel。 +- `player_y`:主角方塊的Y座標,表示方塊的`中心點`座標值,單位 pixel。 +- `player_size`:主角方塊的大小,表示方塊的長寬,單位 pixel。 +- `player_vel`:主角方塊的速度,表示方塊每幀移動的像素,單位 pixel。 - `foods`:食物的清單,清單內每一個物件都是一個食物的左上方座標值,也會提供此食物是什麼類型和分數多少。 - `type` 食物類型: `GOOD_1`, `GOOD_2`, `GOOD_3`, `BAD_1`, `BAD_2`, `BAD_3` - `score`:目前得到的分數 diff --git a/blockly.json b/blockly.json index 0435f5a..d3059b8 100644 --- a/blockly.json +++ b/blockly.json @@ -9,8 +9,10 @@ "SCENE_INFO": [ ["scene_info['frame']", "# frame", "# 幀數"], ["scene_info['status']", "game status", "遊戲狀態"], - ["scene_info['ball_x']", "x coordinate of ball", "球的 x 座標"], - ["scene_info['ball_y']", "y coordinate of ball", "球的 y 座標"], + ["scene_info['player_x']", "x coordinate of player", "玩家角色的 x 座標"], + ["scene_info['player_y']", "y coordinate of player", "玩家角色的 y 座標"], + ["scene_info['player_size']", "y coordinate of player", "玩家角色的大小"], + ["scene_info['player_vel']", "velocity of player", "玩家角色的速度"], ["scene_info['score']", "score", "目前的分數"], ["scene_info['foods']", "list of foods positions", "點點的位置清單"], ["scene_info['score_to_pass']", "the score for next level", "通關分數"], @@ -21,8 +23,7 @@ [800, "right boundary", "右邊界"], [0, "top boundary", "上邊界"], [600, "bottom boundary", "下邊界"], - [30, "ball width", "球身的寬度"], - [30, "ball height", "球身的高度"], + [30, "player size", "玩家角色的初始大小"], [8, "food lv1 size", "等級一食物的寬高度"], [12, "food lv2 size", "等級二食物的高度"], [16, "food lv3 size", "等級三食物的高度"] diff --git a/src/game.py b/src/game.py index 62299ec..52aa4d9 100644 --- a/src/game.py +++ b/src/game.py @@ -82,7 +82,6 @@ class EasyGame(PaiaGame): self.ball = Ball() self.foods.empty() - # todo validate food count 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: @@ -148,16 +147,18 @@ class EasyGame(PaiaGame): to_players_data = {} foods_data = [] for food in self.foods: - + # TODO 確認要提供中心點座標還是左上角座標。 foods_data.append({"x": food.rect.x, "y": food.rect.y, "type": food.type, "score": food.score}) - # TODO add velocity and ball_size - # TODO change ball to player data_to_1p = { "frame": self.frame_count, - "ball_x": self.ball.rect.centerx, - "ball_y": self.ball.rect.centery, + # TODO 確認要提供中心點座標還是左上角座標。 + "player_x": self.ball.rect.centerx, + "player_y": self.ball.rect.centery, + "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, "status": self.get_game_status() diff --git a/src/game_object.py b/src/game_object.py index c6b58b0..d24f1e6 100644 --- a/src/game_object.py +++ b/src/game_object.py @@ -19,7 +19,6 @@ class Ball(pygame.sprite.Sprite): self._score = 0 self._vel = BALL_VEL - def update(self, motion): # for motion in motions: if motion == "UP": @@ -33,7 +32,6 @@ class Ball(pygame.sprite.Sprite): self.rect.centerx += self._vel # self.angle -= 5 - # self.image = pygame.transform.rotate(self.origin_image, self.angle) # print(self.angle) # center = self.rect.center @@ -51,14 +49,17 @@ class Ball(pygame.sprite.Sprite): self.color ) - def eat_food(self, food:Food): - self._score+=food.score - lv = math.ceil((self._score+1) / BALL_GROWTH_SCORE_STEP) - self.rect.width = min(BALL_W + lv*BALL_GROWTH_SIZE_STEP,BALL_SIZE_MAX) - self.rect.height = min(BALL_H + lv*BALL_GROWTH_SIZE_STEP,BALL_SIZE_MAX) - self._vel = min(BALL_VEL +lv*BALL_GROWTH_VEL_STEP,BALL_VEL_MAX) + def eat_food(self, food: Food): + self._score += food.score + lv = math.ceil((self._score + 1) / BALL_GROWTH_SCORE_STEP) + self.rect.width = min(BALL_W + lv * BALL_GROWTH_SIZE_STEP, BALL_SIZE_MAX) + self.rect.height = min(BALL_H + lv * BALL_GROWTH_SIZE_STEP, BALL_SIZE_MAX) + self._vel = min(BALL_VEL + lv * BALL_GROWTH_VEL_STEP, BALL_VEL_MAX) pass + @property def score(self): return self._score - + @property + def vel(self): + return self._vel \ No newline at end of file