show cool down time of plant card
modify potatomine expolode range
This commit is contained in:
parent
9c1dc63eb9
commit
c9038b31fb
@ -19,8 +19,8 @@ plant_name_list = [c.SUNFLOWER, c.PEASHOOTER, c.SNOWPEASHOOTER, c.WALLNUT,
|
|||||||
c.PUFFMUSHROOM, c.POTATOMINE, c.SQUASH, c.SPIKEWEED,
|
c.PUFFMUSHROOM, c.POTATOMINE, c.SQUASH, c.SPIKEWEED,
|
||||||
c.JALAPENO, c.SCAREDYSHROOM]
|
c.JALAPENO, c.SCAREDYSHROOM]
|
||||||
plant_sun_list = [50, 100, 175, 50, 150, 325, 200, 150, 0, 25, 50, 100, 125, 25]
|
plant_sun_list = [50, 100, 175, 50, 150, 325, 200, 150, 0, 25, 50, 100, 125, 25]
|
||||||
plant_frozen_time_list = [0, 5000, 5000, 10000, 5000, 5000, 5000, 5000, 8000, 8000,
|
plant_frozen_time_list = [7500, 7500, 7500, 30000, 50000, 7500, 7500, 7500, 7500, 30000,
|
||||||
8000, 8000, 8000, 5000]
|
30000, 7500, 50000, 7500]
|
||||||
all_card_list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
|
all_card_list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
|
||||||
|
|
||||||
def getSunValueImage(sun_value):
|
def getSunValueImage(sun_value):
|
||||||
@ -41,7 +41,7 @@ def getSunValueImage(sun_value):
|
|||||||
class Card():
|
class Card():
|
||||||
def __init__(self, x, y, name_index, scale=0.78):
|
def __init__(self, x, y, name_index, scale=0.78):
|
||||||
self.loadFrame(card_name_list[name_index], scale)
|
self.loadFrame(card_name_list[name_index], scale)
|
||||||
self.rect = self.image.get_rect()
|
self.rect = self.orig_image.get_rect()
|
||||||
self.rect.x = x
|
self.rect.x = x
|
||||||
self.rect.y = y
|
self.rect.y = y
|
||||||
|
|
||||||
@ -49,6 +49,7 @@ class Card():
|
|||||||
self.sun_cost = plant_sun_list[name_index]
|
self.sun_cost = plant_sun_list[name_index]
|
||||||
self.frozen_time = plant_frozen_time_list[name_index]
|
self.frozen_time = plant_frozen_time_list[name_index]
|
||||||
self.frozen_timer = -self.frozen_time
|
self.frozen_timer = -self.frozen_time
|
||||||
|
self.refresh_timer = 0
|
||||||
self.select = True
|
self.select = True
|
||||||
|
|
||||||
def loadFrame(self, name, scale):
|
def loadFrame(self, name, scale):
|
||||||
@ -56,8 +57,9 @@ class Card():
|
|||||||
rect = frame.get_rect()
|
rect = frame.get_rect()
|
||||||
width, height = rect.w, rect.h
|
width, height = rect.w, rect.h
|
||||||
|
|
||||||
self.image = tool.get_image(frame, 0, 0, width, height, c.BLACK, scale)
|
self.orig_image = tool.get_image(frame, 0, 0, width, height, c.BLACK, scale)
|
||||||
|
self.image = self.orig_image
|
||||||
|
|
||||||
def checkMouseClick(self, mouse_pos):
|
def checkMouseClick(self, mouse_pos):
|
||||||
x, y = mouse_pos
|
x, y = mouse_pos
|
||||||
if(x >= self.rect.x and x <= self.rect.right and
|
if(x >= self.rect.x and x <= self.rect.right and
|
||||||
@ -83,12 +85,30 @@ class Card():
|
|||||||
def setFrozenTime(self, current_time):
|
def setFrozenTime(self, current_time):
|
||||||
self.frozen_timer = current_time
|
self.frozen_timer = current_time
|
||||||
|
|
||||||
def update(self, sun_value, current_time):
|
def createShowImage(self, sun_value, current_time):
|
||||||
if (self.sun_cost > sun_value or
|
'''create a card image to show cool down status
|
||||||
(current_time - self.frozen_timer) <= self.frozen_time):
|
or disable status when have not enough sun value'''
|
||||||
self.image.set_alpha(128)
|
time = current_time - self.frozen_timer
|
||||||
|
if time < self.frozen_time: #cool down status
|
||||||
|
image = pg.Surface([self.rect.w, self.rect.h])
|
||||||
|
frozen_image = self.orig_image.copy()
|
||||||
|
frozen_image.set_alpha(128)
|
||||||
|
frozen_height = (self.frozen_time - time)/self.frozen_time * self.rect.h
|
||||||
|
|
||||||
|
image.blit(frozen_image, (0,0), (0, 0, self.rect.w, frozen_height))
|
||||||
|
image.blit(self.orig_image, (0,frozen_height),
|
||||||
|
(0, frozen_height, self.rect.w, self.rect.h - frozen_height))
|
||||||
|
elif self.sun_cost > sun_value: #disable status
|
||||||
|
image = self.orig_image.copy()
|
||||||
|
image.set_alpha(192)
|
||||||
else:
|
else:
|
||||||
self.image.set_alpha(255)
|
image = self.orig_image
|
||||||
|
return image
|
||||||
|
|
||||||
|
def update(self, sun_value, current_time):
|
||||||
|
if (current_time - self.refresh_timer) >= 500:
|
||||||
|
self.image = self.createShowImage(sun_value, current_time)
|
||||||
|
self.refresh_timer = current_time
|
||||||
|
|
||||||
def draw(self, surface):
|
def draw(self, surface):
|
||||||
surface.blit(self.image, self.rect)
|
surface.blit(self.image, self.rect)
|
||||||
|
|||||||
@ -461,7 +461,7 @@ class PotatoMine(Plant):
|
|||||||
self.init_timer = 0
|
self.init_timer = 0
|
||||||
self.bomb_timer = 0
|
self.bomb_timer = 0
|
||||||
self.explode_y_range = 0
|
self.explode_y_range = 0
|
||||||
self.explode_x_range = c.GRID_X_SIZE//2
|
self.explode_x_range = c.GRID_X_SIZE//3 * 2
|
||||||
|
|
||||||
def loadImages(self, name, scale):
|
def loadImages(self, name, scale):
|
||||||
self.init_frames = []
|
self.init_frames = []
|
||||||
@ -489,7 +489,8 @@ class PotatoMine(Plant):
|
|||||||
self.is_init = False
|
self.is_init = False
|
||||||
|
|
||||||
def canAttack(self, zombie):
|
def canAttack(self, zombie):
|
||||||
if not self.is_init and abs(zombie.rect.x - self.rect.x) <= self.explode_x_range:
|
if (not self.is_init and zombie.rect.right >= self.rect.x and
|
||||||
|
(zombie.rect.x - self.rect.x) <= self.explode_x_range):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -589,6 +590,7 @@ class Spikeweed(Plant):
|
|||||||
class Jalapeno(Plant):
|
class Jalapeno(Plant):
|
||||||
def __init__(self, x, y):
|
def __init__(self, x, y):
|
||||||
Plant.__init__(self, x, y, c.JALAPENO, c.PLANT_HEALTH, None)
|
Plant.__init__(self, x, y, c.JALAPENO, c.PLANT_HEALTH, None)
|
||||||
|
self.orig_pos = (x, y)
|
||||||
self.state = c.ATTACK
|
self.state = c.ATTACK
|
||||||
self.start_explode = False
|
self.start_explode = False
|
||||||
self.explode_y_range = 0
|
self.explode_y_range = 0
|
||||||
@ -624,6 +626,9 @@ class Jalapeno(Plant):
|
|||||||
self.animate_timer = self.current_time
|
self.animate_timer = self.current_time
|
||||||
self.image = self.frames[self.frame_index]
|
self.image = self.frames[self.frame_index]
|
||||||
|
|
||||||
|
def getPosition(self):
|
||||||
|
return self.orig_pos
|
||||||
|
|
||||||
class ScaredyShroom(Plant):
|
class ScaredyShroom(Plant):
|
||||||
def __init__(self, x, y, bullet_group):
|
def __init__(self, x, y, bullet_group):
|
||||||
Plant.__init__(self, x, y, c.SCAREDYSHROOM, c.PLANT_HEALTH, bullet_group)
|
Plant.__init__(self, x, y, c.SCAREDYSHROOM, c.PLANT_HEALTH, bullet_group)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user