Пример #1
0
    def gameOverScreen(self):  # It controls all the menu Screens
        rospy.Subscriber("/bender/joy/joy0", Joy, callback)

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                quit()
            if event.type == KEYDOWN:
                if event.key == K_ESCAPE:
                    pygame.quit()
                    quit()

        if START == 1:
            print "START: ", START
            FaceOrder.ChangeFace("happy3")
            rospy.sleep(2)
            FaceOrder.ChangeFace("happy1")
            return True

# video.SetDisplay(WIDTH, HEIGHT, video.getFullscreen())
#               break
        if EXIT == 1:
            FaceOrder.ChangeFace("sad2")
            pygame.mixer.music.fadeout(2000)
            rospy.sleep(2)
            Talk.getInstance("oh!  you didn't like this game! ", 4)
            Talk.getInstance("let's go to the next one! ", 4)
            FaceOrder.ChangeFace("happy1")
            pygame.quit()
            sys.exit()
Пример #2
0
 def __fin_win(self):
     # rospy.sleep(5)
     FaceOrder.ChangeFace("happy3")
     pygame.mixer.music.fadeout(5000)
     rospy.sleep(5)
     Talk.getInstance("you are a great driver! ", 4)
     FaceOrder.ChangeFace("happy1")
     pygame.quit()
     #return
     sys.exit()
Пример #3
0
 def __fin(self):
     FaceOrder.ChangeFace("sad2")
     rospy.sleep(5)
     pygame.mixer.music.fadeout(4000)
     rospy.sleep(4)
     Talk.getInstance("better luck next time! ", 4)
     FaceOrder.ChangeFace("happy1")
     pygame.quit()
     #return
     sys.exit()
Пример #4
0
 def __fin_exit(self):
     # rospy.sleep(5)
     FaceOrder.ChangeFace("sad2")
     pygame.mixer.music.fadeout(2000)
     rospy.sleep(2)
     Talk.getInstance("oh!  you didn't like this game! ", 4)
     Talk.getInstance("let's go to the next one! ", 4)
     FaceOrder.ChangeFace("happy1")
     pygame.quit()
     #return
     sys.exit()
Пример #5
0
 def Kill(self, ID):
     #self.ENEMY_LIST[ID] = pygame.Surface((32,32))
     #self.ENEMY_LIST.remove(self.ENEMY_LIST[ID])
     self.ENEMY_LIST[ID] = self.EnemyAlien(0, AlienType.Type0)
     self.EnemiesLeft -= 1
     # print "Muerto!!!"
     FaceOrder.ChangeFace("happy2")
     return self.EnemiesLeft
Пример #6
0
    def __hit_speed_boost(self):
        path = rospack.get_path('uchile_fun')
        path += "/src/uchile_fun/SwervinMervin/"
        if self.speed_boost == 1:
            boost_sfx = pygame.mixer.Sound(
                os.path.join(path + "lib", "speed_boost.ogg"))
            boost_sfx.play()

            self.__set_special_text("Speed boost!", 2)

        FaceOrder.ChangeFace("happy2")
        self.speed_boost = 1.6
Пример #7
0
    def __hit_competitor(self):
        path = rospack.get_path('uchile_fun')
        path += "/src/uchile_fun/SwervinMervin/"
        crash_sfx = pygame.mixer.Sound(
            os.path.join(path + "lib", "car_crash.ogg"))
        crash_sfx.play()

        self.speed = self.speed / s.CRASH_DIVISOR

        FaceOrder.ChangeFace("surprise")

        if self.status == self.ALIVE:
            self.points -= self.points * s.POINT_LOSS_COMP
Пример #8
0
    def __hit_bonus(self):
        path = rospack.get_path('uchile_fun')
        path += "/src/uchile_fun/SwervinMervin/"
        if self.status == self.ALIVE:
            self.lap_bonus += s.BONUS_AMOUNT

        bonus_sfx = pygame.mixer.Sound(
            os.path.join(path + "lib", "oh_yeah.ogg"))
        bonus_sfx.play()

        FaceOrder.ChangeFace("happy2")

        self.__set_special_text("Bonus time!", 2)
Пример #9
0
    def checkPlayerCollitions(self):
        # Checks if the Nao's Balls hit the player
        playerCollides = pygame.sprite.spritecollide(self.player, self.balls,
                                                     True)
        if len(playerCollides) != 0:
            self.player.looseLive()
            # Set last hit to remember what killed bender
            self.player.setDeath(0)

            pygame.mixer.Sound.play(self.hitSound)
            #======================BENDER EMOTION==================
            FaceOrder.ChangeFace("surprise")

        playerCollidesWithNao = pygame.sprite.spritecollide(
            self.player, self.naos, False)
        if len(playerCollidesWithNao) != 0:
            self.player.looseLive(3)
            # Set last hit to remember what killed bender
            self.player.setDeath(1)

            pygame.mixer.Sound.play(self.hitSound)
            #======================BENDER EMOTION==================
            FaceOrder.ChangeFace("surprise")
Пример #10
0
    def __hit_hooker(self):
        path = rospack.get_path('uchile_fun')
        path += "/src/uchile_fun/SwervinMervin/"
        crash_sfx = pygame.mixer.Sound(os.path.join(path + "lib",
                                                    "scream.ogg"))
        splat_sfx = pygame.mixer.Sound(os.path.join(path + "lib", "blood.ogg"))
        self.blood_alpha = 255

        # Yeah, I'm a sicko....
        if self.status == self.ALIVE:
            self.points += s.POINT_GAIN_PROSTITUTE
            self.__set_special_text("+%d points!" % s.POINT_GAIN_PROSTITUTE, 2)

        crash_sfx.play()
        splat_sfx.play()
        FaceOrder.ChangeFace("happy2")
Пример #11
0
    def __hit_world_object(self):
        path = rospack.get_path('uchile_fun')
        path += "/src/uchile_fun/SwervinMervin/"
        pygame.mixer.music.set_volume(0.2)

        crash_sfx = pygame.mixer.Sound(
            os.path.join(path + "lib", "you_fool.ogg"))
        self.crashed = True
        self.speed = 0
        self.speed_boost = 1

        crash_sfx.play()

        FaceOrder.ChangeFace("angry3")

        if self.status == self.ALIVE:
            deduction = self.points * s.POINT_LOSS_SPRITE
            self.points -= deduction
            self.__set_special_text("-%d points!" % deduction, 2)
Пример #12
0
    def checkCollitions(self):
        # Checks if the player's Rockets hit a Nao
        rockets = self.rockets.sprites()
        rocketsQuantity = len(rockets)
        for i in range(0, rocketsQuantity, 1):
            collides = pygame.sprite.spritecollide(rockets[i], self.naos, True)
            if len(collides) != 0:
                rockets[i].kill()
                #======================BENDER EMOTION==================
                FaceOrder.ChangeFace("happy2")

                self.naosOnMap -= 1
                if self.naosOnMap == 0 and not self.bossTime:
                    # Here the game conditions change
                    self.boss = MotherShip(WIDTH / 2, 10)
                    self.naos.add(self.boss)
                    self.naosOnMap = 1
                    self.bossTime = True
                    self.maxNaoBalls += 3
                    pygame.mixer.music.stop()
                    pygame.mixer.music.load(BOSS_MUSIC)
                    pygame.mixer.music.play(-1)
Пример #13
0
    def progress(self, window):
        txt = str(self.remaining) if self.remaining > 0 else "GO"
        cd_text = self.cd_font.render(txt, 1, s.COLOURS["text"])
        level_text = self.text_font.render(
            "Level %d: %s" % (self.level_number, self.level_name), 1,
            s.COLOURS["text"])
        freq = 440 if self.remaining > 0 else 570
        beep = pygame.mixer.Sound(os.path.join("lib", "%d.wav" % freq))

        window.fill(s.COLOURS["black"])
        window.blit(level_text, u.middle(level_text, y=25))
        window.blit(cd_text,
                    u.middle(cd_text, y_offset=(level_text.get_height())))

        beep.set_volume(0.2)
        beep.play()

        self.remaining -= 1

        if self.remaining < 0:
            FaceOrder.ChangeFace("happy1")
            self.finished = True
