예제 #1
0
    def __init__(self, parent, unit, health_limit_min, health_limit_max):
        self.parent = parent
        self.unit = unit

        self.label_name = ttk.Label(self.parent, text=self.unit.name)
        self.unit_identifier = Unit_Identifier(self)
        self.healthbar = Healthbar(self, health_limit_min, health_limit_max)
예제 #2
0
    def __init__(self, imgPath, name, damageMult, healthMult, player):
        self.player = player

        self.name = name
        self.nameTextObj = drawer.createTextObject( drawer.createFont(int(drawer.DISPLAY_HEIGHT*0.095)), self.name )
        self.nameX = int(drawer.DISPLAY_WIDTH / 2 - self.nameTextObj.get_rect().width/2)
        self.nameY = int(drawer.DISPLAY_HEIGHT * -0.01)

        self.IMG_stand = loadIMG(imgPath + 'stand.png')
        self.IMG_ausholen = loadIMG(imgPath + 'ausholen.png')
        self.IMG_attack = loadIMG(imgPath + 'attack.png')
        
        self.centerPos = (drawer.CENTER[0] - int(self.IMG_stand.get_rect().width/2), int(drawer.CENTER[1]*0.35) )
        self.attackPos = ( self.centerPos[0], int(self.centerPos[1]*2.1) )


        self.curIMG = self.IMG_stand
        self.curPos = self.centerPos

        self.posMode = 0
        self.clock = 0
        self.ausholDuration = 0.5
        self.attackDuration = 0.3
        self.standDuration = 2

        self.damageMult = damageMult
        self.damage = 10

        self.healthMult = healthMult
        self.maxHealth = 100
        self.health = self.maxHealth

        self.healthbar = Healthbar(self.maxHealth, \
            int(drawer.DISPLAY_WIDTH / 2), int(self.centerPos[1] * 0.5 ), \
            int(drawer.DISPLAY_WIDTH * 0.7), int(drawer.DISPLAY_HEIGHT*0.05) )
예제 #3
0
    def __init__(self):
        self.IMG_stand = loadIMG(path + 'stand.png')
        self.IMG_dodgeL = loadIMG(path + 'dodgeL.png')
        self.IMG_dodgeR = loadIMG(path + 'dodgeR.png')
        self.IMG_attack = loadIMG(path + 'attack.png')

        self.centerPos = (drawer.CENTER[0] -
                          int(self.IMG_stand.get_rect().width / 2),
                          int(drawer.CENTER[1] * 1.1))
        self.leftPos = (int(self.centerPos[0] * 0.7), self.centerPos[1])
        self.rightPos = (int(self.centerPos[0] * 1.3), self.centerPos[1])
        self.attackPos = (self.centerPos[0], int(self.centerPos[1] * 0.7))

        self.curImg = self.IMG_stand
        self.curPos = self.centerPos

        self.posMode = 0
        self.timeTillStand = 0
        self.dodgeTime = 0.5
        self.attackDuration = 0.3

        self.damage = 20

        self.killedBosses = 0

        self.maxHealth = 100
        self.health = self.maxHealth

        self.healthbar = Healthbar(self.maxHealth,
                                   int(drawer.DISPLAY_WIDTH / 2),
                                   int(drawer.DISPLAY_HEIGHT * 0.9),
                                   int(drawer.DISPLAY_WIDTH * 0.4),
                                   int(drawer.DISPLAY_HEIGHT * 0.05))
