Esempio n. 1
0
 def generate_background(self, loc="LEO"):
     self.background_loc = loc
     if loc == 'LEO':            
         self.background=[]
         self.background.append( util.load_sprite('images/Earth_at_day.png') )
         self.background.append( util.load_sprite('images/Earth_at_day.png') )
         self.background.append( util.load_sprite('images/Earth_at_night.png') )            
         self.background.append( util.load_sprite('images/Earth_at_night.png') )
         #for j in self.background: j.scale=.9
     self.update(0)
 def refresh_image(self):    
     if not util.GRAPHICS: return                
     if self.name == 'Water': 
         self.imgfile = 'images/glitch-assets/cup_of_water/cup_of_water__x1_iconic_png_1354833111.png'
     else:
         self.imgfile = 'images/glitch-assets/contraband/contraband__x1_1_png_1354836014.png'
     self.sprite = util.load_sprite(self.imgfile)
Esempio n. 3
0
 def __init__(self, position, create_bullet_callback):
     self.create_bullet_callback = create_bullet_callback
     self.laser_sound = load_sound('laser')
     self.explosion_sound = load_sound("crush")
     self.direction = Vector2(UP)
     super().__init__(position, rotozoom(load_sprite("spaceship"), 0, 0.5),
                      Vector2(0))
Esempio n. 4
0
	def __init__(self,image,x1,y1,x2,y2,vitesse):
		self.sprite = util.load_sprite(image)
		self.sprite.rect.centerx = x1
		self.sprite.rect.centery = y1
		self.x2 = x2
		self.y2 = y2
		self.vitesse = vitesse
Esempio n. 5
0
    def __init__(self):
        self.sprites = {}
        self.images = []
        self.batches = {}
        self.batches['open'] = pyglet.graphics.Batch()
        self.batches['closed'] = pyglet.graphics.Batch()
        self.sprites['open'] = []
        self.sprites['closed'] = []
        self.batches['items'] = pyglet.graphics.Batch()
        img = pyglet.resource.image('ui/inventory.png')
        img.anchor_x = 0
        img.anchor_y = img.height
        self.background = pyglet.sprite.Sprite(img,
                                               x=gamestate.norm_w,
                                               y=gamestate.norm_h)

        self.visible = True

        self.items = {}

        self.held_item = None

        self.isopen = False

        # Create the inventory closed state first
        self.sprites['closed'].append(
            util.load_sprite(['ui', 'purse.png'],
                             x=gamestate.norm_w,
                             y=gamestate.norm_h - 15,
                             batch=self.batches['closed']))
        self.translate_bottomleft_to_topright(self.sprites['closed'])

        # Create the inventory open state now
        self.sprites['open'].append(
            util.load_sprite(['ui', 'purseopen.png'],
                             x=gamestate.norm_w - 5,
                             y=gamestate.norm_h - 21,
                             batch=self.batches['open']))
        self.translate_bottomleft_to_topright(self.sprites['open'])

        self.height = self.sprites['open'][0].height

        self.rect_left = 0
        self.rect_right = 0

        gamestate.event_manager.set_inventory(self)
Esempio n. 6
0
	def __init__(self,infos):
		self.viePleine = infos[0]
		self.vieCourante = infos[0]
		self.puissance = infos[1]
		self.vitesse = infos[2]
		self.argent = infos[3]
		self.sprite = util.load_sprite(infos[4])
		self.sprite.rect.centerx = 400
		self.sprite.rect.top = 31
Esempio n. 7
0
    def __init__(self, position, create_meteroid_callback, size=3):
        self.size = size
        self.create_meteroid_callback = create_meteroid_callback
        self.explosion_sound = load_sound("meteriod_explo")
        self.explosion_sound.set_volume(100)

        size_to_scale = {3: .66, 2: 0.44, 1: 0.25}
        scale = size_to_scale[size]
        sprite = rotozoom(load_sprite("meteroid"), 0, scale)

        super().__init__(position, sprite, get_random_velocity(1, 2))