Пример #14
0
    def updateModel(self):  # Updates the model according to the events

        currentTime = pygame.time.get_ticks()

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                #======================BENDER EMOTION==================
                # FaceOrder.ChangeFace("sad2")
                # pygame.mixer.music.fadeout(2000)
                # rospy.sleep(2)
                # Talk.getInstance("oh!  you didn't like this game! ",4)
                # Talk.getInstance("let's go to the next one! ",4)
                # FaceOrder.ChangeFace("happy1")

                pygame.quit()
                quit()
            if event.type == self.shootEvent:
                self.model.spawnNaoBalls()
                pygame.time.set_timer(self.shootEvent, 150)

            if event.type == self.animateEvent:
                self.model.animateNaos()
                pygame.time.set_timer(self.animateEvent, 200)

            if event.type == KEYDOWN:
                if event.key == K_ESCAPE:
                    #======================BENDER EMOTION==================
                    # FaceOrder.ChangeFace("sad2")
                    # pygame.mixer.music.fadeout(2000)
                    # rospy.sleep(2)
                    # Talk.getInstance("oh!  you didn't like this game! ",4)
                    # Talk.getInstance("let's go to the next one! ",4)
                    # FaceOrder.ChangeFace("happy1")

                    pygame.quit()
                    quit()
                if event.key == K_LEFT:
                    self.player_H_Speed = -3
                if event.key == K_RIGHT:
                    self.player_H_Speed = 3
                if event.key == K_SPACE:
                    self.model.playerRocket()
            if event.type == pygame.KEYUP:
                if event.key == K_LEFT or event.key == K_RIGHT:
                    self.player_H_Speed = 0

        if RIGHT_LEFT > 0 or RIGHT_LEFT == 1:
            self.player_H_Speed = -3
        if RIGHT_LEFT < 0 or RIGHT_LEFT == -1:
            self.player_H_Speed = 3
        if RIGHT_LEFT == 0:
            self.player_H_Speed = 0
        if B == 1:
            self.model.playerRocket()
        if EXIT == 1:
            FaceOrder.ChangeFace("surprise")
            pygame.mixer.music.fadeout(2000)
            rospy.sleep(2)
            Talk.getInstance("oh!  you didn't like this game! ", 4)
            Talk.getInstance("let's go to the next one! ", 4)
            FaceOrder.ChangeFace("happy1")
            pygame.quit()
            sys.exit()

        self.model.move()
        self.model.movePlayer(self.player_H_Speed)

        self.previousTime = currentTime
        self.clock.tick(60)
