Пример #1
0
def check_key_down(event, mario, platforms_top, screen, fireballs, viewport):
    # character jumps only when he is on the floor. this prevents him from doing multiple jumps while in the air
    if event.key == pygame.K_d:
        if not mario.finish:
            mario.jump(platforms_top)

    if event.key == pygame.K_f:
        if not mario.finish:
            if mario.status == 'fire':
                if len(fireballs) < 2:

                    pygame.mixer.Channel(3).play(
                        pygame.mixer.Sound('resources/sounds/fireball.wav'))

                    if mario.direction == "right":
                        mario.change_image(15)
                        fireball = Fireball(screen, mario)
                    elif mario.direction == 'left':
                        mario.change_image(16)
                        fireball = Fireball(screen, mario)

                    fireballs.add(fireball)
                    viewport.add(fireballs)

    if event.key == pygame.K_q:
        sys.exit()
Пример #2
0
    def __init__(self, settings, model, agentName, layer, agentManager, uniqInMap=True):
        super(Wizard, self).__init__(settings, model, agentName, layer, uniqInMap)
        self.state = _STATE_NONE
        self.waypoints = ((67, 80), (75, 44))
        self.waypoint_counter = 0
        self.agentManager = agentManager
        self.hero = self.layer.getInstance('PC')
        self.isActive = 0
        self.lastFireballUsed = 0
        self.fireballs = []
        for i in range(1, 5):
            fireball = Fireball(settings, model, 'NPC:fireball:0{}'.format(i), layer)
            fireball.start()
            self.fireballs.append(fireball)
        self.health = 100
        self.magic = 100
        self.layer = layer
        
        self.SPEED = 3 * float(self.settings.get("rio", "TestAgentSpeed"))
        self.SPELL_COST = 15

        self.t = Timer(1, self.addMagic)
        self.t.start()

        self.onDestroy = False
Пример #3
0
 def throw_fireball(self, screen, settings, fireball_group, map_group):
     if self.facing_left:
         f = Fireball(screen, settings, self.rect.left, self.rect.centery)
         f.facing_left = True
         f.add(map_group, fireball_group)
     else:
         f = Fireball(screen, settings, self.rect.right, self.rect.centery)
         f.facing_left = False
         f.add(map_group, fireball_group)
     self.fireball = False
Пример #4
0
 def blitme_throwfire(self, stats):
     if stats.mario_facing_left:
         self.image = pygame.image.load('images/FireMario/14.png')
         self.screen.blit(self.image, self.rect)
     if stats.mario_facing_right:
         self.image = pygame.image.load('images/FireMario/15.png')
         self.screen.blit(self.image, self.rect)
     pygame.display.flip()
     fireball = Fireball(stats, self)
     fireball.bounce(stats, self)
     sleep(.04)
Пример #5
0
Файл: game.py Проект: Platash/UJ
 def check_collision_demon(self):
     if self.attack_my.isExploding:
         if pow(self.attack_my.current_point[0] - (self.demon.current_point[0] + self.demon.w/2), 2) + \
                        pow(self.attack_my.current_point[1] - (self.demon.current_point[1] + self.demon.h/2 ), 2) > \
                 pow(self.attack_my.current_r, 2):
             self.points += 1
             fireball = Fireball(self.demon.current_point, self.demon.speed_vector, [255, 0, 0])
             fireball.explode()
             self.fireballs.append(fireball)
             self.demon.init()
             return
Пример #6
0
    def emit(self):
        '''Protocol to emit a new FireBall'''
        Direction = random.randint(0, 1)
        fireball = Fireball(self.posX, self.posY, 1 - 2 * Direction)

        self.Fireballs.append(fireball)
        self.times = 0
Пример #7
0
    def castSpell(self):
        if self._attackCounter > 0:
            return

        if self.stats['mana'] < 7:
            return

        self.stats['mana'] -= 7  # Każdy czar kosztuje 7 many
        self._attackCounter = 40
        _modifier = (self.stats['intelligence'] * 67 +
                     self.stats['agility'] * 33) / 10000.0
        if self._spell & MAGIC_ICE:
            _id = 'hero_iceblast_' + str(random.randint(0, 1048576))
            _layer = self._map.getLayer('Missiles')
            _layer.add(
                _id,
                Iceblast(self._map, _layer, _id, self._direction, self._pos,
                         _modifier))

        elif self._spell & MAGIC_FIRE:
            _id = 'hero_fireball_' + str(random.randint(0, 1048576))
            _layer = self._map.getLayer('Missiles')
            _layer.add(
                _id,
                Fireball(self._map, _layer, _id, self._direction, self._pos,
                         _modifier))

        elif self._spell & MAGIC_HEAL:
            _id = 'hero_heal_' + str(random.randint(0, 1048576))
            _layer = self._map.getLayer('Missiles')
            _layer.add(
                _id,
                Heal(self._map, _layer, _id, self._direction, self._pos,
                     _modifier))
Пример #8
0
 def __init__(self, fireball_num, pit_depth, colour, screen_x, screen_y,
              fireball_images):
     self.fireballs = []
     self.fireball_images = fireball_images
     for i in range(0, fireball_num):
         self.fireballs.append(Fireball(fireball_images, screen_x,
                                        screen_y))
     self.renderer = pygame.sprite.RenderPlain(self.fireballs)
Пример #9
0
 def test_vel_max(self):
     df = Fireball().fireballdf
     df['velocity'] = df['Velocity (km/s)']
     df_adj = df[np.abs(df.velocity -
                        df.velocity.mean()) <= (1.5 * df.velocity.std())]
     self.assertTrue(
         (df_adj.velocity.max() >
          1.5 * df_adj.velocity.std()))  # verify the equation works
Пример #10
0
    def test_blocking(self):
        for test in range(30):
            board = game.Board(0, 3, 1)
            pos = self.get_blocking(board)
            pos_x = pos[0]
            pos_y = pos[1]

            fireball = Fireball(pos_x - 1, pos_y, 1)
            #print pos, self.get_fireball(board)
            board.moveFireball(fireball)
Пример #11
0
 def CreateFireball(self, location, monsterIndex):
     if len(self.Fireballs) < len(self.Enemies) * 5:
         self.Fireballs.append(
             Fireball(self.IMAGES["fireballright"], (location[0], location[1] + 15), len(self.Fireballs),
                      2 + len(self.Enemies)/2, self.rng, self._dir))
         # Starts monster's animation
         self.Enemies[monsterIndex].setStopDuration(15)
         self.Enemies[monsterIndex].setPosition(
             (self.Enemies[monsterIndex].getPosition()[0], self.Enemies[monsterIndex].getPosition()[1] - 12))
         self.Enemies[monsterIndex].setCenter(self.Enemies[monsterIndex].getPosition())
         self.createGroups()  # We recreate the groups so the fireball is added
