Esempio n. 1
0
            if position_player[1] > 80 and position_player[1] < 474:
                self.rect.y = position_player[1] - 12

    def die(self):

        self.is_dead = True
        #self.image = pygame.image.load('template\character\player_dead.png').convert_alpha()


player_explo = pyganim.PygAnimation(
    [('template/explo/ship/bubble_explo1.png', 0.1),
     ('template/explo/ship/bubble_explo3.png', 0.1),
     ('template/explo/ship/bubble_explo3.png', 0.1),
     ('template/explo/ship/bubble_explo4.png', 0.1),
     ('template/explo/ship/bubble_explo5.png', 0.1),
     ('template/explo/ship/bubble_explo6.png', 0.1),
     ('template/explo/ship/bubble_explo7.png', 0.1),
     ('template/explo/ship/bubble_explo8.png', 0.1),
     ('template/explo/ship/bubble_explo9.png', 0.1),
     ('template/explo/ship/bubble_explo10.png', 0.1)],
    loop=False)


# ENEMY
class Enemy(pygame.sprite.Sprite):
    def __init__(self):
        super().__init__()
        rand_enemy = random.randrange(1, 8)

        if rand_enemy == 1:
            self.image = pygame.image.load(
Esempio n. 2
0
def getTestAnimObj():
    # Returns a standard PygAnimation object.
    frames = [('bolt%s.png' % (i), BOLT_DURATIONS)
              for i in range(1, NUM_BOLT_IMAGES + 1)]
    return pyganim.PygAnimation(frames)
Esempio n. 3
0
 def test_loadingAnimatedGif(self):
     animObj = pyganim.PygAnimation(
         'banana.gif')  # IT'S PEANUT BUTTER JELLY TIME
     self.assertEqual(len(animObj._images), 8)
     for i in range(8):
         self.assertEqual(animObj._durations[i], 100)
Esempio n. 4
0
explosion_weak_images = explosion_weak_spritesheet.load_strip((0, 0, 100, 100),
                                                              3, 3, -1)
explosion_normal_images = explosion_normal_spritesheet.load_strip(
    (0, 0, 100, 100), 4, 4, -1)
ANIMATION_SPEED_WEAK = 1.0 / 15.0
ANIMATION_SPEED_NORMAL = 1.0 / 16.0
explosion_animation_weak = []
explosion_animation_normal = []
explosion_animations = []
for i in explosion_weak_images:
    explosion_animation_weak.append((i, ANIMATION_SPEED_WEAK))

for i in explosion_normal_images:
    explosion_animation_normal.append((i, ANIMATION_SPEED_NORMAL))

explosion_animation_weak = pyganim.PygAnimation(explosion_animation_weak,
                                                loop=False)
explosion_animation_weak.convert_alpha()
explosion_animation_normal = pyganim.PygAnimation(explosion_animation_normal,
                                                  loop=False)
explosion_animation_normal.convert_alpha()


def add_explosion(x, y, total_frames, damage=150.0):
    if damage < 140:
        is_weak = True
    else:
        is_weak = False
    if is_weak:
        explosion_animations.append(
            (explosion_animation_weak.getCopy(), (x - 39, y - 39), is_weak))
    else:
Esempio n. 5
0
		def make_boltAnim(anim_list, delay):
			boltAnim = []
			for anim in anim_list:
				boltAnim.append((anim, delay))
			Anim = pyganim.PygAnimation(boltAnim)
			return Anim
Esempio n. 6
0
 def MakeFrameAnim(animWay, delay):
     FrameAnim = []
     for anim in animWay:
         FrameAnim.append((anim, delay))
     ReadyAnim = pyganim.PygAnimation(FrameAnim)
     return ReadyAnim
Esempio n. 7
0
def runGame():
    minutes = 0
    seconds = 0
    milliseconds = 0
    # Create the player
    player = Player()

    # Create all the levels
    level_list = []
    level_list.append(Level_01(player))

    # Set the current level
    current_level_no = 0
    current_level = level_list[current_level_no]

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

    player.rect.x = 650
    player.rect.y = 450
    active_sprite_list.add(player)

    door = pygame.image.load("door2.png").convert()

    #Loop until the user clicks the close button.
    done = False

    fireAnim = pyganim.PygAnimation([('testimages/flame_a_0001.png', 0.1),
                                     ('testimages/flame_a_0002.png', 0.1),
                                     ('testimages/flame_a_0003.png', 0.1),
                                     ('testimages/flame_a_0004.png', 0.1),
                                     ('testimages/flame_a_0005.png', 0.1),
                                     ('testimages/flame_a_0006.png', 0.1)])

    fireAnim2 = fireAnim.getCopy()

    fireAnim2.smoothscale((200, 200))

    fireAnim.rate = 1.2
    # start playing the fire animations
    fireAnim.play()
    fireAnim2.play()

    # Used to manage how fast the screen updates
    clock = pygame.time.Clock()

    # -------- Main Program Loop -----------
    while not done:
        sound.play()
        player.checkwin(minutes, seconds)
        player.checkover(minutes, seconds)
        for event in pygame.event.get():

            if event.type == pygame.QUIT:
                terminate()
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_LEFT:
                    player.go_left()
                if event.key == pygame.K_RIGHT:
                    player.go_right()
                if event.key == pygame.K_UP:
                    player.jump()
                if event.key == K_ESCAPE:
                    showGameOverScreen(minutes, seconds)
            if event.type == pygame.KEYUP:
                if event.key == pygame.K_LEFT and player.change_x < 0:
                    player.stop()
                if event.key == pygame.K_RIGHT and player.change_x > 0:
                    player.stop()
                if event.key == K_ESCAPE:
                    showGameOverScreen(minutes, seconds)

        # Update the player.
        active_sprite_list.update()

        # Update items in the level
        current_level.update()

        # If the player gets near the right side, shift the world left (-x)
        if player.rect.right > SCREEN_WIDTH:
            player.rect.right = SCREEN_WIDTH

        # If the player gets near the left side, shift the world right (+x)
        if player.rect.left < 0:
            player.rect.left = 0
        screen.blit(door, (10, 10))

        current_level.draw(screen)
        screen.blit(door, (10, 10))
        active_sprite_list.draw(screen)

        fireAnim2.blit(screen, (-75, 480))
        fireAnim2.blit(screen, (0, 480))
        fireAnim2.blit(screen, (75, 480))
        fireAnim2.blit(screen, (150, 480))

        fireAnim2.blit(screen, (225, 480))
        fireAnim2.blit(screen, (300, 480))
        fireAnim2.blit(screen, (375, 480))
        fireAnim2.blit(screen, (450, 480))

        fireAnim2.blit(screen, (525, 480))
        fireAnim2.blit(screen, (600, 480))
        fireAnim2.blit(screen, (675, 480))
        drawScore(minutes, seconds)
        pygame.display.update()

        if milliseconds > 1000:
            seconds += 1
            milliseconds -= 1000
        if seconds > 60:
            minutes += 1
            seconds -= 60

        drawScore(minutes, seconds)
        milliseconds += FPSCLOCK.tick_busy_loop(60)

        clock.tick(60)

        pygame.display.flip()
Esempio n. 8
0
from game_objects import Player, Background, Plasmoid, Meteor
from settings import SIZE, WHITE

#Процесс инициализации pygame. Запускается ядро pygame написанное на С
pygame.init()

#Поздороваемся и назовоём окно отображения 'hello world'
pygame.display.set_caption('my_game_2_v_1.0.0')

#Всё что показывается в игре содержится в переменной screen.
screen = pygame.display.set_mode(SIZE)
clock = pygame.time.Clock()

#Анимация в игре
explosion_anim = pyganim.PygAnimation(
    [('game_data/blue_explosion/1_{}.png'.format(i), 50) for i in range(17)],
    loop=False)

#Music
music = pygame.mixer.Sound('game_data/music/space.wav')
music.play(-1)

#Создадим группы в которых будем хранить все объекты
all_game_objects = pygame.sprite.Group()
plasmoids = pygame.sprite.Group()
meteors = pygame.sprite.Group()
explosions = []

#Добавляем объекты в нашу игру
player = Player(clock, plasmoids)
back = Background(clock)
width = 64
height = 64
direction = 'left'  #start off as left facing
moveleft = moveright = moveup = movedown = False

#loading in characters and enviroment
background = pygame.image.load('sprites/background1.png')
leftidle = pygame.image.load("sprites/left.png")
rightidle = pygame.image.load("sprites/right.png")
upidle = pygame.image.load("sprites/up.png")
downidle = pygame.image.load("sprites/down.png")

#pyganim aminations for character
charanim = {}
charanim["walkleft"] = pyganim.PygAnimation([("sprites/left2.png", 100),
                                             ("sprites/left.png", 100),
                                             ("sprites/left3.png", 100),
                                             ("sprites/left.png", 10)])
charanim["walkright"] = pyganim.PygAnimation([("sprites/right2.png", 100),
                                              ("sprites/right.png", 100),
                                              ("sprites/right3.png", 100),
                                              ("sprites/right.png", 10)])
charanim["walkup"] = pyganim.PygAnimation([("sprites/up2.png", 100),
                                           ("sprites/up.png", 100),
                                           ("sprites/up3.png", 100),
                                           ("sprites/up.png", 10)])
charanim["walkdown"] = pyganim.PygAnimation([("sprites/down2.png", 100),
                                             ("sprites/down.png", 100),
                                             ("sprites/down3.png", 100),
                                             ("sprites/down.png", 10)])

charanim["shootright"] = pyganim.PygAnimation([
Esempio n. 10
0
#Viser spillvinduet med tittel
spillVindu = pygame.display.set_mode((vinduBredde, vinduHoyde))
pygame.display.set_caption(
    "Get a way")  #tittelen til spillet som skrives øvers på vinduet

klokke = pygame.time.Clock()  #klokken til spillet som tar tiden

#Henter bilder som skal vises på skjermen
figur1Bilde = pygame.image.load("figur1.png")  #figuren når den står i ro
figur2Bilde = pygame.image.load("figur2.png")  #figuren når den går
myntBilde = pygame.image.load("mynt.png")
steinBilde = pygame.image.load("stein.png")
bgIntroBilde = pygame.image.load("bg_intro.png")
bgBilde = pygame.image.load("bg.png")

animasjon = pyganim.PygAnimation([(figur1Bilde, 80), (figur2Bilde, 80)
                                  ])  #beskrivelse av animasjonen til figuren
fig_gaar = 0
krav = 0


#Definisjoner
def poengsum(count):
    global krav
    font = pygame.font.SysFont(
        None, 25)  #skrifttypen til teksten som viser poengsummen
    tekst = font.render("Mynter: " + str(count) + "/" + str(krav), True,
                        svart)  #teksten som viser poengsummen
    spillVindu.blit(tekst, (0, 0))  #viser teksten på skjermen


def figur(x, y, fig_gaar):
Esempio n. 11
0
import pygame
import sys

import pyganim

from constats import *
from game_obj import Player, Background, Plasmoid, Meteorite

pygame.init()
pygame.display.set_caption(TITLE)

screen = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HIGTH))
clock = pygame.time.Clock()

explostion_animation = pyganim.PygAnimation(
    [('assets/blue_explosion/1_%s.png' % i, 50) for i in range(17)],
    loop=False)

# music = pygame.mixer.Sound('assets/music/game.wav')
# music.play(-1)

all_obj = pygame.sprite.Group()
plasmoids = pygame.sprite.Group()
meteors = pygame.sprite.Group()

explosions = []

player = Player(clock, plasmoids)
background = Background()

all_obj.add(background, player)
Esempio n. 12
0
shoot1f = pygame.transform.flip(shoot1, True, False)
shoot2f = pygame.transform.flip(shoot2, True, False)
shoot3f = pygame.transform.flip(shoot3, True, False)

bgm1f = pygame.transform.flip(bgm1, True, False)
bgm2f = pygame.transform.flip(bgm2, True, False)
bgm3f = pygame.transform.flip(bgm3, True, False)
bgm4f = pygame.transform.flip(bgm4, True, False)
bgm5f = pygame.transform.flip(bgm5, True, False)
bgm6f = pygame.transform.flip(bgm6, True, False)
bgm7f = pygame.transform.flip(bgm7, True, False)
bgm8f = pygame.transform.flip(bgm8, True, False)

#initialize animation
boltAnim = pyganim.PygAnimation([(player, 150), (player2, 150), (player3, 150),
                                 (player4, 150), (player5, 150),
                                 (player6, 150), (player7, 150),
                                 (player8, 150)])

boltAnimf = pyganim.PygAnimation([(playerf, 150), (player2f, 150),
                                  (player3f, 150), (player4f, 150),
                                  (player5f, 150), (player6f, 150),
                                  (player7f, 150), (player8f, 150)])

boltAnim_m = pyganim.PygAnimation([(move1, 150), (move2, 150), (move3, 150),
                                   (move4, 150), (move5, 150), (move6, 150)])
boltAnim_mf = pyganim.PygAnimation([(move1f, 150), (move2f, 150),
                                    (move3f, 150), (move4f, 150),
                                    (move5f, 150), (move6f, 150)])

boltAnim_s = pyganim.PygAnimation([(shoot1, 150), (shoot2, 150),
                                   (shoot3, 150)])
Esempio n. 13
0
def readyinstance(screen, background, windowSize):
    arrayready = []
    # Load settings and sounds
    settings = loadsettings(settings_file)
    sounds = loadsound(["sfx_countdown.ogg"])
    if settings[0]:
        sounds['countdown'].play()
    # Creation of banner GO! with the characteristics we want
    banner_go = Banner("GO!", 72)
    banner_go.set_color(selected_item_color)
    banner_go.center(windowSize, True, False)
    # Creation of 3 banners for the countdown (3,2,1)
    for i in range(3, 0, -1):
        temp = Banner(str(i) + "!", 72)
        temp.set_color(selected_item_color)
        temp.center(windowSize, True, False)
        arrayready.append(temp.image)
    # Animate the banners
    arrayready.append(banner_go.image)
    animatelist = createanimationlist(arrayready, 1.3)
    animobj = pyganim.PygAnimation(animatelist, loop=False)
    animobj.play()
    # Bird's start position
    temp = [0, 0]
    # Creation of the bird
    bird1 = Bird()
    loadbird(bird1)
    # Random position that the bird has to reach to make his path
    randompos = [
        random.randint(0 + bird1.rect.width, windowSize[0] / 4),
        random.randint(0 + bird1.rect.height,
                       windowSize[1] - bird1.rect.height * 2)
    ]
    # Bird animation
    animatelist1 = createanimationlist(bird1.frames, wingsanimationspeed)
    animobj1 = pyganim.PygAnimation(animatelist1, loop=True)
    animobj1.play()

    while 1:
        # Until he reaches the random position this flow corrects bird's position
        if temp != randompos:
            if temp[0] < randompos[0]:
                temp[0] += 0.5
            if temp[0] > randompos[0]:
                temp[0] -= 0.5
            if temp[1] < randompos[1]:
                temp[1] += 0.5
            if temp[1] > randompos[1]:
                temp[1] -= 0.5
        else:
            # If the bird arrived at the random position, we generate another (this process only ends when the countdown
            # reaches GO!)
            randompos = [
                random.randint(0 + bird1.rect.width, windowSize[0] / 4),
                random.randint(0 + bird1.rect.height,
                               windowSize[1] - bird1.rect.height * 2)
            ]

        ev = event.poll()
        if ev.type == pygame.QUIT:
            pygame.quit()
            sys.exit()
        screen.blit(background, (0, 0))
        animobj.blit(screen, (windowSize[0] / 2 -
                              animobj.getCurrentFrame().get_rect().width / 2,
                              windowSize[1] / 2 -
                              animobj.getCurrentFrame().get_rect().height / 2))
        animobj1.blit(screen, temp)
        pygame.display.flip()
        # We start the game when the banners' animation is finished
        if animobj.isFinished() is True or animobj.state == 'stopped':
            return temp
Esempio n. 14
0
 def animate(self, frames, speed):
     self.animatelist = createanimationlist(frames, speed)
     self.animobj = pyganim.PygAnimation(self.animatelist, loop=False)
     self.animobj.play()
Esempio n. 15
0
]
#stone_wall_tavern = [x for x in range(1,7)]

