Example #1
0
 def update(self):
     # while a solid bullet
     if not self.destroyed:
         # Move
         if self.dir == "UP":
             self.y -= self.speed
             self.rect.y = int(self.y)
         elif self.dir == "DOWN":
             self.y += self.speed
             self.rect.y = int(self.y)
         elif isinstance(self.dir, tuple):
             self.y += self.dir[0] * self.speed
             self.rect.y = int(self.y)
             self.x += self.dir[1] * self.speed
             self.rect.x = int(self.x)
         # Check if reach bottom or top
         if self.rect.top >= self.screen.get_rect().bottom:
             GOL.del_go(self)
         elif self.rect.bottom <= self.screen.get_rect().top:
             GOL.del_go(self)
         # Check if hit anything
         if isinstance(self.ship, Player):
             for alien in GOL.get_golist(Aliens):
                 if self.rect.colliderect(alien.rect):
                     if alien.spawned and not alien.destroyed:
                         alien.take_dmg(self.dmg)
                         self.destroyed = True
         elif isinstance(self.ship, Aliens):
             if GOL.get_go(Player):
                 if self.rect.colliderect(GOL.get_go(Player).rect):
                     GOL.get_go(Player).take_dmg(self.dmg)
                     self.destroyed = True
Example #2
0
 def __init__(self):
     self.hp_bar = self.Bar(30,
                            100,
                            1,
                            10,
                            10, (250, 0, 0),
                            GOL.get_go(Player),
                            "hp",
                            icon=r"images\ui\hp_icon.png")
     self.shield_bar = self.Bar(30,
                                100,
                                1,
                                50,
                                10, (0, 100, 250),
                                GOL.get_go(Player),
                                "shield_hp",
                                icon=r"images\ui\shield_icon.png")
     self.shield_charge_bar = self.Bar(10,
                                       100,
                                       1,
                                       80,
                                       10, (0, 200, 250),
                                       GOL.get_go(Player),
                                       "shield_charge",
                                       icon=r"images\ui\energy_icon.png")
     self.shield_charge_bar.var_max_value = 60 * 5
     self.base_hp = self.Bar(20,
                             100,
                             4,
                             100,
                             10, (250, 250, 0),
                             GOL.get_go(Base),
                             "hp",
                             icon=r"images\ui\hq_icon.png")
Example #3
0
 def update(self):
     if self.spawned:
         Ships.update(self)
         if not self.destroyed:
             # Movement
             self.y += self.speed
             self.rect.y = int(self.y)
             # Fire
             self.fire()
             # Check if reached bottom
             if self.rect.top == self.screen.get_rect().bottom:
                 GOL.get_go(Base).take_dmg(self.hp)
                 GOL.del_go(self)
     else:
         if self.spawn_timer <= 0:
             self.spawned = True
         else:
             self.spawn_timer -= 1
Example #4
0
def check_event():
    for event in pygame.event.get():
        # Exit check
        if event.type == pygame.QUIT:
            sys.exit()
        # Ship movement
        if GOL.get_go(Player):
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_d or event.key == pygame.K_RIGHT:
                    GOL.get_go(Player).moving_right = True
                if event.key == pygame.K_a or event.key == pygame.K_LEFT:
                    GOL.get_go(Player).moving_left = True
                if event.key == pygame.K_w or event.key == pygame.K_UP:
                    GOL.get_go(Player).moving_up = True
                if event.key == pygame.K_s or event.key == pygame.K_DOWN:
                    GOL.get_go(Player).moving_down = True
                if event.key == pygame.K_SPACE:
                    GOL.get_go(Player).firing = True
            elif event.type == pygame.KEYUP:
                if event.key == pygame.K_d or event.key == pygame.K_RIGHT:
                    GOL.get_go(Player).moving_right = False
                if event.key == pygame.K_a or event.key == pygame.K_LEFT:
                    GOL.get_go(Player).moving_left = False
                if event.key == pygame.K_w or event.key == pygame.K_UP:
                    GOL.get_go(Player).moving_up = False
                if event.key == pygame.K_s or event.key == pygame.K_DOWN:
                    GOL.get_go(Player).moving_down = False
                if event.key == pygame.K_SPACE:
                    GOL.get_go(Player).firing = False