Пример #15
0
def getInstance():

 
    rospy.Subscriber("/bender/joy/joy0", Joy, callback)

    global START
    global EXIT
    global RIGHT_LEFT
    global B
    global WIDTH 
    global HEIGHT


    #Setup Variables
    START_GAME = False
    GAME_OVER = False
    GAME_WIN = False

    #Setup Classes
    video = Video()
    fps = FPS()


    player = Player()

    #Init Pygame
    pygame.init()

    #Hide Mouse
    pygame.mouse.set_visible(0)

    #Enable Keyinput repeat
    pygame.key.set_repeat(10,10)

    #Setup Video
    video.SetDisplay(WIDTH, HEIGHT, False)


    path = rospack.get_path('uchile_fun')
    path+="/src/uchile_fun/BenderVaders/"

    #Setup TTF Stuff
    Player_Info_Font = pygame.font.Font(path+"data/fonts/arialbd.ttf", 24)

    GameOver_Font = pygame.font.Font(path+"data/fonts/VeraMoBd.ttf", 20)
    GameWin_Font = pygame.font.Font(path+"data/fonts/VeraMoBd.ttf", 60)

    #Game Music
    pygame.mixer.music.load(path+"data/Sounds/race1.ogg")
    pygame.mixer.music.play(-1)


    # Final Message
    win_surface = pygame.image.load(path+"data/images/Win.png")


    #Start the Enemy Fire Monitoring Thread
    thread.start_new_thread(EnemyFire_Monitor, ())

    #Game Loop
    Loop_Count = 0 #Keep track of how many times we have looped
    Loop_Count_GameOver = 0 #Keep track of many times the game over loop has looped
    while 1:
        ##################################
        #GAME STUFF
        if START_GAME == True and GAME_OVER == False:
            #Check Player Life Count
            if player.LIFE <= 0:
                #Since the player has no more lives, the game is over
                GAME_OVER = True
                FaceOrder.ChangeFace("sad2")

                # rospy.sleep(3)
                # pygame.quit()
                # sys.exit()

            #FPS
            fps.Tick()
        
            #Events
            for event in pygame.event.get():
                #Keydown
                if event.type == pygame.QUIT:
                    pygame.quit()
                    quit()
                    
                if event.type == KEYDOWN:
                    if event.key == K_ESCAPE:
                        pygame.quit()
                        sys.exit(0)
                    if event.key == K_RIGHT:
                        player.MoveRight()
                    if event.key == K_LEFT:
                        player.MoveLeft()
                    if event.key == K_SPACE:
                        player.Fire()

                    # if event.key == K_BACKSLASH:
                    #     if video.getFullscreen() == False:
                    #         video.SetDisplay(WIDTH, HEIGHT, True)
                    #     else:
                    #         video.SetDisplay(WIDTH, HEIGHT, False)

            if RIGHT_LEFT>0 or RIGHT_LEFT==1:
                player.MoveLeft()
            if RIGHT_LEFT<0 or RIGHT_LEFT==-1:
                player.MoveRight()                    
            if B ==1:   
                player.Fire()
            if EXIT ==1:
            	FaceOrder.ChangeFace("surprise")

            	pygame.mixer.music.fadeout(2000)
                rospy.sleep(2)
                Talk.getInstance("oh!  you didn't like this game! ",4)
                Talk.getInstance("let's go to the next one! ",4)
                FaceOrder.ChangeFace("happy1")

                pygame.quit()
                #return
                sys.exit()








                    #CAN I HAVE CHEATS?
                    # if event.key == K_F1:
                    #     player.LIFE += 1
                    # if event.key == K_F2:
                    #     player.SCORE += 500
                    # if event.key == K_F3:
                    #     player.FIRE_SPEED += 2

            global killed
            #Collision Check - Player Missile Hitting Enemy Alien
            for i in range(0, len(enemy_man.ENEMY_LIST)):
                #Dont Check Type0 Enemy Types
                if enemy_man.ENEMY_LIST[i].getType() != AlienType.Type0:
                    if(player.FIRE_SPRITE.get_rect( center=(player.FIRE_XPOS, player.FIRE_YPOS) ).colliderect\
                       (enemy_man.ENEMY_LIST[i].SPRITE[enemy_man.ENEMY_LIST[i].FRAME].get_rect\
                        ( center=(enemy_man.ENEMY_LIST[i].getX(), enemy_man.ENEMY_LIST[i].getY()) ))) == True:
                
                        #print "Collision[", i, "]"
                        player.FIRE_DISPLAY = False #Hide Player Missile

                        #Update player's score accordingly
                        if enemy_man.ENEMY_LIST[i].getType() == AlienType.Type1:
                            player.SCORE += 50
                        elif enemy_man.ENEMY_LIST[i].getType() == AlienType.Type2:
                            player.SCORE += 40
                        elif enemy_man.ENEMY_LIST[i].getType() == AlienType.Type3:
                            #Since there are two rows of Type3, there are two
                            #score possibilites
                            index = random.randrange(0,10)
                            if index <= 5:
                                player.SCORE += 20
                            else:
                                player.SCORE += 30     
                        elif enemy_man.ENEMY_LIST[i].getType() == AlienType.MotherShip:
                            player.SCORE += 250

                        # print "x,y: ",enemy_man.ENEMY_LIST[i].getX(), ", ", enemy_man.ENEMY_LIST[i].getY()

                        enemy_num = enemy_man.Kill(i) #"Kill" Enemy Alien that was hit
                        killed[i]=0


                        # Check if there are no more enemies
                        if enemy_num == 0:
                            pygame.display.get_surface().blit(win_surface, (10,10))
                            pygame.draw.line(pygame.display.get_surface(), (0,255,0), (0, 500), (900, 500), 2)
                            pygame.display.get_surface().blit(Score_Surface, (10, 500))
                            pygame.display.get_surface().blit(Life_Surface, (10, 550))
                            #Update screen
                            pygame.display.flip()
                            FaceOrder.ChangeFace("happy3")
                            GAME_WIN = True
                            

                        #Break from collision check loop
                        break
            	# print "x,y: ",enemy_man.ENEMY_LIST[i].getX(), ", ", enemy_man.ENEMY_LIST[i].getY(), ": ", killed[i], "#: ", player.XPOS, ", ", player.YPOS
            	disX = abs(enemy_man.ENEMY_LIST[i].getX()-player.XPOS)
            	disY = abs(enemy_man.ENEMY_LIST[i].getY()-player.YPOS)
            	# print disX, ", ", disY, ", ", killed[i]

            	if (killed[i] ==1 and disX<50 and disY<60):#disX<40 and disY<60
            		GAME_OVER = True
            		break
                if (killed[i] ==1 and disY<40):#disX<40 and disY<60
                    rospy.sleep()
                    GAME_OVER = True
                    break

            #Collision Check - Enemy Missile Hitting Player
            for i in range(0, len(enemy_man.ENEMY_LIST)):
                if(enemy_man.ENEMY_LIST[i].FIRE_SPRITE.get_rect(center=(enemy_man.ENEMY_LIST[i].FIRE_XPOS, enemy_man.ENEMY_LIST[i].FIRE_YPOS) ).colliderect\
                    (player.SPRITE.get_rect(center=(player.XPOS, player.YPOS)))) == True:

                        if enemy_man.ENEMY_LIST[i].FIRE_DISPLAY == True:
                            #Remove a life from player
                            player.LIFE -= 1
                            # print "Ouch!!!"
                            FaceOrder.ChangeFace("surprise")

                        #Update Enemy Missile Variables
                        enemy_man.ENEMY_LIST[i].FIRE_DISPLAY = False
                        enemy_man.ENEMY_LIST[i].FIRE_XPOS = 0
                        enemy_man.ENEMY_LIST[i].FIRE_YPOS = 0

                        #Break from collisioin check loop
                        break
            
            
                
            #Clear screen before rendering
            video.SCREEN.fill((0,0,0))

            #Rendering (Blitting)
            enemy_man.Render()
            player.Render()

            #Render Player Information
            Score_Str = "Score: " + str(player.SCORE)
            Score_Surface = Player_Info_Font.render(str(Score_Str), False, (255,255,255))
            Life_Str = "Lives: x" + str(player.LIFE)
            Life_Surface = Player_Info_Font.render(str(Life_Str), False, (255,255,255))
            for i in range(0, int(player.LIFE)):
                #Blit Images to represent number of current lifes
                pygame.display.get_surface().blit(player.SPRITE, (90 + (i*(player.SPRITE.get_width()+10)), HEIGHT-52))
                
            # #If the player Wins display Win Message
            if GAME_WIN:
                # pygame.display.get_surface().blit(win_surface, (10,10))
                pygame.mixer.music.fadeout(3000)
                rospy.sleep(3)
                Talk.getInstance("did you have fun killing naos? ",4)
                FaceOrder.ChangeFace("happy1")

                pygame.quit()
                #return
                sys.exit()

            
            pygame.draw.line(pygame.display.get_surface(), (0,255,0), (0, HEIGHT-100), (WIDTH + 100, HEIGHT-100), 2)
            pygame.display.get_surface().blit(Score_Surface, (10, HEIGHT-100))
            pygame.display.get_surface().blit(Life_Surface, (10, HEIGHT-50))

            #Update screen
            pygame.display.flip()


   

        ##################################

        #MENU STUFF
        elif START_GAME == False:
            if Loop_Count < 1:
                Menu_Logo = pygame.image.load(path+"data/images/Logo.png")
                Start_Game_Text = Player_Info_Font.render("Press  Green  Button  To  Begin", False, (0,255,0))
                # Hi_Text = Player_Info_Font.render("Hi!!", False, (255,255,255))
                # ImBender_Text = Player_Info_Font.render("I  am  Bender  and  I  need  your  help!", False, (255,255,255))
                # ControlMe_Text = Player_Info_Font.render("Control  me  and  shoot  the  Naos'  spaceships", False, (255,255,255))
                # Avoid_Text = Player_Info_Font.render("down.  Avoid  the  football!", False, (255,255,255))
                # Controls_Text = Player_Info_Font.render("The  controls  are:", False, (255,255,255))
                # Controls1_Text = Player_Info_Font.render("Move  left:  left  stick  to  left", False, (255,255,255))
                # Controls2_Text = Player_Info_Font.render("Move  right:  left  stick  to  right", False, (255,255,255))
                # Controls3_Text = Player_Info_Font.render("Fire:  red  button", False, (255,255,255))

