From bd2b338a04350e7773f7e025492e7ea8d23c9669 Mon Sep 17 00:00:00 2001 From: Kylin_on_Mac Date: Thu, 16 Nov 2023 16:36:43 +0800 Subject: [PATCH 1/3] feat: add levels --- levels/011.json | 12 ++++++++++++ levels/012.json | 12 ++++++++++++ levels/013.json | 12 ++++++++++++ levels/014.json | 12 ++++++++++++ levels/015.json | 12 ++++++++++++ 5 files changed, 60 insertions(+) create mode 100644 levels/011.json create mode 100644 levels/012.json create mode 100644 levels/013.json create mode 100644 levels/014.json create mode 100644 levels/015.json diff --git a/levels/011.json b/levels/011.json new file mode 100644 index 0000000..eea3d17 --- /dev/null +++ b/levels/011.json @@ -0,0 +1,12 @@ +{ + "time_to_play": 1800, + "playground_size_w":700, + "playground_size_h":600, + "score_to_pass": 100, + "food_1": 8, + "food_2": 6, + "food_3": 3, + "garbage_1": 10, + "garbage_2": 8, + "garbage_3": 4 +} \ No newline at end of file diff --git a/levels/012.json b/levels/012.json new file mode 100644 index 0000000..da9fdc9 --- /dev/null +++ b/levels/012.json @@ -0,0 +1,12 @@ +{ + "time_to_play": 1800, + "playground_size_w":700, + "playground_size_h":600, + "score_to_pass": 100, + "food_1": 5, + "food_2": 4, + "food_3": 3, + "garbage_1": 10, + "garbage_2": 8, + "garbage_3": 4 +} \ No newline at end of file diff --git a/levels/013.json b/levels/013.json new file mode 100644 index 0000000..368abaf --- /dev/null +++ b/levels/013.json @@ -0,0 +1,12 @@ +{ + "time_to_play": 1800, + "playground_size_w":700, + "playground_size_h":600, + "score_to_pass": 100, + "food_1": 5, + "food_2": 4, + "food_3": 3, + "garbage_1": 12, + "garbage_2": 10, + "garbage_3": 4 +} \ No newline at end of file diff --git a/levels/014.json b/levels/014.json new file mode 100644 index 0000000..e03af81 --- /dev/null +++ b/levels/014.json @@ -0,0 +1,12 @@ +{ + "time_to_play": 1800, + "playground_size_w":700, + "playground_size_h":600, + "score_to_pass": 100, + "food_1": 8, + "food_2": 6, + "food_3": 3, + "garbage_1": 14, + "garbage_2": 12, + "garbage_3": 5 +} \ No newline at end of file diff --git a/levels/015.json b/levels/015.json new file mode 100644 index 0000000..84eba37 --- /dev/null +++ b/levels/015.json @@ -0,0 +1,12 @@ +{ + "time_to_play": 1800, + "playground_size_w":700, + "playground_size_h":600, + "score_to_pass": 100, + "food_1": 6, + "food_2": 5, + "food_3": 3, + "garbage_1": 14, + "garbage_2": 12, + "garbage_3": 5 +} \ No newline at end of file From db3644fd84578773e27741027e4a80a90f641f26 Mon Sep 17 00:00:00 2001 From: Kylin_on_Mac Date: Thu, 16 Nov 2023 16:39:10 +0800 Subject: [PATCH 2/3] refac: update garbage class --- src/foods.py | 65 +++++++++++++++++++++------------------------- src/game_object.py | 3 --- 2 files changed, 29 insertions(+), 39 deletions(-) diff --git a/src/foods.py b/src/foods.py index 0cfeaf2..c2f9639 100644 --- a/src/foods.py +++ b/src/foods.py @@ -49,9 +49,9 @@ class Food1(Food): def __init__(self, group): super().__init__(group, FoodTypeEnum.FOOD_1, IMG_ID_FOOD01_L, [FOOD_LV1_SIZE, FOOD_LV1_SIZE], 1) - self._vel = FOOD1_VEL * random.choice([-1,1]) + self._vel = FOOD1_VEL * random.choice([-1, 1]) - self.image_id= IMG_ID_FOOD01_R if self._vel > 0 else IMG_ID_FOOD01_L + self.image_id = IMG_ID_FOOD01_R if self._vel > 0 else IMG_ID_FOOD01_L def update(self, playground: Rect, squid: pygame.sprite.Sprite): @@ -87,6 +87,7 @@ class Food2(Food): self._vel = -FOOD2_VEL self.image_id = IMG_ID_FOOD02_L + class Food3(Food): def __init__(self, group): super().__init__(group, FoodTypeEnum.FOOD_3, IMG_ID_FOOD03_L, [FOOD_LV3_SIZE, FOOD_LV3_SIZE], 4) @@ -105,58 +106,50 @@ class Food3(Food): elif self.rect.right > playground.right and self._vel > 0.0: self._vel = -FOOD3_VEL self.image_id = IMG_ID_FOOD03_L -class Garbage1(Food): - def __init__(self, group): - super().__init__(group, FoodTypeEnum.GARBAGE_1, "garbage01", - [FOOD_LV1_SIZE, FOOD_LV1_SIZE], -1) + + +class Garbage(Food): + def __init__(self, group, type: FoodTypeEnum, image_id: str, image_size: list, score): + super().__init__(group, type, image_id, image_size, score) self._vel = FOOD1_VEL + self._bias_x_list = [-0.5, -0.7, -1, -1.3, 0, 1, 1.3, 0.3, 0.5, 0.7] def update(self, playground: Rect, squid: pygame.sprite.Sprite): - self.rect_float_x += random.choice([-0.3, -0.5, -0.7, 0, 0.3, 0.5, 0.7]) + self.rect_float_x += random.choice(self._bias_x_list) self.rect_float_y += self._vel self.rect.centerx = self.rect_float_x self.rect.centery = self.rect_float_y - + self._move_to_new_position(playground) + def _move_to_new_position(self, playground): if self.rect.top > playground.bottom: - self.rect.y = playground.top + self.rect.bottom = playground.top self.rect_float_y = self.rect.centery + self.rect_float_x = random.randint(playground.left, playground.right) + self.rect.centerx = self.rect_float_x pass -class Garbage2(Food): +class Garbage2(Garbage): def __init__(self, group): super().__init__(group, FoodTypeEnum.GARBAGE_2, "garbage02", [FOOD_LV2_SIZE, FOOD_LV2_SIZE], -4) self._vel = FOOD2_VEL - - def update(self, playground: Rect, squid: pygame.sprite.Sprite): - self.rect_float_x += random.choice([-0.5, -0.7, -1, -1.3, 0, 1, 1.3, 0.3, 0.5, 0.7]) - self.rect_float_y += self._vel - self.rect.centerx = self.rect_float_x - self.rect.centery = self.rect_float_y - - if self.rect.top > playground.bottom: - self.rect.y = playground.top - self.rect_float_y = self.rect.centery - - pass + self._bias_x_list = [-0.5, -0.7, -1, -1.3, 0, 1, 1.3, 0.3, 0.5, 0.7] -class Garbage3(Food): + +class Garbage1(Garbage): + def __init__(self, group): + super().__init__(group, FoodTypeEnum.GARBAGE_1, "garbage01", + [FOOD_LV1_SIZE, FOOD_LV1_SIZE], -1) + self._vel = FOOD1_VEL + self._bias_x_list = [-0.3, -0.5, -0.7, 0, 0.3, 0.5, 0.7] + + +class Garbage3(Garbage): def __init__(self, group): super().__init__(group, FoodTypeEnum.GARBAGE_3, "garbage03", [FOOD_LV3_SIZE, FOOD_LV3_SIZE], -10) - self._vel = FOOD1_VEL - - def update(self, playground: Rect, squid: pygame.sprite.Sprite): - self.rect_float_x += random.choice([-0.7, -1, -1.3, -1.7, 0, 1.7, 1, 1.3, 0.3, 0.7]) - self.rect_float_y += self._vel - self.rect.centerx = self.rect_float_x - self.rect.centery = self.rect_float_y - - if self.rect.top > playground.bottom: - self.rect.y = playground.top - self.rect_float_y = self.rect.centery - - pass + self._vel = FOOD3_VEL + self._bias_x_list = [-0.7, -1, -1.3, -1.7, 0, 1.7, 1, 1.3, 0.3, 0.7] diff --git a/src/game_object.py b/src/game_object.py index 1ef29d7..03f0389 100644 --- a/src/game_object.py +++ b/src/game_object.py @@ -1,7 +1,4 @@ import math - -from typing import List - import pydantic import pygame.sprite From 4a831ce7a60ae4935b661abdbba017fc9b965272 Mon Sep 17 00:00:00 2001 From: Kylin_on_Mac Date: Thu, 16 Nov 2023 16:39:34 +0800 Subject: [PATCH 3/3] doc:update version --- game_config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/game_config.json b/game_config.json index 56f7a19..2c8e26f 100644 --- a/game_config.json +++ b/game_config.json @@ -1,6 +1,6 @@ { "game_name": "swimming-squid", - "version": "2.4a4", + "version": "2.4a5", "url": "https://github.com/PAIA-Playful-AI-Arena/swimming-squid", "description": "這是一個魷魚吃東西小遊戲,除了讓你熟習所有基本操作,也是 PAIA 的遊戲教學範例", "logo": [