Example #1
0
    def receive(self, message, emitter=None, data=None):
        if message == TitleScene.Events.DONE:
            current_scene = MenuScene()
            current_scene.render()
            current_scene.loop()
        elif message == MenuScene.Events.CREATE_CHARACTER:
            current_scene = CreateFighterScene()
            current_scene.render()
            current_scene.loop()
        elif message == CreateFighterScene.Events.CREATE:
            Director.characters.append(data)

        elif message == CreateFighterScene.Events.DONE:
            current_scene = MenuScene()
            current_scene.render()
            current_scene.loop()

        elif message == MenuScene.Events.LIST_CHARACTER:
            self.characters = Fighter.all()
            current_scene = ShowCharactersScene(self.characters)
            current_scene.render()
            current_scene.show_fighters()

        elif message == MenuScene.Events.SELECT_CHARACTER:
            # TODO:
            print('PENDING: make select character scene')
        elif message == MenuScene.Events.REMOVE_CHARACTER:
            # TODO:
            print('PENDING: make remove character scene')
Example #2
0
 def process_input(self, events, pressed_keys):
     for event in events:
         if event.type == pygame.MOUSEBUTTONDOWN:
             mouse_pos = event.pos
             if self.back_button.collidepoint(mouse_pos):
                 from menu_scene import MenuScene
                 self.switch_to_scene(MenuScene())
Example #3
0
def init():
    """ Scenes need pygame to be initialized (in main) before their creation. """
    global scene_manager
    scenes = { 
        SCN_MENU: MenuScene(), 
        SCN_GAME: GameScene(),
        SCN_OVER: GameOverScene() 
        }
    scene_manager = _SceneManager(scenes, SCN_MENU)
Example #4
0
    def __init__(self):
        self.director = Director((512, 480), 'Super Mario')

        self.menu_scene = MenuScene(self.director)
        self.game_scene = GameScene(self.director)
        self.scores_scene = ScoresScene(self.director)

        self.director.scene_list = {
            'menu': self.menu_scene,
            'game': self.game_scene,
            'scores': self.scores_scene
        }

        self.director.set_scene('menu')
Example #5
0
    def __init__(self):
        self.director = Director((1200, 800), "Space Invaders")

        self.menu_scene = MenuScene(self.director)
        self.game_scene = GameScene(self.director)
        self.scores_scene = ScoresScene(self.director)

        self.director.scene_list = {
            "menu": self.menu_scene,
            "game": self.game_scene,
            "scores": self.scores_scene
        }

        self.director.set_scene("menu")
Example #6
0
    def process_input(self, events, pressed_keys):
        for event in events:
            if not self.game_paused and event.type == pygame.MOUSEBUTTONDOWN:
                mouse_pos = event.pos
                if self.menu_button.collidepoint(mouse_pos):
                    self.save()
                    self.game_paused = False
                    from menu_scene import MenuScene
                    self.switch_to_scene(MenuScene())
                if self.pause_button.collidepoint(mouse_pos):
                    self.game_paused = True

            if self.game_paused and event.type == pygame.MOUSEBUTTONDOWN:
                mouse_pos = event.pos
                if self.menu_pause_button.collidepoint(mouse_pos):
                    self.save()
                    self.game_paused = False
                    from menu_scene import MenuScene
                    self.switch_to_scene(MenuScene())
                if self.continue_button.collidepoint(mouse_pos):
                    self.game_paused = False

            if not self.game_paused and event.type == pygame.KEYDOWN:
                if event.key == pygame.K_w:
                    self.space_ship.speed += 0
                elif event.key == pygame.K_s:
                    self.space_ship.speed -= 0
                elif event.key == pygame.K_a:
                    self.space_ship.angle_speed = -4
                elif event.key == pygame.K_d:
                    self.space_ship.angle_speed = 4
            elif not self.game_paused and event.type == pygame.KEYUP:
                if event.key == pygame.K_a:
                    self.space_ship.angle_speed = 0
                elif event.key == pygame.K_d:
                    self.space_ship.angle_speed = 0
Example #7
0
    def process_input(self, events, pressed_keys):
        for event in events:
            if event.type == pygame.MOUSEBUTTONDOWN:
                mouse_pos = event.pos

                if self.play_button.collidepoint(mouse_pos):
                    if self.name_input_form.get_text() != '':
                        self.save()
                        self.switch_to_scene(GameScene())
                        self.blank_from = False
                    else:
                        self.hint_text = self.FONT.render(
                            'Enter name!', False, pygame.Color(RED))
                if self.back_button.collidepoint(mouse_pos):
                    from menu_scene import MenuScene
                    self.switch_to_scene(MenuScene())
            self.name_input_form.handle_event(event)
Example #8
0
def main():

    # configure the logger before anything else happens
    logging.config.fileConfig('logging.conf')

    # The game logger is configured when the config module is imported.
    log = logging.getLogger('game')
    log.info('Main started')

    # load levels
    levels = load_level_set(LEVELS_FILENAME, LEVELS_MAXSIZE)  # list

    pg.init()
    pg.display.set_caption('Sokobalt')
    pview.set_mode(BASE_RES)
    clock = pg.time.Clock()
    scenes = {SCN_MENU: MenuScene(levels), SCN_GAME: GameScene(levels)}
    cur_scene = scenes[SCN_MENU]

    while True:
        ms = clock.tick(FPS)  # throttle

        # poll controls
        outcome = controller.poll()  # get player input
        if outcome == OUT_QUIT:
            break
        elif outcome == OUT_FSCR:
            pview.toggle_fullscreen()
            cur_scene.redraw()

        # tick scene
        next_scene_id, kwargs = cur_scene.tick(ms)
        if next_scene_id == SCN_QUIT:  # quit via dummy scene constant
            break
        elif next_scene_id is not None:  # change scene
            cur_scene.pause()
            cur_scene = scenes[next_scene_id]
            cur_scene.resume(**kwargs)
Example #9
0
from ezpygame import Application

from menu_scene import MenuScene

mod_pack = {
    "mods": ["minecraft"],
    "generator": "minecraft:SimpleGenerator",
    "controller": ["minecraft:ExploreGravityControl"],
    "player": ("minecraft:Player", (-5, 110)),
    "gravity": (0, -20)
}

app = Application("", (1, 1), 0)
app.run(MenuScene(mod_pack))
Example #10
0
import pygame
from config import *
from menu_scene import MenuScene

pygame.font.init()
pygame.init()
screen = pygame.display.set_mode(DISPLAY)
pygame.display.set_caption(GAME_TITLE)
clock = pygame.time.Clock()
done = False
active_scene = MenuScene()
while not done:
    clock.tick(FPS)
    pressed_keys = pygame.key.get_pressed()
    filtered_events = []
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            done = True
        else:
            filtered_events.append(event)
    active_scene.process_input(filtered_events, pressed_keys)
    active_scene.update()
    active_scene.render(screen)
    active_scene = active_scene.next

    pygame.display.update()
Example #11
0
import pygame

from director import Director
from game_scene import GameScene
from menu_scene import MenuScene

pygame.init()

game_director = Director((800, 450), "Simple Ping Pong")

game_scene = GameScene(game_director, True)
menu_scene = MenuScene(game_director, game_scene)

game_scene.set_menu_scene(menu_scene)

game_director.change_scene(menu_scene)
game_director.loop()