Beispiel #1
0
def run_game():
	pygame.init() #initialize all the pygame modules
	game_settings = Settings() #create an instance of settings class
	screen = pygame.display.set_mode(game_settings.screen_size) #Set the screen size with set_mode
	pygame.display.set_caption("Monster Attack") #set the message on the status bar
	
	#music 
	pygame.mixer.music.load('.wav')
	pygame.mixer.music.play(-1)
	
	hero = Hero(screen) #set a variable equal to the class and pass it the screen
	bad_guy = Bad_guy(screen)
	bullets = Group() #set the bullets to group
	#create a play button object and assign to a var
	play_button = Play_button(screen, 'Play Game')

	

	while 1: #run this loop forever...
		gf.check_events(hero, bullets, game_settings, screen, bad_guy, play_button) #call gf (aliased from game_functions module) and get the check_events method
		gf.update_screen(game_settings, screen, hero, bullets, bad_guy, play_button) #call the update_screen method which handles updating the screen
		print bool(theDict)
		if (theDict):
			print "Some music for a different hit"
		if(game_settings.game_active):
			hero.update() #update the hero flags
			bad_guy.update()		
			bullets.update() #call the update method in the while loop
Beispiel #2
0
def run_game():
    pygame.init()  # initialize all the pygame modules
    game_settings = Settings()  #create an instance of settings class
    screen = pygame.display.set_mode(
        game_settings.screen_size)  #set the screen size with set_mode
    pygame.display.set_caption(
        "Monster Attack")  #set the message on the status bar

    pygame.mixer.music.load('sounds/music.wav')
    pygame.mixer.music.play(-1)

    play_button = Play_button(screen, "Play Game")
    hero = Hero(
        screen)  # set a variable equal to the class and pass it the screen
    enemies = Group()
    bullets = Group()  #set bullets
    enemies.add(Enemy(screen, game_settings))

    tick = 0

    while 1:  #run this loop forever...
        tick += 1

        if tick % 150 == 0:
            enemies.add(Enemy(screen, game_settings))

        gf.check_events(
            hero, bullets, game_settings, screen, play_button
        )  #call gf (aliased from game_functions module) and get the check_events
        if game_settings.game_active:
            hero.update()  #update the hero flags
            enemies.update(hero, game_settings.enemy_speed)
            bullets.update()  #call the update method in the while loop
        gf.update_screen(game_settings, screen, hero, bullets, enemies,
                         play_button)  # call the update_screen method

        for enemy in enemies:
            for bullet in bullets:  # get rid of bullets that are off the screen
                if bullet.rect.bottom <= 0:  #bullet bottom is at the top of the screen
                    bullets.remove(bullet)  #call remove()
                if len(bullets) >= 15:
                    bullets.remove(bullet)
                if enemy.rect.colliderect(bullet.rect):
                    enemies.remove(enemy)
                    bullets.remove(bullet)
            if enemy.rect.colliderect(hero.rect):
                print "The monster got you! You died!"
                exit(0)
Beispiel #3
0
def run_game():
    pygame.init()  #initialize all the pygame modules
    game_settings = Settings()  #create an instance of settings class
    screen = pygame.display.set_mode(
        game_settings.screen_size)  #Set the screen size with set_mode
    pygame.display.set_caption(
        "Monster Attack")  #set the message on the status bar

    # music courtesy of http://ericskiff.com/music/
    pygame.mixer.music.load('sounds/music.wav')
    pygame.mixer.music.play(-1)

    # Create a playbutton object and assign to a var
    play_button = Play_button(screen, 'Play')
    print play_button.rect

    hero = Hero(
        screen)  #set a variable equal to the class and pass it the screen
    bullets = Group()  #set the bullets to group
    enemies = Group()
    enemies.add(Monster(screen))

    tick = 0  #init counter at 0

    while 1:  #run this loop forever...
        gf.check_events(
            hero, bullets, game_settings, screen, play_button
        )  #call gf (aliased from game_functions module) and get the check_events method
        gf.update_screen(
            game_settings, screen, hero, enemies, bullets, play_button
        )  #call the update_screen method which handles updating the screen
        if game_settings.game_active:
            hero.update()  #update the hero flags
            enemies.update(hero, game_settings.enemy_speed)
            tick += 1
            if tick % 150 == 0:
                enemies.add(Monster(screen))
            bullets.update()  #call the update method in the while loop
            theDict = groupcollide(enemies, bullets, True, True)
            # print bool(theDict) #if empty... false
            if (theDict):
                print "You hit a monster. Play some winning type music"
            for bullet in bullets:  #get rid of bullets that are off the screen
                if bullet.rect.bottom <= 0:  #bullet bottom is at the top of the screen
                    bullets.remove(bullet)  #call remove() against the group
def run_game():
    pygame.init()
    game_settings = Settings()
    screen = pygame.display.set_mode(game_settings.screen_size)
    pygame.display.set_caption("Ataque Monstruoso")
    hero = Hero(screen)

    pygame.mixer.music.load('sounds/music.wav')
    pygame.mixer.music.play(-1)

    play_button = Play_button(screen, 'Pressiona para começar')

    count = 0
    count_update = "Monatros mortos: %d" % count
    scoreboard = Scoreboard(screen, count_update)

    enemies = Group()
    bullets = Group()
    enemies.add(Enemy(screen, game_settings))

    tick = 0
Beispiel #5
0
def run_game():
    pygame.init()
    game_settings = Settings()
    message = input("Start Game:")
    screen = pygame.display.set_mode(game_settings.screen_size)
    pygame.display.set_caption("Monster Attack")
    #hero = Hero(screen)
    #bullets = Group()
    play_button = Play_button(screen, message)

    while 1:
        gf.check_events(hero, bullets, game_settings, screen, play_button)
        gf.update_screen(game_settings, screen, hero, bullets, play_button)
        if game_settings.game_active:
            hero.update()
            bullets.update()
            for bullet in bullets:
                if bullet.rect.bottom <= 0:
                    bullets.remove(bullet)
                if len(bullets) > 15:
                    bullets.remove(bullet)
Beispiel #6
0
def run_game():
    pygame.init()  #initialize all the pygame modules
    game_settings = Settings()  #create an instance of settings class
    screen = pygame.display.set_mode(
        game_settings.screen_size)  # set the screen size with set_mode
    pygame.display.set_caption(
        "Monster Attack")  #set the message on the status bar
    play_button = Play_button(screen, 'Press Play')

    pygame.mixer.music.load('sounds/music.wav')
    pygame.mixer.music.play(-1)
    hero = Hero(
        screen)  #set a variable equal to the class and pass it the screen
    monster = Monster(screen, game_settings)
    bullets = Group()  #set the bullets to group

    while 1:  #run this loop forever
        gf.check_events(
            hero, bullets, game_settings, screen, monster, play_button
        )  #call gf (aliased from game_functions module) and get the check_events method
        gf.update_screen(
            game_settings, screen, hero, bullets, monster, play_button
        )  # call the update_screen method which updates updating the screen
        if game_settings.game_active:
            hero.update()  #update the hero flags
            monster.update()
            bullets.update()  #call the update method in the while loop
            # the Dict = groupcollide(enemies, bullets, True, True)
            # if(theDict):
            # 	print "you hit the monster. play some type of music"
            for bullet in bullets:  #get rid of bullets that are off the screen
                if bullet.rect.bottom <= 0:  #bullet bottom is at the top of the screen
                    bullets.remove(bullet)
                if bullet.rect.top == monster.rect.bottom:
                    bullets.remove(bullet)
                    monster.speed = -2