Пример #12
0
Файл: game.py Проект: Platash/UJ
    def check_collision_soul(self, x_f, y_f, w, h):
        if self.attack_my.isExploding:
            #print("attack exploding")
            if pow(self.attack_my.current_point[0] - (self.soul.current_point[0] + self.soul.w/2), 2) + \
                    pow(self.attack_my.current_point[1] - (self.soul.current_point[1] + self.soul.h/2), 2) > \
                    pow(self.attack_my.current_r, 2):
                self.points += 1
                fireball = Fireball(self.soul.current_point, self.soul.speed_vector, [255, 0, 0])
                fireball.explode()
                self.fireballs.append(fireball)
                self.soul.init()
                return

        if self.soul.direction == 0:
            #print("direction 0")
            if (self.soul.current_point[0] + self.soul.w) in range(x_f, x_f + w) and \
                    (self.soul.current_point[1] + self.soul.h) in range (y_f, y_f + h):
                if not self.soul.isTurning:
                    fireball_exp = Fireball(self.soul.current_point, self.soul.speed_vector, [255, 0, 0])
                    fireball_exp.explode()
                    self.fireballs.append(fireball_exp)

                    self.soul.speed_vector[0] = -self.soul.speed_vector[0]
                    self.hp -= 2
                    self.soul.isTurning = True

        else:
            #print("direction 1")
            if self.soul.current_point[0] in range(x_f, x_f + w) and \
                    self.soul.current_point[1] + self.soul.h in range(y_f, y_f + h):
                if not self.soul.isTurning:
                    fireball_exp = Fireball(self.soul.current_point, self.soul.speed_vector, [255, 0, 0])
                    fireball_exp.explode()
                    self.fireballs.append(fireball_exp)

                    self.soul.speed_vector[0] = -self.soul.speed_vector[0]
                    self.hp -= 2
                    self.soul.isTurning = True
Пример #13
0
    def moveFireball(self, Fireball):
        '''Controls Movement Of Fireball'''

        prevX = Fireball.posX
        prevY = Fireball.posY

        newX = Fireball.posX
        newY = Fireball.posY + Fireball.dir

        rand = random.randint(0, 1)

        if self.checkBlocking(newX, newY) or self.checkFireball(newX, newY):
            print "YAY"
            if rand:
                Fireball.changeDir()
            return Fireball

        if self.board[newX + 1][newY] == GENERICCHAR:
            while self.board[newX + 1][newY] == GENERICCHAR:
                newX += 1
            if rand:
                Fireball.changeDir()

        if self.board[newX + 1][newY] == WALLCHAR and newX + 2 < ROWS:
            if self.board[newX + 2][newY] == STAIRCHAR:
                newX += 1
                if rand:
                    Fireball.changeDir()
            while self.board[newX + 1][newY] != WALLCHAR:
                newX += 1

        self.board[prevX][prevY] = self.abc[self.orign[prevX][prevY]]
        if newX == ROWS - 2 and newY == 1:
            return None

        if self.checkPlayer(prevX, prevY) or self.checkPlayer(newX, newY):
            self.Player.dies()

        self.board[newX][newY] = FIREBALLCHAR

        Fireball.setPos(newX, newY)
        return Fireball
Пример #14
0
    def moveFireball(self, Fireball):
        '''Controls Movement Of Fireball'''

        prevX = Fireball.posX
        prevY = Fireball.posY

        newX = Fireball.posX
        newY = Fireball.posY + Fireball.dir

        rand = random.randint(0, 1)

        if self.checkBlocking(newX, newY) or self.checkFireball(newX, newY):
            print "YAY"
            if rand:
                Fireball.changeDir()
            return Fireball

        if self.board[newX + 1][newY] == GENERICCHAR:
            while self.board[newX + 1][newY] == GENERICCHAR:
                newX += 1
            if rand:
                Fireball.changeDir()

        if self.board[newX + 1][newY] == WALLCHAR and newX + 2 < ROWS:
            if self.board[newX + 2][newY] == STAIRCHAR:
                newX += 1
                if rand:
                    Fireball.changeDir()
            while self.board[newX + 1][newY] != WALLCHAR:
                newX += 1

        self.board[prevX][prevY] = self.abc[self.orign[prevX][prevY]]
        if newX == ROWS - 2 and newY == 1:
            return None

        if self.checkPlayer(prevX, prevY) or self.checkPlayer(newX, newY):
            self.Player.dies()

        self.board[newX][newY] = FIREBALLCHAR

        Fireball.setPos(newX, newY)
        return Fireball
Пример #15
0
    def test_gravityfall(self):
        for test in range(30):
            board = game.Board(0, 3, 1)
            pos = self.get_genericchar(board)
            pos_x = pos[0]
            pos_y = pos[1]

            fireball = Fireball(pos_x - 1, pos_y, 1)
            board.moveFireball(fireball)

            new = self.get_fireball(board)
            if not new:
                continue

            new_x = new[0]
            new_y = new[1]

            assert pos_y == new_y - 1
            assert board.board[new_x + 1][new_y] != game.GENERICCHAR
Пример #16
0
def check_keydown_events(event, ai_settings, screen, dragon, fireballs):
    '''Reaction for pressing the button.'''
    if event.key == pygame.K_UP:
        dragon.moving_up = True
    elif event.key == pygame.K_DOWN:
        dragon.moving_down = True
    elif event.key == pygame.K_RIGHT:
        dragon.moving_right = True
    elif event.key == pygame.K_LEFT:
        dragon.moving_left = True

    elif event.key == pygame.K_SPACE:
        #Creating new fireball and adding it to the group
        if (len(fireballs)
            ) < ai_settings.fireballs_allowed and dragon.orient == 1:
            new_fireball = Fireball(ai_settings, screen, dragon)
            fireballs.add(new_fireball)

    elif event.key == pygame.K_q:
        sys.exit()