#                Exit_Game_Text = Player_Info_Font.render("Press Escape To Exit", False, (255,0,0))
                Copyright_Text = Player_Info_Font.render("Bonder whut? Bender YES", False, (255,255,255))
                Control_Text = pygame.image.load(path+"data/images/Controls.png")
                #video.SetDisplay(swidth, sheight, False)
            
                #FPS
                fps.Tick()
            
            #Events
            for event in pygame.event.get():
                #Keydown
                if event.type == pygame.QUIT:
                    pygame.quit()
                    quit()
                    
                if event.type == KEYDOWN:
                    if event.key == K_ESCAPE:
                        pygame.quit()
                        sys.exit(0)
                    if event.key == K_RETURN:
                        START_GAME = True
                        # video.SetDisplay(WIDTH, HEIGHT, video.getFullscreen())
                        break
                    # if event.key == K_BACKSLASH:
                    #     if video.getFullscreen() == False:
                    #         video.SetDisplay(swidth, sheight, True)
                    #         Loop_Count = 0 #Re-Load data for menu, and render
                    #     else:
                    #         video.SetDisplay(swidth, sheight, False)
                    #         Loop_Count = 0 #Re-Load data for menu, and render
            print ""    
            if START ==1:
            	FaceOrder.ChangeFace("happy3")
            	rospy.sleep(3)
            	FaceOrder.ChangeFace("happy1")
                START_GAME = True
                # video.SetDisplay(WIDTH, HEIGHT, video.getFullscreen())
