Esempio n. 1
0
class Gameview(object):

	def __init__(self, world, player, images, debug=None):
		self.world = world
		self.player = player
		self.screenSize = (1024, 600)
		self.surface = pygame.display.set_mode(self.screenSize)
		self.images = images
		self.debug = debug
		self.renderTime = 0
		self.boxes = []
		
		self.viewportPos = (28, 28)
		viewportLength = Viewport.size * Cell.size
		self.viewportRect = pygame.Rect(self.viewportPos, (viewportLength, viewportLength))
		self.boxes.append(self.viewportRect)
		self.viewport = Viewport(self.surface.subsurface(self.viewportRect), self.viewportPos, world, player, images)
		
		self.displayPos = (viewportLength + 56, 28)
		self.displayRect = pygame.Rect(self.displayPos, (Cell.size * 12, viewportLength))
		self.display = DisplayPanel(self.surface.subsurface(self.displayRect), self.displayPos, self.player, images)
		
		player.screenshot = self.printscreen

	def draw(self):

		self.surface.fill(THECOLORS["royalblue4"])
		self.viewport.draw()
		self.display.draw()
		if self.debug is not None and self.player.debug:
			self.viewport.display(self.debug())
		
		pygame.display.flip()

	def notify(self, pos, event):
		if self.viewportRect.collidepoint(pos):
			self.viewport.notify(pos, event)
		if self.displayRect.collidepoint(pos):
			self.display.notify(pos, event)
		
	def printscreen(self):
		date = time.gmtime() 
		fileName =	"screenshot_" + \
				str(date[0]) + '-' + \
				str(date[1]) + '-' + \
				str(date[2]) + '-' + \
				str(date[3]-8) + '-' + \
				str(date[4]) + '-' + \
				str(date[5]) + \
				'.jpg'

		pygame.image.save(self.surface, fileName)
Esempio n. 2
0
class DisplayView():
    __instance = None

    @staticmethod
    def getInstance():
        """ Static access method. """
        if DisplayView.__instance is None:
            DisplayView()
        return DisplayView.__instance

    def __init__(self):
        """ Virtually private constructor. """
        self.__viewport = None
        if DisplayView.__instance is not None:
            raise Exception("This class is a singleton!")
        else:
            DisplayView.__instance = self

    def get_display(self):
        return self.__viewport

    def init_welcome_screen(self):
        self.__viewport = Viewport(*globales.DIMENSION)
        self.__viewport.init_viewport(globales.LOGO, globales.CAPTION)
        self.__viewport.bkg_color(globales.COLOR_FONDO)
        self.init_welcome_text()

    def init_welcome_text(self):
        self.__welcome_msg = Texto(globales.TEXTO[0], globales.FONT,
                                   (120, 3, 12), customEnums.TipoTexto.TITULO)
        posX = self.__viewport.horizontal_center(
            self.__welcome_msg.getSurface())
        posY = self.__viewport.vertical_center(self.__welcome_msg.getSurface())
        self.__welcome_msg.setPosicion(posX, posY)

    def main_menu_draw(self):
        self.__viewport.draw(self.__welcome_msg.getSurface(),
                             self.__welcome_msg.getPosicion())
