Exemple #1
0
 def prep_lives(self):
     self.lives = Group()
     for i in range(self.stats.ships_left):
         live = Lives(self.screen)
         live.rect.x = 10 + i * live.rect.width
         live.rect.top = 10
         self.lives.add(live)
     live = Lives(self.screen)
     self.width = live.rect.width * self.stats.ships_left
Exemple #2
0
 def perp_ship(self):
     self.ships = Group()
     for ship_number in range(self.stats.ships_left):
         ship = Lives(self.ai_setings, self.screen)
         ship.rect.x = 10 + ship_number * ship.rect.width
         ship.rect.y = 10
         self.ships.add(ship)
Exemple #3
0
    def prep_lives(self):

        self.lives = Group()
        for life_number in range(self.stats.ships_left):
            life = Lives()
            life.rect.x = 10 + life_number * life.rect.width + life_number * 10
            life.rect.y = 10
            self.lives.add(life)
Exemple #4
0
 def prep_lives(self):
     """Show how many lives are left"""
     self.lives = Group()
     for lives_number in range(self.stats.ships_left):
         life = Lives(self.ai_settings, self.screen)
         life.rect.x = 10 + lives_number * life.rect.width
         life.rect.y = 10
         self.lives.add(life)
Exemple #5
0
    def __init__(self, i_fenetre):
        '''
            Définition des variables du constructeur.
        '''

        self.fenetre = i_fenetre  # Stocke les paramètres de la fenêtre.
        self.canevas = tk.Canvas(
            self.fenetre,
            width=self.largeur_fenetre(),
            height=self.hauteur_fenetre(
            ))  # Crée un canvas ( Support de tout les éléments d'affichage. )
        self.canevas.place(x=0, y=0)  # Place le Canvas

        self.raquette = Raquette(self)  # Crée une instance de Raquette.
        self.balle = Balle(self)  # Crée une instance de Balle.
        self.level_id = -1  # Numéro du niveau à charger.
        self.niveau = Level(self,
                            self.level_id)  # Crée une instance du Niveau .
        self.lives = Lives(self, 3,
                           self.largeur_fenetre() / 16,
                           (self.hauteur_fenetre() * 15) /
                           16)  # Crée une instance des Vies.

        self.touche_possible = [
            "q", "d", "Q", "D"
        ]  # Liste des touches qui seront utilisées pour jouer.
        self.touche_options = [
            'plus', 'minus', 'slash'
        ]  # Liste des touches qui seront utilisées pour les options du jeu (Augmenter le taux de rafraîchissement : +, le Diminuer : -, Mettre en place un sol : / ).

        # Capture les événements de la souris.
        self.canevas.bind(
            "<Motion>",
            self.moved)  # Coordonnées du curseur de la souris en abscisse.
        self.canevas.bind("<Button-3>",
                          self.rightClick)  # Si le click droit a été activé.
        self.canevas.bind(
            "<Leave>",
            self.leave)  # Si la souris a quitté le périmètre de la fenêtre.
        self.canevas.bind(
            "<Enter>",
            self.enter)  # Si la souris est entrée le périmètre de la fenêtre.

        # Capture les événements du clavier.
        self.fenetre.bind(
            "<KeyPress>", self.checkKeyPressed
        )  # Active la capture des touches du clavier dans la fenêtre.
        self.resetGame(
        )  # Initialise tout les objets avec leurs paramètres par défaut.