예제 #4
0
class PlayerShip(ship.Ship):
    def __init__(self):
        super(PlayerShip, self).__init__(False, Resources.Image_Ship_Module_Base)

        self.upgrade(smsp.ShipComponentLaser(1, 0, self, smsp.LaserType.AngleLaser))
        self._healthbar = Healthbar(self)
        self._shieldbar = Shieldbar(self)
        # self.upgrade(smsp.ShipComponentLaser(0, -2, self, smsp.LaserType.HeavyLaser))
        # self.upgrade(smsp.ShipComponentLaser(0, 2, self, smsp.LaserType.HeavyLaser))
        # self.upgrade(smsp.ShipComponentLaser(1, -1, self, smsp.LaserType.SimpleLaser))
        # self.upgrade(smsp.ShipComponentLaser(1, 1, self, smsp.LaserType.SimpleLaser))
        # self.upgrade(HeavyHull(0, 1, self))
        # self.upgrade(HeavyHull(0, -1, self))
        # self.upgrade(HeavyHull(-1, 2, self))
        # self.upgrade(HeavyHull(-1, -2, self))
        # self.upgrade(RepairCrane(-1, 1, self))
        # self.upgrade(RepairCrane(-1, -1, self))
        # self.upgrade(Jet(-2, -1, self))
        # self.upgrade(Jet(-2, 0, self))
        # self.upgrade(Jet(-2, 1, self))

    def update(self, dt):
        """
        :param dt:
        :return:
        """
        self._healthbar.update()
        self._shieldbar.update()
        # controls:
        if globals.controls[Controls.Up]:
            self.y += self.engine_power / self.mass * dt
        if globals.controls[Controls.Down]:
            self.y -= self.engine_power / self.mass * dt
        if globals.controls[Controls.Left]:
            self.x -= self.engine_power / self.mass * dt
        if globals.controls[Controls.Right]:
            self.x += self.engine_power / self.mass * dt

        if self.x < 0:
            self.x = 0
        if self.y < 0:
            self.y = 0
        if self.x > globals.window.width:
            self.x = globals.window.width
        if self.y > globals.window.height:
            self.y = globals.window.height

        # first superclass.update
        super(PlayerShip, self).update(dt)
예제 #5
0
class StoryEnemy(ship.Ship):
    def __init__(self, is_enemy, resource, *args, **kwargs):
        super().__init__(is_enemy, resource, *args, **kwargs)
        self._healthbar = Healthbar(self)
        self._shieldbar = Shieldbar(self)

    def update(self, dt):
        self._healthbar.update()
        self._shieldbar.update()
        self.time += dt
        # fly up and down
        self.y += math.sin(self.time) * self.engine_power / self.mass * dt
        # fly to the left
        if self.x > globals.window.width * 0.75:
            self.x -= 0.5 * self.engine_power / self.mass * dt

        super(StoryEnemy, self).update(dt)

        # kill the drone if its out of screen
        if self.x < -50:
            self.alive = False
예제 #6
0
    def __init__(self):
        super(PlayerShip, self).__init__(False, Resources.Image_Ship_Module_Base)

        self.upgrade(smsp.ShipComponentLaser(1, 0, self, smsp.LaserType.AngleLaser))
        self._healthbar = Healthbar(self)
        self._shieldbar = Shieldbar(self)
예제 #7
0
파일: enemy.py 프로젝트: team-42/repairenge
 def __init__(self, is_enemy, resource, *args, **kwargs):
     super().__init__(is_enemy, resource, *args, **kwargs)
     self._healthbar = Healthbar(self)
     self._shieldbar = Shieldbar(self)