Пример #17
0
    def _punch(self):
        """Atakuje czarem ognia lub lodu."""

        if random.randint(
                1,
                2) == 1 and (not random.randint(0, 8)
                             or utils.distance(self._grid[:2],
                                               self._target.getGrid()[:2]) > 1
                             ):  # ogniem najlepiej wtedy gdy cel jest daleko
            _id = 'mage_fireball_' + str(random.randint(0, 1048576))
            _layer = self._map.getLayer('Missiles')
            _layer.add(
                _id,
                Fireball(self._map, _layer, _id, self._direction, self._pos))

        else:
            _id = 'mage_iceblast_' + str(random.randint(0, 1048576))
            _layer = self._map.getLayer('Missiles')
            _layer.add(
                _id,
                Iceblast(self._map, _layer, _id, self._direction, self._pos))
Пример #18
0
    def FireballMotion(self):
        """Controls the occurrence and speed of fireballs"""

        if self.__cnt_fireballs == 150:
            for donkey in self.__donkeys:
                pos = donkey.getPosRight()
                if self.__board.getCharAt(pos) != "H":
                    self.__fireballs.append(Fireball(self.__board, pos, self.__player))
                    self.__fire_affect.play()
            self.__cnt_fireballs = 0
        else:   
            self.__cnt_fireballs += 1

        if self.__mov_fireballs == 1 or self.__cnt_fireballs == 0:
            for ball in self.__fireballs:
                if ball.getDeadFlag() == False:
                    ball.Motion(self.__board, self.__player)
                else:
                    self.__fireballs.remove(ball)
            self.__mov_fireballs = 0
        else:
            self.__mov_fireballs += 1
Пример #19
0
def main():
    pygame.init()
 
    size = [SCREEN_WIDTH, SCREEN_HEIGHT]
    screen = pygame.display.set_mode(size)
 
    pygame.display.set_caption("Donkey Kong")
    
    
    score=0
                
    player = Player()
    player.score = score             
    current_level = Level_num(player)

    don = Donkey()
    don.level = current_level
    current_level.donkey.add(don)

    k = 845
    for i in range(1):
        for j in range(10):
            fireball = Fireball()
            fireball.rect.x = random.randint(300,800)
            fireball.rect.y = SCREEN_HEIGHT - k
            fireball.level = current_level
            fireball.player = player
            fireball.donkey = don
            current_level.fireball_list.add(fireball)
            k-=80

    k=845
    for i in range(10):
        for j in range(2):
            coin = Coins()
            coin.rect.x = random.randint(300,800)
            coin.rect.y = SCREEN_HEIGHT - random.randint(k,k+50)
            current_level.coins_list.add(coin)
        k-=80

    q = Queen()
    current_level.queen.add(q)

    active_sprite_list = pygame.sprite.Group()

    player.level = current_level


    player.rect.x = 340
    player.rect.y = SCREEN_HEIGHT - 2*player.rect.height
    active_sprite_list.add(player)


    done = False

    clock = pygame.time.Clock()

    while not done:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                done = True

            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_a:
                    player.go_left()
                if event.key == pygame.K_d:
                    player.go_right()
                if event.key == pygame.K_w:
                    player.go_down()
                if event.key == pygame.K_s:
                    player.go_up()
                if event.key == pygame.K_SPACE:
                    player.jump()

            if event.type == pygame.KEYUP:
                if event.key == pygame.K_a and player.change_x < 0:
                    player.stop()
                if event.key == pygame.K_d and player.change_x > 0:
                    player.stop()
                if event.key == pygame.K_w and player.change_y < 0:
                    player.stop()
                if event.key == pygame.K_s and player.change_y > 0:
                    player.stop()
        
        
            # if not player.chances:
            #     game = False
            #     break 
        active_sprite_list.update()

        current_level.update()

        #fireball_group.update()

        if player.rect.right > SCREEN_WIDTH:
            player.rect.right = SCREEN_WIDTH

        if player.rect.left < 0:
            player.rect.left = 0
        
        current_level.draw(screen)
        active_sprite_list.draw(screen)
        clock.tick(60)

        pygame.display.flip()
Пример #20
0
		finally:
			termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
		return ch
class _GetchWindows:
    def __init__(self):
            import msvcrt

    def __call__(self):
        import msvcrt
        return msvcrt.getch()

screen=set_screen()

player = Player(28,1)
player.arr = screen.arr
fireballs = Fireball()
fireballs.arr = player.arr
fireballs.pposx = player.posx
fireballs.pposy = player.posy
fireballs.life = player.life

don = Donkey()
don.arr = player.arr
don.set_pos(7,1)
quen = Queen()
quen.arr = player.arr
quen.set_pos(2,17)
for i in range(30):
	for j in range(45):
		sys.stdout.write(screen.arr[i][j])
	print ''	
def mario_move(mario, settings, screen, fireball):
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            sys.exit()
        elif event.type == pygame.KEYDOWN:
            if event.key == pygame.K_RIGHT:
                # mario.is_idle = False
                mario.is_facing_left = False
                mario.moving_left = False
                mario.is_facing_right = True
                mario.moving_right = True
                mario.go_down = False
            elif event.key == pygame.K_LEFT:
                # mario.is_idle = False
                mario.is_facing_right = False
                mario.moving_right = False
                mario.is_facing_left = True
                mario.moving_left = True
                mario.go_down = False
            elif event.key == pygame.K_SPACE:
                # check_mario_ground(settings, screen, mario, ground)
                #  mario.is_idle = False
                if not mario.falling:
                    mario.moving_left = False
                    mario.moving_right = False
                    mario.jump = True
                    mario.go_down = False
                    mario.last_y_position = mario.rect.y

                # if not mario.mario_bounce:
                #     mario.last_y_position = mario.rect.y

                if event.key == pygame.K_RIGHT:
                    mario.moving_left = False
                    mario.moving_right = True
                    mario.jump = True
                    mario.go_down = False
            elif event.key == pygame.K_LSHIFT or pygame.K_RSHIFT:
                mario.sprint = True
            if event.key == pygame.K_DOWN:
                if mario.is_big:
                    # mario.is_idle = False
                    mario.moving_right = False
                    mario.moving_left = False
                    mario.crouch = True
                elif not mario.is_big:
                    mario.moving_right = False
                    mario.moving_left = False
                    mario.jump = False
                    mario.crouch = False
            if mario.is_fire:
                if event.key == pygame.K_LSHIFT or pygame.K_RSHIFT:
                    mario.throw_fire = True
                    if len(fireball) < settings.fireballs_allowed:
                        new_fireball = Fireball(settings, screen, mario)
                        fireball.add(new_fireball)
            elif event.key == pygame.K_q:
                sys.exit()
        elif event.type == pygame.KEYUP:
            if event.key == pygame.K_RIGHT:
                # mario.is_idle = True
                mario.moving_right = False
            elif event.key == pygame.K_LEFT:
                # mario.is_idle = True
                mario.moving_left = False
            elif event.key == pygame.K_SPACE:
                # mario.is_idle = True
                mario.jump = False
                mario.falling = True
            elif event.key == pygame.K_LSHIFT or pygame.K_RSHIFT:
                mario.sprint = False
            if mario.is_fire:
                if event.key == pygame.K_LSHIFT or pygame.K_RSHIFT:
                    mario.throw_fire = False
            if mario.is_big:
                if event.key == pygame.K_DOWN:
                    mario.crouch = False
