Example #1
0
    def __init__(self, player_file):
        self.file = player_file
        # Stats
        self.stats = Stats(STATS, defaults=DEF_PLAYER)
        # Stats object for held weapon/tool
        self.item_stats = Stats(TOOL_STATS)
        self.stats.add_stats(self.item_stats)
        # Inventory
        self.inventory = PlayerInventory(self)
        self.item_used, self.use_time = None, 0
        self.used_left = True
        self.first_swing = True
        # Player image
        self.surface = c.scale_to_fit(
            pg.image.load("res/player/player_pig.png"), w=1.5 * BLOCK_W)
        # Rectangle and block dimensions
        self.rect = pg.Rect((0, 0), self.surface.get_size())
        self.dim = [1.5, self.rect.h / BLOCK_W]
        # Player sprite for world map
        self.sprite = c.scale_to_fit(self.surface, w=c.SPRITE_W, h=c.SPRITE_W)
        # Arm sprite
        self.arm = pg.Surface((int(self.rect.w / 4), int(self.rect.h / 3)))
        self.arm.fill((200, 128, 0))
        # This determines the area in which items are collected
        self.collection_range = Rect(0, 0, 6 * BLOCK_W, 6 * BLOCK_W)
        # This determines the area that you can place blocks
        self.placement_range = Rect(0, 0, 7 * BLOCK_W, 7 * BLOCK_W)
        # Physics variables
        self.pos = [0, 0]
        self.v = [0., 0.]
        self.a = [0., 20.]
        # Collisions  in x and y
        self.collisions = [0, 0]
        # Distance fallen
        self.fall_dist = 0
        # Attack immunity
        self.immunity = 0
        # Respawn counter
        self.respawn_counter = 0
        # Whether we can move or not
        self.can_move = True
        # Stores an active ui and position of source block if applicable
        self.active_ui = None
        self.active_block = [0, 0]
        self.active_ui_pos = [0, 0]
        self.dragging_ui = False
        # Crafting UI
        self.crafting_ui = CraftingUI(self)
        self.crafting_open = True
        # If the world map is open or not
        self.map_open = False
        # Map object
        self.map = None

        self.set_pos((0, 0))
Example #2
0
 def __init__(self):
     super().__init__(name="Cat",
                      w=3,
                      img=MOB + "cat.png",
                      rarity=1,
                      stats=Stats(ENEMY_STATS,
                                  defaults=DEF_MOB,
                                  hp=15,
                                  max_speedx=2,
                                  jump_speed=9))
Example #3
0
 def __init__(self):
     super().__init__(name="Zombie",
                      w=1.5,
                      aggressive=True,
                      img=MOB + "zombie.png",
                      rarity=2,
                      stats=Stats(ENEMY_STATS,
                                  defaults=DEF_MOB,
                                  hp=50,
                                  damage=40,
                                  defense=5))
Example #4
0
    def __init__(self,
                 name="No Name",
                 w=1,
                 aggressive=False,
                 rarity=1,
                 img="",
                 sprite="",
                 stats=Stats(ENEMY_STATS)):
        self.rarity = rarity
        # Stores entity info
        self.name = name
        self.stats = stats
        self.aggressive = aggressive
        # Toggles gravity's affect on this entity
        self.zero_gravity = False
        # Toggles if this entity interacts with blocks
        self.hits_blocks = True
        # Toggles knockback immunity
        self.no_knockback = False
        # Is a boss
        self.boss = False

        # Is there drag
        self.drag = False

        # Movement variables
        self.pos = [0., 0.]
        self.v = [0., 0.]
        self.a = [0., 20.]
        # Direction of image
        self.direction = math.copysign(1, self.v[0])
        self.time = 0
        self.immunity = 0
        self.collisions = [0, 0]

        # Load image
        if isfile(img):
            self.set_image(scale_to_fit(pg.image.load(img), w=w * BLOCK_W))
        else:
            self.img = pg.Surface((int(w * BLOCK_W), int(w * BLOCK_W)))
        self.dim = (w, self.img.get_size()[1] / BLOCK_W)
        # Load map sprite
        if sprite == "":
            self.sprite = None
        elif isfile(sprite) and (sprite.endswith(".png")
                                 or sprite.endswith(".jpg")):
            self.sprite = scale_to_fit(pg.image.load(sprite),
                                       w=SPRITE_W,
                                       h=SPRITE_W)
        else:
            self.sprite = pg.Surface((SPRITE_W, SPRITE_W))
        # Hit box
        self.rect = pg.Rect((0, 0), self.img.get_size())
