Skip to content

Commit

Permalink
Added chests and debug text. Auto formatter padding my lines added, y…
Browse files Browse the repository at this point in the history
…a love to see it.
  • Loading branch information
tdgood committed Apr 14, 2024
1 parent cd9352d commit d237e72
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 10 deletions.
12 changes: 11 additions & 1 deletion src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
Warrior,
Ranger,
Mage,
Chest,
Button,
)

Expand Down Expand Up @@ -60,12 +61,21 @@ def generate_room(self):
self.all_enemies,
self.all_entities,
)
if random.random() < 0.05:
Chest(
(random.randint(0, SCREEN_WIDTH), random.randint(0, SCREEN_HEIGHT)),
self.all_enemies,
self.all_entities,
)

def spawn_playable_unit(self, pos):
if not any(e.rect.collidepoint(pos) for e in self.all_enemies):
if self.playable_units[self.selected_unit] > 0:
self.playable_units[self.selected_unit] -= 1
self.selected_unit.create_new(pos, self.all_players, self.all_entities)
spawned_unit = self.selected_unit.create_new(
pos, self.all_players, self.all_entities
)
print(spawned_unit)

def transition_state(self, new_state: States):
self.screen_state = new_state
Expand Down
87 changes: 78 additions & 9 deletions src/sprites.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import enum
import random
import pygame
from pygame import image, Surface
from pygame.font import Font
Expand Down Expand Up @@ -87,6 +88,9 @@ def __init__(
self.image = self.standing_surf
self.rect = self.image.get_rect(center=centerpos)

def __repr__(self):
return f"{self.__class__.__name__}(pos={self.rect.center}, {self.health=}, {self.attack=}, {self.speed=}, {self.attack_speed=})"

def __set_surf(self):
if self.walking:
if self.image not in [self.walking_1_surf, self.walking_2_surf]:
Expand Down Expand Up @@ -155,18 +159,63 @@ def do_attack(self, group: Group):


class Warrior(Unit):
health = 5
attack = 2
speed = 5
attack_speed_scale = 1

def __init__(self, centerpos: tuple[int, int], *groups):
super().__init__(centerpos, "knight", 5, 2, 5, 2000, 0, False, *groups)
super().__init__(
centerpos,
"knight",
Warrior.health,
Warrior.attack,
Warrior.speed,
(1000 // Warrior.attack_speed_scale) + 1000,
0,
False,
*groups,
)


class Ranger(Unit):
health = 3
attack = 3
speed = 6
attack_speed_scale = 1

def __init__(self, centerpos: tuple[int, int], *groups):
super().__init__(centerpos, "ranger", 3, 3, 6, 2000, 200, False, *groups)
super().__init__(
centerpos,
"ranger",
Ranger.health,
Ranger.attack,
Ranger.speed,
(1000 // Ranger.attack_speed_scale) + 1000,
200,
False,
*groups,
)


class Mage(Unit):
health = 1
attack = 5
speed = 4
attack_speed_scale = 1

def __init__(self, centerpos: tuple[int, int], *groups):
super().__init__(centerpos, "mage", 1, 5, 4, 3000, 300, True, *groups)
super().__init__(
centerpos,
"mage",
Mage.health,
Mage.attack,
Mage.speed,
(1000 // Mage.attack_speed_scale) + 2000,
300,
True,
*groups,
)


class Skeleton(Unit):
Expand All @@ -178,9 +227,6 @@ class Skeleton(Unit):
def __init__(self, centerpos: tuple[int, int], *groups):
super().__init__(centerpos, "skeleton", Skeleton.health, Skeleton.attack, Skeleton.speed, (1000//Skeleton.attack_speed_scale) + 1000, 0, False, *groups)

def __repr__(self):
return f"{self.__class__.__name__}(pos={self.rect.center}, {self.health=}, {self.attack=}, {self.speed=}, {self.attack_speed=})"

@classmethod
def reset_stats(cls):
cls.health = 3
Expand All @@ -198,9 +244,6 @@ class Zombie(Unit):
def __init__(self, centerpos: tuple[int, int], *groups):
super().__init__(centerpos, "zombie", Zombie.health, Zombie.attack, Zombie.speed, (1000//Zombie.attack_speed_scale) + 1000, 0, False, *groups)

def __repr__(self):
return f"{self.__class__.__name__}(pos={self.rect.center}, {self.health=}, {self.attack=}, {self.speed=}, {self.attack_speed=})"

@classmethod
def reset_stats(cls):
cls.health = 2
Expand All @@ -209,6 +252,32 @@ def reset_stats(cls):
cls.attack_speed_scale = 1


class Chest(Sprite):
def __init__(self, centerpos, *groups):
super().__init__(*groups)
self.health = 10
self.image = pygame.Surface((50, 50))
self.image.fill((0, 0, 0))
self.rect = self.image.get_rect(center=centerpos)

def update(self, screen_rect, group, delta_time):
self.rect.clamp_ip(screen_rect)

def kill(self):
random_class = random.choice([Warrior, Ranger, Mage])
random_stat = random.randint(1, 4)
if random_stat == 1:
random_class.attack += 1
elif random_stat == 2:
random_class.speed += 1
elif random_stat == 3:
random_class.attack_speed_scale += 1
elif random_stat == 4:
random_class.health += 1
print(f"CHEST GAVE: {random_class} - {random_stat}")
super().kill()


class TextArea(Sprite):
# Besides font and value, takes a third parameter for its position, which must be keyworded.
# This can use all the same arguments as get_rect() for positioning Rects (topleft, center, etc)
Expand Down

0 comments on commit d237e72

Please sign in to comment.