#               break
            if EXIT ==1:
            	FaceOrder.ChangeFace("sad2")
            	pygame.mixer.music.fadeout(2000)
                rospy.sleep(2)
                Talk.getInstance("oh!  you didn't like this game! ",4)
                Talk.getInstance("let's go to the next one! ",4)
            	FaceOrder.ChangeFace("happy1")

                pygame.quit()
                #return
                sys.exit()

                                

            pygame.display.get_surface().blit(Menu_Logo, (WIDTH/2 - 375/2,20))

            # pygame.display.get_surface().blit(Hi_Text, (WIDTH/2 - 180,240))
            # pygame.display.get_surface().blit(ImBender_Text, (WIDTH/2 - 180,260))

            # pygame.display.get_surface().blit(ControlMe_Text, (WIDTH/2 - 180,290))
            # pygame.display.get_surface().blit(Avoid_Text, (WIDTH/2 - 180,310))

            # pygame.display.get_surface().blit(Controls_Text, (WIDTH/2 - 180,340))
            # pygame.display.get_surface().blit(Controls1_Text, (WIDTH/2 - 180,360))
            # pygame.display.get_surface().blit(Controls2_Text, (WIDTH/2 - 180,380))
            # pygame.display.get_surface().blit(Controls3_Text, (WIDTH/2 - 180,400))

