feat: add food1
This commit is contained in:
parent
c4953cd57a
commit
473bb3ea3c
|
@ -5,6 +5,11 @@
|
||||||
"score_to_pass": 10,
|
"score_to_pass": 10,
|
||||||
"good_food_count": [0,0,0],
|
"good_food_count": [0,0,0],
|
||||||
"bad_food_count": [0,0,0],
|
"bad_food_count": [0,0,0],
|
||||||
"fish": 3
|
"food_1": 3,
|
||||||
|
"food_2": 0,
|
||||||
|
"food_3": 0,
|
||||||
|
"garbage_1": 3,
|
||||||
|
"garbage_2": 0,
|
||||||
|
"garbage_3": 0
|
||||||
|
|
||||||
}
|
}
|
60
src/foods.py
60
src/foods.py
|
@ -1,4 +1,3 @@
|
||||||
import math
|
|
||||||
import random
|
import random
|
||||||
|
|
||||||
import pygame.sprite
|
import pygame.sprite
|
||||||
|
@ -7,6 +6,8 @@ from pygame import Rect
|
||||||
from .env import FoodTypeEnum, FOOD_COLOR_MAP, FOOD_LV1_SIZE, FOOD_LV2_SIZE, FOOD_LV3_SIZE
|
from .env import FoodTypeEnum, FOOD_COLOR_MAP, FOOD_LV1_SIZE, FOOD_LV2_SIZE, FOOD_LV3_SIZE
|
||||||
from mlgame.view.view_model import create_rect_view_data
|
from mlgame.view.view_model import create_rect_view_data
|
||||||
|
|
||||||
|
FOOD1_VEL = 1
|
||||||
|
|
||||||
|
|
||||||
class Food(pygame.sprite.Sprite):
|
class Food(pygame.sprite.Sprite):
|
||||||
def __init__(self, group):
|
def __init__(self, group):
|
||||||
|
@ -18,9 +19,11 @@ class Food(pygame.sprite.Sprite):
|
||||||
|
|
||||||
self.rect = self.image.get_rect()
|
self.rect = self.image.get_rect()
|
||||||
self.angle = 0
|
self.angle = 0
|
||||||
|
|
||||||
def set_center_x_and_y(self, x: int, y: int):
|
def set_center_x_and_y(self, x: int, y: int):
|
||||||
self.rect.centerx = x
|
self.rect.centerx = x
|
||||||
self.rect.centery = y
|
self.rect.centery = y
|
||||||
|
|
||||||
def update(self, *args, **kwargs) -> None:
|
def update(self, *args, **kwargs) -> None:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -45,6 +48,7 @@ class GoodFoodLv1(Food):
|
||||||
self.score = 1
|
self.score = 1
|
||||||
self.rect = self.image.get_rect()
|
self.rect = self.image.get_rect()
|
||||||
|
|
||||||
|
|
||||||
class GoodFoodLv2(Food):
|
class GoodFoodLv2(Food):
|
||||||
def __init__(self, group):
|
def __init__(self, group):
|
||||||
super().__init__(group)
|
super().__init__(group)
|
||||||
|
@ -55,6 +59,7 @@ class GoodFoodLv2(Food):
|
||||||
self.score = 2
|
self.score = 2
|
||||||
self.rect = self.image.get_rect()
|
self.rect = self.image.get_rect()
|
||||||
|
|
||||||
|
|
||||||
class GoodFoodLv3(Food):
|
class GoodFoodLv3(Food):
|
||||||
def __init__(self, group):
|
def __init__(self, group):
|
||||||
super().__init__(group)
|
super().__init__(group)
|
||||||
|
@ -64,7 +69,9 @@ class GoodFoodLv3(Food):
|
||||||
self.color = FOOD_COLOR_MAP[self.type]
|
self.color = FOOD_COLOR_MAP[self.type]
|
||||||
self.score = 4
|
self.score = 4
|
||||||
self.rect = self.image.get_rect()
|
self.rect = self.image.get_rect()
|
||||||
class Fish(Food):
|
|
||||||
|
|
||||||
|
class Food1(Food):
|
||||||
def __init__(self, group):
|
def __init__(self, group):
|
||||||
super().__init__(group)
|
super().__init__(group)
|
||||||
|
|
||||||
|
@ -73,39 +80,26 @@ class Fish(Food):
|
||||||
self.color = FOOD_COLOR_MAP[self.type]
|
self.color = FOOD_COLOR_MAP[self.type]
|
||||||
self.score = 1
|
self.score = 1
|
||||||
self.rect = self.image.get_rect()
|
self.rect = self.image.get_rect()
|
||||||
self._target_x=400
|
self.rect_float_x = 0
|
||||||
self._target_y=400
|
self.rect_float_y = 0
|
||||||
self._direction = 1
|
self._vel = FOOD1_VEL
|
||||||
self._vel=2
|
def set_center_x_and_y(self, x: int, y: int):
|
||||||
self._vely=1
|
self.rect.centerx = x
|
||||||
def update(self,playground:Rect):
|
self.rect.centery = y
|
||||||
|
self.rect_float_x = self.rect.centerx
|
||||||
|
self.rect_float_y = self.rect.centery
|
||||||
|
|
||||||
|
def update(self, playground: Rect, squid: pygame.sprite.Sprite):
|
||||||
|
|
||||||
if self._direction==1:
|
self.rect_float_x += self._vel
|
||||||
if self.rect.centerx > self._target_x:
|
self.rect_float_y += random.choice([-0.3,-0.5,-0.7,0,0.3,0.5,0.7])
|
||||||
# change
|
self.rect.centerx = self.rect_float_x
|
||||||
self._direction= - self._direction
|
self.rect.centery = self.rect_float_y
|
||||||
self._target_x = random.randint(playground.left, playground.right)
|
|
||||||
self._target_y = self.rect.centery + random.randint(-20,20)
|
|
||||||
self._vely = self._vel * ((self._target_y - self.rect.centery)/(self._target_x - self.rect.centerx) )
|
|
||||||
|
|
||||||
pass
|
if self.rect.left < playground.left and self._vel < 0.0:
|
||||||
# move to right
|
self._vel = FOOD1_VEL
|
||||||
self.rect.centerx += self._vel
|
elif self.rect.right > playground.right and self._vel>0.0:
|
||||||
self.rect.centery = self.rect.centery +self._vely
|
self._vel = - FOOD1_VEL
|
||||||
elif self._direction==-1:
|
|
||||||
if self.rect.centerx < self._target_x:
|
|
||||||
# change
|
|
||||||
self._direction= - self._direction
|
|
||||||
self._target_x = random.randint(playground.left, playground.right)
|
|
||||||
self._target_y = self.rect.centery + random.randint(-50,50)
|
|
||||||
self.rect.centery = self.rect.centery + self._vely
|
|
||||||
|
|
||||||
pass
|
|
||||||
self.rect.centerx -= self._vel
|
|
||||||
self.rect.centery -= math.sin(self.rect.centerx)
|
|
||||||
pass
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -119,6 +113,7 @@ class BadFoodLv1(Food):
|
||||||
self.rect = self.image.get_rect()
|
self.rect = self.image.get_rect()
|
||||||
self.angle = 0
|
self.angle = 0
|
||||||
|
|
||||||
|
|
||||||
class BadFoodLv2(Food):
|
class BadFoodLv2(Food):
|
||||||
def __init__(self, group):
|
def __init__(self, group):
|
||||||
super().__init__(group)
|
super().__init__(group)
|
||||||
|
@ -129,6 +124,7 @@ class BadFoodLv2(Food):
|
||||||
self.score = -2
|
self.score = -2
|
||||||
self.rect = self.image.get_rect()
|
self.rect = self.image.get_rect()
|
||||||
|
|
||||||
|
|
||||||
class BadFoodLv3(Food):
|
class BadFoodLv3(Food):
|
||||||
def __init__(self, group):
|
def __init__(self, group):
|
||||||
super().__init__(group)
|
super().__init__(group)
|
||||||
|
|
|
@ -96,7 +96,7 @@ class EasyGame(PaiaGame):
|
||||||
self._create_foods(BadFoodLv1, self._bad_food_count[0])
|
self._create_foods(BadFoodLv1, self._bad_food_count[0])
|
||||||
self._create_foods(BadFoodLv2, self._bad_food_count[1])
|
self._create_foods(BadFoodLv2, self._bad_food_count[1])
|
||||||
self._create_foods(BadFoodLv3, self._bad_food_count[2])
|
self._create_foods(BadFoodLv3, self._bad_food_count[2])
|
||||||
self._create_foods(Fish, game_params.fish)
|
self._create_foods(Food1, game_params.food_1)
|
||||||
|
|
||||||
self.frame_count = 0
|
self.frame_count = 0
|
||||||
self._frame_count_down = self._frame_limit
|
self._frame_count_down = self._frame_limit
|
||||||
|
@ -115,7 +115,7 @@ class EasyGame(PaiaGame):
|
||||||
self.ball.update(action)
|
self.ball.update(action)
|
||||||
revise_ball(self.ball, self.playground)
|
revise_ball(self.ball, self.playground)
|
||||||
# update sprite
|
# update sprite
|
||||||
self.foods.update(playground=self.playground)
|
self.foods.update(playground=self.playground,squid=self.ball)
|
||||||
|
|
||||||
# handle collision
|
# handle collision
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,13 @@ class LevelParams(pydantic.BaseModel):
|
||||||
|
|
||||||
good_food_count:List[int] =[]
|
good_food_count:List[int] =[]
|
||||||
bad_food_count:List[int] =[]
|
bad_food_count:List[int] =[]
|
||||||
fish:int=0
|
|
||||||
|
food_1:int=0
|
||||||
|
food_2:int=0
|
||||||
|
food_3:int=0
|
||||||
|
garbage_1:int=0
|
||||||
|
garbage_2:int=0
|
||||||
|
garbage_3:int=0
|
||||||
|
|
||||||
class Ball(pygame.sprite.Sprite):
|
class Ball(pygame.sprite.Sprite):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
Loading…
Reference in New Issue