Esempio n. 8
0
	def __init__(self):
		self.viePleine = 2
		self.vieCourante = 2
		self.puissance = 2
		self.vitesseTir = 1
		self.vitesseDepl = 1
		self.nbProjectiles = 1
		self.gold = 0
		self.sprite = util.load_sprite("hero.png")
		self.sprite.rect.centerx = 400
		self.sprite.rect.centery = 500
Esempio n. 9
0
    def __init__(self):
        self.sprites = {}
        self.images = []
        self.batches = {}
        self.batches['open'] = pyglet.graphics.Batch()
        self.batches['closed'] = pyglet.graphics.Batch()
        self.sprites['open'] = []
        self.sprites['closed'] = []
        self.batches['items'] = pyglet.graphics.Batch()
        img = pyglet.resource.image('ui/inventory.png')
        img.anchor_x = 0
        img.anchor_y = img.height
        self.background = pyglet.sprite.Sprite(img, x=gamestate.norm_w, y=gamestate.norm_h)
        
        self.visible = True
        
        self.items = {}
        
        self.held_item = None
                
        self.isopen = False
        
        # Create the inventory closed state first
        self.sprites['closed'].append(util.load_sprite(['ui', 'purse.png'], 
                                      x=gamestate.norm_w, y=gamestate.norm_h-15, 
                                      batch=self.batches['closed']))
        self.translate_bottomleft_to_topright(self.sprites['closed'])
                      
        # Create the inventory open state now
        self.sprites['open'].append(util.load_sprite(['ui', 'purseopen.png'], 
                                    x=gamestate.norm_w-5, y=gamestate.norm_h-21, 
                                    batch=self.batches['open']) )
        self.translate_bottomleft_to_topright(self.sprites['open'])
        
        self.height = self.sprites['open'][0].height
        
        self.rect_left = 0
        self.rect_right = 0

        gamestate.event_manager.set_inventory(self)
Esempio n. 10
0
 def __init__(self):
     self.score = 0
     self._init_pygame()
     self.screen = pygame.display.set_mode((self.WIDTH, self.HEIGHT))
     self.background = load_sprite("space1", False)
     self.background_game_music = load_sound("game_play_music")
     self.game_over_music = load_sound("game_over_music")
     self.clock = pygame.time.Clock()
     self.font = pygame.font.Font(None, 64)
     self.message = ""
     self.meteroids = []
     self.bullets = []
     self.spaceship = Spaceship((400, 300), self.bullets.append)
     
     for _ in range(4):
         while True:
             pos = get_random_position(self.screen)
             if pos.distance_to(self.spaceship.position) > self.MIN_METEROID_DIS:
                 break
         self.meteroids.append(Meteroid(pos, self.meteroids.append))
Esempio n. 11
0
from enum import Enum, IntEnum

AIR = 0b00000001  # Something you can shoot through
WALL = 0b00000010  # Something you cannot walk through
ITEM = 0b00000100  # Something you can pick up
STEP = 0b00001000  # Something you can trigger by stepping on
POKE = 0b00010000  # Something you can trigger by poking
GRID = 0b00100000  # Something you can shoot portals on

from util import load_sprite, cut_sheet, draw_sprite, level_surface
import pygame, time, config

SPRITES = load_sprite('level_sprites.png')
GRASS_SPRITE = cut_sheet(SPRITES, 5, 1)


# A cell in the level
class Tile:
    MASK = 0
    SYMBOL = ' '
    BG = False
    FG = False
    MG = False
    COLORED = False
    STICKY = False
    TELE = False
    SPRITE = cut_sheet(SPRITES, 7, 0)

    def is_air(self):
        return self.MASK & AIR