Exemple #6
0
    def __init__(self,gamestate,score,ammo):
        # Konfuguracja

        random.seed()
        #inicjalizaja
        pygame.init()

        self.SCREEN_SIZE = (1280, 720)  # grafiki dopasowane do tego
        self.screen = pygame.display.set_mode(self.SCREEN_SIZE)

        self.tps_clock = pygame.time.Clock()
        self.tps_delta = 0.0
        self.shot = 0.0
        self.supertime = -2

        self.player = Player(self)
        self.aliens = []
        self.opp = 10
        self.bullets = []
        self.alienbulets = []
        self.lives = Lives(self)
        self.lives_number = 3
        self.score = Score(self)
        self.score_number = 0 + score
        self.ammo = Ammo(self)
        self.walls = []
        self.gameover = GameOver(self)
        self.gamestate = gamestate
        self.ammo_number = ammo + 5
        self.nextlevel = NextLevel(self)
        self.tps_max = 300.0
        self.superalien = []
        self.tooClose = False
        self.pauseSign = Pause(self)
        self.pause = 1

        for i in range(0,self.opp):
            self.aliens.append(Alien(self, i * 100 + 100, 100,self.gamestate-1))
            self.aliens.append(Alien(self, i * 100 + 100, 150,self.gamestate-1))
            self.aliens.append(Alien(self, i * 100 + 100, 200,self.gamestate-1))
            self.aliens.append(Alien(self, i * 100 + 100, 250,self.gamestate-1))
            self.aliens.append(Alien(self, i * 100 + 100, 300,self.gamestate-1))
            self.aliens.append(Alien(self, i * 100 + 100, 350,self.gamestate-1))

        self.rand_opp = 6*self.opp

        for i in range(0,5):
            self.walls.append(Wall(self,80+i*340))

        channel_game = pygame.mixer.Channel(1)
        channel_game2 = pygame.mixer.Channel(2)
        channel_game3 = pygame.mixer.Channel(3)

        self.background = pygame.image.load("tlo3.jpg")

        self.text = open("score").readline()

        while self.gamestate !=0:

            if self.rand_opp != 0:
                los = random.randrange(self.rand_opp)
            else:
                los = 0
            # obsługa zdarzen
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    sys.exit()
                elif event.type == pygame.KEYDOWN and event.key == pygame.K_p:
                    self.pause *= -1
                elif event.type == pygame.KEYDOWN and event.key == pygame.K_SPACE and self.ammo_number != 0:
                    self.bullets.append(Bullet(self,self.player.pos[0]+23,self.player.pos[1]))
                    channel_game3.play(pygame.mixer.Sound("mygun.wav"))
                    channel_game3.set_volume(0.5)
                elif (self.lives_number == 0 or self.ammo_number <= 0 or self.tooClose == True) and event.type == pygame.KEYDOWN and event.key == pygame.K_RETURN:
                    self.gamestate = 0
                elif len(self.aliens) == 0 and event.type == pygame.KEYDOWN and event.key == pygame.K_RETURN:
                    self.gamestate += 1
                    Game(self.gamestate,self.score_number,self.ammo_number)
                    self.text = open("score").readline()
                    self.gamestate = 0
                elif event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE and self.pause == -1:
                    self.gamestate = 0
                elif event.type == pygame.KEYDOWN and event.key == pygame.K_p and self.pause == -1:
                    self.pause *= -1





            #ticking
            self.tps_delta += self.tps_clock.tick() / 1000.0
            self.shot += self.tps_clock.tick()+0.000000003*(self.gamestate-1) / 1.0
            self.supertime += self.tps_clock.tick() / 1.0

            while self.tps_delta > 1 / self.tps_max:
                self.tick()
                self.tps_delta -= 1 / self.tps_max

            while(self.shot >= 0.001 / self.tps_max and len(self.aliens)!=0 and (self.lives_number != 0 and self.ammo_number > 0) and self.tooClose == False and self.pause == 1):
                self.shot = 0
                channel_game.play(pygame.mixer.Sound("shot.wav"))
                channel_game.set_volume(0.5)
                self.alienbulets.append(AlienBullet(self,self.aliens[los].x,self.aliens[los].y))

            while self.supertime >= 0.001 / self.tps_max:
                self.supertime = -2
                if(len(self.superalien)==0 and self.tooClose == False and self.lives_number !=0 and self.ammo_number > 0 and self.pause == 1):
                    self.superalien.append(SuperAlien(self))
                    channel_game2.play(pygame.mixer.Sound("supersound.wav"))
                    channel_game2.set_volume(0.3)

            #rendering
            self.screen.fill((0, 0, 0))
            self.screen.blit(self.background, (0, 0))
            self.draw()
            pygame.display.flip()
Exemple #7
0
    def __init__(self):
        pygame.init()
        pygame.mixer.init()
        pygame.font.init()
        self.clock = pygame.time.Clock()
        self.screen = pygame.display.set_mode((WIDTH, HEIGHT))
        pygame.display.set_caption(TITLE)
        self.running = True
        self.background = pygame.image.load(
            "img/spaceInvadersBG.jpg").convert()
        self.all_sprites = pygame.sprite.Group()
        self.enemies = pygame.sprite.Group()
        self.player = Player()
        self.all_sprites.add(self.player)
        self.player_bullets = pygame.sprite.Group()
        self.enemy_bullets = pygame.sprite.Group()
        self.obstacles = pygame.sprite.Group()
        self.lives = Lives(3)
        """ Making the rows of enemies """
        for b in range(5):  # 5 vertical rows of enemies
            self.xPos = 100  # Original starting x position
            for i in range(11):  # 11 horizontal rows of enemies
                self.e = Enemy(self.xPos, 40 + (30 * b))  # Spawning an enemy
                self.all_sprites.add(
                    self.e)  # Adding it to the all_sprites group
                self.enemies.add(self.e)  # Adding it to the enemies group
                self.xPos += 50  # Change x position every time with the same value when a new enemy has been made
        """ drawing the obstacles """
        # TODO: make the code shorter
        for b in range(5):
            self.xPos = (WIDTH * (1 / 3)) - 70
            for i in range(7):  #
                self.obstacle = Obstacle(self.xPos, HEIGHT - 140 + (10 * b))  #
                self.all_sprites.add(
                    self.obstacle)  # Adding it to the all_sprites group
                self.obstacles.add(self.obstacle)
                self.xPos += 10

        for b in range(5):
            self.xPos = (WIDTH / 2) - 35
            for i in range(7):  #
                self.obstacle = Obstacle(self.xPos, HEIGHT - 140 + (10 * b))  #
                self.all_sprites.add(
                    self.obstacle)  # Adding it to the all_sprites group
                self.obstacles.add(self.obstacle)
                self.xPos += 10

        for b in range(5):
            self.xPos = WIDTH * (2 / 3)
            for i in range(7):  #
                self.obstacle = Obstacle(self.xPos, HEIGHT - 140 + (10 * b))  #
                self.all_sprites.add(
                    self.obstacle)  # Adding it to the all_sprites group
                self.obstacles.add(self.obstacle)
                self.xPos += 10

            # Game Loop
        while self.running:
            self.clock.tick(FPS)
            self.events()
            self.update()
            self.enemy_shoot()
            self.draw()

        quit()
        pygame.quit()
        sys.exit()
