示例#1
0
 def event(self, event):
     if (event.type == pygame.KEYDOWN):
         globes.stop_music()
         globes.play_music("game.ogg")
         score = globes.Globals.GAME.score
         timeremaining = globes.Globals.GAME.timeremaining
         lives = globes.Globals.GAME.lives
         globes.Globals.STATE = gameover.GameOver(score, timeremaining,
                                                  lives)
         globes.Globals.GAME.initialize_lvl(0)
示例#2
0
 def death(self):
     """Handles the player death"""
     self.player1.killed = False  # reset killed
     self.player1.onmp = False
     self.lives -= 1  # decrease lives by 1
     if self.lives < 0:  # if lives are less than 0: GAME OVER
         globes.Globals.GAME = None
         globes.stop_music()
         globes.Globals.STATE = \
             gameover.GameOver(self.score, 0, self.lives)
     #else:
     #self.spawn_enemies()  # respawn enemies
     self.initialize_lvl(0)
     for door in self.doors:  # put player in front of door of curr level
         if door.lvl_num == globes.Globals.LVL_NUM:
             self.player1.rect.bottomleft = door.rect.bottomleft
     self.player1.x_velocity, self.player1.y_velocity = 0, 0
示例#3
0
 def level_complete(self):
     """Handles level completion"""
     if globes.Globals.LVL_NUM == len(level.LVL_FILES) - 1:
         globes.Globals.GAME = None
         globes.stop_music()
         globes.Globals.STATE = gameover.GameOver(self.score,
                                                  self.timeremaining,
                                                  self.lives)
     else:
         if globes.Globals.LVL_NUM == globes.Globals.LVLS_UNLOCKED:
             globes.Globals.LVLS_UNLOCKED += 1
         if self.timeremaining >= 0:
             self.score += self.timeremaining
         self.initialize_lvl(0)
         for door in self.doors:
             if door.lvl_num == globes.Globals.LVL_NUM:
                 self.player1.rect.bottomleft = door.rect.bottomleft
         self.player1.x_velocity, self.player1.y_velocity = 0, 0
示例#4
0
    def step(self):
        self.enemySpawner.spawn(self.trail)
        self.borderSpawner.spawn(self.trail)

        self.trail.draw(self.screen.displaysurf)

        self.hud.set_score(self.trail.score / GameDefine.SCORE_DECIMAL)
        self.hud.set_speed(self.trail.actualFallSpeed /
                           self.trail.defaultFallSpeed)
        self.hud.set_level(self.trail.level)
        self.hud.set_lost(not self.has_signal)
        self.hud.draw(self.screen.displaysurf)

        if self.lives <= 0:
            self.screen.setWorld(gameover.GameOver(self.trail.score))
            del self

        elif not self.trail.isActive:
            self.screen.setWorld(
                DotGame(self.lives - 1, self.trail.score, self.trail.level))
            del self
示例#5
0
    def __init__(self, language=None, reversed_btn=None):
        settings.MOVES_PER_SECOND = 2

        reversed = False
        if reversed_btn is not None:
            reversed = reversed_btn.reversed

        self.game_exit = False
        # 0: main menu, 1: game, 2: gameover
        self.game_state = 0
        self.prev_move = time.time()

        self.grid = [[False for j in range(settings.NUM_ROWS)] for i in range(settings.NUM_COLUMNS)]

        self.stats_collector = stats.Stats()

        self.language = language
        if language is not None:
            self.word_generator = words.WordGenerator(self.language, self.stats_collector, reversed)
        self.word, self.answer = "Temp", "Temp"
        self.apple_num = 3
        self.apples = []
        self.temp_apple = None
        self.temp_start = None

        
        if language is not None:
            self.grid[5][5] = True
            self.reset_apples()
        self.snake_obj = snake.Snake(self.word, self.grid)
        self.directions = []
        

        self.game_over_screen = gameover.GameOver(self.stats_collector)
        self.main_menu_screen = main_menu.MainMenu()
        self.loading_screen = loading.Loading()