Example #5
0
 def __init__(self):
     super().__init__(name="Doom Bunny",
                      w=1,
                      aggressive=True,
                      img=MOB + "doom_bunny.png",
                      rarity=3,
                      stats=Stats(ENEMY_STATS,
                                  defaults=DEF_MOB,
                                  hp=5,
                                  damage=100,
                                  defense=1,
                                  jump_speed=15,
                                  maxspeedx=7))
Example #6
0
 def __init__(self):
     super().__init__(name="Birdie",
                      w=.75,
                      aggressive=False,
                      img=MOB + "birdie.png",
                      rarity=1,
                      stats=Stats(ENEMY_STATS,
                                  defaults=DEF_MOB,
                                  hp=5,
                                  max_speedx=5,
                                  max_speedy=5,
                                  acceleration=5,
                                  jump_speed=10))
Example #7
0
 def __init__(self):
     super().__init__(name="Helicopter",
                      w=1.5,
                      aggressive=True,
                      img=MOB + "helicopter.png",
                      rarity=1,
                      stats=Stats(ENEMY_STATS,
                                  defaults=DEF_MOB,
                                  hp=5,
                                  damage=25,
                                  defense=1,
                                  max_speedx=7,
                                  max_speedy=7,
                                  acceleration=5))
Example #8
0
 def __init__(self, element=MagicContainer.NONE, level=1):
     element_name = MagicContainer.ELEMENT_NAMES[element]
     super().__init__(name="%s Mage" % element_name,
                      w=1.5,
                      img="%s%s_mage.png" % (MOB, element_name),
                      stats=Stats(ENEMY_STATS,
                                  defaults=DEF_MOB,
                                  hp=100,
                                  max_speedx=1))
     self.element = element
     self.level = level
     self.magic = 0
     self.target = (-1, -1)
     self.transfer_cooldown = 0
 def __init__(self,
              idx,
              upgrade_tree,
              stats=Stats(WEAPON_STATS),
              projectiles=(),
              **kwargs):
     super().__init__(idx, upgrade_tree, **kwargs)
     self.swing = True
     self.is_weapon = True
     self.stats = stats
     self.projectiles = projectiles
     self.max_stack = 1
     # Get inventory image
     from pygame.transform import scale, rotate
     from Tools.constants import INV_IMG_W
     self.inv_img = scale(rotate(self.image, 45), (INV_IMG_W, INV_IMG_W))
Example #10
0
 def __init__(self):
     super().__init__(name="Main Boss",
                      aggressive=True,
                      w=3,
                      rarity=3,
                      img=MOB + "main_boss/shadow_dude_0.png",
                      sprite=MOB + "main_boss/shadow_dude_0.png",
                      stats=Stats(ENEMY_STATS,
                                  defaults=DEF_MOB,
                                  hp=2,
                                  damage=100,
                                  defense=25,
                                  max_speedy=30))
     self.no_knockback = True
     self.stage = self.jump_count = self.launch_angle = 0
     self.launch_target = [0, 0]
     # Start in launch mode
     self.launch()
Example #11
0
 def __init__(self):
     super().__init__(name="Dragon",
                      aggressive=True,
                      w=5,
                      rarity=3,
                      img=MOB + "dragon/dragon_0.png",
                      sprite=MOB + "dragon/dragon_0.png",
                      stats=Stats(ENEMY_STATS,
                                  defaults=DEF_MOB,
                                  hp=100,
                                  damage=65,
                                  defense=10,
                                  max_speedx=15,
                                  max_speed_y=15))
     self.rising_anim = OscillateAnimation(folder=MOB + "dragon/",
                                           dim=self.img.get_size(),
                                           delay=.1)
     self.attacking_img = scale_to_fit(pg.image.load(MOB +
                                                     "dragon_attack.png"),
                                       w=5 * BLOCK_W)
     self.zero_gravity = True
     self.hits_blocks = False
     self.no_knockback = True
     self.stage = 0
Example #12
0
 def __init__(self, player):
     super().__init__(self.DIM, max_stack=1)
     # These stat objects are created ONCE
     self.stats = [Stats(STATS) for i in range(len(self.ARMOR_ORDER))]
     for s in self.stats:
         player.stats.add_stats(s)
 def __init__(self, idx, upgrade_tree, **kwargs):
     # Default it tool stats
     if "stats" not in kwargs:
         kwargs["stats"] = Stats(TOOL_STATS)
     super().__init__(idx, upgrade_tree, **kwargs)
     self.breaks_blocks = True