Exemplo n.º 1
0
def run_game():
	# Initialize game and create a screen object.
	pygame.init()
	
	ai_settings = Settings()

	screen = pygame.display.set_mode((ai_settings.screen_width, ai_settings.screen_height))
	
	pygame.display.set_caption("Alien Invasion")
	#Make a ship
	ship = Ship(ai_settings,screen)

	#Make a group to store bullets in (similar to lists)
	bullets = Group()

	#Make a group of Aliens
	aliens = Group()


	#Create a fleet of aliens
	gf.createFleet(ai_settings, screen, ship, aliens)

	# Start the main loop for the game.
	while True:
		# Watch for keyboard and mouse events.
		gf.checkEvents(ai_settings, screen, ship, bullets)
		ship.update()
		gf.updateBullets(bullets)
		gf.updateAliens(ai_settings, aliens)
		gf.updateScreen(ai_settings, screen, ship, aliens, bullets)
Exemplo n.º 2
0
def runGame():
    # Initialize game, settings and screen object
    pygame.init()
    drSettings = Settings()
    screen = pygame.display.set_mode(
        (drSettings.screenWidth, drSettings.screenHeight))
    pygame.display.set_caption("Drag Race")
    totalTime = 0

    # Make the car
    car = Car(drSettings, screen)

    # Initialize the timer, gear text and speed
    hud = HeadUpDisplay(drSettings, screen, totalTime, car) 

    # Store the game statistics
    stats = GameStats()

    # Start the main loop for the game
    while True:
        # Check for keypresses
        gf.checkEvents(car, stats)

        # Update the game active state
        if not car.onScreen:
            stats.gameActive = False

        if stats.gameActive:
            # Update the position of the car and the hud
            car.update() 
            hud.update(stats.totalTime, car)
            stats.totalTime += drSettings.timeIncrement

        # Update the screen
        gf.updateScreen(drSettings, screen, car, hud)
Exemplo n.º 3
0
def initGame():
    """Initialize the game and create a screen object"""
    pygame.init()
    # Create the principal surface of the game (The window).
    screen = pygame.display.set_mode(consts.SCREEN_DIMENSIONS)

    # Configure Screen General Surface
    settings.configureScreen(screen)

    # Create a ship Surface
    ship = humanShip(screen)

    aliens = pygame.sprite.Group()

    game.createAliens(screen, aliens)

    #Start the main loop for the game.
    while True:
        game.checkEvents(ship, aliens)
        ship.move()
        ship.bullets.update()
        aliens.update()
        print(len(aliens))
        # Redraw the screen during each pass through the loop.
        game.redrawSurfaces(screen, aliens, ship)
        collisions = pygame.sprite.groupcollide(ship.bullets, aliens, True,
                                                True)
        #Make the most recently drawn screen visible.
        pygame.display.flip()
Exemplo n.º 4
0
def run_game():
    #Инициализация игры и создание объекта на экране
    #timer = pygame.time.Clock()
    pygame.init()
    ai_setting = Settings()
    screen = pygame.display.set_mode(
        (ai_setting.screen_width, ai_setting.screen_height))
    pygame.display.set_caption("Arcanoid")
    platform = Platform(ai_setting, screen)
    bricks = Group()
    ball = Ball(ai_setting, screen, platform, bricks)

    #блок музыки - начало игры
    music_file = "mus/title.mp3"
    pygame.mixer.music.load(music_file)
    pygame.mixer.music.play()  #Проигрываем5
    #

    # Create the wall of bricks.
    gameF.create_wall(ai_setting, screen, platform, bricks)

    #Запуск основного цикла в игре
    while True:
        #    timer.tick(240)
        if (ai_setting.life == 0):

            break
        gameF.checkEvents(platform)  #Функция реагирования на события
        platform.update()  #Обновление платформы
        ball.update()  #Обновление мяча

        gameF.updateScreen(ai_setting, screen, platform, ball,
                           bricks)  #Функция перерисовки экрана