예제 #8
0
class Unit_Widget:


    height = 2


    def __init__(self, parent, unit, health_limit_min, health_limit_max):
        self.parent = parent
        self.unit = unit

        self.label_name = ttk.Label(self.parent, text=self.unit.name)
        self.unit_identifier = Unit_Identifier(self)
        self.healthbar = Healthbar(self, health_limit_min, health_limit_max)



    def forget(self):
        ''' Forget all subwidgets. '''

        self.label_name.grid_forget()
        self.unit_identifier.forget()
        self.healthbar.forget()
    
    
    
    def forget_and_destroy(self):
        ''' Calling this method will hide and destroy all subwidgets.
            This effectively destroys the Unit_Widget. '''

        self.label_name.grid_forget()
        self.label_name.destroy()
        self.unit_identifier.forget_and_destroy()
        self.healthbar.forget_and_destroy()



    def grid(self, column, row, columnspan=1):
        ''' This method calls tkinters grid manager to place all subwidgets on the window.
            The Unit_Widget will never exceed the dimensions specified in the method parameters.
            Try calling self.update() if the Unit_Widget is not showing properly. '''

        self.label_name.grid(column=column, row=row)
        self.unit_identifier.grid(column + 1, row)
        self.healthbar.grid(column, row + 1, columnspan=columnspan)



    def new_health_limit(self, health_limit_min, health_limit_max):
        ''' Change the health limit on the Unit_Widget's healthbar.
            The health limit is used to scale the healthbar.
            Assigning the same health limits to all Unit_Widgets will cause the healthbars to align on the zero health mark
            and to have the same length per health.
            If the unit's health values {health_min, health_max} are outside the assigned health limit [health_limit_min,health_limit_max],
            the health limit will automatically be extended beyond the specified parameters to fit the entire health bar.
            This may cause healthbars to not align anymore and can be avoided by passing valid health limits. '''

        self.healthbar.new_health_limit(health_limit_min, health_limit_max)



    def update(self):
        ''' Update the entire Unit_Widget. '''

        self.unit_identifier.update()
        self.healthbar.update()
예제 #9
0
class Boss(object):
    """Ein Gegner in dem Spiel"""

    def __init__(self, imgPath, name, damageMult, healthMult, player):
        self.player = player

        self.name = name
        self.nameTextObj = drawer.createTextObject( drawer.createFont(int(drawer.DISPLAY_HEIGHT*0.095)), self.name )
        self.nameX = int(drawer.DISPLAY_WIDTH / 2 - self.nameTextObj.get_rect().width/2)
        self.nameY = int(drawer.DISPLAY_HEIGHT * -0.01)

        self.IMG_stand = loadIMG(imgPath + 'stand.png')
        self.IMG_ausholen = loadIMG(imgPath + 'ausholen.png')
        self.IMG_attack = loadIMG(imgPath + 'attack.png')
        
        self.centerPos = (drawer.CENTER[0] - int(self.IMG_stand.get_rect().width/2), int(drawer.CENTER[1]*0.35) )
        self.attackPos = ( self.centerPos[0], int(self.centerPos[1]*2.1) )


        self.curIMG = self.IMG_stand
        self.curPos = self.centerPos

        self.posMode = 0
        self.clock = 0
        self.ausholDuration = 0.5
        self.attackDuration = 0.3
        self.standDuration = 2

        self.damageMult = damageMult
        self.damage = 10

        self.healthMult = healthMult
        self.maxHealth = 100
        self.health = self.maxHealth

        self.healthbar = Healthbar(self.maxHealth, \
            int(drawer.DISPLAY_WIDTH / 2), int(self.centerPos[1] * 0.5 ), \
            int(drawer.DISPLAY_WIDTH * 0.7), int(drawer.DISPLAY_HEIGHT*0.05) )
    
    def update(self, dt):
        if self.health <= 0:
            return True
        if self.posMode == 0:
            self.clock += np.random.rand() * dt / 2
        if self.clock > 0:
            self.clock -= dt
            return

        # Wenn der Code hier weitergeht, muss in die nächste Phase gegangen werden
        if self.posMode == 0:
            self.ausholen()
            return
        if self.posMode == 1:
            self.attack()
            return
        if self.posMode == 2:
            self.goMiddle()
            return

    
    def draw(self):
        drawer.showIMG(self.curPos[0], self.curPos[1], self.curIMG)
        self.healthbar.draw()
        drawer.write(self.nameX, self.nameY, self.nameTextObj)
    
    def ausholen(self):
        self.curIMG = self.IMG_ausholen
        self.posMode = 1
        self.clock = self.ausholDuration
    
    def attack(self):
        self.posMode = 2
        self.curIMG = self.IMG_attack
        self.curPos = self.attackPos
        self.clock = self.attackDuration

        if self.player.posMode == 0 or self.player.posMode == 3:
            self.player.hurt(self.damage)

    def goMiddle(self):
        self.posMode = 0
        self.curIMG = self.IMG_stand
        self.curPos = self.centerPos
        self.clock = self.standDuration
    
    def hurt(self, amount):
        self.health -= amount

        if self.health <= 0:
            self.health = 0
            self.die()
        
        self.healthbar.setVal(self.health)
    
    def die(self):
        self.player.killedBosses += 1
    
    def ressurect(self):
        self.goMiddle()
        self.health = self.maxHealth
        self.healthbar.maxVal = self.maxHealth
        self.healthbar.setVal(self.health)
        self.clock = 0