#            pygame.display.get_surface().blit(Exit_Game_Text, (10,300))
            pygame.display.get_surface().blit(Control_Text, (WIDTH/2 - 220,310))
            pygame.display.get_surface().blit(Start_Game_Text, (WIDTH/2 - 175,720))#680

#            pygame.display.get_surface().blit(Copyright_Text, (5,sheight-50))

            if Loop_Count < 1:
                #Update screen
                pygame.display.flip()

        #GAME OVER STUFF
        elif GAME_OVER == True:
            if Loop_Count_GameOver < 1:
                GameOver_Text = GameOver_Font.render("GAME OVER!", False, (255,0,0))
                GameOver_Image = pygame.image.load(path+"data/images/GameOver.png")
                Score_Str = str(player.SCORE)
                Score_Surface = Player_Info_Font.render(str(Score_Str), False, (255,255,255))
                Life_Str = str(player.LIFE)
                Life_Surface = Player_Info_Font.render(str(Life_Str), False, (255,255,255))

            #FPS
            fps.Tick()

            #Events
            # for event in pygame.event.get():
            #     if event.type == pygame.QUIT:
            #         pygame.quit()
            #         quit()
            #     #Keydown
            #     if event.type == KEYDOWN:
            #         if event.key == K_ESCAPE:
            #             pygame.quit()
            #             sys.exit(0)
            #         if event.key == K_BACKSLASH:
            #             if video.getFullscreen() == False:
            #                 video.SetDisplay(WIDTH, HEIGHT, True)
            #                 Loop_Count_GameOver = 0
            #             else:
            #                 video.SetDisplay(WIDTH, HEIGHT, False)
            #                 Loop_Count_GameOver = 0


            enemy_man.Render()
            video.SCREEN.fill((0,0,0))
            
            #pygame.display.get_surface().blit(GameOver_Text, (400,300))
            pygame.display.get_surface().blit(GameOver_Image, (0,0))
            pygame.display.get_surface().blit(Score_Surface, (425, HEIGHT-50))
            pygame.display.get_surface().blit(Life_Surface, (425, HEIGHT))
            pygame.display.get_surface().blit(enemy_man.tmpSurface, (WIDTH/4,HEIGHT-535))

            #Clear screen before rendering
            pygame.display.flip()

            if Loop_Count_GameOver < 1:
                pygame.display.flip()

            #Update Game Over Loop Count
            Loop_Count_GameOver += 1
            pygame.mixer.music.fadeout(3000)
            rospy.sleep(3)
            Talk.getInstance("better luck next time! ",4)
            rospy.sleep(1)
            FaceOrder.ChangeFace("happy1")

            pygame.quit()
            return
            # sys.exit(0)

        ##################################
        Loop_Count += 1 #Update Count
Пример #16
0
    def progress(self, window):
        #        rospy.init_node('listener', anonymous=True)
        rospy.Subscriber("/bender/joy/joy0", Joy, callback)
        path = rospack.get_path('uchile_fun')
        path += "/src/uchile_fun/SwervinMervin/"

        global RIGHT_LEFT
        global A
        global EXIT

        txt_title = self.fonts["title"].render("Player: Bender", 1,
                                               s.COLOURS["text"])
        player = s.PLAYERS[self.selected]
        lpad = 40
        start_point = (s.DIMENSIONS[0] / 2) + (lpad / 2)
        step = player["sprites"]["mugshot_small"]["width"]
        large_mugshot = pygame.image.load(
            os.path.join(path + "lib",
                         player["sprites"]["mugshot_large"]["path"]))

        self.selection_colour = 1 if self.selection_colour == 0 else 0

        window.blit(self.background, (0, 0))
        window.blit(txt_title, ((s.DIMENSIONS[0] / 2) -
                                (txt_title.get_size()[0] / 2), 10))

        for i, p in enumerate(s.PLAYERS):
            details = p["sprites"]["mugshot_small"]
            mugshot = pygame.image.load(
                os.path.join(path + "lib", details["path"]))
            x = start_point + (i * (step + lpad))
            y = 120

            window.blit(mugshot, (x, y))

            if i == self.selected:
                bw = 10
                pygame.draw.rect(
                    window, s.COLOURS["selection"][self.selection_colour], [
                        x - (bw / 2), y -
                        (bw / 2), details["width"] + bw, details["width"] + bw
                    ], bw)

        # Player name and picture.
        window.blit(large_mugshot,
                    (0, s.DIMENSIONS[1] -
                     player["sprites"]["mugshot_large"]["height"]))
        window.blit(
            self.fonts["name"].render(player["name"], 1, s.COLOURS["text"]),
            (start_point - bw, 200))
        window.blit(
            self.fonts["details"].render(player["city"], 1, s.COLOURS["text"]),
            (start_point - bw, 228))

        # Player stats.
        desired_acceleration = int(
            self.normalise(player["acceleration_factor"], *s.HARD_ACCELERATION)
            * 155)
        desired_handling = int(
            (1.0 -
             self.normalise(player["centrifugal_force"], *s.HARD_HANDLING)) *
            155)
        desired_top_speed = int(
            self.normalise(player["top_speed"], *s.HARD_TOP_SPEED) * 155)

        window.blit(
            self.fonts["stats"].render("Acceleration", 1, s.COLOURS["text"]),
            (start_point - bw, 260))
        window.blit(
            self.fonts["stats"].render("Handling", 1, s.COLOURS["text"]),
            (start_point - bw, 284))
        window.blit(self.fonts["stats"].render("Speed", 1, s.COLOURS["text"]),
                    (start_point - bw, 308))

        su = pygame.Surface((155, 18), pygame.SRCALPHA)
        su.fill(s.COLOURS["opaque_white"])

        window.blit(su, (start_point + 105, 255))
        window.blit(su, (start_point + 105, 279))
        window.blit(su, (start_point + 105, 303))

        pygame.draw.rect(window, s.COLOURS["text"],
                         [start_point + 105, 255, desired_acceleration, 18])

        pygame.draw.rect(window, s.COLOURS["text"],
                         [start_point + 105, 279, desired_handling, 18])

        pygame.draw.rect(window, s.COLOURS["text"],
                         [start_point + 105, 303, desired_top_speed, 18])

        if self.player_chosen:
            self.finalise_selection(player)

        for e in pygame.event.get():
            u.try_quit(e)

            if e.type == pygame.KEYDOWN and not self.player_chosen:
                if e.key == pygame.K_LEFT and self.selected > 0:
                    self.selected -= 1
                elif e.key == pygame.K_RIGHT and self.selected < len(
                        s.PLAYERS) - 1:
                    self.selected += 1
                elif e.key == pygame.K_RETURN:
                    self.player_chosen = True

        #self.selected += 1

        if not self.player_chosen:
            # if RIGHT_LEFT>0 and self.selected > 0:
            #     self.selected -= 1
            # elif RIGHT_LEFT<0 and self.selected < len(s.PLAYERS) - 1:
            #     self.selected += 1
            if A == 1:
                FaceOrder.ChangeFace("happy3")
                self.player_chosen = True
            elif EXIT == 1:
                FaceOrder.ChangeFace("sad2")
                pygame.mixer.music.fadeout(2000)
                rospy.sleep(2)
                Talk.getInstance("oh!  you don't want to play this game! ", 4)
                Talk.getInstance("let's go to the next one! ", 4)
                FaceOrder.ChangeFace("happy1")

                pygame.quit()
                #return
                sys.exit()