Started issue Gameplay: Economy & Base #4

This commit is contained in:
2026-11-30 23:20:10 +01:00
parent 451635947f
commit b60c25364b
6 changed files with 40 additions and 8 deletions
+1 -1
View File
@@ -53,6 +53,6 @@ check with pylint
pylint game/ pylint game/
### Strcuture is written with Claude ### Strcuture is written with Claude (this read.me not the architecuture)
### Ai was used as a thinking aid tool, only small parts are written with ai, most of the code is written by ScriptSorcerer ### Ai was used as a thinking aid tool, only small parts are written with ai, most of the code is written by ScriptSorcerer
### For resources, Coding with Russ and Fluffypotato helped me alot. ### For resources, Coding with Russ and Fluffypotato helped me alot.
+4 -1
View File
@@ -69,7 +69,10 @@ class Editor():
self.mpos = pg.mouse.get_pos() self.mpos = pg.mouse.get_pos()
# print(self.mpos) # print(self.mpos)
self.mpos = (self.mpos[0] / RENDER_SCALE, self.mpos[1] / RENDER_SCALE) self.mpos = (self.mpos[0] / RENDER_SCALE, self.mpos[1] / RENDER_SCALE)
self.tile_pos = (int((self.mpos[0] + self.scroll[0]) // self.tilemap.tile_size), int((self.mpos[1] + self.scroll[1]) // self.tilemap.tile_size)) self.tile_pos = (
int((self.mpos[0] + self.scroll[0]) // self.tilemap.tile_size),
int((self.mpos[1] + self.scroll[1]) // self.tilemap.tile_size)
)
# print(self.tile_pos) # print(self.tile_pos)
self.scroll[0] += (self.movment[1] - self.movment[0]) * 2 self.scroll[0] += (self.movment[1] - self.movment[0]) * 2
+14
View File
@@ -34,6 +34,9 @@ class Game:
"assets/theme/theme.json" "assets/theme/theme.json"
) )
self.tilemap = Tilemap(self) self.tilemap = Tilemap(self)
self._money = 100
#wird vom HUD gesetzt (label)
self.on_money_changed = None
self.assets={ self.assets={
"base": load_images('/tiles/test'), "base": load_images('/tiles/test'),
@@ -88,3 +91,14 @@ class Game:
pygame.display.update() pygame.display.update()
pygame.quit() pygame.quit()
@property
def money(self):
return self._money
@money.setter
def money(self, value):
if value != self._money:
self._money = value
if self.on_money_changed:
self.on_money_changed(value)
+15
View File
@@ -49,6 +49,14 @@ class GamePlay(BaseScreen):
self.enemy = Enemy(self.game, 0.5, 200) self.enemy = Enemy(self.game, 0.5, 200)
self.enemy_group.add(self.enemy) self.enemy_group.add(self.enemy)
self.money_label = pgi.elements.UILabel(
relative_rect=pg.Rect(self.width - 200, 50, 200, 30), # x, y, Breite, Höhe
text=f"Geld: {self.game.money}",
manager=self.game.ui_manager,
)
self.game.on_money_changed = lambda m: self.money_label.set_text(f"Geld: {m}")
self.buy_button = pgi.elements.UIButton( self.buy_button = pgi.elements.UIButton(
relative_rect=pg.Rect( relative_rect=pg.Rect(
self.width - 200, self.width - 200,
@@ -136,6 +144,8 @@ class GamePlay(BaseScreen):
if not any(tw.tile_pos == self.tile_pos for tw in self.tower_group): 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') tower = Tower(self.game, self.mpos, self.tile_pos, 'cannon')
self.tower_group.add(tower) self.tower_group.add(tower)
#TODO richtier Kauf wert
self.game.money -= 50
self.bought = False self.bought = False
elif event.button == 3 and self.tile_pos is not None: elif event.button == 3 and self.tile_pos is not None:
@@ -145,7 +155,12 @@ class GamePlay(BaseScreen):
elif event.type == pgi.UI_BUTTON_PRESSED: elif event.type == pgi.UI_BUTTON_PRESSED:
if event.ui_element == self.buy_button: if event.ui_element == self.buy_button:
#TODO buy new Tower (cost)
if self.game.money >= 50:
self.bought = True self.bought = True
else:
#TODO display on screen for user
print("You have insufficient money")
# self.tower = Tower(self.game, self.mpos, self.tile_pos, 'cannon') # self.tower = Tower(self.game, self.mpos, self.tile_pos, 'cannon')
if event.ui_element == self.cancel_button: if event.ui_element == self.cancel_button:
self.bought = False self.bought = False
+3 -3
View File
@@ -2,8 +2,8 @@
UPGRADE_DATA = { UPGRADE_DATA = {
'cannon': { 'cannon': {
1: {'damage': 30, 'fire_rate': 180, 'range': 40}, 1: {'damage': 30, 'fire_rate': 180, 'range': 40, 'cost': 10},
2: {'damage': 50, 'fire_rate': 140, 'range': 50}, 2: {'damage': 50, 'fire_rate': 140, 'range': 50, 'cost': 20},
3: {'damage': 80, 'fire_rate': 120, 'range': 65}, 3: {'damage': 80, 'fire_rate': 120, 'range': 65, 'cost': 30},
} }
} }
BIN
View File
Binary file not shown.