Esempio n. 3
0
class Level(Completable, Inputable):
    def __init__(self, surface, level, **kwargs):
        super().__init__(**kwargs)
        self._surface = surface
        self.map = Map(level[0], level[1])

    def start(self):
        self.map.load()
        self._entity_map = {}
        self._position_map = {}
        self._entities = {}
        self._registered = {}
        self._enemySpawns = {}
        for x, y in self.map.getMap().keys():
            self._position_map[(x, y)] = []

        self._total_surface = Surface((self.map.w, self.map.h))
        tid = self.addEntity(register=True,
                             entity=MChar(self,
                                          self.map.getType(Tiles.Start)[0],
                                          inputStream=self.getInputStream()))
        self._camera = Viewport(
            tuple([s * const.res for s in const.screenSize]),
            lambda: self.map.getAttr("scale"), self.get(tid),
            (150, 200, 150, 200), self.map)
        self._background = Parallax(const.backgrounds)
        self.editor = Editor(self.map,
                             self._surface,
                             enabled=False,
                             inputStream=self.getInputStream())

        self._input = Input(inputStream=self.getInputStream())
        self._input.set(KEYDOWN, self.editor.toggleEnabled, K_e)
        self._input.set(KEYDOWN, self.start, K_r)

        # self._sound = Sound("assets\\music.ogg")
        # self._sound.play(-1)

        try:
            self._healthBar = HealthBar(10, 10, self.get(tid))
        except AssertionError:
            pass

        for (x, y), val in self.map.enemies.items():
            block = self.map.get(x, y)
            self._enemySpawns[block] = EnemySpawn(level=self,
                                                  anchor=Object(pos=(block.x,
                                                                     block.y)),
                                                  maxEmitted=val,
                                                  timeBetween=2)

        self._countdown = CountdownTimer(const.screenSize[0] * const.res - 50,
                                         10, self.map.getAttr("timeLim"))

    def addEntity(self, register=False, entity=None):
        if not entity:
            raise Exception("Entity must not be None.")

        tid = entity.getId()

        self._entities[tid] = entity
        if register:
            self._registered[tid] = entity

        self._entity_map[tid] = set()
        return tid

    def removeEntity(self, entity):
        del self._entities[entity.id]

    def get(self, entityId):
        return self._entities.get(entityId)

    def process(self):
        for entity in self._entities.values():
            result = entity.tick()

            if not entity.isAlive():
                self._entities.pop(entity.getId())

            # This should generally only apply to playable characters.
            if entity in self._registered.values():
                if Tiles.End in result.keys():
                    self.setFinished()
                if not entity.isAlive():
                    self.setLost()

        for s in self._enemySpawns.values():
            s.tick()

        self._camera.tick()
        self._countdown.tick()
        if self._countdown.isFinished():
            self.setLost()

        if self.editor.enabled():
            self.editor.tick(self._camera)

        if self.isComplete():
            pass
            # self._sound.fadeout(3000)

    def render(self):
        self._surface.fill((0, 0, 0))
        self._background.draw(self._total_surface, self._camera)
        for s in self._enemySpawns.values():
            s.draw(self._total_surface)
        for entity in self._entities.values():
            entity.draw(self._total_surface)

        self.map.draw(self._total_surface)
        if self.editor.enabled():
            self.editor.draw(self._total_surface)

        self._camera.draw(self._surface, self._total_surface)

        self._healthBar.draw(self._surface)
        self._countdown.draw(self._surface)
        if self.editor.enabled():
            self.editor.menu.draw()

    def tick(self):
        self._input()
        self.process()
        self.render()
