refac: add self.vel and self.score in Ball
This commit is contained in:
parent
b7076e4b32
commit
85ac02c435
|
@ -10,10 +10,13 @@ PG_COLOR = "#B3E5FC"
|
||||||
|
|
||||||
# ball
|
# ball
|
||||||
BALL_COLOR = "#FFEB3B"
|
BALL_COLOR = "#FFEB3B"
|
||||||
BALL_VEL = 10.5
|
BALL_VEL = 10
|
||||||
BALL_H = 30
|
BALL_H = 30
|
||||||
BALL_W = 30
|
BALL_W = 30
|
||||||
|
BALL_GROWTH_STEP = 10
|
||||||
|
BALL_H_MAX = 80
|
||||||
|
BALL_W_MAX = 80
|
||||||
|
BALL_VEL_MAX = 25
|
||||||
|
|
||||||
# food
|
# food
|
||||||
class FoodTypeEnum(StringEnum):
|
class FoodTypeEnum(StringEnum):
|
||||||
|
|
|
@ -13,20 +13,26 @@ class Ball(pygame.sprite.Sprite):
|
||||||
self.color = BALL_COLOR
|
self.color = BALL_COLOR
|
||||||
self.rect = self.image.get_rect()
|
self.rect = self.image.get_rect()
|
||||||
self.rect.center = (400, 300)
|
self.rect.center = (400, 300)
|
||||||
|
self.score = 0
|
||||||
|
self.vel = BALL_VEL
|
||||||
|
# TODO refactor score
|
||||||
|
# TODO add velocity and size in Ball
|
||||||
|
|
||||||
|
|
||||||
def update(self, motion):
|
def update(self, motion):
|
||||||
# for motion in motions:
|
# for motion in motions:
|
||||||
if motion == "UP":
|
if motion == "UP":
|
||||||
self.rect.centery -= BALL_VEL
|
self.rect.centery -= self.vel
|
||||||
elif motion == "DOWN":
|
elif motion == "DOWN":
|
||||||
self.rect.centery += BALL_VEL
|
self.rect.centery += self.vel
|
||||||
elif motion == "LEFT":
|
elif motion == "LEFT":
|
||||||
self.rect.centerx -= BALL_VEL
|
self.rect.centerx -= self.vel
|
||||||
# self.angle += 5
|
# self.angle += 5
|
||||||
elif motion == "RIGHT":
|
elif motion == "RIGHT":
|
||||||
self.rect.centerx += BALL_VEL
|
self.rect.centerx += self.vel
|
||||||
# self.angle -= 5
|
# self.angle -= 5
|
||||||
|
|
||||||
|
|
||||||
# self.image = pygame.transform.rotate(self.origin_image, self.angle)
|
# self.image = pygame.transform.rotate(self.origin_image, self.angle)
|
||||||
# print(self.angle)
|
# print(self.angle)
|
||||||
# center = self.rect.center
|
# center = self.rect.center
|
||||||
|
|
Loading…
Reference in New Issue