Exemple #1
0
def runGame():
    #Initialize game and create a window
    pg.init()
    #create a new object using the settings class
    setting = Settings()
    #creaete a new object from pygame display
    screen = pg.display.set_mode((setting.screenWidth, setting.screenHeight))
    #set window caption using settings obj
    pg.display.set_caption(setting.windowCaption)

    playBtn = Button(setting, screen, "PLAY", 200)
    menuBtn = Button(setting, screen, "MENU", 250)
    twoPlayBtn = Button(setting, screen, "2PVS", 250)
    #setBtnbtn = Button(setting, screen, "SETTING", 300)
    aboutBtn = Button(setting, screen, "ABOUT", 300)
    quitBtn = Button(setting, screen, "QUIT", 400)
    greyBtn = Button(setting, screen, "GREY", 200)
    redBtn = Button(setting, screen, "RED", 250)
    blueBtn = Button(setting, screen, "BLUE", 300)
    #make slector for buttons
    sel = Selector(setting, screen)
    sel.rect.x = playBtn.rect.x + playBtn.width + 10
    sel.rect.centery = playBtn.rect.centery

    #Create an instance to stor game stats
    stats = GameStats(setting)
    sb = Scoreboard(setting, screen, stats)

    #Make a ship
    ship = Ship(setting, screen)
    #Ships for two player
    ship1 = Ship(setting, screen)
    ship2 = Ship(setting, screen)

    #make a group of bullets to store
    bullets = Group()
    eBullets = Group()
    setting.explosions = Explosions()

    #Make an alien
    aliens = Group()
    gf.createFleet(setting, screen, ship, aliens)
    pg.display.set_icon(pg.transform.scale(ship.image, (32, 32)))

    #plays bgm
    pg.mixer.music.load("sounds/galtron.mp3")
    pg.mixer.music.set_volume(0.25)
    pg.mixer.music.play(-1)

    runGame = True

    #Set the two while loops to start mainMenu first
    while runGame:
        #Set to true to run main game loop
        while stats.mainMenu:
            mm.checkEvents(setting, screen, stats, sb, playBtn, twoPlayBtn,
                           aboutBtn, quitBtn, menuBtn, sel, ship, aliens,
                           bullets, eBullets)
            mm.drawMenu(setting, screen, sb, playBtn, menuBtn, twoPlayBtn,
                        aboutBtn, quitBtn, sel)

        while stats.playMenu:
            pm.checkEvents(setting, screen, stats, sb, playBtn, greyBtn,
                           redBtn, blueBtn, quitBtn, menuBtn, sel, ship,
                           aliens, bullets, eBullets)
            pm.drawMenu(setting, screen, sb, greyBtn, redBtn, blueBtn, menuBtn,
                        quitBtn, sel)

        while stats.mainGame:
            #Game functions
            gf.checkEvents(setting, screen, stats, sb, playBtn, quitBtn, sel,
                           ship, aliens, bullets, eBullets)  #Check for events

            if stats.gameActive:
                gf.updateAliens(setting, stats, sb, screen, ship, aliens,
                                bullets, eBullets)  #Update aliens
                gf.updateBullets(setting, screen, stats, sb, ship, aliens,
                                 bullets, eBullets)  #Update collisions
                ship.update(bullets)  #update the ship
            #Update the screen
            gf.updateScreen(setting, screen, stats, sb, ship, aliens, bullets,
                            eBullets, playBtn, menuBtn, quitBtn, sel)
        while stats.mainAbout:
            About.checkEvents(setting, screen, stats, sb, playBtn, quitBtn,
                              menuBtn, sel, ship, aliens, bullets, eBullets)
            About.drawMenu(setting, screen, sb, menuBtn, quitBtn, sel)

        while stats.twoPlayer:
            tp.checkEvents(setting, screen, stats, playBtn, quitBtn, sel,
                           bullets, eBullets, ship1, ship2)
            if stats.gameActive:
                ship1.update(bullets)
                ship2.update(bullets)
                tp.updateBullets(setting, screen, stats, ship1, ship2, bullets,
                                 eBullets)
            tp.updateScreen(setting, screen, stats, bullets, eBullets, playBtn,
                            menuBtn, quitBtn, sel, ship1, ship2)
        while stats.mainGame:
            if runGame == True:
                print("test")
Exemple #2
0
def runGame():
	#Initialize game and create a window
	pg.init()
	pg.mixer.init()
	pg.time.delay(1000)
	#create a new object using the settings class
	setting = Settings()
	#creaete a new object from pygame display
	screen = pg.display.set_mode((setting.screenWidth, setting.screenHeight))
	#set window caption using settings obj
	pg.display.set_caption(setting.windowCaption)

	bgm = pg.mixer.Sound('music/背景音乐.ogg')
	bgm.set_volume(0.05)
	bgm.play(-1)


	fps = 120
	fclock = pg.time.Clock()

	playBtn = Button(setting, screen, "PLAY", 200)
	menuBtn = Button(setting, screen, "MENU", 250)
	aboutBtn = Button(setting, screen, "ABOUT", 250)
	quitBtn = Button(setting, screen, "QUIT", 300)

	#make slector for buttons
	sel = Selector(setting, screen)
	sel.rect.x = playBtn.rect.x + playBtn.width + 10
	sel.rect.centery = playBtn.rect.centery

	#Create an instance to stor game stats
	stats = GameStats(setting)
	sb = Scoreboard(setting, screen, stats)

	#Make a ship
	ship = Ship(setting, screen)
	#Ships for two player 
	ship1 = Ship(setting, screen)
	ship2 = Ship(setting, screen)

	#make a group of bullets to store
	bullets = Group()

	#Make an alien
	aliens = Group()
	gf.createFleet(setting, screen, ship, aliens)
	icon = pg.image.load('gfx/SpaceShip.png')
	pg.display.set_icon(icon)

	runGame = True

	#Set the two while loops to start mainMenu first
	while runGame:
		#Set to true to run main game loop
		while stats.mainMenu:
			mm.checkEvents(setting, screen, stats, sb, playBtn, aboutBtn, quitBtn, menuBtn, sel, ship, aliens, bullets)
			mm.drawMenu(setting, screen, sb, playBtn, menuBtn, aboutBtn, quitBtn, sel)

		while stats.mainGame:
			#Game functions
			gf.checkEvents(setting, screen, stats, sb, playBtn, quitBtn, sel, ship, aliens, bullets) #Check for events
			if stats.gameActive:
				gf.updateAliens(setting, stats, sb, screen, ship, aliens, bullets) #Update aliens
				gf.updateBullets(setting, screen, stats, sb, ship, aliens, bullets) #Update collisions
				ship.update() #update the ship
			gf.updateScreen(setting, screen, stats, sb, ship, aliens, bullets, playBtn, menuBtn, quitBtn, sel) #Update the screen

			fclock.tick(fps)

		while stats.mainAbout:
			About.checkEvents(setting, screen, stats, sb, playBtn, quitBtn, menuBtn, sel, ship, aliens, bullets)
			About.drawMenu(setting, screen, sb, menuBtn, quitBtn, sel)

		while stats.mainGame:
			if runGame == True:
				print("test")
Exemple #3
0
                gf.reset = 0
                pg.register_quit(runGame())
            if stats.gameActive:
                gf.updateAliens(setting, stats, sb, screen, ship, aliens, bullets, eBullets)  # Update aliens
                gf.updateBullets(setting, screen, stats, sb, ship, aliens, bullets, eBullets, charged_bullets, items) # Update collisions
                gf.updateItems(setting, screen, stats, sb, ship, aliens, bullets, eBullets, items)
                ship.update(bullets, aliens)  # update the ship
                # Update the screen
            gf.updateScreen(setting, screen, stats, sb, ship, aliens, bullets, eBullets, charged_bullets, bMenu, bgManager, items)

        bMenu.setMenuButtons(aboutButtons)
        bMenu.setPos(None, 500)

        while stats.mainAbout:
            About.checkEvents(setting, screen, stats, sb, bMenu, ship, aliens, bullets, eBullets)
            About.drawMenu(setting, screen, sb, bMenu, aboutImage, aboutImageRect)

        while stats.twoPlayer:
            tp.checkEvents(setting, screen, stats, sb, bMenu, bullets, aliens, eBullets, ship1, ship2)
            if stats.gameActive:
                ship1.update(bullets, aliens)
                ship2.update(bullets, aliens)
                tp.updateBullets(setting, screen, stats, sb, ship1, ship2, aliens, bullets, eBullets, items)
            tp.updateScreen(setting, screen, stats, sb, ship1, ship2, aliens, bullets, eBullets, bMenu, items)

        bMenu.setMenuButtons(settingsMenuButtons)

        while stats.settingsMenu:
            sm.checkEvents1(setting, screen, stats, sb, bMenu, ship, aliens, bullets, eBullets)
            sm.drawMenu(setting, screen, sb, bMenu)
