Added tower upgrading
Issue #8 (pylint problem resolved with this change) Upgrade system not done, only simplel upgrading added
This commit is contained in:
+34
-19
@@ -34,7 +34,6 @@ class GamePlay(BaseScreen):
|
||||
self.center = (self.game_surface.get_width() /2, self.game_surface.get_height() /2)
|
||||
self.movment = [False, False, False, False]
|
||||
self.selected = None
|
||||
self.notunselect = True
|
||||
|
||||
self.map = 'desert'
|
||||
self.path = 'assets/maps/' + str(self.map) + '.json'
|
||||
@@ -72,12 +71,25 @@ class GamePlay(BaseScreen):
|
||||
text="Cancel",
|
||||
manager=self.game.ui_manager
|
||||
)
|
||||
self.upgrade_button = pgi.elements.UIButton(
|
||||
relative_rect=pg.Rect(
|
||||
self.width - 200,
|
||||
self.height -100,
|
||||
150,
|
||||
50
|
||||
),
|
||||
|
||||
text="Upgrade Tower",
|
||||
manager=self.game.ui_manager
|
||||
)
|
||||
self.buy_button.hide()
|
||||
self.cancel_button.hide()
|
||||
self.upgrade_button.hide()
|
||||
self.bought = False
|
||||
self.elements = [
|
||||
self.buy_button,
|
||||
self.cancel_button
|
||||
self.cancel_button,
|
||||
self.upgrade_button
|
||||
]
|
||||
|
||||
self.mpos = (0, 0)
|
||||
@@ -109,27 +121,20 @@ class GamePlay(BaseScreen):
|
||||
else:
|
||||
self.tile_pos = None
|
||||
|
||||
if event.type == pgi.UI_BUTTON_PRESSED:
|
||||
if event.ui_element == self.buy_button:
|
||||
self.bought = True
|
||||
# self.tower = Tower(self.game, self.mpos, self.tile_pos, 'cannon')
|
||||
if event.ui_element == self.cancel_button:
|
||||
self.bought = False
|
||||
|
||||
self.tile_pos = (int(self.tile_pos_decimal[0]), int(self.tile_pos_decimal[1]))
|
||||
if event.type == pg.MOUSEBUTTONDOWN:
|
||||
if self.tile_pos is not None:
|
||||
if event.button == 1:
|
||||
self.selected = self.select_turret(self.tile_pos)
|
||||
self.clear_selection()
|
||||
if self.selected is not None:
|
||||
print(f'selected: {self.selected}')
|
||||
self.selected.selected = True
|
||||
print(f'{self.selected}')
|
||||
if event.button == 1:
|
||||
if self.tile_pos is not None:
|
||||
if game_rect.collidepoint(self.mpos):
|
||||
# only clear and reselect when clicking inside the game surface
|
||||
self.clear_selection()
|
||||
self.selected = self.select_tower(self.tile_pos)
|
||||
if self.selected is not None:
|
||||
self.selected.selected = True
|
||||
if self.bought:
|
||||
if self.game.tilemap.placeable(self.tile_pos):
|
||||
if not any(tw.tile_pos == self.tile_pos for tw in self.tower_group):
|
||||
tower = Tower(self.game, self.mpos, self.tile_pos, 'cannon', 40)
|
||||
tower = Tower(self.game, self.mpos, self.tile_pos, 'cannon')
|
||||
self.tower_group.add(tower)
|
||||
self.bought = False
|
||||
if event.button == 3:
|
||||
@@ -137,6 +142,16 @@ class GamePlay(BaseScreen):
|
||||
if tower.tile_pos == self.tile_pos:
|
||||
tower.kill()
|
||||
|
||||
if event.type == pgi.UI_BUTTON_PRESSED:
|
||||
if event.ui_element == self.buy_button:
|
||||
self.bought = True
|
||||
# self.tower = Tower(self.game, self.mpos, self.tile_pos, 'cannon')
|
||||
if event.ui_element == self.cancel_button:
|
||||
self.bought = False
|
||||
if event.ui_element == self.upgrade_button:
|
||||
if self.selected:
|
||||
self.selected.upgrade()
|
||||
|
||||
if event.type == pg.KEYDOWN:
|
||||
if event.key == pg.K_a:
|
||||
self.movment[0] = True
|
||||
@@ -206,7 +221,7 @@ class GamePlay(BaseScreen):
|
||||
|
||||
surface.blit(self.game_surface, (0, self.height/6))
|
||||
|
||||
def select_turret(self, tile_pos):
|
||||
def select_tower(self, tile_pos):
|
||||
"""Return the tower at tile_pos, or ``None`` if the tile is empty.
|
||||
|
||||
Args:
|
||||
|
||||
Reference in New Issue
Block a user