示例#6
0
 def on_win(self):
     self.parent.add(gameover.GameOver(win=True), z=10)
     return True
示例#7
0
 def on_game_over(self):
     self.parent.add(gameover.GameOver(win=False), z=10)
     return True
示例#8
0
class App:
    stat = "MENU"  #estados possiveis: "MENU"; "PAUSA"; "JOGO"; "CREDITOS"; "GAMEOVER";
    status = [
        mi.Iniciar(180, 80),
        mp.Pause(180, 80),
        j.Jogo(180, 80),
        c.Creditos(180, 80),
        go.GameOver(180, 80)
    ]
    width = 0
    height = 0
    sound = True
    soundChange = True
    pontos = 0
    estadoJogador = True

    def __init__(self, w, h):
        self.width = w
        self.height = h
        pyxel.init(self.width, self.height)
        pyxel.load("assets/menu.pyxres")
        pyxel.run(self.update, self.draw)

    def update(self):
        if pyxel.btn(pyxel.KEY_Q):
            pyxel.quit()

        if self.soundChange == True:
            self.play_music()

        self.mudaEstado()

        if self.stat == "MENU":
            self.status[0].update()
        elif self.stat == "PAUSA":
            self.status[1].update()
        elif self.stat == "JOGO":
            self.status[2].update()
        elif self.stat == "CREDITOS":
            self.status[3].update()
        elif self.stat == "GAMEOVER":
            self.status[4].update()
        self.status[4].setPontos(self.pontos)

    def draw(self):
        pyxel.cls(3)
        if self.stat == "MENU":
            self.status[0].draw()
        elif self.stat == "PAUSA":
            self.status[1].draw()
        elif self.stat == "JOGO":
            self.status[2].draw()
        elif self.stat == "CREDITOS":
            self.status[3].draw()
        elif self.stat == "GAMEOVER":
            self.status[4].draw()

    def mudaEstado(self):
        if self.stat == "MENU":
            prox = self.status[0].mouse()
            if prox[0] == True:
                if prox[1] == 0:  #Música ON
                    self.sound = True
                    self.soundChange = True
                elif prox[1] == 1:  #Música OFF
                    self.sound = False
                    self.soundChange = True
                elif prox[1] == 2:  #Creditos
                    self.stat = "CREDITOS"
                    self.soundChange = True
                elif prox[1] == 3:  #Iniciar
                    self.status[2].reset()
                    self.stat = "JOGO"
                    self.soundChange = True

        elif self.stat == "PAUSA":
            prox = self.status[1].mouse()
            if prox[0] == True:
                if prox[1] == 0:  #Música ON
                    self.sound = True
                    self.soundChange = True
                elif prox[1] == 1:  #Música OFF
                    self.sound = False
                    self.soundChange = True
                elif prox[1] == 2:  #JOGAR
                    self.stat = "JOGO"
                    self.soundChange = True
                elif prox[1] == 3:  #SAIR
                    self.stat = "MENU"
                    self.soundChange = True

        elif self.stat == "JOGO":
            prox = self.status[2].mouse()
            if prox[0] == True:
                if prox[1] == 0:  #VOLTAR
                    self.stat = "PAUSA"
                    self.soundChange = True
                elif prox[1] == 1:
                    self.stat = "GAMEOVER"
                    self.soundChange = True
                    self.pontos = prox[2]

        elif self.stat == "CREDITOS":
            prox = self.status[3].mouse()
            if prox[0] == True:
                if prox[1] == 0:  #VOLTAR
                    self.stat = "MENU"
                    self.soundChange = True

        elif self.stat == "GAMEOVER":
            prox = self.status[4].mouse()
            if prox[0] == True:
                if prox[1] == 0:  #Música ON
                    self.sound = True
                    self.soundChange = True
                elif prox[1] == 1:  #Música OFF
                    self.sound = False
                    self.soundChange = True
                elif prox[1] == 2:  #JOGO
                    self.status[2].reset()
                    self.stat = "JOGO"
                    self.soundChange = True
                elif prox[1] == 3:  #SAIR
                    self.stat = "MENU"
                    self.soundChange = True

    def play_music(self):
        if self.sound == True:
            if self.stat == "MENU" or self.stat == "PAUSA" or self.stat == "CREDITOS":
                pyxel.play(1, 0, loop=True)
            if self.stat == "JOGO":
                pyxel.play(1, 2, loop=True)
            if self.stat == "GAMEOVER":
                pyxel.play(1, 3, loop=True)
        else:
            pyxel.stop(1)
        self.soundChange = False