Exemple #8
0
import time
from turtle import Screen
from player import Player
from car_manager import CarManager
from scoreboard import Scoreboard
from lives import Lives

screen = Screen()
screen.title("Turtler")
screen.colormode(255)
screen.setup(width=600, height=600)
screen.tracer(0)
player = Player()
score = Scoreboard()
cars = CarManager()
lives = Lives()
screen.listen()
screen.onkey(player.move_forward, "Up")

game_is_on = True
while game_is_on:
    time.sleep(0.1)
    screen.update()
    cars.create_car()
    cars.car_automate()

    # DETECT ROADKILL
    for car in cars.car_group:
        if player.distance(car) < 25:
            game_is_on = False
            lives.take_one()
Exemple #9
0
    def __init__(self):
        pygame.init()
        self.settings = Settings()
        self.bullets = pygame.sprite.Group()
        self.enemies = pygame.sprite.Group()
        self.evil_bullets = pygame.sprite.Group()
        
        self.a_map = World_map()
                
        self.screen = pygame.display.set_mode(
            (self.settings.screen_width,self.settings.screen_height))
        pygame.display.set_caption("Invasion")
               
        self.level = 0
        self.stats = Stats(self)
        
        temp_x, temp_y = 200, 50
        temp_color = (0, 100, 0)
        temp_text_color =(255, 255, 255)
        self.play_button = Button(self, temp_x, temp_y, temp_color, temp_text_color, "PLAY")
        self.play_button.rect.y -= 65
        self.play_button._prep_msg("NEW GAME")
        
        
        temp_x, temp_y = 200, 50
        temp_color = (20, 40, 0)
        temp_text_color =(255, 255, 255)
        self.exit_button = Button(self, temp_x, temp_y, temp_color, temp_text_color, "EXIT")
        self.exit_button.rect.y += 185
        self.exit_button._prep_msg("EXIT")
        
        temp_x, temp_y = 200, 50
        temp_color = (80, 60, 0)
        temp_text_color =(255, 255, 255)
        self.title_button = Button(self, temp_x, temp_y, temp_color, temp_text_color, "TITLE")
        self.title_button.rect.y += 125
        self.title_button._prep_msg("TITLE")
        self.title = Title(self)
        self.title_active = False
        
        temp_x, temp_y = 200, 50
        temp_color = (150, 200, 0)
        temp_text_color =(255, 255, 255)
        self.help_button = Button(self, temp_x, temp_y, temp_color, temp_text_color, "HELP")
        self.help_button.rect.y += 65
        self.help_button._prep_msg("HELP")
        self.help_ = Help(self)
        self.help_active = False
        
        temp_x, temp_y = 200, 50
        temp_color = (150, 200, 0)
        temp_text_color =(255, 255, 255)
        self.back_button = Button(self, temp_x, temp_y, temp_color, temp_text_color, "BACK")
        self.back_button.rect.y += 185
        self.back_button._prep_msg("BACK")

        
        
        temp_x, temp_y = 250, 50
        temp_color = (0, 240, 0)
        temp_text_color =(255, 255, 255)
        self.restart_button = Button(self, temp_x, temp_y, temp_color, temp_text_color, "Restart level")
        
        temp_x, temp_y = 350, 50
        temp_color = (100, 100, 100)
        temp_text_color =(255, 0, 0)
        self.win_button = Button(self, temp_x, temp_y, temp_color, temp_text_color, "YOU ARE A WINNER!")
        
        self.myTank = Ship(self)
        self.myTank.live  = 0
        
        #interface
        self.liveboard = Lives(self)
        self.score = 0
        self.scoreboard = Score(self)

        self.image = pygame.image.load('images/brick_wall3.png')        
        self.rect = self.image.get_rect()
        
        self.aid = pygame.image.load('images/aid.png')