Пример #22
0
    def animate(self, dt):
        if pygame.time.get_ticks() - self.time >= self.tmp:
            if self.jump_animation:
                if self.key == self.jump_sheet.get_nb_sprites() - 1:
                    self.jump()
                elif self.moving_right:
                    self.key += 1
                    self.image = self.jump_right_sprites[self.key][0]
                else:
                    self.key += 1
                    self.image = self.jump_left_sprites[self.key][0]
                self.tmp = self.jump_left_sprites[self.key][1]
            elif self.ulti:
                if self.key == self.ultimate_sheet.get_nb_sprites() - 1:
                    self.ulti = False
                    self.change_animation()
                elif self.key == self.ultimate_sheet.get_nb_sprites() - 2:
                    laser = Laser_Beam(self.W, self.H, self.ulti_pos)
                    self.laser_beam.add(laser)
                    self.key += 1
                    self.ulti_prev_surf_alpha = 5
                    self.ulti_prev_surf.fill(
                        (0, 0, 0, self.ulti_prev_surf_alpha))
                    self.ulti_temp_time = pygame.time.get_ticks()
                    self.ulti_time_seconds = 5
                else:
                    self.ulti_prev_surf_alpha += 15
                    self.ulti_prev_surf.fill(
                        (0, 0, 0, self.ulti_prev_surf_alpha))
                    if self.moving_right:
                        self.key += 1
                        self.image = self.ultimate_right_sprites[self.key][0]
                    else:
                        self.key += 1
                        self.image = self.ultimate_left_sprites[self.key][0]
                self.tmp = self.ultimate_left_sprites[self.key][1]
            elif self.spelling:
                if self.key == self.spell_sheet.get_nb_sprites() - 1:
                    self.spelling = False
                    if self.moving_right:
                        fireball = Fireball(
                            (self.rect.right, self.rect.centery), 1)
                    else:
                        fireball = Fireball(
                            (self.rect.left, self.rect.centery), -1)
                    fireball.add(self.fireballs)
                    self.change_animation()
                elif self.moving_right:
                    self.key += 1
                    self.image = self.spell_right_sprites[self.key][0]
                else:
                    self.key += 1
                    self.image = self.spell_left_sprites[self.key][0]
                self.tmp = self.spell_left_sprites[self.key][1]

            elif not self.moving:
                self.key = (self.key + 1) % self.idle_sheet.get_nb_sprites()
                self.tmp = self.idle_right_sprites[self.key][1]
                if self.moving_right:
                    self.image = self.idle_right_sprites[self.key][0]
                else:
                    self.image = self.idle_left_sprites[self.key][0]
            else:
                self.key = (self.key + 1) % self.move_sheet.get_nb_sprites()
                self.tmp = self.move_right_sprites[self.key][1]
                if not self.moving_right:
                    self.image = self.move_left_sprites[self.key][0]

                else:
                    self.image = self.move_right_sprites[self.key][0]
            x, bottom = self.rect.x, self.rect.bottom
            self.rect = self.image.get_rect(x=x, bottom=bottom)
            self.time = pygame.time.get_ticks()