Esempio n. 4
0
class Level(Completable, Inputable):
    def __init__(self, surface, level, **kwargs):
        super().__init__(**kwargs)
        self._surface = surface
        self.map = Map(level[0], level[1])

    def start(self):
        self.map.load()
        self._entity_map = {}
        self._position_map = {}
        self._entities = {}
        self._registered = {}
        self._enemySpawns = {}
        for x, y in self.map.getMap().keys():
            self._position_map[(x, y)] = []

        self._total_surface = Surface((self.map.w, self.map.h))
        tid = self.addEntity(register=True,
                             entity=MChar(self,
                                          self.map.getType(Tiles.Start)[0],
                                          inputStream=self.getInputStream()))
        self._camera = Viewport(tuple([s * const.res for s in const.screenSize]),
                                lambda: self.map.getAttr("scale"),
                                self.get(tid),
                                (150, 200, 150, 200),
                                self.map)
        self._background = Parallax(const.backgrounds)
        self.editor = Editor(self.map,
                             self._surface,
                             enabled=False,
                             inputStream=self.getInputStream())

        self._input = Input(inputStream=self.getInputStream())
        self._input.set(KEYDOWN, self.editor.toggleEnabled, K_e)
        self._input.set(KEYDOWN, self.start, K_r)

        # self._sound = Sound("assets\\music.ogg")
        # self._sound.play(-1)

        try:
            self._healthBar = HealthBar(10, 10, self.get(tid))
        except AssertionError:
            pass

        for (x, y), val in self.map.enemies.items():
            block = self.map.get(x, y)
            self._enemySpawns[block] = EnemySpawn(level=self,
                                                  anchor=Object(pos=(block.x, block.y)),
                                                  maxEmitted=val,
                                                  timeBetween=2)

        self._countdown = CountdownTimer(const.screenSize[0] * const.res - 50, 10,
                                         self.map.getAttr("timeLim"))

    def addEntity(self, register=False, entity=None):
        if not entity:
            raise Exception("Entity must not be None.")

        tid = entity.getId()

        self._entities[tid] = entity
        if register:
            self._registered[tid] = entity

        self._entity_map[tid] = set()
        return tid

    def removeEntity(self, entity):
        del self._entities[entity.id]

    def get(self, entityId):
        return self._entities.get(entityId)

    def process(self):
        for entity in self._entities.values():
            result = entity.tick()

            if not entity.isAlive():
                self._entities.pop(entity.getId())

            # This should generally only apply to playable characters.
            if entity in self._registered.values():
                if Tiles.End in result.keys():
                    self.setFinished()
                if not entity.isAlive():
                    self.setLost()

        for s in self._enemySpawns.values():
            s.tick()

        self._camera.tick()
        self._countdown.tick()
        if self._countdown.isFinished():
            self.setLost()

        if self.editor.enabled():
            self.editor.tick(self._camera)

        if self.isComplete():
            pass
            # self._sound.fadeout(3000)

    def render(self):
        self._surface.fill((0, 0, 0))
        self._background.draw(self._total_surface, self._camera)
        for s in self._enemySpawns.values():
            s.draw(self._total_surface)
        for entity in self._entities.values():
            entity.draw(self._total_surface)

        self.map.draw(self._total_surface)
        if self.editor.enabled():
            self.editor.draw(self._total_surface)

        self._camera.draw(self._surface, self._total_surface)

        self._healthBar.draw(self._surface)
        self._countdown.draw(self._surface)
        if self.editor.enabled():
            self.editor.menu.draw()

    def tick(self):
        self._input()
        self.process()
        self.render()
Esempio n. 5
0
    clock.tick(120)
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()
        elif event.type == KEYDOWN:
            if event.key == K_ESCAPE:
                pygame.quit()
                sys.exit()
            elif event.key == K_SPACE:
                cont = True


# render once quick before first loop
window_surf.fill(pygame.Color("#000000"))
rects = vp.draw(window_surf)
pygame.display.update(rects)


enterprise = Enterprise()
vp.hud.enterprise = enterprise
vp.dirty = 1
vp.render()

counter = 0

while True:

    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
Esempio n. 6
0
     else:
         mosquito.unsuck = False
     for killer in filter(lambda x: x.killer, viewport.collisions):
         pygame.mixer.music.stop()
         if isinstance(killer, Bat):
             if not 'jebacnietopyra' in sys.argv:
                 print("ZAJEBOŁ CIE NETOPYR")
                 game.scene = Game.SCENE_GAME_OVER
         elif isinstance(killer, RaidBall):
             if mosquito.hasGasMaskOn:
                 mosquito.hasGasMaskOn = False
             else:
                 print("ZAJEBOŁ CIE JOŁOP Z RAIDEM")
                 game.scene = Game.SCENE_GAME_OVER
     viewport.updateForTimeOnEnemies(time)
     viewport.draw()
     score.showScore()
     ###TODO poładnić
     game.screen.blit(blood_bg, (20, 500))
     pygame.draw.rect(screen, pygame.Color(255, 0, 0),
                      (27, 695, 36, -mosquito.blood_percent * 1.9))
     game.screen.blit(blood_fg, (20, 500))
     if mosquito.hasGasMaskOn:
         game.screen.blit(gasMaskIcon, (10, 10))
 else:
     if not wasfrozen:
         viewport.modal = Modals(game.screen)
         viewport.modal.time_remaining = 400
     else:
         viewport.modal.time_remaining -= time
     if not viewport.modal.finished: