Exemple #1
0
 def __init__(self):
     self.screen = pygame.display.set_mode([Game.WIDTH, Game.HEIGHT])
     pygame.display.set_caption('the orange box')
     self.clock = pygame.time.Clock()
     self.state_manager = StateManager(
         [MenuState(), GameState(), DeathState()], 1)
     self.start()
Exemple #2
0
class Game:

    WIDTH = 640
    HEIGHT = 480
    FPS = 60

    def __init__(self):
        self.screen = pygame.display.set_mode([Game.WIDTH, Game.HEIGHT])
        pygame.display.set_caption('the orange box')
        self.clock = pygame.time.Clock()
        self.state_manager = StateManager(
            [MenuState(), GameState(), DeathState()], 1)
        self.start()

    def stop(self):
        self.running = False

    def start(self):
        self.running = True
        self.loop()

    def loop(self):
        while self.running:

            for event in pygame.event.get():

                if event.type == pygame.QUIT:
                    self.running = False

                if event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_ESCAPE:
                        self.running = False
                    self.state_manager.keydown(event.key)

                if event.type == pygame.KEYUP:
                    self.state_manager.keyup(event.key)

                if event.type == pygame.MOUSEBUTTONUP:
                    self.state_manager.mousebuttonup()

            self.tick()
            self.draw()
            self.clock.tick(Game.FPS)

        pygame.quit()

    def tick(self):
        self.state_manager.tick()

    def draw(self):
        self.screen.fill((0, 0, 0))
        self.state_manager.draw(self.screen)
        pygame.display.flip()
Exemple #3
0
    def __init__(self):
        pygame.init()
        self.config = Config()

        if self.config["fullscreen"]==1:
            self.screen = pygame.display.set_mode((1024, 768), FULLSCREEN, 32)
        else:
            self.screen = pygame.display.set_mode((1024, 768), 0, 32)

        pygame.display.set_caption("Viking's Story")
        pygame.mouse.set_visible(False)
        self.clock = pygame.time.Clock()
        pointer = Sheet("./data/image/menu/cursor.png")
        self.cursor = Cursor([pointer.get_at((0, 1, 16, 16), True), \
                      pointer.get_at((16, 1, 16, 16), True), \
                      pointer.get_at((33, 0, 16, 16), True)], self.screen)
        self.player = Player("./data/profiles/default.mkm")
        self.sound_manager = SoundManager()
        self.sound_manager.change_volume("background", self.config["bsound"])
        self.sound_manager.change_volume("sound", self.config["sfx"])
        self.state_manager = StateManager(self.player, self.config, \
                                          self.screen, [1024, 768], \
                                          self.cursor, self.sound_manager)
        Game("game", self.state_manager)
        Menu("menu", self.state_manager)
        World("map", self.state_manager)
        Shop("shop", self.state_manager)
        self.state_manager.set_state("menu")
        self.version = 0.9
Exemple #4
0
class Viking:

    def __init__(self):
        pygame.init()
        self.config = Config()

        if self.config["fullscreen"]==1:
            self.screen = pygame.display.set_mode((1024, 768), FULLSCREEN, 32)
        else:
            self.screen = pygame.display.set_mode((1024, 768), 0, 32)

        pygame.display.set_caption("Viking's Story")
        pygame.mouse.set_visible(False)
        self.clock = pygame.time.Clock()
        pointer = Sheet("./data/image/menu/cursor.png")
        self.cursor = Cursor([pointer.get_at((0, 1, 16, 16), True), \
                      pointer.get_at((16, 1, 16, 16), True), \
                      pointer.get_at((33, 0, 16, 16), True)], self.screen)
        self.player = Player("./data/profiles/default.mkm")
        self.sound_manager = SoundManager()
        self.sound_manager.change_volume("background", self.config["bsound"])
        self.sound_manager.change_volume("sound", self.config["sfx"])
        self.state_manager = StateManager(self.player, self.config, \
                                          self.screen, [1024, 768], \
                                          self.cursor, self.sound_manager)
        Game("game", self.state_manager)
        Menu("menu", self.state_manager)
        World("map", self.state_manager)
        Shop("shop", self.state_manager)
        self.state_manager.set_state("menu")
        self.version = 0.9

    def loop(self):
        font = pygame.font.Font("./data/font/viking.ttf", 24)
        paused = -1

        while True:
            for event in pygame.event.get():
                self.state_manager.event(event)
                if event.type == QUIT:
                    exit()
                elif event.type == KEYDOWN:
                    if event.key == K_q:
                        exit()
                    elif event.key in [K_p, K_PAUSE] and \
                         self.state_manager.current_state == "game":
                         self.player.paused *= -1

            self.screen.fill((0, 0, 0))
            self.state_manager.update()
            self.cursor.update()
            
            if self.config["fps"]==1:
                fps = "FPS: "+'%.2f' % self.clock.get_fps()
                fp = font.render(fps, True, (255, 255, 255))
                self.screen.blit(fp,(8,8))

            pygame.display.update()
            self.clock.tick(30)
Exemple #5
0
 def __init__(self):
     pygame.init()
     self.screen = pygame.display.set_mode((1024, 768), 0, 32)
     pygame.display.set_caption("Viking's Story")
     pygame.mouse.set_visible(False)
     self.clock = pygame.time.Clock()
     pointer = Sheet("./data/image/menu/cursor.png")
     self.cursor = Cursor([pointer.get_at((0, 1, 16, 16), True), \
                   pointer.get_at((16, 1, 16, 16), True)], self.screen)
     self.player = Player("./data/profiles/default.mkm")
     self.state_manager = StateManager(self.player, self.screen, \
                         [1024, 768], self.cursor)
     Game("game", self.state_manager)
     Menu("menu", self.state_manager)
     self.state_manager.set_state("menu")
     self.version = 0.9
Exemple #6
0
def main():
    if TelegramAPIManager().check_token():
        logging.info('Start working')
        states = StateManager('states')
        upwork_feed = RSSManager()
        upwork_feed.parse_feed()
        upwork_jobs = JobManager(upwork_feed, states)
        while True:
            jobs = upwork_jobs.get_new_jobs()
            for job in jobs:
                TelegramJobPoster(job).post_job()
                sleep(1)
            sleep(30)
    else:
        logging.info('Invalid token')
        pass
Exemple #7
0
class Viking:

    def __init__(self):
        pygame.init()
        self.screen = pygame.display.set_mode((1024, 768), 0, 32)
        pygame.display.set_caption("Viking's Story")
        pygame.mouse.set_visible(False)
        self.clock = pygame.time.Clock()
        pointer = Sheet("./data/image/menu/cursor.png")
        self.cursor = Cursor([pointer.get_at((0, 1, 16, 16), True), \
                      pointer.get_at((16, 1, 16, 16), True)], self.screen)
        self.player = Player("./data/profiles/default.mkm")
        self.state_manager = StateManager(self.player, self.screen, \
                            [1024, 768], self.cursor)
        Game("game", self.state_manager)
        Menu("menu", self.state_manager)
        self.state_manager.set_state("menu")
        self.version = 0.9

    def loop(self):
        font = pygame.font.Font("./data/font/viking.ttf", 12)
        show_fps = False
        while True:
            self.screen.fill((0, 0, 0))
            for event in pygame.event.get():
                self.state_manager.event(event)
                if event.type == QUIT:
                    exit()
                elif event.type == KEYDOWN:
                    if event.key == K_q:
                        exit()
                    elif event.key == K_f:
                        if show_fps:
                            show_fps = False
                        else:
                            show_fps = True
            
            self.state_manager.update()
            self.cursor.update()
            
            if show_fps:
                fps = font.render(str(self.clock.get_fps()), True, (255, 255, 255))
                self.screen.blit(fps,(1,1))

            pygame.display.update()
            self.clock.tick(30)
     1.3),  # 19 <= Medium (Brug onder)
    (-1, False, 'StrandGolfbaan_b_01.mp4', (848, 480),
     1.3),  # 20 <= Kort en bruikbaar
]
frame_rate, flip_frame, wh, video_list_name, video_url, video_file_name = \
    FileSelection(video_source, video_list).file_with_index(
        2
    )

print('Project opened')
window_title = '{} ({})'.format(video_file_name, video_list_name)
video_stream = VideoStream(video_url, grab=False, resize=wh)
if video_stream.load():
    rectangle_stream = RectangleStream(video_stream.wh(), (8 * 1, 8 * 1),
                                       rows=10,
                                       margin=1)
    window_stream = WindowStream(window_title, frame_rate)
    state = StateManager(video_stream, rectangle_stream, window_stream)
while True:
    # noinspection PyUnboundLocalVariable
    if not video_stream.next():
        video_stream.disable_auto_grab()
    # noinspection PyUnboundLocalVariable
    state.show()
    # noinspection PyUnboundLocalVariable
    key = window_stream.show(video_stream.view_frame())
    # noinspection PyUnboundLocalVariable
    if state.accept(key) is False:
        break
print('Project closed')
        self.led_color = social_state.color


class EasterEgg(State):

    label = "Easter Egg"

    def display(self):
        display_bg_and_text(image="images/easter_egg/easter_egg.bmp")
        time.sleep(4.0)  # Wait 4 seconds, then return to main state_manager.
        state_manager.previous_state()


main_menu = MainMenu(NameBadge, SocialBattery, QrCode, Credits, PressStart)

state_manager = StateManager()
state_manager.add(
    main_menu,
    PressStart(),
    Credits(),
    NameBadge(),
    QrCode(),
    SocialBattery(),
    EasterEgg(),
)
state_manager.state = PressStart

while True:
    state_manager.check_for_event()
    time.sleep(0.15)  # Prevent duplicate button presses.
Exemple #10
0
def Main():
    sm = StateManager()
    sm.run()