Esempio n. 12
0
def play(screen, varOptions):
    jeu = 1
    pygame.init()
    # Background + Zone ---------------------------------------------------------------------
    background = util.load_sprite("background.png")
    niveauActuel = 0
    bg = util.load_sprite(levelBg[niveauActuel])
    bg.rect = [0, 31]

    myfont = pygame.font.SysFont("monospace", 30)
    myfont.set_bold(1)
    # Creation Classes Boss+Hero ------------------------------------------------------------
    cBoss = classes.Enemy(classes.bosses[niveauActuel])
    cHero = classes.Hero()
    # Sprites du heros -------------------------------------------------------------------------
    heroDeb = util.load_image("hero.png")
    heroPasG = util.load_image("heroPasG.png")
    heroPasD = util.load_image("heroPasD.png")
    if varOptions[1] == 0:
        heroDebA = util.load_image("heroDebAD.png")
        heroPasDA = util.load_image("heroPasDAD.png")
        heroPasGA = util.load_image("heroPasGAD.png")
    else:
        heroDebA = util.load_image("heroDebAG.png")
        heroPasDA = util.load_image("heroPasDAG.png")
        heroPasGA = util.load_image("heroPasGAG.png")
    # Variables ---------------------------------------------------------------------------------
    timerPas = 0
    marche = 20
    pas = 1

    timerTir = 0
    bullet_rects = []

    timerMenu = 20
    timerSon = 50
    timerPause = 50

    timerMobSpawn = 50
    mob_rects = []

    timerBossAttack = 50
    timerMoveBoss = 50
    timerSp = 50
    sensDir = 1
    EnemyBullets_rects = []

    vie = util.load_sprite("vie.png")
    # Boucle du jeu ##############################################
    while jeu == 1:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()
        # Mise a jour des timers --------------------------------------------------------------------
        marche -= 1
        timerPas -= 1
        timerTir -= 1
        timerMenu -= 1
        timerMobSpawn -= 1
        timerBossAttack -= 1
        timerMoveBoss -= 1
        timerSp -= 1
        timerSon -= 1
        timerPause -= 1
        # Set de la valeur de l'argent du personnage -----------------------------------------------
        label = myfont.render(str(cHero.gold), 1, (255, 185, 0))
        # Gestion des touches clavier --------------------------------------------------------------
        keys = pygame.key.get_pressed()

        if keys[pygame.K_ESCAPE] and timerMenu <= 0:
            jeu = 0

        if keys[pygame.K_m] and timerSon <= 0:
            if varOptions[0] == 0:
                pygame.mixer.music.unpause()
            else:
                pygame.mixer.music.pause()
            timerSon = 50
            varOptions[0] = abs(varOptions[0] - 1)

        if keys[pygame.K_p] and timerPause <= 0:
            pause = 1
            timerPause = 30
            pygame.time.wait(100)
            while pause == 1:
                for event in pygame.event.get():
                    if event.type == pygame.QUIT:
                        sys.exit()
                keys = pygame.key.get_pressed()
                timerPause -= 1
                if keys[pygame.K_p] and timerPause <= 0:
                    pause = 0
                    timerPause = 30
                pygame.time.wait(10)

        if keys[pygame.K_UP] and cHero.sprite.rect.bottom > 350:
            cHero.sprite.rect = cHero.sprite.rect.move(0, -(cHero.vitesseDepl))
            marche = 5
        if keys[pygame.K_DOWN] and cHero.sprite.rect.bottom < 530:
            cHero.sprite.rect = cHero.sprite.rect.move(0, cHero.vitesseDepl)
            marche = 5
        if keys[pygame.K_LEFT] and cHero.sprite.rect.left > 5:
            cHero.sprite.rect = cHero.sprite.rect.move(-(cHero.vitesseDepl), 0)
            marche = 5
        if keys[pygame.K_RIGHT] and cHero.sprite.rect.right < 795:
            cHero.sprite.rect = cHero.sprite.rect.move(cHero.vitesseDepl, 0)
            marche = 5

        if keys[pygame.K_SPACE] or varOptions[2] == 1:
            if timerTir <= 0:
                timerTir = tabVitesseTir[cHero.vitesseTir]
                if cHero.puissance < 6:
                    tb = util.load_sprite("armes/rock.png")
                elif cHero.puissance > 5 and cHero.puissance < 11:
                    tb = util.load_sprite("armes/dague.png")
                elif cHero.puissance > 10 and cHero.puissance < 16:
                    tb = util.load_sprite("armes/lance.png")
                elif cHero.puissance > 15 and cHero.puissance < 26:
                    tb = util.load_sprite("armes/dague_aura.png")
                elif cHero.puissance > 25 and cHero.puissance < 36:
                    tb = util.load_sprite("armes/bombe.png")
                elif cHero.puissance > 35 and cHero.puissance < 46:
                    tb = util.load_sprite("armes/feu.png")
                else:
                    tb = util.load_sprite("armes/feu_blue.png")

                tb.rect.left = (cHero.sprite.rect.right + cHero.sprite.rect.left) / 2
                tb.rect.top = cHero.sprite.rect.top - 2
                bullet_rects.append(tb)
            if marche > 0:
                if pas == 1:
                    cHero.sprite.image = heroPasGA
                else:
                    cHero.sprite.image = heroPasDA
                if timerPas <= 0:
                    pas = abs(pas - 1)
                    timerPas = 20
            else:
                cHero.sprite.image = heroDebA
        else:
            if marche > 0:
                if pas == 1:
                    cHero.sprite.image = heroPasG
                else:
                    cHero.sprite.image = heroPasD
                if timerPas <= 0:
                    pas = abs(pas - 1)
                    timerPas = 20
            else:
                cHero.sprite.image = heroDeb
        # Spawn des mobs ------------------------------------------------------------------------
        if timerMobSpawn <= 0:
            tm = classes.Enemy(classes.mobs[niveauActuel])
            tm.sprite.rect.centery = 31 + (tm.sprite.rect.height / 2)
            tm.sprite.rect.centerx = random.randint(50, 750)
            mob_rects.append(tm)
            timerMobSpawn = mobSpawnTime[niveauActuel]
        # Gestion une fois mort + Affichage menu etc ---------------------------------------------
        if cHero.vieCourante <= 0:
            cHero = util.upgrades(screen, cHero)
            if cHero.vieCourante <= 0:
                jeu = 0
            else:
                timerMenu = 50
                niveauActuel = 0
                cBoss = classes.Enemy(classes.bosses[niveauActuel])
                bg = util.load_sprite(levelBg[niveauActuel])
                bg.rect = [0, 31]
                mob_rects = []
                EnemyBullets_rects = []
        # Gestion si boss mort ---------------------------------------------------------------------
        if cBoss.vieCourante <= 0:
            niveauActuel += 1
            # si le jeu est fini
            if niveauActuel == 9:
                jeu = 0
                util.win(screen)
            else:
                cHero.gold += cBoss.argent
                bg = util.load_sprite(levelBg[niveauActuel])
                bg.rect = [0, 31]
                cBoss = classes.Enemy(classes.bosses[niveauActuel])
                mob_rects = []
                EnemyBullets_rects = []
        # Gestion des projectiles boss -------------------------------------------------------------
        if timerBossAttack <= 0:
            if niveauActuel == 0:
                EnemyBullets_rects.append(
                    classes.Projectile(
                        projectiles[niveauActuel],
                        (cBoss.sprite.rect.left + 230),
                        (cBoss.sprite.rect.top + 200),
                        (cBoss.sprite.rect.left + 80),
                        600,
                        1,
                    )
                )
                EnemyBullets_rects.append(
                    classes.Projectile(
                        projectiles[niveauActuel],
                        (cBoss.sprite.rect.left + 250),
                        (cBoss.sprite.rect.top + 200),
                        (cBoss.sprite.rect.left + 400),
                        600,
                        1,
                    )
                )
                timerBossAttack = 200
            if niveauActuel == 1:
                EnemyBullets_rects.append(
                    classes.Projectile(
                        projectiles[niveauActuel],
                        (cBoss.sprite.rect.left + 185),
                        (cBoss.sprite.rect.top + 190),
                        (cHero.sprite.rect.centerx),
                        600,
                        1,
                    )
                )
                timerBossAttack = 100
            if niveauActuel == 2:
                EnemyBullets_rects.append(
                    classes.Projectile(
                        projectiles[niveauActuel],
                        (cBoss.sprite.rect.left + 105),
                        (cBoss.sprite.rect.top + 230),
                        (cBoss.sprite.rect.left + 145),
                        600,
                        2,
                    )
                )
                EnemyBullets_rects.append(
                    classes.Projectile(
                        projectiles[niveauActuel],
                        (cBoss.sprite.rect.left + 180),
                        (cBoss.sprite.rect.top + 230),
                        (cBoss.sprite.rect.left + 220),
                        600,
                        2,
                    )
                )
                timerBossAttack = 100
            if niveauActuel == 3:
                EnemyBullets_rects.append(
                    classes.Projectile(
                        projectiles[niveauActuel],
                        (cBoss.sprite.rect.left + 70),
                        (cBoss.sprite.rect.top + 80),
                        (cBoss.sprite.rect.left + 70),
                        600,
                        2,
                    )
                )
                EnemyBullets_rects.append(
                    classes.Projectile(
                        projectiles[niveauActuel],
                        (cBoss.sprite.rect.left + 120),
                        (cBoss.sprite.rect.top + 80),
                        (cBoss.sprite.rect.left + 120),
                        600,
                        2,
                    )
                )
                timerBossAttack = 40
            if niveauActuel == 4:
                EnemyBullets_rects.append(
                    classes.Projectile(
                        projectiles[niveauActuel],
                        (cBoss.sprite.rect.left + 60),
                        (cBoss.sprite.rect.top + 145),
                        (cBoss.sprite.rect.left + 60),
                        600,
                        3,
                    )
                )
                EnemyBullets_rects.append(
                    classes.Projectile(
                        projectiles[niveauActuel],
                        (cBoss.sprite.rect.left + 90),
                        (cBoss.sprite.rect.top + 145),
                        (cBoss.sprite.rect.left + 90),
                        600,
                        3,
                    )
                )
                EnemyBullets_rects.append(
                    classes.Projectile(
                        projectiles[niveauActuel],
                        (cBoss.sprite.rect.left + 120),
                        (cBoss.sprite.rect.top + 145),
                        (cBoss.sprite.rect.left + 120),
                        600,
                        3,
                    )
                )
                EnemyBullets_rects.append(
                    classes.Projectile(
                        projectiles[niveauActuel],
                        (cBoss.sprite.rect.left + 150),
                        (cBoss.sprite.rect.top + 145),
                        (cBoss.sprite.rect.left + 150),
                        600,
                        3,
                    )
                )
                timerBossAttack = 200
            if niveauActuel == 5:
                EnemyBullets_rects.append(
                    classes.Projectile(
                        projectiles[niveauActuel],
                        (cBoss.sprite.rect.left + 50),
                        (cBoss.sprite.rect.top + 80),
                        (cBoss.sprite.rect.left + 50),
                        600,
                        4,
                    )
                )
                timerBossAttack = 50
            if niveauActuel == 6:  # 84 122 26 122
                lo = random.randint(0, 1)
                EnemyBullets_rects.append(
                    classes.Projectile(
                        projectiles[niveauActuel],
                        (cBoss.sprite.rect.left + 26 + 58 * lo),
                        (cBoss.sprite.rect.top + 122),
                        (cBoss.sprite.rect.left + 26 + 58 * lo),
                        600,
                        1,
                    )
                )
                timerBossAttack = 40
                if timerSp <= 0:
                    EnemyBullets_rects.append(
                        classes.Projectile(
                            projectiles[7],
                            (cBoss.sprite.rect.left + 53),
                            (cBoss.sprite.rect.top + 44),
                            (cBoss.sprite.rect.left + 53),
                            600,
                            5,
                        )
                    )
                    timerSp = 300
            if niveauActuel == 7:
                EnemyBullets_rects.append(
                    classes.Projectile(
                        projectiles[niveauActuel],
                        (cBoss.sprite.rect.left + 190),
                        (cBoss.sprite.rect.top + 120),
                        (cHero.sprite.rect.centerx),
                        (cHero.sprite.rect.centery),
                        2,
                    )
                )
                timerBossAttack = 80
            if niveauActuel == 8:
                EnemyBullets_rects.append(
                    classes.Projectile(
                        projectiles[niveauActuel],
                        (cBoss.sprite.rect.left + 135),
                        (cBoss.sprite.rect.top + 120),
                        (cHero.sprite.rect.centerx),
                        (cHero.sprite.rect.centery),
                        2,
                    )
                )
                EnemyBullets_rects.append(
                    classes.Projectile(
                        projectiles[niveauActuel],
                        (cBoss.sprite.rect.left + 190),
                        (cBoss.sprite.rect.top + 120),
                        (cHero.sprite.rect.centerx),
                        (cHero.sprite.rect.centery),
                        2,
                    )
                )
                EnemyBullets_rects.append(
                    classes.Projectile(
                        projectiles[niveauActuel],
                        (cBoss.sprite.rect.left + 250),
                        (cBoss.sprite.rect.top + 120),
                        (cHero.sprite.rect.centerx),
                        (cHero.sprite.rect.centery),
                        2,
                    )
                )
                timerBossAttack = 80

        # Gestion des mouvements boss ----------------------------------------------------------
        if timerMoveBoss <= 0:
            if niveauActuel == 0:
                if cBoss.sprite.rect.centerx < cHero.sprite.rect.centerx:
                    cBoss.sprite.rect = cBoss.sprite.rect.move(cBoss.vitesse, 0)
                elif cBoss.sprite.rect.centerx > cHero.sprite.rect.centerx:
                    cBoss.sprite.rect = cBoss.sprite.rect.move(-cBoss.vitesse, 0)
                else:
                    # Attaque speciale
                    if timerSp <= 0:
                        EnemyBullets_rects.append(
                            classes.Projectile(
                                projectiles[niveauActuel],
                                (cBoss.sprite.rect.left + 230),
                                (cBoss.sprite.rect.top + 200),
                                (cBoss.sprite.rect.left + 230),
                                600,
                                1.5,
                            )
                        )
                        EnemyBullets_rects.append(
                            classes.Projectile(
                                projectiles[niveauActuel],
                                (cBoss.sprite.rect.left + 250),
                                (cBoss.sprite.rect.top + 200),
                                (cBoss.sprite.rect.left + 250),
                                600,
                                1.5,
                            )
                        )
                        timerSp = 15
                timerMoveBoss = 5
            if niveauActuel == 1 or niveauActuel == 2:
                if cBoss.sprite.rect.centerx < cHero.sprite.rect.centerx:
                    cBoss.sprite.rect = cBoss.sprite.rect.move(cBoss.vitesse, 0)
                elif cBoss.sprite.rect.centerx > cHero.sprite.rect.centerx:
                    cBoss.sprite.rect = cBoss.sprite.rect.move(-cBoss.vitesse, 0)
                timerMoveBoss = 3
            if niveauActuel == 3:
                if (cBoss.sprite.rect.centerx < cHero.sprite.rect.centerx) and cBoss.sprite.rect.left > 0:
                    cBoss.sprite.rect = cBoss.sprite.rect.move(-cBoss.vitesse, 0)
                elif (cBoss.sprite.rect.centerx > cHero.sprite.rect.centerx) and cBoss.sprite.rect.right < 800:
                    cBoss.sprite.rect = cBoss.sprite.rect.move(cBoss.vitesse, 0)
                else:
                    if timerSp <= 0:
                        cBoss.sprite.rect.top = 34
                        cBoss.sprite.rect.centerx = 400
                        timerSp = 1000
            if niveauActuel == 4:
                if timerSp <= 0:
                    EnemyBullets_rects.append(
                        classes.Projectile(
                            projectiles[niveauActuel],
                            (cBoss.sprite.rect.left + 60),
                            (cBoss.sprite.rect.top + 145),
                            (cBoss.sprite.rect.left - 200),
                            600,
                            2,
                        )
                    )
                    EnemyBullets_rects.append(
                        classes.Projectile(
                            projectiles[niveauActuel],
                            (cBoss.sprite.rect.left + 150),
                            (cBoss.sprite.rect.top + 145),
                            (cBoss.sprite.rect.left + 410),
                            600,
                            2,
                        )
                    )
                    timerSp = 500
            if niveauActuel == 5:
                if timerSp <= 0:
                    for i in range(1, 25):
                        EnemyBullets_rects.append(
                            classes.Projectile(projectiles[niveauActuel], 10 + i * 30, 35, 10 + i * 30, 600, 1)
                        )
                        timerSp = 400
            if niveauActuel == 6:
                if cBoss.sprite.rect.centerx < cHero.sprite.rect.centerx:
                    cBoss.sprite.rect = cBoss.sprite.rect.move(cBoss.vitesse, 0)
                elif cBoss.sprite.rect.centerx > cHero.sprite.rect.centerx:
                    cBoss.sprite.rect = cBoss.sprite.rect.move(-cBoss.vitesse, 0)
                timerMoveBoss = 2
            if niveauActuel == 7 or niveauActuel == 8:
                if sensDir == 1:
                    cBoss.sprite.rect = cBoss.sprite.rect.move(cBoss.vitesse, 0)
                    if cBoss.sprite.rect.right > 800:
                        sensDir = 0
                else:
                    cBoss.sprite.rect = cBoss.sprite.rect.move(-cBoss.vitesse, 0)
                    if cBoss.sprite.rect.left < 0:
                        sensDir = 1
                timerMoveBoss = 5
        # Blit du background + zone de combat ---------------------------------------------------
        screen.blit(background.image, background.rect)
        screen.blit(bg.image, bg.rect)
        # Blit des projectiles boss -----------------------------------------------------------------
        ebullet_vdb = 0
        auto = 0
        for i in EnemyBullets_rects:
            if i.sprite.rect.bottom > 536 or i.sprite.rect.left > 800 or i.sprite.rect.right < 0:
                EnemyBullets_rects.pop(ebullet_vdb)
            elif pygame.sprite.collide_mask(cHero.sprite, i.sprite):
                cHero.vieCourante -= cBoss.puissance
                EnemyBullets_rects.pop(ebullet_vdb)
            else:
                bullet_vdb = 0
                for u in bullet_rects:
                    if pygame.sprite.collide_mask(u, i.sprite):
                        bullet_rects.pop(bullet_vdb)
                        EnemyBullets_rects.pop(ebullet_vdb)
                    bullet_vdb += 1
                if i.x2 == 0 and i.y2 == 0:  # Si tir autoguide
                    i.x2 = cHero.sprite.rect.centerx
                    i.y2 = cHero.sprite.rect.centery
                    auto = 1

                    # i.sprite.rect.centerx et i.sprite.rect.centery = coordonnees point de depart
                    # i.x2 et i.y2 = coordonnes point d arrivee

                    # si les x sont 2* plus grands que les y
                if (abs(i.x2 - i.sprite.rect.centerx)) > 2 * (abs(i.y2 - i.sprite.rect.centery)):
                    if i.x2 - i.sprite.rect.centerx > 0:
                        i.sprite.rect = i.sprite.rect.move(i.vitesse * 2, 0)
                    else:
                        i.sprite.rect = i.sprite.rect.move(-i.vitesse * 2, 0)

                        # si les y sont 2* plus grands que les x
                elif (abs(i.y2 - i.sprite.rect.centery)) > 2 * (abs(i.x2 - i.sprite.rect.centerx)):
                    if i.y2 - i.sprite.rect.centery > 0:
                        i.sprite.rect = i.sprite.rect.move(0, i.vitesse * 2)
                    else:
                        i.sprite.rect = i.sprite.rect.move(0, -i.vitesse * 2)
                        # sinon, bouge normalement
                else:
                    if i.y2 - i.sprite.rect.centery > 0:
                        i.sprite.rect = i.sprite.rect.move(0, i.vitesse)
                    else:
                        i.sprite.rect = i.sprite.rect.move(0, -i.vitesse)

                    if i.x2 - i.sprite.rect.centerx > 0:
                        i.sprite.rect = i.sprite.rect.move(i.vitesse, 0)
                    else:
                        i.sprite.rect = i.sprite.rect.move(-i.vitesse, 0)

                if auto == 1:
                    i.x2 = 0
                    i.y2 = 0
                    auto = 0

                screen.blit(i.sprite.image, i.sprite.rect)
            ebullet_vdb += 1

        # Blit des projectiles joueur ----------------------------------------------------------------
        bullet_vdb = 0
        for i in bullet_rects:
            if i.rect.top < 35:
                bullet_rects.pop(bullet_vdb)
            elif pygame.sprite.collide_mask(cBoss.sprite, i):
                cBoss.vieCourante -= cHero.puissance
                try:
                    bullet_rects.pop(bullet_vdb)
                except IndexError:
                    print("nope")
            else:
                i.rect.top = i.rect.top - 10
                screen.blit(i.image, i.rect)
            bullet_vdb += 1
        # Affichage mobs --------------------------------------------------------------------------
        mobs_vdb = 0
        for k in mob_rects:
            if pygame.sprite.collide_mask(k.sprite, cHero.sprite):
                mob_rects.pop(mobs_vdb)
                cHero.vieCourante -= k.puissance
            elif k.sprite.rect.bottom > 536:
                mob_rects.pop(mobs_vdb)
            else:
                bullet_vdb = 0
                for u in bullet_rects:
                    if pygame.sprite.collide_mask(k.sprite, u):
                        bullet_rects.pop(bullet_vdb)
                        k.vieCourante -= cHero.puissance
                        if k.vieCourante <= 0:
                            mob_rects.pop(mobs_vdb)
                            cHero.gold += k.argent
                    bullet_vdb += 1
            mobs_vdb += 1
        for k in mob_rects:
            k.sprite.rect = k.sprite.rect.move(0, k.vitesse)
            screen.blit(k.sprite.image, k.sprite.rect)
        # -------------------------------------------------------------------------------------------
        screen.blit(cHero.sprite.image, cHero.sprite.rect)
        screen.blit(cBoss.sprite.image, cBoss.sprite.rect)
        # Blit de la barre de vie du heros ----------------------------------------------------------
        for i in range(1, ((cHero.vieCourante * 50) / cHero.viePleine) + 1):
            vie.rect.centery = 579
            vie.rect.left = 296 + i * 4
            screen.blit(vie.image, vie.rect)
        # Blit de la barre de vie du boss -----------------------------------------------------------
        for i in range(1, ((cBoss.vieCourante * 125) / cBoss.viePleine) + 1):
            vie.rect.centery = 15
            vie.rect.left = 284 + i * 4
            screen.blit(vie.image, vie.rect)
        # -------------------------------------------------------------------------------------------
        screen.blit(label, (565, 551))

        pygame.display.flip()
        screen.blit

        pygame.time.wait(10)
Esempio n. 13
0
 def __init__(self, position, velocity):
     super().__init__(position, rotozoom(load_sprite("pizza"), 0, 0.5),
                      velocity)
Esempio n. 14
0
import sys
import pygame
import os
import game,util

pygame.init()

os.environ['SDL_VIDEO_CENTERED'] = '1'
size = width, height = 800, 600
screen = pygame.display.set_mode(size)

background = util.load_sprite("menu.png")

menuPos = [98,199,300,401,502]

select = util.load_sprite("select.png")
select.rect.right = 520
select.rect.centery = menuPos[0]

pygame.mixer.music.load("menutheme.mp3")
pygame.mixer.music.play(1000)

choix = 0
timer = 0
timerMenu = 0

varOptions = [1,0,0]
	# 0:(optSon) 0 = Mute / 1 = Play
	# 1:(optGD) 0 = Droitier / 1 = Gaucher
	# 2:(optTir) 0 = Manuel / 1 = Automatique