Пример #23
0
def main(turns, score):
    pygame.init()
    pygame.display.set_caption('Donkey Kong')
    swidth = 800
    sheight = 620
    clock = pygame.time.Clock()
    disp = pygame.display.set_mode([swidth, sheight], 0, 32)

    BLACK = (0, 0, 0)

    class Gameline(pygame.sprite.Sprite):
        def __init__(self, color, length):

            pygame.sprite.Sprite.__init__(self)
            self.image = pygame.Surface([length, 4])
            self.image.fill(color)
            self.rect = self.image.get_rect()

    class Vertline(pygame.sprite.Sprite):
        def __init__(self):

            pygame.sprite.Sprite.__init__(self)
            self.image = pygame.Surface([4, 45])
            self.image.fill(BLACK)
            self.rect = self.image.get_rect()
            self.rect.y = 10

    line1 = Vertline()
    line1.rect.x = 250
    line2 = Vertline()
    line2.rect.x = 450
    list_obj = pygame.sprite.Group()
    pl_list = pygame.sprite.Group()
    coin_list = pygame.sprite.Group()
    ladder_list = pygame.sprite.Group()
    fire_list = pygame.sprite.Group()
    gor_list = pygame.sprite.Group()
    heart = pygame.sprite.Group()
    ps_list = pygame.sprite.Group()
    list_obj.add(line1)
    list_obj.add(line2)

    for i in range(3):
        line = Gameline(BLACK, 600)
        line.rect.x = -10
        line.rect.y = 100 + i * 200
        list_obj.add(line)
    for i in range(2):
        line = Gameline(BLACK, 600)
        line.rect.x = 230
        line.rect.y = 200 + i * 200
        list_obj.add(line)

    line = Gameline(BLACK, 810)
    line.rect.x = -10
    line.rect.y = 600
    list_obj.add(line)

    line = Gameline(BLACK, 200)
    line.rect.x = 250
    line.rect.y = 50
    list_obj.add(line)

    mario = Player()
    pl_list.add(mario)

    gor = Gorilla()
    gor_list.add(gor)

    ps = Princess()
    ps_list.add(ps)

    ladxy = [520, 298, 550, 498, 300, 398, 300, 198, 540, 98]
    for i in range(0, 10, 2):
        lad = Ladders(ladxy[i], ladxy[i + 1])
        ladder_list.add(lad)

    for i in range(12):
        c = Coins()
        c.cd(1)
        coin_list.add(c)
    for i in range(12):
        c = Coins()
        c.cd(2)
        coin_list.add(c)
    c = 50

    while True:
        heart.empty()
        life(turns, heart)

        font = pygame.font.Font(None, 36)
        text = font.render("Score = " + str(score), 1, (10, 10, 10))
        for event in pygame.event.get():
            if event.type == QUIT:
                pygame.quit()
                sys.exit()
        s = pygame.sprite.groupcollide(pl_list, coin_list, False, True)
        score += (len(s) * 5)
        if score >= 50:
            list_obj.remove(line1)
            list_obj.remove(line2)
        flag = pygame.sprite.groupcollide(pl_list, ladder_list, False, False)
        if len(flag) > 0:
            for i in ladder_list:
                if flag.values()[0][0] == i:
                    i.move(mario)
        else:
            mario.move()
            mario.rect.y = mario.checkmove(list_obj)
        keys = pygame.key.get_pressed()
        if keys[K_q]:
            pygame.quit()
            sys.exit()
        if keys[K_SPACE]:
            flag = 1
            v = -50
        if flag == 1:
            mario.rect.y += v
            v += 10
            if v == 40:
                flag = 0
        if c % 100 == 0:
            f = Fireball(gor, fire_list)
            c = 850
        else:
            c += 1
        for qw in fire_list:
            ladcol = pygame.sprite.spritecollideany(qw,
                                                    ladder_list,
                                                    collided=None)
            plcol = pygame.sprite.spritecollideany(qw, pl_list, collided=None)
            gorcol = pygame.sprite.groupcollide(gor_list, pl_list, False,
                                                False)
            """if ladcol != None :
					r=random.randrange(0,2)
					print r
					if r == 1 :
						qw.state = 1
						qw.h += 20
						if qw.state == 1 :
							qw.rect.y += qw.h
							qw.h += 1
						if qw.h == 23 :
							qw.state = 0
							qw.h = 0
				else :	
				"""
            if plcol != None or len(gorcol) < 0:
                turns -= 1
                if turns == 0:
                    font = pygame.font.Font(None, 72)
                    text = font.render("GAME OVER ", 1, (10, 10, 10))
                    disp.blit(text, (150, 300))
                    pygame.display.update()
                    time.sleep(2)
                    pygame.quit()
                    sys.exit()
                main(turns, score)
            qw.move(pl_list, list_obj, fire_list)
        gor.move(500, 20)
        ps.move(410, 260)
        if mario.rect.x >= 260 and mario.rect.x <= 400 and mario.rect.y >= 00 and mario.rect.y <= 30:
            font = pygame.font.Font(None, 72)
            text = font.render("YOU WIN SCORE = " + str(score), 1,
                               (10, 10, 10))
            disp.blit(text, (150, 300))
            pygame.display.update()
            time.sleep(2)
            pygame.quit()
            sys.exit()
        bgimg = pygame.image.load('background.png')
        #bgimg.rect = pygame.get_rect()
        disp.blit(bgimg, (0, 0))
        disp.blit(text, (650, 70))
        pl_list.draw(disp)
        coin_list.draw(disp)
        ladder_list.draw(disp)
        heart.draw(disp)
        gor_list.draw(disp)
        list_obj.draw(disp)
        fire_list.draw(disp)
        ps_list.draw(disp)
        pygame.display.update()
        clock.tick(20)
Пример #24
0
 def test_fb(self):
     df = Fireball().fireballdf
     self.assertTrue(isinstance(df, pd.DataFrame))
Пример #25
0
 def fire_fireball(self):
     """Create a new fireball and add it to the fireballs group."""
     if len(self.fireballs) < self.settings.fireballs_allowed:
         new_fireball = Fireball(self)
         self.fireballs.add(new_fireball)
Пример #26
0
 def test_size(self):
     df = Fireball().fireballdf
     self.assertTrue(len(df) == 822)
Пример #27
0
 def test_header(self):
     df = Fireball().fireballdf
     head = Fireball().get_header()
     self.assertTrue(len(head) <= 5)
Пример #28
0
 def fire(self):
     if self.facing_right:
         ball = Fireball(self.screen, self, 5)
     else:
         ball = Fireball(self.screen, self, -5)
     self.fireballs.add(ball)
Пример #29
0
 def addFireball(self):
     self.fireballs.append(
         Fireball(self.fireball_images, self.fireballs[0].screen_x,
                  self.fireballs[0].screen_y))
     self.renderer = pygame.sprite.RenderPlain(self.fireballs)
Пример #30
0
def main():
    pygame.init()

    screen = pygame.display.set_mode((WIDTH, HEIGHT))
    pygame.display.set_caption("DonkeyKong")

    # Initialize level

    lifes = 3
    score = 0
    COINS = 20
    times = 0

    done = False
    donkey = Donkey()
    donkey_group = pygame.sprite.GroupSingle(donkey.makeDonkey())

    hero = Player()
    hero_group = pygame.sprite.GroupSingle(hero.makePlayer(lifes))

    fireball_group = pygame.sprite.OrderedUpdates()
    Fireballs = []

    fireballS = Fireball()
    fireSource = pygame.sprite.GroupSingle(fireballS.makeFireSource())

    coinGroup = comLevels.genCoins(COINS)

    pygame.key.set_repeat(8, 10)
    FIRETIME = pygame.USEREVENT + 1
    pygame.time.set_timer(pygame.USEREVENT, 150)
    pygame.time.set_timer(FIRETIME, 2000)

    while done == False:

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                done = True
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_q or event.key == pygame.K_ESCAPE:
                    done = True
                elif event.key == pygame.K_SPACE:
                    hero.setState("JUMPING")
                elif event.key == pygame.K_w or event.key == pygame.K_UP:
                    hero.moveUP(screen, hero_group, level.getStairGroup())
                elif event.key == pygame.K_s or event.key == pygame.K_DOWN:
                    hero.moveDown(screen, hero_group, level.getStairGroup())
                elif event.key == pygame.K_a or event.key == pygame.K_LEFT:
                    if hero.getState == ("JUMPING"):
                        hero.allowLeft(True)
                    hero.moveLeft(screen)
                elif event.key == pygame.K_d or event.key == pygame.K_RIGHT:
                    if hero.getState() == "JUMPING":
                        hero.allowRight(True)
                    hero.moveRigth(screen)
                elif event.key == pygame.K_f:
                    for ball in Fireballs:
                        ball.setSpeedP()
                elif event.key == pygame.K_b:
                    for ball in Fireballs:
                        ball.setSpeedN()
            if event.type == pygame.USEREVENT:
                donkey.move()
                donkey.chgSpeed()
            if event.type == FIRETIME:
                fireball = Fireball()
                fireball_group.add(fireball.makeFireball())
                Fireballs.append(fireball)
            for ball in Fireballs:
                ball.moveBalls()
                ball.gravity()
                ball.onBarless()
                ball.killFireball()

        collDon = pygame.sprite.groupcollide(donkey_group, hero_group, False,
                                             True)
        collFire = pygame.sprite.groupcollide(fireball_group, hero_group,
                                              False, True)
        if len(collDon) > 0 or len(collFire) > 0:
            if score >= 25:
                score -= 25
            else:
                score = 0
            print "player: D " + str(hero.getPosition("D"))
            print "player: L " + str(hero.getPosition("L"))
            print "donkey: D " + str(donkey.getPosition("D"))
            print "donkey: L " + str(donkey.getPosition("L"))
            lifes = hero.playerDied(screen)
            pygame.display.update()
            hero_group = pygame.sprite.GroupSingle(hero.makePlayer(lifes))
            try:
                time.sleep(3)
            except:
                print "key"

        collCoin = pygame.sprite.groupcollide(coinGroup, hero_group, True,
                                              False)
        if len(collCoin) > 0:
            score += 20

        if hero.getState() == "JUMPING":
            hero.printPos()
            print "--------"
        times = hero.jump(times)
        if times == 4:
            hero.setState("STANDING")
            hero.allowLeft(False)
            hero.allowRight(False)
            times = 0
        level.selectLevel(screen, 1)
        coinGroup.draw(screen)
        hero_group.draw(screen)
        fireSource.draw(screen)
        fireball_group.draw(screen)
        donkey_group.draw(screen)
        comLevels.updateLife(lifes, screen)
        comLevels.updateScore(score, screen)
        pygame.display.update()

        if lifes == 0:
            break

    pygame.quit()
    sys.exit()