Beispiel #7
0
def run_game():
    pygame.init()  #initializes pygame modules
    game_settings = Settings()  #create instance of settings class
    # screen = pygame.display.set_mode((1000, 800)) #set screen size, need double parenthesis, or set width and height to variable
    screen = pygame.display.set_mode(game_settings.screen_size)
    pygame.display.set_caption("Alien Attack")  #set msg on status bar
    hero = Hero(
        screen)  #set variable equal to the class and pass it to the screen

    pygame.mixer.music.load("sounds/music.wav")
    pygame.mixer.music.play(-1)

    play_button = Play_button(screen, "PLAY")
    score_board = Score_board(screen, "Score = ")
    bullets = Group()  #set the bullets to group
    aliens = Group()

    # def set_interval(func, sec):
    # 	def func_wrapper():
    # 		set_interval(func, sec)
    # 		func()
    # 	t = threading.Timer(sec, func_wrapper)
    # 	t.start()
    # 	return t
    tick = 0

    def setInterval(interval, time=-1):
        def outer_wrap(function):
            def wrap(*args, **kwargs):
                stop = threading.Event()

                def inner_wrap():
                    i = 0
                    while i != times and not stop.isSet():
                        stop.wait(interval)
                        function(*args, **kwargs)
                        i += 1

                t = threading.Timer(0, inner_wrap)
                t.daemon = True
                t.start()
                return stop

            return wrap

        return outer_wrap

    @setInterval(5)
    def add_alien(screen, game_settings, aliens):
        print "SPAWNING!!!!!"
        new_alien = Alien(screen, game_settings)
        # aliens.add(Alien(screen, game_settings))
        aliens.add(new_alien)

    while 1:  #1 is true, run this loop forever...
        gf.check_events(hero, bullets, game_settings, screen, aliens,
                        play_button, score_board)
        gf.update_screen(game_settings, screen, hero, bullets, aliens,
                         play_button,
                         score_board)  #call method to update screen

        if game_settings.game_active:
            hero.update()  #update the hero flags
            bullets.update()
            aliens.update()
            tick += 1
            if tick % 30 == 0:
                aliens.add(Alien(screen, game_settings))
            theDict = groupcollide(aliens, bullets, True, True)
            # print theDict

            if (theDict):  # if theDict not empty
                game_settings.score = len(theDict)

            #fill the background(bg) with our color
            gf.update_screen(game_settings, screen, hero, bullets, aliens,
                             play_button,
                             score_board)  #call method to update screen
            #get rid of bullets that are off the screen
            for bullet in bullets:
                if bullet.rect.bottom <= 0:  #bullet bottom is at the top of the screen
                    bullets.remove(bullet)  #call remove against the group
Beispiel #8
0
def run_game():
    pygame.init()  # initialize all the pygame modules
    game_settings = Settings()  #create an instance of settings class
    screen = pygame.display.set_mode(
        game_settings.screen_size)  #set the screen size with set_mode
    pygame.display.set_caption(
        "Monster Attack")  #set the message on the status bar
    hero = Hero(
        screen)  # set a variable equal to the class and pass it the screen

    #music
    pygame.mixer.music.load('sounds/music.wav')
    pygame.mixer.music.play(-1)

    # create a play button object and assign to a bar
    play_button = Play_button(screen, 'Press to begin')

    # create a scoreboard object
    count = 0
    count_update = "Enemies Killed: %d" % count
    scoreboard = Scoreboard(screen, count_update)

    enemies = Group()
    bullets = Group()  #set bullets
    enemies.add(Enemy(screen, game_settings))

    tick = 0

    while 1:  #run this loop forever
        gf.check_events(
            hero, bullets, game_settings, screen, play_button
        )  #call gf (aliased from game_functions module) and get the check_events
        gf.update_screen(game_settings, screen, hero, bullets, enemies,
                         play_button,
                         scoreboard)  # call the update_screen method
        if game_settings.game_active:
            hero.update()  #update the hero flags
            enemies.update(hero, game_settings.enemy_speed)
            tick += 1
            if tick % 50 == 0:
                enemies.add(Enemy(screen, game_settings))
            bullets.update()  #call the update method in the while loop

            for enemy in enemies:
                for bullet in bullets:  # get rid of bullets that are off the screen
                    if bullet.rect.bottom <= 0:  #bullet bottom is at the top of the screen
                        bullets.remove(bullet)  #call remove()
                    if len(bullets) >= 10:
                        bullets.remove(bullet)
                    if enemy.rect.colliderect(bullet.rect):
                        count += 1
                        count_update = "Enemies Killed: %d" % count
                        scoreboard = Scoreboard(screen, count_update)

                        enemies.remove(enemy)
                        bullets.remove(bullet)
                        pygame.mixer.music.load('sounds/win.wav')
                        pygame.mixer.music.play(0)
                if enemy.rect.colliderect(hero.rect):
                    print "The monster got you! You died!"
                    pygame.mixer.music.load('sounds/lose.wav')
                    pygame.mixer.music.play(0)