Exemplo n.º 5
0
def runGame():
    pygame.init()

    settings = Settings()
    screen = pygame.display.set_mode((settings.screenWidth, settings.screenHeight))
    pygame.display.set_caption("AI Game")
    player = Player(screen, settings)
    map = Group()

    # testing spikes
    spikes = Group()
    newSpike, newSpike2 = Spike(settings, screen), Spike(settings, screen)
    newSpike.rect.x, newSpike.rect.bottom = 250, settings.screenHeight -50
    newSpike2.rect.x, newSpike2.rect.bottom = 600, settings.screenHeight -50
    spikes.add(newSpike, newSpike2)
    # creates a lone block above the rest for testing
    newBlock = Map(settings, screen)
    newBlock.rect.x, newBlock.rect.y = 300, settings.screenHeight - 100
    map.add(newBlock)
    gf.makeMap(map, screen, settings) # makes the bottom layer right now

    while True:
        screen.fill(settings.bgColor)    # Fills background with solid color, can add clouds or something later
        gf.blitMap(map)                  # Draws the map on screen
        gf.drawGrid(settings, screen)    # Draw the Grid, helps for coding can be removed

        gf.checkEvents(player)           # Checks Button Presses
        gf.checkCollide(player, map, spikes)     # Checks to see if player is hitting the world around him
        player.updatePlayer(map)         # Movement of the player
        player.drawPlayer()              # Draws the player
        gf.checkJump(player)             # Checks to see if top of jump is reached

        spikes.draw(screen)

        pygame.display.flip()            # Makes the display work (Don't Touch, Make sure this stay near the bottom)
Exemplo n.º 6
0
def runGame():
    pygame.init()
    aiSettings = Settings()
    screen = pygame.display.set_mode(
        (aiSettings.screenWidth, aiSettings.screenHeight))
    pygame.display.set_caption("Alien Invision")
    ship = Ship(aiSettings, screen)
    bullets = Group()
    while True:
        # gf.checkEvents(ship)
        gf.checkEvents(aiSettings, screen, ship, bullets)
        ship.update()
        gf.updateBullets(bullets)
        gf.updateScreen(aiSettings, screen, ship, bullets)
Exemplo n.º 7
0
def runGame():
    pygame.init()

    settings = Settings()
    screen = pygame.display.set_mode(
        (settings.screenWidth, settings.screenHeight))
    pygame.display.set_caption("AI Game")
    player = Player(screen, settings)

    map = Group()  # Group of all Blocks
    spikes = Group()  # testing spikes
    enemies = Group()  # testing enemy

    newEnemy = Baddie(screen, settings)
    newEnemy.rect.x, newEnemy.rect.y = 550, settings.screenHeight - 85
    enemies.add(newEnemy)

    newSpike, newSpike2 = Spike(settings, screen), Spike(settings, screen)
    newSpike.rect.x, newSpike.rect.bottom = 250, settings.screenHeight - 50
    newSpike2.rect.x, newSpike2.rect.bottom = 600, settings.screenHeight - 50
    spikes.add(newSpike, newSpike2)
    gf.makeMap(map, screen, settings)  # makes the bottom layer right now

    while True:
        screen.fill(
            settings.bgColor
        )  # Fills background with solid color, can add clouds or something later
        gf.blitMap(map)  # Draws the map on screen
        gf.drawGrid(settings,
                    screen)  # Draw the Grid, helps for coding can be removed

        gf.checkEvents(player)  # Checks Button Presses
        gf.checkCollide(
            player, map,
            spikes)  # Checks to see if player is hitting the world around him
        gf.enemyBlockCollide(enemies, map)
        gf.enemyPlayerCollide(player, enemies)
        player.updatePlayer(map)  # Movement of the player
        player.drawPlayer()  # Draws the player

        for enemy in enemies:
            enemy.update()
            enemy.blit()

        gf.checkJump(player)
        spikes.draw(screen)

        pygame.display.flip(
        )  # Makes the display work (Don't Touch, Make sure this stay near the bottom)