Пример #31
0
 def release_fireball(self):
     if len(self.fireballs) < self.settings.fireballs_allowed:
         new_fireball = Fireball(self)
         self.fireballs.add(new_fireball)
Пример #32
0
def main():

    l = 1  # variable to store the present level

    score = 0

    #initialising pygame

    pygame.init()

    # declaring game objects for the first time

    size = [constants.SCREEN_WIDTH, constants.SCREEN_HEIGHT]
    screen = pygame.display.set_mode(size)

    pygame.display.set_caption("Donkey Kong")

    # declaring player object

    player = Player()

    # donkey object

    donkey = Donkey()

    donkey.rect.x = random.randrange(100, 280)
    donkey.rect.y = 89

    donkey_list = pygame.sprite.Group()

    donkey_list.add(donkey)

    # fireball instance

    fireball_list = pygame.sprite.Group()
    fireball = Fireball()
    fireball.rect.x = donkey.rect.x + 40
    fireball.rect.y = donkey.rect.y
    fireball_list.add(fireball)

    level_list = []
    level_list.append(level.Board(player))

    current_level_no = 0
    current_level = level_list[current_level_no]

    active_sprite_list = pygame.sprite.Group()
    player.level = current_level

    player.rect.x = 40
    player.rect.y = constants.SCREEN_HEIGHT - player.rect.height

    active_sprite_list.add(player)
    active_sprite_list.add(donkey)

    done = False

    background_image = pygame.image.load("./images/background2.jpg").convert()
    background_image = pygame.transform.scale(background_image, [1000, 700])

    clock = pygame.time.Clock()

    restart = False

    # Main loop where all the updation takes place

    while not done:

        f = 0  # flag variable

        # to check which keys are pressed

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                done = True

            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_q:
                    done = True

            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_a:
                    player.go_left()
                if event.key == pygame.K_d:
                    player.go_right()
                if event.key == pygame.K_SPACE:
                    player.jump()
                if event.key == pygame.K_w and len(
                        pygame.sprite.spritecollide(
                            player, player.level.ladder_list, False)) > 0:
                    f = 1
                    player.go_up()
                if event.key == pygame.K_s and len(
                        pygame.sprite.spritecollide(
                            player, player.level.ladder_list, False)) > 0:
                    f = 1
                    player.go_down()

            if event.type == pygame.KEYUP:
                if event.key == pygame.K_a and player.change_x < 0:
                    player.stop()

                if event.key == pygame.K_d and player.change_x > 0:
                    player.stop()

                if event.key == pygame.K_w and len(
                        pygame.sprite.spritecollide(
                            player, player.level.ladder_list, False)) > 0:
                    player.stop2()
                if event.key == pygame.K_s and len(
                        pygame.sprite.spritecollide(
                            player, player.level.ladder_list, False)) > 0:
                    player.stop2()

        #checking for collisions

        if len(
                pygame.sprite.spritecollide(player, player.level.ladder_list,
                                            False)) > 0:
            f = 1

        if len(pygame.sprite.spritecollide(player, donkey_list, False)) > 0:
            done = True

        if len(pygame.sprite.spritecollide(player, fireball_list, False)) > 0:
            player.lives -= 1
            player.score -= 25
            player.reset()

        if player.lives == 0:
            done = True

        if len(
                pygame.sprite.spritecollide(player, player.level.queen_list,
                                            False)) > 0:
            restart = True

        ######### Restarts game when queen is rescued ##########

        if restart == True:

            l += 1

            score += player.score

            player = Player()

            donkey = Donkey()

            donkey.rect.x = random.randrange(100, 280)
            donkey.rect.y = 89

            donkey_list = pygame.sprite.Group()

            donkey_list.add(donkey)

            # fireball instance

            fireball_list = pygame.sprite.Group()
            fireball = Fireball()

            fireball.rect.x = donkey.rect.x + 40
            fireball.rect.y = donkey.rect.y
            fireball.speed = l
            fireball_list.add(fireball)

            level_list = []
            level_list.append(level.Board(player))

            current_level_no = 0
            current_level = level_list[current_level_no]

            active_sprite_list = pygame.sprite.Group()
            player.level = current_level

            player.rect.x = 40
            player.rect.y = constants.SCREEN_HEIGHT - player.rect.height

            active_sprite_list.add(player)
            active_sprite_list.add(donkey)

            player.score = score

            restart = False

        # updating all game objects

        fireball_list.update()
        active_sprite_list.update(f)
        current_level.update()

        if player.rect.right > constants.SCREEN_WIDTH:
            player.rect.right = constants.SCREEN_WIDTH

        if player.rect.left < 0:
            player.rect.left = 0

        screen.blit(background_image, [0, 0])

        # generating fireballs

        if donkey.count == 0:

            fireball = Fireball()

            p = getPosition(donkey)

            fireball.speed = l
            fireball.rect.x = p[0] + 40
            fireball.rect.y = p[1]
            fireball_list.add(fireball)

        for j in fireball_list:
            hit_platform = pygame.sprite.spritecollide(
                j, player.level.platform_list, False)

            if len(hit_platform) > 0:
                j.rect.bottom = hit_platform[0].rect.top

        if done:

            font = pygame.font.SysFont("serif", 25)
            text = font.render("Game Over :(  ,  Now we are going to exit",
                               True, constants.RED)
            center_x = (constants.SCREEN_WIDTH // 2) - (text.get_width() // 2)
            center_y = (constants.SCREEN_HEIGHT // 2) - (text.get_height() //
                                                         2)
            screen.blit(text, [center_x, center_y])

        ##########  Dispaying the game score, no of lives left and present Level   #############

        if not done:

            current_level.draw(screen)
            active_sprite_list.draw(screen)
            fireball_list.draw(screen)

            font = pygame.font.SysFont("serif", 25)
            text = font.render("Game Score %s" % player.score, True,
                               constants.WHITE)
            center_x = 0
            center_y = (constants.SCREEN_HEIGHT - 25)
            screen.blit(text, [center_x, center_y])

            font = pygame.font.SysFont("serif", 25)
            text = font.render("Lives Left : %s" % player.lives, True,
                               constants.WHITE)
            center_x = 700
            center_y = (constants.SCREEN_HEIGHT - 25)
            screen.blit(text, [center_x, center_y])

            font = pygame.font.SysFont("serif", 25)
            text = font.render("LEVEL %s" % l, True, constants.WHITE)
            center_x = 850
            center_y = (constants.SCREEN_HEIGHT - 25)
            screen.blit(text, [center_x, center_y])

        clock.tick(60)

        pygame.display.update()

    pygame.quit()
Пример #33
0
def main():

    l = 1  # variable to store the present level
    
    score = 0

    #initialising pygame

    pygame.init()

    # declaring game objects for the first time
    
    size = [constants.SCREEN_WIDTH, constants.SCREEN_HEIGHT]
    screen = pygame.display.set_mode(size)

    pygame.display.set_caption("Donkey Kong")

    # declaring player object

    player = Player()

    # donkey object

    donkey = Donkey()

    donkey.rect.x = random.randrange(100,280)
    donkey.rect.y = 89

    donkey_list = pygame.sprite.Group()

    donkey_list.add(donkey)

    # fireball instance

    fireball_list = pygame.sprite.Group()
    fireball = Fireball()
    fireball.rect.x = donkey.rect.x + 40
    fireball.rect.y = donkey.rect.y
    fireball_list.add(fireball)


    level_list = []
    level_list.append(level.Board(player))

    current_level_no = 0
    current_level = level_list[current_level_no]

    active_sprite_list = pygame.sprite.Group()
    player.level = current_level


    player.rect.x = 40
    player.rect.y = constants.SCREEN_HEIGHT - player.rect.height

    active_sprite_list.add(player)
    active_sprite_list.add(donkey)

    done = False

    background_image = pygame.image.load("./images/background2.jpg").convert()
    background_image = pygame.transform.scale(background_image,[1000,700])


    clock = pygame.time.Clock()

    restart = False

    # Main loop where all the updation takes place

    while not done:

        f=0 # flag variable

        # to check which keys are pressed

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                done = True
            
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_q:
                    done = True

            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_a:
                    player.go_left()
                if event.key == pygame.K_d:
                    player.go_right()
                if event.key == pygame.K_SPACE:
                    player.jump()
                if event.key == pygame.K_w  and len(pygame.sprite.spritecollide(player, player.level.ladder_list, False))>0:
                    f =1
                    player.go_up()
                if event.key == pygame.K_s  and len(pygame.sprite.spritecollide(player, player.level.ladder_list, False))>0:
                    f =1
                    player.go_down()



            if event.type == pygame.KEYUP:
                if event.key == pygame.K_a and player.change_x < 0:
                    player.stop()
                
                if event.key == pygame.K_d and player.change_x > 0:
                    player.stop()

                if event.key == pygame.K_w and len(pygame.sprite.spritecollide(player, player.level.ladder_list, False))>0:
                    player.stop2()
                if event.key == pygame.K_s and len(pygame.sprite.spritecollide(player, player.level.ladder_list, False))>0:
                    player.stop2()
                    
        #checking for collisions


        if len(pygame.sprite.spritecollide(player, player.level.ladder_list, False))>0 :
            f=1
        
        if len(pygame.sprite.spritecollide(player, donkey_list, False))>0:
            done = True

        if len(pygame.sprite.spritecollide(player, fireball_list, False))>0:
            player.lives -=1
            player.score -=25
            player.reset()

        if player.lives == 0:
            done = True

        if len(pygame.sprite.spritecollide(player,player.level.queen_list, False))>0:
            restart = True

        ######### Restarts game when queen is rescued ##########
        
        
        if restart ==  True:


            l +=1
            
            score+=player.score
            
            player = Player()


            donkey = Donkey()

            donkey.rect.x = random.randrange(100,280)
            donkey.rect.y = 89

            donkey_list = pygame.sprite.Group()

            donkey_list.add(donkey)

        # fireball instance

            fireball_list = pygame.sprite.Group()
            fireball = Fireball()

            fireball.rect.x = donkey.rect.x + 40
            fireball.rect.y = donkey.rect.y
            fireball.speed = l
            fireball_list.add(fireball)


            level_list = []
            level_list.append(level.Board(player))

            current_level_no = 0
            current_level = level_list[current_level_no]

            active_sprite_list = pygame.sprite.Group()
            player.level = current_level


            player.rect.x = 40
            player.rect.y = constants.SCREEN_HEIGHT - player.rect.height

            active_sprite_list.add(player)
            active_sprite_list.add(donkey)

            player.score = score

            restart = False

            
        # updating all game objects

        fireball_list.update()
        active_sprite_list.update(f)
        current_level.update()

        if player.rect.right > constants.SCREEN_WIDTH:
            player.rect.right = constants.SCREEN_WIDTH

        if player.rect.left < 0:
            player.rect.left = 0

        screen.blit(background_image, [0,0])

        # generating fireballs

        if donkey.count == 0:

            fireball = Fireball()
            
            p = getPosition(donkey)

            fireball.speed = l
            fireball.rect.x = p[0] + 40
            fireball.rect.y = p[1]
            fireball_list.add(fireball)

        
        for j in fireball_list:    
            hit_platform = pygame.sprite.spritecollide(j,player.level.platform_list, False)

            if len(hit_platform)>0:
                j.rect.bottom = hit_platform[0].rect.top

        if done:

            font = pygame.font.SysFont("serif", 25) 
            text = font.render("Game Over :(  ,  Now we are going to exit", True, constants.RED)
            center_x = (constants.SCREEN_WIDTH // 2) - (text.get_width() // 2)
            center_y = (constants.SCREEN_HEIGHT // 2) - (text.get_height() // 2)
            screen.blit(text, [center_x, center_y])

        ##########  Dispaying the game score, no of lives left and present Level   #############
                                                                                             
        if not done:
        
            current_level.draw(screen)
            active_sprite_list.draw(screen)
            fireball_list.draw(screen)


            font = pygame.font.SysFont("serif", 25)
            text = font.render("Game Score %s" %player.score, True, constants.WHITE)
            center_x = 0
            center_y = (constants.SCREEN_HEIGHT -25)
            screen.blit(text, [center_x, center_y])


            font = pygame.font.SysFont("serif", 25)
            text = font.render("Lives Left : %s" %player.lives, True, constants.WHITE)
            center_x = 700
            center_y = (constants.SCREEN_HEIGHT -25)
            screen.blit(text, [center_x, center_y])


            font = pygame.font.SysFont("serif", 25)
            text = font.render("LEVEL %s" %l, True, constants.WHITE)
            center_x = 850
            center_y = (constants.SCREEN_HEIGHT -25)
            screen.blit(text, [center_x, center_y])

        clock.tick(60)

        pygame.display.update()

    pygame.quit()
Пример #34
0
 def spawn_fireball(self, x, y, move_direction):
     self.projectiles.append(Fireball(x, y, move_direction))
Пример #35
0
 def shoot(self, target):
     self.cooldown = self.cooldown_max
     return Fireball(self.pos, target)
Пример #36
0
def main():
    pygame.init()

    screen = pygame.display.set_mode((WIDTH,HEIGHT))
    pygame.display.set_caption("DonkeyKong")
    
    # Initialize level
    
    lifes = 3
    score = 0
    COINS = 20
    times = 0

    done = False
    donkey = Donkey()
    donkey_group = pygame.sprite.GroupSingle(donkey.makeDonkey())

    hero = Player()
    hero_group = pygame.sprite.GroupSingle(hero.makePlayer(lifes))

    fireball_group =  pygame.sprite.OrderedUpdates()
    Fireballs = []
    
    fireballS = Fireball()
    fireSource = pygame.sprite.GroupSingle(fireballS.makeFireSource())
    
    coinGroup = comLevels.genCoins(COINS)

    pygame.key.set_repeat(8,10)
    FIRETIME = pygame.USEREVENT + 1
    pygame.time.set_timer(pygame.USEREVENT, 150)
    pygame.time.set_timer(FIRETIME, 2000)

    while done == False :

        for event in pygame.event.get() :
            if event.type == pygame.QUIT :
                done = True
            if event.type == pygame.KEYDOWN :
                if event.key == pygame.K_q or event.key == pygame.K_ESCAPE:
                    done = True
                elif event.key == pygame.K_SPACE :
                    hero.setState("JUMPING")
                elif event.key == pygame.K_w or event.key == pygame.K_UP :
                    hero.moveUP(screen,hero_group,level.getStairGroup())
                elif event.key == pygame.K_s or event.key == pygame.K_DOWN :
                    hero.moveDown(screen,hero_group,level.getStairGroup())
                elif event.key == pygame.K_a or event.key == pygame.K_LEFT :
                    if hero.getState == ("JUMPING") :
                        hero.allowLeft(True)
                    hero.moveLeft(screen)
                elif event.key == pygame.K_d or event.key == pygame.K_RIGHT :
                    if hero.getState() == "JUMPING" :
                        hero.allowRight(True)
                    hero.moveRigth(screen)
                elif event.key == pygame.K_f :
                    for ball in Fireballs :
                        ball.setSpeedP()
                elif event.key == pygame.K_b :
                    for ball in Fireballs :
                        ball.setSpeedN()
            if event.type == pygame.USEREVENT :
                donkey.move()
                donkey.chgSpeed()
            if event.type == FIRETIME :
                fireball = Fireball()
                fireball_group.add(fireball.makeFireball())            
                Fireballs.append(fireball)
            for ball in Fireballs :
                ball.moveBalls()
                ball.gravity()
                ball.onBarless()
                ball.killFireball()

        collDon = pygame.sprite.groupcollide(donkey_group,hero_group,False,True)
        collFire = pygame.sprite.groupcollide(fireball_group,hero_group,False,True)
        if len(collDon) > 0 or len(collFire) > 0 :
            if score >= 25 :
                score -= 25
            else :
                score = 0
            print "player: D " + str(hero.getPosition("D"))
            print "player: L " + str(hero.getPosition("L"))
            print "donkey: D " + str(donkey.getPosition("D"))
            print "donkey: L " + str(donkey.getPosition("L"))
            lifes = hero.playerDied(screen)
            pygame.display.update()
            hero_group = pygame.sprite.GroupSingle(hero.makePlayer(lifes))
            try:
                time.sleep(3)
            except :
                print "key"
        
        collCoin = pygame.sprite.groupcollide(coinGroup,hero_group,True,False)
        if len(collCoin) > 0 :
            score += 20
        
        if hero.getState() == "JUMPING":
            hero.printPos()
            print "--------"
        times = hero.jump(times)
        if times == 4:
            hero.setState("STANDING")
            hero.allowLeft(False)
            hero.allowRight(False)
            times = 0
        level.selectLevel(screen,1)
        coinGroup.draw(screen)
        hero_group.draw(screen)
        fireSource.draw(screen)
        fireball_group.draw(screen)
        donkey_group.draw(screen)
        comLevels.updateLife(lifes,screen)
        comLevels.updateScore(score,screen)
        pygame.display.update()
        
        if lifes == 0:
            break


    pygame.quit()
    sys.exit()
Пример #37
0
 def launch_fire(self):
     self.all_fireball.add(Fireball(self))
Пример #38
0
def shoot_fireball(settings, screen, hero, fireballs):
    """Shoot a fireball from the hero if the limit has not been reached."""
    if len(fireballs) < settings.fireballs_allowed:
        new_fireball = Fireball(settings, screen, hero)
        fireballs.add(new_fireball)