コード例 #1
0
ファイル: _Main.py プロジェクト: vorcepa/PygameTutorial
    def __init__(self, gameWindow):
        self.gameWindow = gameWindow
        pg.display.set_caption("Pygame Tutorial")
        self.clock = pg.time.Clock()
        self.FPS = 30

        self.enemies = BasicEnemy.Enemy.enemies
        self.player = PlayerActive()
        self.objv = Objective()
        self.scoreB = utils.ScoreBoard(gameWindow)
        self.map = GameMap()
コード例 #2
0
    def __init__(self):
        self.gameWindow = pygame.display.set_mode((1000, 600))
        pygame.display.set_caption("MN Shooter")
        self.clock = pygame.time.Clock()
        self.FPS = 60

        self.objv = Objective()
        self.scoreBoard = Utils.ScoreBoard()
        self.player = PlayerActive(Utils.green)

        self.enemies = BasicEnemy.Enemy.enemies
        self.enemies.add(BasicEnemy.Enemy())
コード例 #3
0
    def __init__(self):

        self.gw = pygame.display.set_mode(
            (1000, 600))  #Create the game window, set up
        pygame.display.set_caption("Pygame Tutorial")
        self.clock = pygame.time.Clock()

        self.enemies = BasicEnemy.Enemy.enemies

        self.player = PlayerActive()  #The player object
        self.objv = Objective()
        self.scoreB = utils.ScoreBoard(self.gw)
        self.map = gameMap()

        self.FPS = 30
コード例 #4
0
    def __init__(self):

        self.gw = pygame.display.set_mode((1000, 600))                  #Create the game window, set up
        pygame.display.set_caption("Pygame Tutorial")
        self.clock = pygame.time.Clock()

        self.enemies = BasicEnemy.Enemy.enemies

        self.player = PlayerActive()                                            #The player object
        self.objv = Objective()
        self.scoreB = utils.ScoreBoard(self.gw)
        self.map = gameMap()

        self.FPS = 30
コード例 #5
0
ファイル: firstGame.py プロジェクト: MeachD/Spider-king
import pygame

import BasicEnemy
import utils
from GenericPlayer import PlayerActive, Objective

pygame.init()

gameWindow = pygame.display.set_mode((1000, 600))                  #Create the game window, set up
pygame.display.set_caption("Pygame Tutorial")
clock = pygame.time.Clock()

enemies = BasicEnemy.Enemy.enemies

player = PlayerActive()                                            #The player object
objv = Objective()
scoreB = utils.ScoreBoard()

FPS = 30
gameActive = True
while gameActive:                                                  #Game loop
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            gameActive = False

    activeKey = pygame.key.get_pressed()                           #Events for key presses
    if activeKey[pygame.K_RIGHT]:
        player.move(1, 0)
    if activeKey[pygame.K_LEFT]:
        player.move(-1, 0)
    if activeKey[pygame.K_UP]:
コード例 #6
0
class Game():
    def __init__(self):
        self.gameWindow = pygame.display.set_mode((1000, 600))
        pygame.display.set_caption("MN Shooter")
        self.clock = pygame.time.Clock()
        self.FPS = 60

        self.objv = Objective()
        self.scoreBoard = Utils.ScoreBoard()
        self.player = PlayerActive(Utils.green)

        self.enemies = BasicEnemy.Enemy.enemies
        self.enemies.add(BasicEnemy.Enemy())

    def launchMenu(self):
        menu = True
        while menu:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    pygame.quit()
                    quit()
                if event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_q or event.key == pygame.K_ESCAPE:
                        menu = False
                print("Intro")

                self.gameWindow.fill(Utils.white)
                text = Utils.getFont(size=96, style="bold").render(
                    "Menu", True, Utils.black)
                textRect = text.get_rect()
                textRect.center = self.gameWindow.get_rect().center
                textRect.y -= 200

                self.gameWindow.blit(text, textRect)
                pygame.display.update()
                self.clock.tick(self.FPS)

    def pause(self):
        pause = True
        text = Utils.getFont(size=96,
                             style="bold").render("Game Paused", True,
                                                  Utils.black)
        textRect = text.get_rect()
        textRect.center = self.gameWindow.get_rect().center
        while pause:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    pygame.quit()
                    quit()
                if event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_p or event.key == pygame.K_ESCAPE:
                        print("Game Unpaused")
                        pause = False

                self.gameWindow.blit(text, textRect)

                pygame.display.update()
                self.clock.tick(self.FPS)

    def launchGame(self):
        self.launchMenu()
        gameActive = True
        while gameActive:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    gameActive = False
                if event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_ESCAPE or event.key == pygame.K_p:
                        print("Game Paused")
                        self.pause()
            activeKey = pygame.key.get_pressed()

            if activeKey[pygame.K_d]:
                self.player.move(1, 0)
            if activeKey[pygame.K_a]:
                self.player.move(-1, 0)
            if activeKey[pygame.K_w]:
                self.player.move(0, -1)
            if activeKey[pygame.K_s]:
                self.player.move(0, 1)
            if activeKey[pygame.K_SPACE]:
                self.player.doObjective(self.objv)

            mouseClick = pygame.mouse.get_pressed()
            cur = pygame.mouse.get_pos()

            self.gameWindow.fill(Utils.white)

            # Math stuff
            if mouseClick[0]:
                self.player.shoot(cur)

            # Collisions
            playerCollisions = pygame.sprite.spritecollide(
                self.player, self.enemies, False)
            for enemy in playerCollisions:
                self.player.takeDamage()
                enemy.destroy()

            bulletCollisions = pygame.sprite.groupcollide(
                self.enemies, self.player.bullets, False, True)
            for enemy in bulletCollisions:
                enemy.getDmg()

            objvCollision = pygame.sprite.spritecollide(
                self.objv, self.player.bullets, False)
            for bullet in objvCollision:
                tempLetter = self.objv.winMessage[len(
                    self.objv.displayMessage)]
                if tempLetter.upper() == bullet.name:
                    self.objv.displayMessage += tempLetter
                    self.objv.redraw()
                    bullet.destroy()
                    if self.objv.winMessage[len(
                            self.objv.displayMessage)] == " ":
                        self.objv.displayMessage += " "

            # Spawning
            BasicEnemy.spawn()

            # UPDATES
            self.objv.update(self.gameWindow)
            self.scoreBoard.update(self.gameWindow)
            self.player.update(self.gameWindow)

            self.enemies.update(self.player)

            # Drawing
            self.enemies.draw(self.gameWindow)

            # END Drawing Stuff
            pygame.display.update()
            self.clock.tick(self.FPS)

        pygame.quit()
        quit()
コード例 #7
0
class Tutorial_Game():
    def __init__(self):

        self.gw = pygame.display.set_mode((1000, 600))                  #Create the game window, set up
        pygame.display.set_caption("Pygame Tutorial")
        self.clock = pygame.time.Clock()

        self.enemies = BasicEnemy.Enemy.enemies

        self.player = PlayerActive()                                            #The player object
        self.objv = Objective()
        self.scoreB = utils.ScoreBoard(self.gw)
        self.map = gameMap()

        self.FPS = 30

    def quitGame(self):
        pygame.quit()
        quit()

    def gotoMenu(self):
        rect = self.gw.get_rect()

        def startPlay():
            self.menu = False


        playB = TextButton((rect.centerx, rect.centery-50), (200, 80), utils.green, "Play", startPlay)
        quitB = TextButton((rect.centerx, rect.centery+50), (200, 80), utils.red, "Quit", self.quitGame)

        self.menu = True
        while self.menu:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    self.quitGame()
                if event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_q:
                        menu = False

                self.gw.fill(utils.white)

                text = utils.getFont(size=82, style="bold").render("Tutorial Game", True, utils.black)
                textRect = text.get_rect()
                textRect.center = self.gw.get_rect().center
                textRect.y -= 200
                self.gw.blit(text, textRect)

                playB.update(self.gw)
                quitB.update(self.gw)

                pygame.display.update()
                self.clock.tick(self.FPS)

    def pause(self):
        pause = True
        while pause:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    pygame.quit()
                    quit()
                if event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_p:
                        print "game unpaused"
                        pause = False

                text = utils.getFont(size=96, style="bold").render("Paused", True, utils.black)
                textRect = text.get_rect()
                textRect.center = self.gw.get_rect().center

                self.gw.blit(text, textRect)

                pygame.display.update()
                self.clock.tick(self.FPS)

    def playGame(self):
        self.gotoMenu()

        gameActive = True
        while gameActive:                                                  #Game loop
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    gameActive = False
                if event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_p:
                        print "game Paused"
                        self.pause()


            activeKey = pygame.key.get_pressed()                           #Events for key presses
            if activeKey[pygame.K_RIGHT]:
                self.player.move(1, 0)
            if activeKey[pygame.K_LEFT]:
                self.player.move(-1, 0)
            if activeKey[pygame.K_UP]:
                self.player.move(0, -1)
            if activeKey[pygame.K_DOWN]:
                self.player.move(0, 1)
            if activeKey[pygame.K_SPACE]:
                self.player.doObjective(self.objv)

            cur = pygame.mouse.get_pos()
            mouse = pygame.mouse.get_pressed()                             #Events for mouse presses

            self.gw.fill(utils.white)
            self.map.resetMap()

            if mouse[0]:                                                   #Left-Click events
                self.player.shoot((cur[0] - self.map.offsetX, cur[1] - self.map.offsetY))

            #COLLISION DETECTION
            playerCollisions = pygame.sprite.spritecollide(self.player, self.enemies, False)
            for enemy in playerCollisions:                                 #Enemy-to-player collisions
                enemy.destroy()
                self.player.takeDamage()

            bulletCollision = pygame.sprite.groupcollide(self.enemies, self.player.bullets, False, True)
            for enemy in bulletCollision:                                  #Enemy-to-bullet collisions
                enemy.takeDamage()

            objvCollision = pygame.sprite.spritecollide(self.objv, self.player.bullets, False)
            if self.objv.winMessage != self.objv.displayMessage:
                for bullet in objvCollision:
                    tempLett = self.objv.winMessage[len(self.objv.displayMessage)]
                    if tempLett.upper() == bullet.name:
                        self.objv.displayMessage += tempLett
                        self.objv.redraw()
                        bullet.destroy()
                        if self.objv.winMessage != self.objv.displayMessage:
                            if self.objv.winMessage[len(self.objv.displayMessage)] == " ":
                                self.objv.displayMessage += " "

            #Spawning
            BasicEnemy.spawn()
            #Updates
            self.player.update(self.map.activeMap)
            self.enemies.update(self.player)
            self.objv.update(self.map.activeMap)

            #Drawing
            self.enemies.draw(self.map.activeMap)

            #END drawing stuff
            self.map.update(self.gw, self.player.rect)

            #UI Stuff
            self.scoreB.update(self.gw)

            pygame.display.update()
            self.clock.tick(self.FPS)

        self.quitGame()
コード例 #8
0
ファイル: _Main.py プロジェクト: vorcepa/PygameTutorial
class Tutorial_Game():
    def __init__(self, gameWindow):
        self.gameWindow = gameWindow
        pg.display.set_caption("Pygame Tutorial")
        self.clock = pg.time.Clock()
        self.FPS = 30

        self.enemies = BasicEnemy.Enemy.enemies
        self.player = PlayerActive()
        self.objv = Objective()
        self.scoreB = utils.ScoreBoard(gameWindow)
        self.map = GameMap()

    def quitGame(self):
        pg.quit()
        raise SystemExit(0)

    def gotoMenu(self):
        rect = self.gameWindow.get_rect()

        def startPlay():
            self.menu = False

        playB = TextButton((rect.centerx, rect.centery - 100), (200, 80),
                           utils.GREEN, "Play", startPlay)
        quitB = TextButton((rect.centerx, rect.centery + 50), (200, 80),
                           utils.RED, "Quit", self.quitGame)

        self.menu = True
        while self.menu:
            for event in pg.event.get():
                if event.type == pg.QUIT:
                    self.quitGame()
                if event.type == pg.KEYDOWN:
                    if event.key == pg.K_q:
                        self.menu = False

            self.gameWindow.fill(utils.WHITE)
            text = utils.getFont(size=82,
                                 style='bold').render("Tutorial Game", True,
                                                      utils.BLACK)
            textRect = text.get_rect()
            textRect.center = self.gameWindow.get_rect().center
            textRect.y -= 250
            self.gameWindow.blit(text, textRect)
            playB.update(self.gameWindow)
            quitB.update(self.gameWindow)

            pg.display.update()
            self.clock.tick(self.FPS)

    def pause(self):
        pause = True
        while pause:
            for event in pg.event.get():
                if event.type == pg.QUIT:
                    self.quitGame()
                if event.type == pg.KEYDOWN:
                    if event.key == pg.K_p:
                        print("Game unpaused.")
                        pause = False

                text = utils.getFont(size=96, style='bold').render(
                    "PAUSED", True, utils.BLACK)
                textRect = text.get_rect()
                textRect.center = self.gameWindow.get_rect().center

                self.gameWindow.blit(text, textRect)
                pg.display.update()
                self.clock.tick(self.FPS)

    def playGame(self):
        self.gotoMenu()

        gameActive = True
        while gameActive:
            for event in pg.event.get():
                if event.type == pg.QUIT:
                    gameActive = False
                if event.type == pg.KEYDOWN:
                    if event.key == pg.K_p:
                        print("Game Paused.")
                        self.pause()

            activeKey = pg.key.get_pressed()
            if activeKey[pg.K_RIGHT]:
                self.player.move(1, 0)
            if activeKey[pg.K_LEFT]:
                self.player.move(-1, 0)
            if activeKey[pg.K_UP]:
                self.player.move(0, -1)
            if activeKey[pg.K_DOWN]:
                self.player.move(0, 1)
            if activeKey[pg.K_SPACE]:
                self.player.doObjective(self.objv)

            playerCollision = pg.sprite.spritecollide(self.player,
                                                      self.enemies, False)
            for enemy in playerCollision:
                enemy.destroy()
                self.player.takeDamage()

            bulletCollision = pg.sprite.groupcollide(self.enemies,
                                                     self.player.bullets,
                                                     False, True)
            for enemy in bulletCollision:
                enemy.takeDamage()

            objvCollision = pg.sprite.spritecollide(self.objv,
                                                    self.player.bullets, False)
            for bullet in objvCollision:
                tempLetter = self.objv.winMessage[len(
                    self.objv.displayMessage)]
                if tempLetter.upper() == bullet.name:
                    self.objv.displayMessage += tempLetter
                    self.objv.redraw()
                    bullet.destroy()
                    if self.objv.winMessage[len(
                            self.objv.displayMessage)] == " ":
                        self.objv.displayMessage += " "
                        print(self.objv.displayMessage)

            self.gameWindow.fill(utils.WHITE)
            self.map.resetMap()

            self.player.update(self.map.activeMap)
            self.enemies.update(self.player)
            self.objv.update(self.map.activeMap)
            self.enemies.draw(self.map.activeMap)
            self.player.moveAmmo()
            self.objv.redraw()

            BasicEnemy.spawn()

            cur = pg.mouse.get_pos()
            mouse = pg.mouse.get_pressed()
            if mouse[0]:
                self.player.shoot(
                    (cur[0] - self.map.offsetX, cur[1] - self.map.offsetY))

            self.map.update(self.gameWindow, self.player.rect)
            self.scoreB.update(self.gameWindow)
            pg.display.update()
            self.clock.tick(self.FPS)

        self.quitGame()
コード例 #9
0
class Tutorial_Game():
    def __init__(self):

        self.gw = pygame.display.set_mode(
            (1000, 600))  #Create the game window, set up
        pygame.display.set_caption("Pygame Tutorial")
        self.clock = pygame.time.Clock()

        self.enemies = BasicEnemy.Enemy.enemies

        self.player = PlayerActive()  #The player object
        self.objv = Objective()
        self.scoreB = utils.ScoreBoard(self.gw)
        self.map = gameMap()

        self.FPS = 30

    def quitGame(self):
        pygame.quit()
        quit()

    def gotoMenu(self):
        rect = self.gw.get_rect()

        def startPlay():
            self.menu = False

        playB = TextButton((rect.centerx, rect.centery - 50), (200, 80),
                           utils.green, "Play", startPlay)
        quitB = TextButton((rect.centerx, rect.centery + 50), (200, 80),
                           utils.red, "Quit", self.quitGame)

        self.menu = True
        while self.menu:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    self.quitGame()
                if event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_q:
                        menu = False

                self.gw.fill(utils.white)

                text = utils.getFont(size=82, style="bold").render(
                    "Tutorial Game", True, utils.black)
                textRect = text.get_rect()
                textRect.center = self.gw.get_rect().center
                textRect.y -= 200
                self.gw.blit(text, textRect)

                playB.update(self.gw)
                quitB.update(self.gw)

                pygame.display.update()
                self.clock.tick(self.FPS)

    def pause(self):
        pause = True
        while pause:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    pygame.quit()
                    quit()
                if event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_p:
                        print "game unpaused"
                        pause = False

                text = utils.getFont(size=96, style="bold").render(
                    "Paused", True, utils.black)
                textRect = text.get_rect()
                textRect.center = self.gw.get_rect().center

                self.gw.blit(text, textRect)

                pygame.display.update()
                self.clock.tick(self.FPS)

    def playGame(self):
        self.gotoMenu()

        gameActive = True
        while gameActive:  #Game loop
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    gameActive = False
                if event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_p:
                        print "game Paused"
                        self.pause()

            activeKey = pygame.key.get_pressed()  #Events for key presses
            if activeKey[pygame.K_RIGHT]:
                self.player.move(1, 0)
            if activeKey[pygame.K_LEFT]:
                self.player.move(-1, 0)
            if activeKey[pygame.K_UP]:
                self.player.move(0, -1)
            if activeKey[pygame.K_DOWN]:
                self.player.move(0, 1)
            if activeKey[pygame.K_SPACE]:
                self.player.doObjective(self.objv)

            cur = pygame.mouse.get_pos()
            mouse = pygame.mouse.get_pressed()  #Events for mouse presses

            self.gw.fill(utils.white)
            self.map.resetMap()

            if mouse[0]:  #Left-Click events
                self.player.shoot(
                    (cur[0] - self.map.offsetX, cur[1] - self.map.offsetY))

            #COLLISION DETECTION
            playerCollisions = pygame.sprite.spritecollide(
                self.player, self.enemies, False)
            for enemy in playerCollisions:  #Enemy-to-player collisions
                enemy.destroy()
                self.player.takeDamage()

            bulletCollision = pygame.sprite.groupcollide(
                self.enemies, self.player.bullets, False, True)
            for enemy in bulletCollision:  #Enemy-to-bullet collisions
                enemy.takeDamage()

            objvCollision = pygame.sprite.spritecollide(
                self.objv, self.player.bullets, False)
            if self.objv.winMessage != self.objv.displayMessage:
                for bullet in objvCollision:
                    tempLett = self.objv.winMessage[len(
                        self.objv.displayMessage)]
                    if tempLett.upper() == bullet.name:
                        self.objv.displayMessage += tempLett
                        self.objv.redraw()
                        bullet.destroy()
                        if self.objv.winMessage != self.objv.displayMessage:
                            if self.objv.winMessage[len(
                                    self.objv.displayMessage)] == " ":
                                self.objv.displayMessage += " "

            #Spawning
            BasicEnemy.spawn()
            #Updates
            self.player.update(self.map.activeMap)
            self.enemies.update(self.player)
            self.objv.update(self.map.activeMap)

            #Drawing
            self.enemies.draw(self.map.activeMap)

            #END drawing stuff
            self.map.update(self.gw, self.player.rect)

            #UI Stuff
            self.scoreB.update(self.gw)

            pygame.display.update()
            self.clock.tick(self.FPS)

        self.quitGame()