Exemplo n.º 8
0
def startGame():
    setting = Settings()
    pg.init()
    screen = pg.display.set_mode(
        (setting.screen_width, setting.screeen_height))
    pg.display.set_caption('Alien: Isolation')

    ship = Ship(screen)

    while True:
        gf.checkEvents(ship)  # цикл обработки событий
        ship.update()

        gf.updateScreen(setting, screen,
                        ship)  # функция отрисовки/обновления экрана
Exemplo n.º 9
0
def run_game():
    # Initialisiere das Spiel.
    pygame.init()
    # mySettings ist eine Instanz der Klasse Settings aus der Datei settings.
    mySettings = settings.Settings()

    # Spiel im Fenstermodus. Sinnvoll bei der Fehlersuche.
    # Darum ist die Zeile auskommentiert.
    # So kann die Zeile einfach wieder aktiviert werden.
    screen = pygame.display.set_mode((mySettings.screenWidth, mySettings.screenHight))

    # Spiel im Vollbilsmodus.
    #screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
    pygame.display.set_caption(mySettings.windowCaption)
    # Schalte die Maus aus, damit sie nicht mehr sichtbar ist.
    pygame.mouse.set_visible(False)
    # einstellen der fps
    clock = pygame.time.Clock()

    font = pygame.freetype.Font("fonts/sans.ttf")

    gameRunning = True

    # myShip ist eine Instanz der Klasse Ship aus der Datei ship.
    myShip = ship.Ship(screen)

    bullets = pygame.sprite.Group()
    asteroids = pygame.sprite.Group()

    # Starte die Hauptschleife des Spiels.
    if mySettings.gameRunning == True:
        while True:
            clock.tick(mySettings.fps)
            gf.checkEvents(mySettings, screen, myShip, bullets)
            myShip.update()
            gf.updateBullets(bullets, asteroids)
            gf.updateAsteriods(mySettings, screen, asteroids)
            gf.updateScreen(mySettings, screen, myShip, bullets, asteroids)
            if mySettings.gameRunning == False:
                break
    if mySettings.gameRunning == False:
        while True:
            gf.checkEventNewGame(mySettings)
            if mySettings.newGame == True:
                break
    if mySettings.newGame == True:
        mySettings.newGame = False
        run_game()
Exemplo n.º 10
0
def runGame():
    #runs the game and sets proper display resolution
    pygame.init()
    gameSettings = Settings()
    screen = pygame.display.set_mode(
        (gameSettings.screen_width, gameSettings.screen_height
         )  #imports screen resolution from settings.py
    )

    #create an instance to store the game's stats
    stats = gameStats(gameSettings)

    #draws the ship on the screen, creates a group of bullets, and a group of aliens
    ship = Ship(gameSettings, screen)
    bullets = Group()
    aliens = Group()

    #create first fleet of aliens
    gf.createFleet(gameSettings, screen, ship, aliens)

    #main loop for the game
    while True:
        #window title
        pygame.display.set_caption("Space Invaders Ripoff")

        #draw the play button
        playButton = Button(gameSettings, screen, "PLAY")

        #draw everything on screen constantly
        screen.fill(gameSettings.bgColor)
        ship.blit()

        #updates the ship based on real-time occurences in-game
        gf.checkEvents(gameSettings, screen, stats, playButton, ship, aliens,
                       bullets)

        if stats.gameActive:
            ship.update()
            gf.updateBullets(gameSettings, screen, ship, aliens, bullets)
            gf.updateAliens(gameSettings, stats, screen, ship, aliens, bullets)

        gf.updateScreen(gameSettings, screen, stats, ship, aliens, bullets,
                        playButton)

        #drawing the most recent screen refresh
        pygame.display.flip()
Exemplo n.º 11
0
def runGame():
    pygame.init()
    pongSettings = Settings()
    screen = pygame.display.set_mode(
        (pongSettings.screenWidth, pongSettings.screenHeight))
    pygame.display.set_caption("Pong 2")

    paddleTopBottom = Group()
    paddleLeftRight = Group()

    paddle = Paddle(pongSettings, screen, "player", "bottom")
    paddle3 = Paddle2(pongSettings, screen, "right")
    paddle5 = Paddle(pongSettings, screen, "player", "top")

    paddle2 = Paddle2(pongSettings, screen, "left")
    paddle4 = Paddle(pongSettings, screen, "AI", "top")
    paddle6 = Paddle(pongSettings, screen, "AI", "bottom")

    paddleTopBottom.add(paddle, paddle4, paddle5, paddle6)
    paddleLeftRight.add(paddle2, paddle3)
    ball = Ball(pongSettings, screen)
    divide = Divider(pongSettings, screen)

    play_button = Button(pongSettings, screen, "Play")
    sb = Scoreboard(pongSettings, screen)
    startScreen = Start(pongSettings, screen)

    while True:
        gf.checkEvents(pongSettings, paddle, paddle3, paddle5, play_button, sb)
        if pongSettings.gameActive:
            gf.checkPaddleBallCollision(ball, paddleTopBottom, paddleLeftRight,
                                        pongSettings)
            gf.checkOutOfBounds(ball, pongSettings, screen, sb)
            paddle.update(ball)
            paddle2.update(ball)
            paddle3.update(ball)
            paddle4.update(ball)
            paddle5.update(ball)
            paddle6.update(ball)
            ball.update()
            gf.updateScreen(pongSettings, screen, paddle, paddle2, paddle3,
                            paddle4, paddle5, paddle6, ball, divide, sb)
        else:
            gf.startGame(play_button, startScreen)
Exemplo n.º 12
0
def runGame():
    pygame.init()
    aiSettings = Settings()
    screen = pygame.display.set_mode((aiSettings.screenWidth, aiSettings.screenHeight))
    pygame.display.set_caption("Alien Invasion")
    stats = GameStats(aiSettings)
    ship = Ship(aiSettings, screen)
    bullets = Group()
    aliens = Group()
    gf.createFleet(aiSettings, screen, aliens, ship)
    playButton = Button(aiSettings, screen, "Play")
    sb = Scoreboard(aiSettings, screen, stats)

    while True:
        gf.checkEvents(aiSettings, screen, ship, bullets, aliens, stats, playButton, sb)
        if stats.gameActive:
            ship.update()
            gf.updateBullets(aiSettings, bullets, aliens, screen, ship, stats, sb)
            gf.updateAliens(aiSettings, stats, screen, aliens, bullets, ship, sb)
        gf.updateScreen(aiSettings, screen, ship, bullets, aliens, stats, playButton, sb)
Exemplo n.º 13
0
def runGame():

    # Initialize game and create a screen object.
    pygame.init()  # initialize background settings
    pygame.display.set_caption("Alien Invasion")

    # Set background size.
    aiSettings = Settings()
    screen = pygame.display.set_mode(
        (aiSettings.screenWidth, aiSettings.screenHeight))

    # Make a ship.
    ship = Ship(aiSettings, screen)

    # Start main loop for the game.
    while True:
        # Watch for keyboard and mouse events.
        gf.checkEvents(ship)
        ship.update()
        gf.updateScreen(aiSettings, screen, ship)
Exemplo n.º 14
0
def playGame(screen, myfont):
    scene.starting(screen, myfont)

    enemyList = [Enemy() for i in range(50)]  #difficulty
    iterations = 0
    while True:
        screen.fill(Settings.backgroundColor)
        if not Settings.pause:
            Player.xCoord, Player.yCoord = pygame.mouse.get_pos(
            )  #delete this line to use keys
        pygame.draw.circle(screen,
                           Player.color, [Player.xCoord, Player.yCoord],
                           round(Player.size))  #draws the Player
        for enemy in enemyList:
            enemy.draw(screen)
            if (not Settings.pause) and (iterations % enemy.speed == 0):
                enemy.move(
                )  #makes enemies move in a set direction(determined from the __init__() function)
        for enemy in enemyList:
            if not gf.checkBoundary(enemy):
                enemyList[enemyList.index(enemy)] = Enemy()
        time.sleep(Player.speed)
        gf.checkEvents(Player)
        gf.checkCollision(Player, enemyList)
        textsurface = myfont.render(
            'Size: ' + str(round(Player.actualSize)) + " " * 30 +
            "About the width of : " +
            str(Settings.stageToObject(Settings.stage)), False,
            Settings.colors['WHITE'])  #shows score
        screen.blit(textsurface, (0, 0))
        gf.nextTerm(enemyList)
        pygame.display.flip()
        if Settings.quit:
            break
        iterations += 1
    scene.endCredits(screen, myfont)
Exemplo n.º 15
0
def runGame():
    #initsialise game and create screen object
    pygame.init()  #To initialise the background settings
    cNM_S = Settings(
    )  # object of the settings class cNM_S stands for "Creeper Nah Man! Settings"

    screen = pygame.display.set_mode(
        (cNM_S.screen_width, cNM_S.screen_height)
    )  # We create a display called screen, (1200,800) is a tuple which defines
    # the dimensions of the game window.
    # The screen object just created is called a surface
    # In pygame a surface is part of the screen where we display a game element,eg creeper will be a surface and the Pewdiepie model will be a surface in the game
    pygame.display.set_caption("Creeper Nah Man!")

    #Make a play button
    playButton = Button(cNM_S, screen, "Play")

    #Create an instance to store game stats and create a scoreboard
    stats = GameStats(cNM_S)
    sb = Scoreboard(cNM_S, screen, stats)

    #Make a Pewds model, a group of tridents and a group of creepers:-

    #Create a Pewdiepie model
    pewdsModel = Pewds(
        cNM_S, screen
    )  # Creating an instance of Pewds class , this part is outside while since we do not want to create a new instance of Pewds class on each

    #Make a group to store tridents in
    tridents = Group()
    #The group is created outside the while loop so that we dont create a new group each time we pass through the while loop
    #This group will store all the live tridents so that we can manage the tridents that have already been fired by the user
    #This group will be an instance of the class pygame.sprite.Group, which behaves like a list with some extra functionality which is helpful when
    # building games, we will use this group to draw tridents on the screen on each pass through the main loop (while loop) and to update each tridents'
    # position

    #Make a group of creepers
    creepers = Group()

    #Create a collection of creepers
    gf.createCreeperCollection(cNM_S, screen, pewdsModel, creepers)

    #setting up backround image for the game
    bkgnd = pygame.image.load(
        "C:\\Users\\Rahul Pillai\\Desktop\\_\\College\\SkillShare\\PythonGameDevelopment\\Codes\\CreeperNahMan\\CreeperNahMan\\CreeperNahMan\\ImageAssets\\bkgnd.png"
    )
    #.convert() #convert is used since the image needs to be converted to a format Pygame can more easily work with.

    #set background color (Already done in Settings.py)
    #bg_color=(135,206,250) (Can use this if there was no Settings file)

    #start main loop for the game

    while True:  # while loop that contains the game

        screen.blit(
            bkgnd, [0, 0])  # to set our background initially before everything
        # watch for keyboard and mouse events
        gf.checkEvents(cNM_S, screen, stats, sb, playButton, pewdsModel,
                       creepers,
                       tridents)  #this function exists in gameFunctions.py
        #tridents is passed to this function since we need to check the event when space bar is pressed to shoot trident

        if stats.gameActive:
            pewdsModel.update()

            #tridents is passed to this function since we need to update the tridents drawn to the screen so we see the tridents moving up
            gf.updateTridents(
                cNM_S, screen, stats, sb, creepers, pewdsModel, tridents
            )  # instead of doing tridents.update() and removal of off screen tridents here
            # we have moved that code to a new function in gameFunctions.py

            gf.updateCreepers(cNM_S, stats, screen, sb, pewdsModel, creepers,
                              tridents)

        gf.updateScreen(cNM_S, screen, stats, sb, pewdsModel, tridents,
                        creepers, playButton)
Exemplo n.º 16
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")
Exemplo n.º 17
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")
Exemplo n.º 18
0
def runGame():
    pygame.init()

    # Basic init (clock for fps, settings for easy number changes, gamestats for game variables, screen/display for window)
    clock = pygame.time.Clock()
    settings = Settings()
    gameStats = GameStats()
    screen = pygame.display.set_mode(
        (settings.screenWidth, settings.screenHeight))
    pygame.display.set_caption("AI Game")

    text = Text(screen, settings, "Generation # Text", 30, 10, 10)
    allText = [text]

    spikes = Group()  # group of all spikes
    map = Group()  # Group of all Blocks
    gf.makeMap(map, spikes, screen,
               settings)  # assigns blocks and spikes to groups

    enemies = Group()  # testing enemy
    # newEnemy = Baddie(screen, settings)
    # newEnemy.rect.x, newEnemy.rect.y = 550, settings.screenHeight - 85
    # enemies.add(newEnemy)

    Bots = []
    gf.createBots(screen, settings, Bots)  # For loop to create and append bots

    while True:
        screen.fill(
            settings.bgColor
        )  # Fills background with solid color, can add clouds or something later
        gf.blitMap(map)  # Draws the map on screen
        gf.drawGrid(
            settings, screen,
            gameStats)  # Draw the Grid, helps for coding can be removed

        gf.checkEvents(gameStats)  # Checks Button Presses
        #gf.checkCollide(player, map, spikes)     # Checks to see if player is hitting the world around him
        gf.enemyBlockCollide(enemies, map)
        #gf.enemyPlayerCollide(player, enemies)
        gf.screenRoll(gameStats, map, spikes, Bots)

        if gameStats.pause == False:

            for bot in Bots:
                if gf.checkCollide(bot, map, spikes):
                    gameStats.death += 1
                if bot.dead == False:
                    if bot.rect.x > 19 * (
                            bot.settings.screenWidth / 24
                    ):  # screen roll, Make optional or only scan once
                        gameStats.screen_bot_roll = True
                    data, item = gf.scanFront(bot, map, spikes)
                    bot.chooseInput(data, item)

            if gf.roundTimer(gameStats) or gameStats.death >= len(
                    Bots
            ):  ## Things that are done to prepare for next gen ** Alll this into a function
                gameStats.screen_bot_roll = False  ## This needs to be a function check to turn off
                gf.resetScreen(gameStats, map, spikes, Bots)

                tempTimerAdd = gf.splitBots(
                    Bots
                )  # Deletes the worst half and return the highest score
                gameStats.addTimer(tempTimerAdd)
                ## TIMER MIGHT BE MESS UP RIGHT NOW MUST CHECK LATER *******************************************

                for i in range(len(Bots)):
                    Bots[i].id = i + 1
                    Bots[i].increaseLife()

            gf.printInfo(Bots, gameStats.death, settings)
            for i in range(int(len(Bots))):
                if Bots[i].dead == False:
                    Bots[i].update()
                Bots[i].blit()
        else:  # When pause is True
            for i in range(int(len(Bots))):
                Bots[i].blit()

        for enemy in enemies:  # not affected by pause since it's being tested
            enemy.update()
            enemy.blit()

        gf.printText(allText, gameStats)

        gf.deadBotBox(len(Bots), screen)
        spikes.draw(screen)

        pygame.display.flip(
        )  # Makes the display work (Don't Touch, Make sure this stay near the bottom)
        clock.tick(75)
Exemplo n.º 19
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")
Exemplo n.º 20
0
def runGame():
    """Runs the game, duh!"""
    #initialize window and such
    settings = Settings()
    game.init()
    game.font.init()
    screen = game.display.set_mode(
        (settings.screenWidth, settings.screenHeight))
    game.display.set_caption(settings.title)

    character = boy(screen)

    game.display.set_icon(character.image)

    font = Fonts(character)

    total = 2

    #create a path
    pathList = []
    for i in range(0, 20):
        path = Tile('OverworldPath.png',
                    screen.get_rect().centerx,
                    screen.get_rect().bottom - (i * 32), screen, 0)
        pathList.append(path)

    #create a wall
    wallList = []
    for i in range(0, 8):
        for j in range(0, 8, 2):
            wall = Tile('OverworldWall.png',
                        (screen.get_rect().centerx * 1.5) + (i * 32),
                        (screen.get_rect().centery * 1.5) + (j * 32), screen,
                        1)
            wallList.append(wall)
    for i in range(0, 15):
        wall = Tile('OverworldWall.png', 240, 0 + (32 * i), screen, 1)
        wallList.append(wall)
    for i in range(0, 4):
        wall = Tile('OverworldWall.png', 272 + (32 * i), 96 + (32 * i), screen,
                    1)
        wallList.append(wall)

    #generate some rocks
    rockList = []
    for i in range(0, total):
        randX = randint(0, 1200 - 32)
        randY = randint(0, 800 - 32)
        rock = Tile('OverworldRock.png', randX, randY, screen, 1)
        rockList.append(rock)

    usedMinerals = []
    mineral = -1

    bossPresent = False
    bossCounter = 0

    #main loop for game
    while True:
        if len(usedMinerals) % total == 0 and bossPresent == False and len(
                usedMinerals) != 0:
            boss1 = Tile('BossRock.png', 583, 120, screen, 1)
            bossPresent = True
            bossCounter += 1
            while len(rockList) > 0:
                rockList.pop()
            rockList.append(boss1)

        if character.stage == "OVERWORLD":
            character.walkAnimate()
            character.checkCollision(wallList)
            if character.checkCollision(rockList) == True:
                while True:
                    mineral = randint(1, 10)
                    if mineral not in usedMinerals:
                        break
                if bossPresent == True:
                    enemy = Rock(11 * bossCounter, screen)
                else:
                    enemy = Rock(mineral, screen)
                character.stage = "BATTLE"
                character.setBattleImage("Battle.png")
            character.updatePos()
        if character.stage == "BATTLE":
            gf.checkEvents(character, font, enemy, rockList, mineral,
                           usedMinerals, bossPresent)
            gf.updateScreen(settings, screen, character, pathList, wallList,
                            rockList, font, enemy)
        else:
            gf.checkEvents(character, font)
            gf.updateScreen(settings, screen, character, pathList, wallList,
                            rockList, font)
