feat: add bg
This commit is contained in:
parent
b929f12cec
commit
64259dfc24
Binary file not shown.
Before Width: | Height: | Size: 317 KiB |
|
@ -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
|
||||
|
|
18
src/env.py
18
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")
|
||||
|
|
32
src/game.py
32
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
|
||||
|
@ -85,7 +83,8 @@ class EasyGame(PaiaGame):
|
|||
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]")
|
||||
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)]
|
||||
|
@ -192,8 +189,6 @@ class EasyGame(PaiaGame):
|
|||
self.sound_controller.play_fail()
|
||||
self._init_game()
|
||||
|
||||
|
||||
|
||||
pass
|
||||
|
||||
def _init_game(self):
|
||||
|
@ -221,12 +216,23 @@ 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__,
|
||||
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
|
||||
|
@ -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 = [
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue