コード例 #1
0
	def __init__(self, pos):
		pygame.sprite.Sprite.__init__(self, self.containers)
		self.image = pygame.Surface((64, 448))
		self.image.set_colorkey((0x00,0xff,0x00))
		self.image.fill((0x00,0xff,0x00))
		self.rect=self.image.get_rect()
		self.rect.topleft=pos
		
		self.tpipetile = util.loadPng('pipes.png')
		self.tlateral=util.loadPng('lateral2.png')
コード例 #2
0
    def __init__(self, screen):
        self.screen = screen
        self.clock = pygame.time.Clock()
        self.fps = 60
        self.menu = 0
        self.askname = False

        self.lvl = levelparser.LevelParser()

        self.input = input.Input()
        self.input.bindKey(EXIT, pygame.K_ESCAPE)
        self.input.bindKey(UP, pygame.K_UP, False)
        self.input.bindKey(DOWN, pygame.K_DOWN, False)
        self.input.bindKey(LEFT, pygame.K_LEFT, False)
        self.input.bindKey(RIGHT, pygame.K_RIGHT, False)
        self.input.bindKey(ENTER, pygame.K_RETURN, False)
        self.input.bindKey(BGMUSIC, pygame.K_F11, False)

        menucolor = (0xFF, 0xFF, 0xFF)
        hgcolor = (0xFF, 0xF6, 0x0)
        self.start = util.loadText("New Game", 16, menucolor, "modernab")
        self.hlstart = util.loadText("New Game", 16, hgcolor, "modernab")
        self.cont = util.loadText("Continue   <-  1  ->", 16, menucolor, "modernab")
        self.hlcont = util.loadText("Continue   <-  1  ->", 16, hgcolor, "modernab")
        self.howto = util.loadText("How to play", 16, menucolor, "modernab")
        self.hlhowto = util.loadText("How to play", 16, hgcolor, "modernab")
        self.high = util.loadText("High Scores", 16, menucolor, "modernab")
        self.hlhigh = util.loadText("High Scores", 16, hgcolor, "modernab")
        self.quit = util.loadText("Quit", 16, menucolor, "modernab")
        self.hlquit = util.loadText("Quit", 16, hgcolor, "modernab")

        self.bg = util.loadPng("mainscreen.png")
        self.menuicon = util.loadPng("menuicon.png")
        self.copyright = util.loadText("Created by Wil Alvarez (C) Copyright 2008", 10, (0xA, 0xA, 0xA), "vera")

        self.highscore = objects.HighScore(top=100000, nonames=False)

        self.__reset()

        while True:
            self.clock.tick(self.fps)
            self.__gameInput()

            self.screen.blit(self.bg, (0, 0))
            cx, cy = self.copyright.get_size()
            self.screen.blit(self.copyright, ((512 - cx) / 2, 140))
            self.__updateMenu()

            pygame.display.flip()
コード例 #3
0
	def __init__(self, pos):
		pygame.sprite.Sprite.__init__(self, self.containers)
		tile = util.loadPng("items.png")
		self.image = pygame.Surface((32, 32))
		self.image.set_colorkey((0x00,0xff,0x00))
		self.image.blit(tile, (0,0), (64,0,32,32))
		self.rect = self.image.get_rect()
		self.rect.topleft=pos
		self.blocked=True
コード例 #4
0
	def __init__(self, pos):
		pygame.sprite.Sprite.__init__(self, self.containers)
		self.extinguish=False
		self.pos=pos
		self.move_delay=0
		self.max_move_delay=15
		
		cursor_tile = util.loadPng("cursor.png")
		self.image = pygame.Surface((32, 32))
		self.image.set_colorkey((0x00,0xff,0x00))
		self.image.blit(cursor_tile, (0,0))
		self.rect = self.image.get_rect()
		self.rect.topleft=pos
コード例 #5
0
	def __init__(self, pos, type):
		pygame.sprite.Sprite.__init__(self, self.containers)
		self.blocked=False
		self.flow=False
		self.hp=100
		self.type=type
		
		pipetile = util.loadPng('pipes.png')
		if type=='rightup':
			offset=0
			self.inarray=['right', 'up']
			self.outarray=['down', 'left']
		elif type=='leftup':
			offset=32
			self.inarray=['left', 'up']
			self.outarray=['down', 'right']
		elif type=='rightdown':
			offset=64
			self.inarray=['right','down']
			self.outarray=['up', 'left']
		elif type=='leftdown':
			offset=96
			self.inarray=['left','down']
			self.outarray=['up', 'right']
		elif type=='horizontal':
			offset=128
			self.inarray=['right','left']
			self.outarray=['right', 'left']
		elif type=='vertical':
			offset=160
			self.inarray=['up','down']
			self.outarray=['up','down']
		elif type=='cross':
			offset=192
			self.inarray=['up','down', 'left', 'right']
			self.outarray=['up','down', 'left', 'right']
			
		self.image = pygame.Surface((32, 32))
		self.image.set_colorkey((0x00,0xff,0x00))
		#self.image.fill((0x0,0x0,0xef))
		self.image.blit(pipetile, (0,0), (offset,0,32,32))
		self.rect = self.image.get_rect()
		self.rect.topleft=pos
コード例 #6
0
	def __init__(self, pos, type):
		pygame.sprite.Sprite.__init__(self, self.containers)
		tile = util.loadPng("items.png")
		self.image = pygame.Surface((32, 32))
		self.image.set_colorkey((0x00,0xff,0x00))
		self.rect = self.image.get_rect()
		self.rect.topleft=pos
		self.blocked=True
		self.inarray=[]
		
		if type=='rock1':
			xoffset=96
			yoffset=0
		elif type=='rock2':
			xoffset=128
			yoffset=0
		elif type=='cactus1':
			xoffset=160
			yoffset=0
		elif type=='cactus2':
			xoffset=192
			yoffset=0
		elif type=='bones':
			xoffset=0
			yoffset=32
		elif type=='palmtree':
			xoffset=32
			yoffset=32
		elif type=='shrub1':
			xoffset=64
			yoffset=32
		elif type=='shrub2':
			xoffset=96
			yoffset=32
			
		self.image.blit(tile, (0,0), (xoffset,yoffset,32,32))
コード例 #7
0
    def __init__(self, screen, level, score, highscore):
        self.screen = screen
        self.__loadingScreen()
        self.level = level
        self.score = score
        self.quit = 0
        self.FPS = 60
        self.rdy_delay = self.FPS * 1.5
        self.win_delay = self.FPS * 3
        self.win = None
        self.pause = False
        self.fast = False
        self.clock = pygame.time.Clock()
        self.highscore = highscore
        self.gamingZone = pygame.Rect(0, 0, 448, 448)

        self.__loadSfx()

        self.PAYMENT = 500 * self.level
        self.MIN_PIPES = self.__calculateMinPipes()
        self.TERRAIN = 0  # Loaded from level
        self.MAX_START_DELAY = 1632 - (self.level * 72)  # (192 - 1632)
        self.MAX_FLOW_VALUE = 456 - (self.level * 18)  # (96 - 456)
        self.MIN_FLOW_VALUE = 32

        self.limit_flow_value = self.MAX_FLOW_VALUE
        self.num_pipes = self.MIN_PIPES
        self.usedpipes = 0
        self.currentpipe = None
        self.alarm = False
        self.pumpframe = 0
        self.pumpcount = 0
        self.pipetypes = [
            "rightup",
            "leftup",
            "rightdown",
            "leftdown",
            "horizontal",
            "vertical",
            "cross",
            "horizontal",
            "vertical",
        ]
        self.bartiles = [util.loadPng("lateral0.png"), util.loadPng("lateral1.png"), util.loadPng("scorebar.png")]
        self.stack = []

        self.input = input.Input()
        self.input.bindKey(EXIT, pygame.K_ESCAPE)
        self.input.bindKey(TURBO, pygame.K_SPACE)
        self.input.bindKey(PAUSE, pygame.K_RETURN, False)
        self.input.bindKey(MOTION, input.MOUSE_MOTION)
        self.input.bindKey(BUTTON1, input.MOUSE_BUTTON1, False)

        cursorGroup = pygame.sprite.RenderUpdates()
        pipeGroup = pygame.sprite.RenderUpdates()
        uiGroup = pygame.sprite.RenderUpdates()
        self.messageGroup = pygame.sprite.RenderUpdates()

        objects.Cursor.containers = cursorGroup
        objects.Oil.containers = cursorGroup
        objects.StackBar.containers = uiGroup
        objects.ScoreBar.containers = uiGroup
        objects.Pipe.containers = pipeGroup
        objects.Well.containers = pipeGroup
        objects.Refinery.containers = pipeGroup
        objects.Obstacle.containers = pipeGroup

        self.cursor = objects.Cursor((self.screen.get_width() / 2, self.screen.get_height() / 2))  # (0,0))
        self.stackbar = objects.StackBar((self.screen.get_width() - 64, 0))
        self.scorebar = objects.ScoreBar((0, self.screen.get_height() - 32))

        textcolor = (0xFF, 0xFF, 0xFF)  # (0x02,0x4e,0x02)
        self.leveltxt = util.loadText("Level " + str(self.level), 18, textcolor, "engex")
        self.readytxt = util.loadText("Ready!", 36, textcolor, "engex")
        self.pausetxt = util.loadText("Pause", 36, textcolor, "engex")

        losearray = [
            util.loadText("You have failed", 26, textcolor, "engex"),
            util.loadText("You lost the contract", 26, textcolor, "engex"),
            util.loadText("You're fired!", 26, textcolor, "engex"),
            util.loadText("What are you doing?", 26, textcolor, "engex"),
            util.loadText("Next!", 26, textcolor, "engex"),
            util.loadText("You're a mess!", 26, textcolor, "engex"),
        ]

        self.morepipestxt = util.loadText("You needed more pipes", 26, textcolor, "engex")

        winarray = [
            util.loadText("Good job!", 26, textcolor, "engex"),
            util.loadText("Mission accomplished!", 26, textcolor, "engex"),
            util.loadText("You did it!", 26, textcolor, "engex"),
            util.loadText("Way to go!", 26, textcolor, "engex"),
            util.loadText("Well done!", 26, textcolor, "engex"),
            util.loadText("You're the boss!", 26, textcolor, "engex"),
            util.loadText("You rock!", 26, textcolor, "engex"),
        ]

        self.losetxt = random.choice(losearray)
        self.wintxt = random.choice(winarray)
        self.dialog = util.loadPng("dialog.png")

        for i in range(4):
            self.__pushStack()

        tile = util.loadPng("grounds.png")
        self.bg = pygame.Surface((448, 448))

        lvl = levelparser.LevelParser()
        lvl.saveMaxLevel(self.level)
        level = lvl.parseLevel(self.level)
        offset = 0
        for i in range(14):
            for j in range(14):
                if level[i][j] == (0xB8, 0x16, 0x16, 0xFF):
                    self.oil = objects.Oil((j * 32, i * 32), "right")
                    self.well = objects.Well((j * 32, i * 32))
                    self.bg.blit(tile, (j * 32, i * 32), (0, 0, 32, 32))
                elif level[i][j] == (0xFF, 0xFF, 0xFF, 0xFF):
                    self.refinery = objects.Refinery((j * 32, i * 32))
                    self.bg.blit(tile, (j * 32, i * 32), (32, 0, 32, 32))
                elif level[i][j] == (0x81, 0x81, 0x81, 0xFF):
                    self.bg.blit(tile, (j * 32, i * 32), (random.choice([0, 32]), 0, 32, 32))
                    objects.Obstacle((j * 32, i * 32), "rock1")
                elif level[i][j] == (0x60, 0x4A, 0x20, 0xFF):
                    self.bg.blit(tile, (j * 32, i * 32), (random.choice([0, 32]), 0, 32, 32))
                    objects.Obstacle((j * 32, i * 32), "rock2")
                elif level[i][j] == (0x18, 0x67, 0x00, 0xFF):
                    self.bg.blit(tile, (j * 32, i * 32), (random.choice([0, 32]), 0, 32, 32))
                    objects.Obstacle((j * 32, i * 32), "cactus1")
                elif level[i][j] == (0x3F, 0x9C, 0x22, 0xFF):
                    self.bg.blit(tile, (j * 32, i * 32), (random.choice([0, 32]), 0, 32, 32))
                    objects.Obstacle((j * 32, i * 32), "cactus2")
                elif level[i][j] == (0xC6, 0xC1, 0xB0, 0xFF):
                    self.bg.blit(tile, (j * 32, i * 32), (random.choice([0, 32]), 0, 32, 32))
                    objects.Obstacle((j * 32, i * 32), "bones")
                elif level[i][j] == (0x18, 0x85, 0x51, 0xFF):
                    self.bg.blit(tile, (j * 32, i * 32), (random.choice([0, 32]), 0, 32, 32))
                    objects.Obstacle((j * 32, i * 32), "palmtree")
                elif level[i][j] == (0x0, 0x27, 0x08, 0xFF):
                    self.bg.blit(tile, (j * 32, i * 32), (random.choice([0, 64]), 0, 32, 32))
                    objects.Obstacle((j * 32, i * 32), "shrub1")
                elif level[i][j] == (0xCC, 0xAF, 0x4D, 0xFF):
                    self.bg.blit(tile, (j * 32, i * 32), (random.choice([0, 64]), offset, 32, 32))
                elif level[i][j] == (0xBF, 0xA4, 0x48, 0xFF):
                    self.bg.blit(tile, (j * 32, i * 32), (random.choice([0, 64]), offset, 32, 32))
                elif level[i][j] == (0xB2, 0x99, 0x43, 0xFF):
                    self.bg.blit(tile, (j * 32, i * 32), (96, offset, 32, 32))
                elif level[i][j] == (0xA6, 0x8E, 0x3F, 0xFF):
                    self.bg.blit(tile, (j * 32, i * 32), (128, offset, 32, 32))
                else:
                    continue

        contract = ContractScreen(
            self.screen, self.level, self.MIN_PIPES, self.TERRAIN, self.MAX_FLOW_VALUE, self.PAYMENT
        )
        self.quit = not contract.accept

        bgm = random.choice(["bgm-1.ogg", "bgm-2.ogg", "bgm-3.ogg", "bgm-4.ogg"])
        bgmPlayer("play", bgm)

        while not self.quit:
            self.clock.tick(self.FPS)
            self.screen.blit(self.bg, (0, 0))

            val = self.__prepareGame(pipeGroup, uiGroup, cursorGroup)
            if val == -1:
                continue
            elif val == 1:
                return

            self.__gameInput()

            if self.oil.state == "next":
                list = pygame.sprite.spritecollide(self.oil, objects.Pipe.containers, False)
                if len(list) > 0:
                    self.currentpipe = list[0]
                    if self.oil.dir in self.currentpipe.inarray:
                        if self.num_pipes > 0:
                            self.num_pipes -= 1
                        self.usedpipes += 1
                        self.moneysnd.play()
                        self.score += 50
                        # self.highscore.appendScore('', self.score)
                        self.messageGroup.add(
                            util.Message(self.currentpipe.rect.center, "+50", (0x12, 0x3D, 0x15), 15)
                        )  # (0x02,0x4e,0x02)
                        self.currentpipe.startFlow()
                        i = self.currentpipe.inarray.index(self.oil.dir)
                        self.oil.dir = self.currentpipe.outarray[i]
                        self.oil.flowing()
                    else:
                        self.__spillOil()
                else:
                    self.__spillOil()
            elif (self.oil.state == "flowing") and not self.pause:
                # print 'flow',self.oil.flow_value, self.limit_flow_value
                self.oil.flow_value += self.oil.speed
                if self.currentpipe != None:
                    self.currentpipe.update(self.oil.flow_value, self.limit_flow_value, self.oil.dir)
                if self.oil.flow_value >= self.limit_flow_value:
                    self.oil.moveNext()

                # Check Win (Refinery)
            if self.oil.rect == self.refinery.rect:
                if self.num_pipes == 0:
                    bgmPlayer("stop")
                    self.winsnd.play()
                    self.win = True
                else:
                    self.losesnd.play()
                    self.losetxt = self.morepipestxt
                    self.win = False

            if not self.pause:
                cursorGroup.update()
                self.messageGroup.update()
                pipeGroup.draw(self.screen)
                cursorGroup.draw(self.screen)
                self.messageGroup.draw(self.screen)
            else:
                cx, cy = self.pausetxt.get_size()
                dx, dy = self.dialog.get_size()

                self.screen.blit(self.dialog, ((448 - dx) / 2, (448 - dy) / 2))
                self.screen.blit(self.pausetxt, ((448 - cx) / 2, (416 - cy) / 2 + 16))

            uiGroup.update(self)
            uiGroup.draw(self.screen)

            pygame.display.flip()
コード例 #8
0
    def __init__(self, screen, level, pipes, terrain, pumping, pay):
        self.screen = screen
        self.clock = pygame.time.Clock()
        self.fps = 60
        self.accept = False
        quit = False

        self.input = input.Input()
        self.input.bindKey(ENTER, pygame.K_RETURN, False)
        self.input.bindKey(EXIT, pygame.K_ESCAPE, False)

        fontsize = 11
        fontcolor = (0x0, 0x0, 0x0)

        if terrain == 0:
            type = "Plain"
        elif terrain == 1:
            type = "Rocky"
        elif terrain == 2:
            type = "Wooded"
        elif terrain == 3:
            type = "Mixed"

        if 300 < pumping <= 448:
            pump = "Slow"
        elif 150 < pumping <= 300:
            pump = "Medium"
        else:
            pump = "Fast"

        back = util.loadText("Press 'ENTER' to Accept, 'ESCAPE' to Quit", 10, (0x0, 0x0, 0x0), "vera")
        contracttxt = util.loadText("Contract  " + str(level), 20, (0x0, 0x0, 0x0), "vera")
        mintxt = util.loadText("Minimun Pipes: " + str(pipes), 10, (0x0, 0x0, 0x0), "vera")
        terraintxt = util.loadText("Terrain: " + type, 10, (0x0, 0x0, 0x0), "vera")
        temptxt = util.loadText("Pumping: " + pump, 10, (0x0, 0x0, 0x0), "vera")
        paytxt = util.loadText("Payment: $" + str(pay), 20, (0x0, 0x0, 0x0), "vera")
        leveltxt = util.loadText("A", 20, (0xFF, 0xFF, 0xFF), "vera")

        image = util.loadPng("contract.png")

        bgmPlayer("play", "bgm-contract.ogg")

        while not quit:
            self.clock.tick(self.fps)
            quit = self.__gameInput()

            xoffset = 95
            yoffset = 32
            self.screen.fill((0xA7, 0xA7, 0xA7))
            self.screen.blit(image, (95, 32))

            self.screen.blit(contracttxt, (23 + xoffset, 95 + yoffset))
            self.screen.blit(mintxt, (42 + xoffset, 275 + yoffset))
            self.screen.blit(terraintxt, (42 + xoffset, 295 + yoffset))
            self.screen.blit(temptxt, (42 + xoffset, 315 + yoffset))
            self.screen.blit(paytxt, (42 + xoffset, 340 + yoffset))
            self.screen.blit(leveltxt, (290 + xoffset, 40 + yoffset))
            cx, cy = back.get_size()
            self.screen.blit(back, ((512 - cx) / 2, 420))

            pygame.display.flip()

        bgmPlayer("stop")
コード例 #9
0
	def spill(self):
		tile = util.loadPng("items.png")
		self.image.blit(tile, (0,0), (0,0,32,32))