Exemplo n.º 21
0
def run_game():
    # intialize
    pygame.init()
    pygame.mixer.init()
    # save y of bGround to move it up
    y = 0
    bGround = Background('pic/background.png', [0, y])
    aiSettings = Setting()
    screen = pygame.display.set_mode(
        (aiSettings.screenWidth, aiSettings.screenHeight))
    pygame.display.set_caption(aiSettings.caption)

    # create an instance to store game statistics and scoreboard
    stats = GameStats(aiSettings)
    sb = Scoreboard(aiSettings, screen, stats)

    # sound effect
    shootSound = pygame.mixer.Sound(aiSettings.pew)
    explosionSound = pygame.mixer.Sound(aiSettings.boom)
    wowSound = pygame.mixer.Sound(aiSettings.wow)
    failSound = pygame.mixer.Sound(aiSettings.fail)

    pygame.mixer.music.load(aiSettings.background)
    pygame.mixer.music.set_volume(0.3)

    # make ship
    ship = Ship(screen, aiSettings)

    # make a group to store the bullet
    bullets = Group()

    # make an alien group
    aliens = Group()

    # make an explosion group
    explode = Group

    # play background music
    pygame.mixer.music.play(loops=-1)

    # start screen
    while True:
        gf.checkStart(screen, aiSettings, stats)
        if not stats.gameActive:
            gf.updateStartScreen(screen, aiSettings)
        else:
            break

    # main game
    gf.createFleet(aiSettings, screen, ship, aliens)
    # start the main loop for the game
    while True:
        if stats.gameActive:
            gf.checkEvents(aiSettings, screen, ship, bullets, shootSound,
                           stats)
            ship.update(screen)
            gf.updateBullet(aiSettings, screen, ship, bullets, aliens,
                            explosionSound, wowSound, stats, sb)
            gf.updateAlien(aiSettings, aliens, ship, failSound, stats, screen,
                           bullets, sb)
            gf.updateScreen(screen, ship, bGround, bullets, aliens, sb)
        else:
            # end screen
            gf.checkEnd(screen, aiSettings, stats)
            aliens.empty()
            bullets.empty()
            if not stats.gameActive:
                gf.updateEndScreen(screen, aiSettings)
            else:
                stats.resetStats()
                aiSettings.reset()
                ship.reset()
Exemplo n.º 22
0
        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)
Exemplo n.º 23
0
def runGame():
    pygame.init()
    settings = Settings()
    screen = pygame.display.set_mode(
        (settings.screenWidth, settings.screenHeight))
    pygame.display.set_caption("PacMan")
    mainMenu = Menu(screen, settings)
    play = Play(screen, settings)
    gameStats = GameStats()
    map = BuildMap(screen, settings)
    details = Details(screen, settings)
    blocks = Group()
    dots = Group()
    ghosts = []
    for i in range(4):
        new = Ghost(screen, settings)
        new.type = i
        new.x += 30 * i
        new.prep()
        ghosts.append(new)
    fruit = Fruit(screen, settings)
    powerPills = Group()
    player = Player(screen, settings)
    map.makeMap(blocks, dots, powerPills)
    pygame.mixer.init()

    while True:
        screen.fill((50, 20, 20))
        map.drawMap(blocks, dots, powerPills)

        details.blit()
        gf.checkEvents(player, gameStats, play)
        if gameStats.gameActive:
            if gameStats.pause == False:
                if player.movementRight or player.movementLeft or player.movementUp or player.movementDown:
                    pygame.mixer.music.load('sound/dotSound.mp3')
                    pygame.mixer.music.play(0, .052)
                player.update()
                player.blit()
                for i in range(4):
                    ghosts[i].update(gameStats)
                    ghosts[i].blit()
                    gf.checkScreenLimits(ghosts[i])
                gf.checkScreenLimits(player)
            details.prep(gameStats)
            fruit.blit(gameStats)
            gf.spawnFruit(gameStats, fruit)
            gf.ghostCollide(ghosts[0], blocks)
            gf.ghostCollide(ghosts[2], blocks)
            gf.fruitCollide(player, fruit, gameStats)
            gf.addDiff(ghosts[2], gameStats)
            gf.wallCollide(player, blocks)
            gf.dotCollide(player, dots, gameStats)
            gf.pillCollide(player, powerPills, gameStats)
            for ghost in ghosts:
                gf.playerGhostCollide(player, ghost, gameStats, mainMenu)
            gf.roundEnd(gameStats, player, ghosts, dots, powerPills, map)
        else:
            mainMenu.checkShowHS(gameStats.showHS)
            mainMenu.update()
            mainMenu.blit()
            play.blit()

        pygame.display.flip()