示例#9
0
s.onkey(snake.down, "Down")

game_on = True

# while -280 < snake.head.xcor() < 280 \
#         and -280 < snake.head.ycor() < 280:
while game_on:
    s.update()  # update the screen
    time.sleep(0.2)  # slow down the animation
    snake.move_body()

    # Detect collision with food
    if snake.head.distance(food) < 15:
        food.new_food()
        scoreboard.update()
        snake.extend()

    # Detect collision with wall
    if snake.head.xcor() < -280 or snake.head.xcor() > 280 or snake.head.ycor() < -280 or snake.head.ycor() > 280:
        game_on = False
        gameover.GameOver()

    # If the head collides with any body segment then trigger game over.
    for seg in snake.body[1:]:  # use slicing to get every element except the head
        if snake.head.distance(seg) < 10:
            game_on = False
            gameover.GameOver()


s.exitonclick()
示例#10
0
    def runGame(self):
        pygame.key.set_repeat(500, 30) # Values can be changed as needed. Example values

        startGameTime = time.time()
        self.last = pygame.time.get_ticks()
        rand_blackoutSt = random.randint(5, 8)
        rand_blackoutEnd = random.randint(9, 12)
        blackout2st = random.randint(25, 28)
        blackout2End = random.randint(29, 33)
        blackVocCounter = 0
        blackOut3 = random.randint(50, 52)
        blackout3st = 51
        blackout3End = random.randint(54, 56)
        #print(blackout3)
        while 1:
            for event in pygame.event.get(): # Handles figuring out even 
                if event.type == pygame.QUIT:
                    sys.exit()
            pygame.display.update()
            #seconds = pygame.time.get_ticks()//1000
            self.screen.fill((200,200,200)) # Values can be changed as needed. Example values
            self.time = 90
            self.bg.drawSea()
            self.bg.drawSky()
            self.ship1.draw()
            self.ship2.draw()
            self.ship3.draw()
            secondsPassed = time.time() - startGameTime
            #1st and 2nd Blackout
            if time.time() - startGameTime >= rand_blackoutSt and time.time() - startGameTime <= rand_blackoutEnd or time.time() - startGameTime >= blackout2st and time.time() - startGameTime <= blackout2End:
                if self.voiceCounter == 0:
                    self.channel3.play(self.voicePowerGone, 0)
                if int(time.time()) - int(startGameTime) == int(rand_blackoutEnd) and self.boVoiceCounter == 0:
                    self.channel5.play(self.voicePowerPlus, 0)
                    self.boVoiceCounter += 1
                    print("blackout over")
                startTime = int(time.time())
                endTime = startTime + 10
                while not startTime == endTime:
                    self.screen.fill((0,0,0))
                    startTime += 1
                    self.voiceCounter += 1
            #3rd blackout
            if time.time() - startGameTime >= blackOut3 and time.time() - startGameTime <= blackout3End and blackOut3 == 51:
                if self.voiceCounter == 0:
                    self.channel3.play(self.voicePowerGone, 0)
                if int(time.time()) - int(startGameTime) == int(rand_blackoutEnd) and self.boVoiceCounter == 0:
                    self.channel5.play(self.voicePowerPlus, 0)
                    self.boVoiceCounter += 1
                    print("blackout over")
                startTime = int(time.time())
                endTime = startTime + 10
                while not startTime == endTime:
                    self.screen.fill((0,0,0))
                    startTime += 1
                    self.voiceCounter += 1
            print(pygame.time.get_ticks())
            #if time.time()*1000%1000 ==0:
                #self.time -= 1
            self.scope.move()
            self.moveShips()
            self.screenWrap()
                   

            if time.time() - startGameTime >= self.LENGTHOFGAME and self.torpedo == None:
                pygame.mixer.music.stop()
                pygame.mixer.music.load("menu_bgm.wav")
                pygame.mixer.music.play(-1, 0.0)
                go = gameover.GameOver(self.score)
                g = go.runGameOver()
                if g:
                    return
                else:
                    pygame.init()
                    # re-setup the class game to play the  game
                    self.score = 0
                    self.scoreText = pygame.font.Font("Minecraft.ttf", 30)
                    self.width = 1000
                    self.height = 700
                    self.screen = pygame.display.set_mode((self.width, self.height))
                    self.background = pygame.Surface(self.screen.get_size())
                    self.background = self.background.convert()
                    self.screen.fill((200,200,200)) # Values can be changed as needed. Example values
                    self.bg = background.Background(self.screen, 0, 375)
                    self.ship1Y = random.randint(340, 375)
                    self.ship2Y = random.randint(350, 385)
                    self.ship3Y = random.randint(360, 395)
                    self.ship1 = ships.Ship(self.screen, 0, self.ship1Y)
                    self.ship2 = ships.Ship(self.screen, -200, self.ship2Y)
                    self.ship3 = ships.Ship(self.screen, -400, self.ship3Y) 
                    self.scope = scope.Scope(self.screen)
                    self.linev = scope.Scope(self.screen)
                    self.lineh = scope.Scope(self.screen)
                    self.P1 = (500, 700)
                    self.dx = 0
                    self.dy = 0
                    self.torpedo = None
                    self.ship1Speed = random.randint(1,3)
                    self.ship2Speed = random.randint(1,3)
                    self.ship3Speed = random.randint(1,3)
                    self.explosionLocX = None
                    self.explosionLocY = None
                    self.explosion = None
                    startGameTime = time.time()


            
            key = pygame.key.get_pressed()
            # Catching the ZeroDivisionError using an exception
            self.now = pygame.time.get_ticks()
            try:
                if key[pygame.K_SPACE]:
                    print(self.calculateSlope())
                    #self.torpedoSound.play()
                    if time.time() - startGameTime <= self.LENGTHOFGAME:
                        self.torpedo = torpedo.Torpedo(self.screen, self.dx, self.dy)
                        self.channel1.play(self.torpedoSound, 0)
                        self.channel4.play(self.voiceTorpedo, 0)
                        #self.channel2.play(self.voiceTorp, 0)
                        self.torpedoSound.set_volume(1.0)
            except ZeroDivisionError:
                if time.time() - startGameTime <= self.LENGTHOFGAME:
                    self.torpedo = torpedo.Torpedo(self.screen, self.dx, self.dy)
                    self.torpedo.move()
                    self.channel1.play(self.torpedoSound, 0)
                    #self.channel2.play(self.voiceTorp, 0)
                    self.torpedoSound.set_volume(1.0)
                    pass
            if not self.torpedo == None:
                oldVolume = self.torpedoSound.get_volume()
                self.torpedoSound.set_volume(oldVolume - .005)
                self.torpedo.move()
                if self.collision() or self.torpedo.rect.top < 440:
                    self.collisionShip1()
                    self.collisionShip2()
                    self.collisionShip3()
                    del(self.torpedo)
                    self.torpedoSound.stop()
                    time.sleep(.03)
                    self.torpedo = None
                #if self.torpedo.rect.top < 420:
                    #print("="*15)
                    #del(self.torpedo)
                    #self.torpedo = None
            self.updateScore()
            self.time = self.time - secondsPassed
            self.time = int(self.time)
            #if time.time() - startGameTime <= self.LENGTHOFGAME:
            if time.time() - startGameTime >= self.LENGTHOFGAME:
                self.screen.blit(self.textDis,(830, 35))
            else:
                self.updateTime()