예제 #10
0
class Player(object):
    def __init__(self):
        self.IMG_stand = loadIMG(path + 'stand.png')
        self.IMG_dodgeL = loadIMG(path + 'dodgeL.png')
        self.IMG_dodgeR = loadIMG(path + 'dodgeR.png')
        self.IMG_attack = loadIMG(path + 'attack.png')

        self.centerPos = (drawer.CENTER[0] -
                          int(self.IMG_stand.get_rect().width / 2),
                          int(drawer.CENTER[1] * 1.1))
        self.leftPos = (int(self.centerPos[0] * 0.7), self.centerPos[1])
        self.rightPos = (int(self.centerPos[0] * 1.3), self.centerPos[1])
        self.attackPos = (self.centerPos[0], int(self.centerPos[1] * 0.7))

        self.curImg = self.IMG_stand
        self.curPos = self.centerPos

        self.posMode = 0
        self.timeTillStand = 0
        self.dodgeTime = 0.5
        self.attackDuration = 0.3

        self.damage = 20

        self.killedBosses = 0

        self.maxHealth = 100
        self.health = self.maxHealth

        self.healthbar = Healthbar(self.maxHealth,
                                   int(drawer.DISPLAY_WIDTH / 2),
                                   int(drawer.DISPLAY_HEIGHT * 0.9),
                                   int(drawer.DISPLAY_WIDTH * 0.4),
                                   int(drawer.DISPLAY_HEIGHT * 0.05))

    def update(self, dt):
        if self.health <= 0:
            return 'dead'
        if self.timeTillStand > 0:
            self.timeTillStand -= dt
            return
        if self.posMode != 0:
            self.goMiddle()
            return 'goMiddle'

    def draw(self):
        drawer.showIMG(self.curPos[0], self.curPos[1], self.curImg)
        self.healthbar.draw()

    def dodgeL(self):
        if self.posMode == 0:
            self.posMode = 1
            self.curPos = self.leftPos
            self.curImg = self.IMG_dodgeL
            self.timeTillStand = self.dodgeTime

    def dodgeR(self):
        if self.posMode == 0:
            self.posMode = 2
            self.curPos = self.rightPos
            self.curImg = self.IMG_dodgeR
            self.timeTillStand = self.dodgeTime

    def goMiddle(self):
        self.posMode = 0
        self.curPos = self.centerPos
        self.curImg = self.IMG_stand

    def attack(self, boss):
        if self.posMode == 0:

            boss.hurt(self.damage)

            self.posMode = 3
            self.curPos = self.attackPos
            self.curImg = self.IMG_attack
            self.timeTillStand = self.attackDuration

    def hurt(self, amount):
        self.health -= amount

        if self.health < 0:
            self.health = 0
            self.die()

        self.healthbar.setVal(self.health)

    def die(self):
        print("You killed " + str(self.killedBosses) + " bosses!")
        self.killedBosses = 0

    def ressurect(self):
        self.health = self.maxHealth
        self.timeTillStand = 0
        self.goMiddle()
        self.healthbar.setVal(self.health)
        self.killedBosses = 0