diff --git a/asset/img/food_01.png b/asset/img/food_01.png index 0fc98db..c1c62a7 100644 Binary files a/asset/img/food_01.png and b/asset/img/food_01.png differ diff --git a/asset/img/food_03.png b/asset/img/food_03.png index c1c62a7..0fc98db 100644 Binary files a/asset/img/food_03.png and b/asset/img/food_03.png differ diff --git a/src/env.py b/src/env.py index 0c79f63..e84a53e 100644 --- a/src/env.py +++ b/src/env.py @@ -8,11 +8,11 @@ HEIGHT = 600 BG_COLOR = "#2B2B49" PG_COLOR = "#B3E5FC" -# ball -BALL_COLOR = "#FFEB3B" +# ball -> squid +# BALL_COLOR = "#FFEB3B" BALL_VEL = 10 -BALL_H = 50 BALL_W = 50 +BALL_H = 70 BALL_GROWTH_SCORE_STEP = 15 BALL_GROWTH_SIZE_STEP=10 BALL_GROWTH_VEL_STEP=3 diff --git a/src/game.py b/src/game.py index 3d6bcde..d610690 100644 --- a/src/game.py +++ b/src/game.py @@ -11,11 +11,11 @@ from mlgame.view.decorator import check_game_progress, check_game_result from mlgame.view.view_model import * from .env import * from .foods import * -from .game_object import Ball, LevelParams +from .game_object import Squid, LevelParams from .sound_controller import SoundController -def revise_ball(ball: Ball, playground: pygame.Rect): +def revise_ball(ball: Squid, playground: pygame.Rect): ball_rect = copy.deepcopy(ball.rect) if ball_rect.left < playground.left: ball_rect.left = playground.left @@ -79,7 +79,7 @@ class EasyGame(PaiaGame): self.playground.center = (WIDTH / 2, HEIGHT / 2) # init game - self.ball = Ball() + self.ball = Squid() self.foods.empty() if not isinstance(self._good_food_count, list) or len(self._good_food_count) < 3: @@ -217,15 +217,18 @@ class EasyGame(PaiaGame): # "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") + squid_path = path.join(ASSET_IMAGE_DIR, "squid.png") food01_path = path.join(ASSET_IMAGE_DIR, "food_01.png") + # TODO food01_url = food01_path bg_url = bg_path - + squid_url = squid_path scene_init_data = { "scene": self.scene.__dict__, "assets": [ create_asset_init_data("bg", 1000, 1000, bg_path, bg_url), + create_asset_init_data("squid", BALL_W, BALL_H, squid_path, squid_url), create_asset_init_data("food01", 20, 20, food01_path, food01_url) ], "background": [ diff --git a/src/game_object.py b/src/game_object.py index edd01ed..93cda81 100644 --- a/src/game_object.py +++ b/src/game_object.py @@ -1,14 +1,16 @@ import math + + from typing import List import pydantic import pygame.sprite -from .env import BALL_COLOR, BALL_VEL, BALL_H, BALL_W, BALL_GROWTH_SCORE_STEP, BALL_GROWTH_SIZE_STEP, \ +from .env import BALL_VEL, BALL_H, BALL_W, BALL_GROWTH_SCORE_STEP, BALL_GROWTH_SIZE_STEP, \ BALL_SIZE_MAX, BALL_GROWTH_VEL_STEP, BALL_VEL_MAX, BALL_SIZE_MIN, BALL_VEL_MIN from .foods import Food from .sound_controller import SoundController -from mlgame.view.view_model import create_rect_view_data +from mlgame.view.view_model import create_rect_view_data, create_image_view_data class LevelParams(pydantic.BaseModel): @@ -29,18 +31,19 @@ class LevelParams(pydantic.BaseModel): garbage_3: int = 0 -class Ball(pygame.sprite.Sprite): +class Squid(pygame.sprite.Sprite): + ANGLE_TO_RIGHT = math.radians(-10) + ANGLE_TO_LEFT = math.radians(10) def __init__(self): pygame.sprite.Sprite.__init__(self) self.origin_image = pygame.Surface([BALL_W, BALL_H]) self.image = self.origin_image - self.color = BALL_COLOR self.rect = self.image.get_rect() self.rect.center = (400, 300) self._score = 0 self._vel = BALL_VEL self._lv = 1 - + self.angle =0 def update(self, motion): # for motion in motions: if motion == "UP": @@ -49,11 +52,12 @@ class Ball(pygame.sprite.Sprite): self.rect.centery += self._vel elif motion == "LEFT": self.rect.centerx -= self._vel - # self.angle += 5 + self.angle = self.ANGLE_TO_LEFT elif motion == "RIGHT": self.rect.centerx += self._vel - # self.angle -= 5 - + self.angle = self.ANGLE_TO_RIGHT + else: + self.angle = 0 # self.image = pygame.transform.rotate(self.origin_image, self.angle) # print(self.angle) # center = self.rect.center @@ -62,13 +66,15 @@ class Ball(pygame.sprite.Sprite): @property def game_object_data(self): - return create_rect_view_data( - "ball", + + return create_image_view_data( + "squid", self.rect.x, self.rect.y, self.rect.width, self.rect.height, - self.color + self.angle + ) def eat_food_and_change_level_and_play_sound(self, food: Food, sound_controller: SoundController):