Exemple #4
0
def runGame():
    # Initialize game and create a window
    pg.init()
    # create a new object using the settings class
    setting = Settings()
    # creaete a new object from pygame display
    screen = pg.display.set_mode((setting.screenWidth, setting.screenHeight))

    # intro
    intro.introimages()

    # set window caption using settings obj
    pg.display.set_caption(setting.windowCaption)

    bMenu = ButtonMenu(screen)
    bMenu.addButton("play", "PLAY")
    bMenu.addButton("menu", "MENU")
    bMenu.addButton("twoPlay", "2PVS")
    bMenu.addButton("settings", "SETTINGS")
    bMenu.addButton("invert", "INVERT")
    bMenu.addButton("about", "ABOUT")
    bMenu.addButton("quit", "QUIT")
    bMenu.addButton("grey", "GREY")
    bMenu.addButton("red", "RED")
    bMenu.addButton("blue", "BLUE")
    bMenu.addButton("retry", "RETRY")
    bMenu.addButton("hard", "HARD")
    bMenu.addButton("normal", "NORMAL")

    mainMenuButtons = ["play", "about", "settings", "quit"]  # delete "twoPlay"
    playMenuButtons = ["grey", "red", "blue", "menu", "quit"]
    levelMenuButtons = ["hard", "normal", "quit"]
    mainGameButtons = ["play", "menu", "quit"]
    aboutButtons = ["menu", "quit"]
    settingsMenuButtons = ["menu", "invert", "quit"]

    bgManager = BackgroundManager(screen)
    bgManager.setFillColor((0, 0, 0))
    bgManager.addBackground(
        "universe_1", "gfx/backgrounds/stars_back.png", 0, 1)
    bgManager.addBackground(
        "universe_1", "gfx/backgrounds/stars_front.png", 0, 1.5)
    bgManager.selectBackground("universe_1")

    # Create an instance to stor game stats
    stats = GameStats(setting)
    sb = Scoreboard(setting, screen, stats)

    # Make a ship
    ship = Ship(setting, screen)
    # Ships for two player
    ship1 = Ship(setting, screen)
    ship2 = Ship(setting, screen)

    # make a group of items to store
    items = Group()

    # make a group of bullets to store
    bullets = Group()
    charged_bullets = Group()
    eBullets = Group()
    setting.explosions = Explosions()

    # Make an alien
    aliens = Group()
    gf.createFleet(setting, stats, screen, ship, aliens)
    pg.display.set_icon(pg.transform.scale(ship.image, (32, 32)))

    bgImage = pg.image.load('gfx/title_c.png')
    bgImage = pg.transform.scale(
        bgImage, (setting.screenWidth, setting.screenHeight))
    bgImageRect = bgImage.get_rect()

    aboutImage = pg.image.load('gfx/About_modify2.png')
    aboutImage = pg.transform.scale(
        aboutImage, (setting.screenWidth, setting.screenHeight))
    aboutImageRect = aboutImage.get_rect()

    # plays bgm
    pg.mixer.music.load('sound_bgms/galtron.mp3')
    pg.mixer.music.set_volume(0.25)
    pg.mixer.music.play(-1)

    rungame = True

    sounds.stage_clear.play()
    # Set the two while loops to start mainMenu first
    while rungame:
        # Set to true to run main game loop
        bMenu.setMenuButtons(mainMenuButtons)
        while stats.mainMenu:
            if not stats.gameActive and stats.paused:
                setting.initDynamicSettings()
                stats.resetStats()
                ##stats.gameActive = True

                # Reset the alien and the bullets
                aliens.empty()
                bullets.empty()
                eBullets.empty()

                # Create a new fleet and center the ship
                gf.createFleet(setting, stats, screen, ship, aliens)
                ship.centerShip()

            mm.checkEvents(setting, screen, stats, sb, bMenu,
                           ship, aliens, bullets, eBullets)
            mm.drawMenu(setting, screen, sb, bMenu, bgImage, bgImageRect)

        bMenu.setMenuButtons(levelMenuButtons)
        while stats.levelMenu:
            lm.checkEvents(setting, screen, stats, sb, bMenu,
                           ship, aliens, bullets, eBullets)
            lm.drawMenu(setting, screen, sb, bMenu, bgImage, bgImageRect)

        bMenu.setMenuButtons(playMenuButtons)
        while stats.playMenu:
            pm.checkEvents(setting, screen, stats, sb, bMenu,
                           ship, aliens, bullets, eBullets)
            pm.drawMenu(setting, screen, sb, bMenu)

        bMenu.setMenuButtons(mainGameButtons)

        while stats.mainGame:
            # Game functions
            gf.checkEvents(setting, screen, stats, sb, bMenu, ship, aliens,
                           bullets, eBullets, charged_bullets)  # Check for events
            # Reset Game
            if gf.reset == 1:
                gf.reset = 0
                pg.register_quit(runGame())
            if stats.gameActive:
                gf.updateAliens(setting, stats, sb, screen, ship,
                                aliens, bullets, eBullets)  # Update aliens
                gf.updateBullets(setting, screen, stats, sb, ship, aliens, bullets,
                                 eBullets, charged_bullets, items)  # Update collisions
                gf.updateItems(setting, screen, stats, sb, ship,
                               aliens, bullets, eBullets, items)
                ship.update(bullets, aliens)  # update the ship
                # Update the screen
            gf.updateScreen(setting, screen, stats, sb, ship, aliens,
                            bullets, eBullets, charged_bullets, bMenu, bgManager, items)

        bMenu.setMenuButtons(aboutButtons)
        bMenu.setPos(None, 500)

        while stats.mainAbout:
            About.checkEvents(setting, screen, stats, sb,
                              bMenu, ship, aliens, bullets, eBullets)
            About.drawMenu(setting, screen, sb, bMenu,
                           aboutImage, aboutImageRect)

        while stats.twoPlayer:
            tp.checkEvents(setting, screen, stats, sb, bMenu,
                           bullets, aliens, eBullets, ship1, ship2)
            if stats.gameActive:
                ship1.update(bullets, aliens)
                ship2.update(bullets, aliens)
                tp.updateBullets(setting, screen, stats, sb,
                                 ship1, ship2, aliens, bullets, eBullets, items)
            tp.updateScreen(setting, screen, stats, sb, ship1,
                            ship2, aliens, bullets, eBullets, bMenu, items)

        bMenu.setMenuButtons(settingsMenuButtons)

        while stats.settingsMenu:
            sm.checkEvents1(setting, screen, stats, sb, bMenu,
                            ship, aliens, bullets, eBullets)
            sm.drawMenu(setting, screen, sb, bMenu)

        while stats.mainGame:
            if rungame == True:
                print("test")
Exemple #5
0
			pm.checkEvents(setting, screen, stats, sb, playBtn, greyBtn, redBtn, blueBtn, quitBtn, menuBtn, sel, ship, aliens, bullets, eBullets)
			pm.drawMenu(setting, screen, sb, greyBtn, redBtn, blueBtn, menuBtn, quitBtn, sel)

		while stats.mainGame:
			#Game functions
			gf.checkEvents(setting, screen, stats, sb, playBtn, quitBtn, sel, ship, aliens, bullets, eBullets) #Check for events

			if stats.gameActive:
				gf.updateAliens(setting, stats, sb, screen, ship, aliens, bullets, eBullets) #Update aliens
				gf.updateBullets(setting, screen, stats, sb, ship, aliens, bullets, eBullets) #Update collisions
				ship.update(bullets,aliens) #update the ship
			 #Update the screen
			gf.updateScreen(setting, screen, stats, sb, ship, aliens, bullets, eBullets, playBtn, menuBtn, quitBtn, sel)
		while stats.mainAbout:
			About.checkEvents(setting, screen, stats, sb, playBtn, quitBtn, menuBtn, sel, ship, aliens, bullets, eBullets)
			About.drawMenu(setting, screen, sb, menuBtn, quitBtn, sel)

		while stats.twoPlayer:
			tp.checkEvents(setting, screen, stats, sb, playBtn, quitBtn, sel, ship1, ship2, aliens, bullets, eBullets)
			if stats.gameActive:
				ship1.update(bullets)
				ship2.update(bullets)
#				tp.updateBullets(setting, screen, stats, ship1, ship2, bullets, eBullets)
#			tp.updateScreen(setting, screen, stats, bullets, eBullets, playBtn, menuBtn, quitBtn, sel, ship1, ship2)
		while stats.mainGame:
			if runGame == True:
				print("test")

#init bgm mixer
pg.mixer.pre_init(44100,16,2,4096)
pg.mixer.init(44100,-16,2,4096)