slash1 = image.load('animation/slash/Effect_Slash11.png')
slash2 = image.load('animation/slash/Effect_Slash21.png')
slash3 = image.load('animation/slash/Effect_Slash31.png')
slash4 = image.load('animation/slash/Effect_Slash41.png')

slash_list = [slash1, slash2, slash3, slash4]

boltAnim = pyganim.PygAnimation([('testimages/bolt_strike_0001.png', 0.1),
                                 ('testimages/bolt_strike_0002.png', 0.1),
                                 ('testimages/bolt_strike_0003.png', 0.1),
                                 ('testimages/bolt_strike_0004.png', 0.1),
                                 ('testimages/bolt_strike_0005.png', 0.1),
                                 ('testimages/bolt_strike_0006.png', 0.1),
                                 ('testimages/bolt_strike_0007.png', 0.1),
                                 ('testimages/bolt_strike_0008.png', 0.1),
                                 ('testimages/bolt_strike_0009.png', 0.1),
                                 ('testimages/bolt_strike_0010.png', 0.1)],
                                loop=False)
boltAnim.rotate(270)

fireAnim = pyganim.PygAnimation([
    ('testimages/flame_a_0001.png', 0.2),
    ('testimages/flame_a_0002.png', 0.2),
    ('testimages/flame_a_0003.png', 0.2),
    ('testimages/flame_a_0004.png', 0.2),
    ('testimages/flame_a_0005.png', 0.2),
    ('testimages/flame_a_0006.png', 0.2),
],
import sys
import time
import pyganim

pygame.init()

# set up the window
windowSurface = pygame.display.set_mode((640, 480), 0, 32)
pygame.display.set_caption('Pyganim Test 3')

# create the animation objects
boltAnim0 = pyganim.PygAnimation([('testimages/bolt_strike_0001.png', 0.1),
                                  ('testimages/bolt_strike_0002.png', 0.1),
                                  ('testimages/bolt_strike_0003.png', 0.1),
                                  ('testimages/bolt_strike_0004.png', 0.1),
                                  ('testimages/bolt_strike_0005.png', 0.1),
                                  ('testimages/bolt_strike_0006.png', 0.1),
                                  ('testimages/bolt_strike_0007.png', 0.1),
                                  ('testimages/bolt_strike_0008.png', 0.1),
                                  ('testimages/bolt_strike_0009.png', 0.1),
                                  ('testimages/bolt_strike_0010.png', 0.1)])

# create some copies of the bolt animation
boltAnim1, boltAnim2, boltAnim3, boltAnim4 = boltAnim0.getCopies(4)
boltAnim3.rate = 0.5
boltAnim4.rate = 2.0
bolts = [boltAnim0, boltAnim1, boltAnim2, boltAnim3, boltAnim4]

# supply a "start time" argument to play() so that the bolt animations are
# all in sync with each other.
rightNow = time.time()
for i in range(len(bolts)):