class Game(): """The Game handles the actual game and custom scripts. """ def __init__(self, _meotech): print "Game - init >>>" # Meotech self.meotech = _meotech # Load Inputs self.inputs = InputHandler(self) # Add GameLoop Task taskMgr.add(self.gameLoop, "Game_loop") # Check the engine if we have a player. if self.meotech.engine.GameObjects["player"]: if self.meotech.engine.GameObjects["player"].useBasicMovement: self.hasPlayer = True else: self.hasPlayer = False def gameLoop(self, task): dt = globalClock.getDt() # Add player movement # Check this if its slow change it... if self.hasPlayer: self.meotech.engine.factory.basePhysics.useBasicPlayerMovement(dt) self.inputs.getMouse(dt) # Add Player camera handler return task.cont
def __init__(self, file='../data/sample.json'): # random var for now self.data = [] self.file = file parser = JsonParser(file) self.collection = parser.get_collection() self.handler = InputHandler()
def instantMessageReceived(self, switchboard,message,contact): receivedText = message.getContent() #set the switchboard, so that we can send messages self.switchboard = switchboard #defines how we should handle the commands received from the other end input_handler = InputHandler() output = input_handler.handleInput(receivedText) #send the msg to the buddy msnMessage = MsnInstantMessage() msnMessage.setContent(output) self.sendMessage(msnMessage)
def instantMessageReceived(self, switchboard, message, contact): receivedText = message.getContent() #set the switchboard, so that we can send messages self.switchboard = switchboard #defines how we should handle the commands received from the other end input_handler = InputHandler() output = input_handler.handleInput(receivedText) #send the msg to the buddy msnMessage = MsnInstantMessage() msnMessage.setContent(output) self.sendMessage(msnMessage)
def setUp(self): pygame.init() # @UndefinedVariable screen = pygame.display.set_mode( (PRAM.DISPLAY_WIDTH, PRAM.DISPLAY_HEIGHT)) buttonMap = ButtonMap() actor = SimpleBox() musicPlayer, soundPlayer = soundPlayerFactory() self.renderer = Renderer(screen) player = playerFactory(actor) self.game = Game(player, musicPlayer, soundPlayer, self.renderer) self.inputHandler = InputHandler(self.game, player, buttonMap) self.eventHandler = EventHandler(self.game) self.game.eventHandler = self.eventHandler self.game.inputHandler = self.inputHandler
def __init__(self, _meotech): print "Game - init >>>" # Meotech self.meotech = _meotech # Load Inputs self.inputs = InputHandler(self) # Add GameLoop Task taskMgr.add(self.gameLoop, "Game_loop") # Check the engine if we have a player. if self.meotech.engine.GameObjects["player"]: #if self.meotech.engine.GameObjects["player"].useBasicMovement: self.hasPlayer = True self.player = Player(self) else: self.hasPlayer = False # get the enemies and show them self.npcList = [] if self.meotech.engine.GameObjects["npc"]: self.amountOfNPCs = len(self.meotech.engine.GameObjects["npc"]) for npci in range(self.amountOfNPCs): self.npcList.append(Ghost(self, npci))
class Game(): """The Game handles the actual game and custom scripts. """ def __init__(self, _meotech): print "Game - init >>>" # Meotech self.meotech = _meotech # Load Inputs self.inputs = InputHandler(self) # Add GameLoop Task taskMgr.add(self.gameLoop, "Game_loop") # Check the engine if we have a player. if self.meotech.engine.GameObjects["player"]: #if self.meotech.engine.GameObjects["player"].useBasicMovement: self.hasPlayer = True self.player = Player(self) else: self.hasPlayer = False # get the enemies and show them self.npcList = [] if self.meotech.engine.GameObjects["npc"]: self.amountOfNPCs = len(self.meotech.engine.GameObjects["npc"]) for npci in range(self.amountOfNPCs): self.npcList.append(Ghost(self, npci)) def gameLoop(self, task): dt = globalClock.getDt() #print dt, "Game Loop" # Add player movement # Check this if its slow change it... if self.hasPlayer: #self.meotech.engine.factory.basePhysics.useBasicPlayerMovement(dt) self.inputs.getMouse(dt) # Add Player camera handler return task.cont
def __init__(self, _meotech): print "Game - init >>>" # Meotech self.meotech = _meotech # Load Inputs self.inputs = InputHandler(self) # Add GameLoop Task taskMgr.add(self.gameLoop, "Game_loop") # Check the engine if we have a player. if self.meotech.engine.GameObjects["player"]: if self.meotech.engine.GameObjects["player"].useBasicMovement: self.hasPlayer = True else: self.hasPlayer = False
class Test(unittest.TestCase): def setUp(self): pygame.init() # @UndefinedVariable screen = pygame.display.set_mode( (PRAM.DISPLAY_WIDTH, PRAM.DISPLAY_HEIGHT)) buttonMap = ButtonMap() actor = SimpleBox() musicPlayer, soundPlayer = soundPlayerFactory() self.renderer = Renderer(screen) player = playerFactory(actor) self.game = Game(player, musicPlayer, soundPlayer, self.renderer) self.inputHandler = InputHandler(self.game, player, buttonMap) self.eventHandler = EventHandler(self.game) self.game.eventHandler = self.eventHandler self.game.inputHandler = self.inputHandler def test_eventHandler(self): self.game.addEvent(EventLoadMenu(PRAM.MENU_TEST1)) self.game.addEvent(EventLoadLevel(PRAM.LEV_TEST1)) self.eventHandler.handleEvents() def test_inputHandler(self): ### sudo create key events ### keyPressDefault = SudoKeyEvent(PRAM.INPUT_ACTION) self.game.keydownEvents = [] self.game.keydownEvents.append(keyPressDefault) self.game.keysPressed = list(pygame.key.get_pressed()) self.game.keysPressed[PRAM.INPUT_UP] = 1 self.game.keysPressed[PRAM.INPUT_DOWN] = 1 self.game.keysPressed[PRAM.INPUT_LEFT] = 1 self.game.keysPressed[PRAM.INPUT_RIGHT] = 1 ### test input for level mode ### self.inputHandler.handleInputs() ### test input events for menu mode ### self.game.keydownEvents.append(keyPressDefault) self.game.addEvent(EventLoadMenu(PRAM.MENU_TEST1)) self.eventHandler.handleEvents() self.inputHandler.handleInputs()
class QueryEngine: def __init__(self, file='../data/sample.json'): # random var for now self.data = [] self.file = file parser = JsonParser(file) self.collection = parser.get_collection() self.handler = InputHandler() def search_corp(self, str_query): # probably best if a generator is returned self.last_query = str_query processed_query = self.handler.process_query(str_query) span = self.collection.match(processed_query) # how will we handle different file typers print("successful query call for ", str_query) print(span) return "(use the query on the parser)"
camera.setup() model_data = model.StaticModelData() model_data.setup() # Everybody do the setup shake! # I seriously thing something is wrong with me, putting in all these random comments and strings and stuff. # Oh well clock = pygame.time.Clock() pygame.mouse.set_pos(config.window_info.window_size[0] / 2, config.window_info.window_size[1] / 2) user = User(model.geom_data["spawn"], camera, model_data) input_handler = InputHandler(user) hud = hud.HUD(model_data) scripter = ScriptHolder(model_data, user) scripter.load("script.txt") while True: glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) user.update_camera() camera.apply() model_data.draw() model_data.setup_price_labels(user) hud.apply(user) for event in pygame.event.get(): if event.type == pygame.QUIT:
class Game: def __init__(self, surface: pygame.Surface) -> None: self.notes = { 0 : Note("G", 0, "./data/Sounds/G1.ogg"), 1 : Note("G#", 0, "./data/Sounds/G#1.ogg"), 2 : Note("A", 0.5, "./data/Sounds/A1.ogg"), 3 : Note("A#", 0.5, "./data/Sounds/A#1.ogg"), 4 : Note("B", 1, "./data/Sounds/B1.ogg"), 5 : Note("C", 1.5, "./data/Sounds/C1.ogg"), 6 : Note("C#", 1.5, "./data/Sounds/C#1.ogg"), 7 : Note("D", 2, "./data/Sounds/D2.ogg"), 8 : Note("D#", 2, "./data/Sounds/D#2.ogg"), 9 : Note("E", 2.5, "./data/Sounds/E2.ogg"), 10 : Note("F", 3, "./data/Sounds/F2.ogg"), 11 : Note("F#", 3, "./data/Sounds/F#2.ogg"), 12 : Note("G", 3.5, "./data/Sounds/G2.ogg"), 13 : Note("G#", 3.5, "./data/Sounds/G#2.ogg"), 14 : Note("A", 4, "./data/Sounds/A3.ogg"), 15 : Note("A#", 4, "./data/Sounds/A#3.ogg"), 16 : Note("B", 4.5, "./data/Sounds/B3.ogg"), 17 : Note("C", 5, "./data/Sounds/C3.ogg"), 18 : Note("C#", 5, "./data/Sounds/C#3.ogg"), 19 : Note("D", 5.5, "./data/Sounds/D3.ogg"), 20 : Note("D#", 5.5, "./data/Sounds/D#3.ogg"), 21 : Note("E", 6, "./data/Sounds/E4.ogg"), 22 : Note("F", 6.5, "./data/Sounds/F4.ogg"), 23 : Note("F#", 6.5, "./data/Sounds/F#4.ogg"), 24 : Note("G", 7, "./data/Sounds/G4.ogg"), 25 : Note("G#", 7, "./data/Sounds/G#4.ogg"), 26 : Note("A", 7.5, "./data/Sounds/A4.ogg"), 27 : Note("A#", 7.5, "./data/Sounds/A#4.ogg"), 28 : Note("B", 8, "./data/Sounds/B4.ogg"), #G string 29 : Note("D", 2, "./data/Sounds/D1.ogg"), #D String 30 : Note("A", 4, "./data/Sounds/A2.ogg"), #A String 31 : Note("E", 6, "./data/Sounds/E3.ogg"), } self.surface = surface self.font = self.font = pgfont.Font(pgfont.get_default_font(), 20) self.is_running = True self.fps = 60 self.input_handler = InputHandler() self.staff = Staff(self.surface) self.finger_board = FingerBoard(self.surface, self.input_handler) self.deck = NoteDeck() self.deck.shuffle() self.score = 0 self.max_score = 0 self.current_note = self.deck.next_note() self.staff.set_note(self.notes[self.current_note]) self.playing_note = self.notes[0] self.success_message = "" def run(self) -> None: fps_limiter = pgtime.Clock() while self.is_running: for event in pgevent.get(): if event.type == pygame.QUIT: self.is_running = False self.input_handler.update() self.__update() pgdisplay.flip() fps_limiter.tick(self.fps) def __update(self) -> None: self.surface.fill(WHITE) self.staff.draw() self.finger_board.draw() self.__draw_score() self.__draw_result_message() note = self.finger_board.get_note_pressed_finger() if note != -1: self.max_score += 1 if self.notes[note].position == self.notes[self.current_note].position and self.notes[note].name == self.notes[self.current_note].name: self.score += 1 self.success_message = "Correct, the note was " + self.notes[self.current_note].name + ". You pressed " + self.notes[note].name else: self.success_message = "Wrong, the note was " + self.notes[self.current_note].name + ". You pressed " + self.notes[note].name if self.deck.is_empty(): self.deck.shuffle() self.current_note = self.deck.next_note() self.staff.set_note(self.notes[self.current_note]) self.playing_note.stop() self.playing_note = self.notes[note] self.playing_note.play() def __draw_score(self): score_surface = self.font.render("Score:" + str(self.score) + "/" + str(self.max_score), True, BLACK) self.surface.blit(score_surface, (10, 10), score_surface.get_rect()) def __draw_result_message(self): message_surface = self.font.render(self.success_message, True, BLACK) self.surface.blit(message_surface, (10, 40), message_surface.get_rect())
def __init__(self, surface: pygame.Surface) -> None: self.notes = { 0 : Note("G", 0, "./data/Sounds/G1.ogg"), 1 : Note("G#", 0, "./data/Sounds/G#1.ogg"), 2 : Note("A", 0.5, "./data/Sounds/A1.ogg"), 3 : Note("A#", 0.5, "./data/Sounds/A#1.ogg"), 4 : Note("B", 1, "./data/Sounds/B1.ogg"), 5 : Note("C", 1.5, "./data/Sounds/C1.ogg"), 6 : Note("C#", 1.5, "./data/Sounds/C#1.ogg"), 7 : Note("D", 2, "./data/Sounds/D2.ogg"), 8 : Note("D#", 2, "./data/Sounds/D#2.ogg"), 9 : Note("E", 2.5, "./data/Sounds/E2.ogg"), 10 : Note("F", 3, "./data/Sounds/F2.ogg"), 11 : Note("F#", 3, "./data/Sounds/F#2.ogg"), 12 : Note("G", 3.5, "./data/Sounds/G2.ogg"), 13 : Note("G#", 3.5, "./data/Sounds/G#2.ogg"), 14 : Note("A", 4, "./data/Sounds/A3.ogg"), 15 : Note("A#", 4, "./data/Sounds/A#3.ogg"), 16 : Note("B", 4.5, "./data/Sounds/B3.ogg"), 17 : Note("C", 5, "./data/Sounds/C3.ogg"), 18 : Note("C#", 5, "./data/Sounds/C#3.ogg"), 19 : Note("D", 5.5, "./data/Sounds/D3.ogg"), 20 : Note("D#", 5.5, "./data/Sounds/D#3.ogg"), 21 : Note("E", 6, "./data/Sounds/E4.ogg"), 22 : Note("F", 6.5, "./data/Sounds/F4.ogg"), 23 : Note("F#", 6.5, "./data/Sounds/F#4.ogg"), 24 : Note("G", 7, "./data/Sounds/G4.ogg"), 25 : Note("G#", 7, "./data/Sounds/G#4.ogg"), 26 : Note("A", 7.5, "./data/Sounds/A4.ogg"), 27 : Note("A#", 7.5, "./data/Sounds/A#4.ogg"), 28 : Note("B", 8, "./data/Sounds/B4.ogg"), #G string 29 : Note("D", 2, "./data/Sounds/D1.ogg"), #D String 30 : Note("A", 4, "./data/Sounds/A2.ogg"), #A String 31 : Note("E", 6, "./data/Sounds/E3.ogg"), } self.surface = surface self.font = self.font = pgfont.Font(pgfont.get_default_font(), 20) self.is_running = True self.fps = 60 self.input_handler = InputHandler() self.staff = Staff(self.surface) self.finger_board = FingerBoard(self.surface, self.input_handler) self.deck = NoteDeck() self.deck.shuffle() self.score = 0 self.max_score = 0 self.current_note = self.deck.next_note() self.staff.set_note(self.notes[self.current_note]) self.playing_note = self.notes[0] self.success_message = ""
from input import InputHandler from player import Player, player_data from misc import * from levels import Level, ObjectHandler from level_data import levels FPS = 60 clock = time.Clock() game_input = InputHandler() GAME_STATES = ['start', 'levels', 'game_over'] class Game: def __init__(self, _screen): self.screen = _screen self.running = True self.object_handler = ObjectHandler(self.screen) self.score = 0 self.pt = time.get_ticks() self.game_state = GAME_STATES[0] self.game_levels = [] self.current_level = 0 self.player = None def main(self, _screen): # Set Up Delta Time dt = time.get_ticks() - self.pt dt *= FPS self.pt = time.get_ticks() # Run Game
from game import Game from input import InputHandler, ButtonMap from camera import GameCamera ### SETUP ### pygame.init() # @UndefinedVariable screen = pygame.display.set_mode((PRAM.DISPLAY_WIDTH, PRAM.DISPLAY_HEIGHT)) CLOCK = pygame.time.Clock() DONE = False ### GAME ENGINE ### musicPlayer, soundPlayer = soundPlayerFactory() renderer = Renderer(screen) gameCamera = GameCamera() player = playerFactory() game = Game(player, musicPlayer, soundPlayer, renderer, gameCamera) inputHandler = InputHandler(game, player, ButtonMap()) eventHandler = eventHandlerFactory(game) game.inputHandler = inputHandler game.gameStartup() while not DONE: for event in pygame.event.get(): if event.type == pygame.QUIT: # @UndefinedVariable DONE = True #TODO make this an input that creates a quit event? if event.type == pygame.KEYDOWN: # @UndefinedVariable game.keydownEvents.append(event) #TODO can tell pygame to only check fro specific events game.keysPressed = pygame.key.get_pressed() inputHandler.handleInputs( ) #iterates through the keydown and keypressed events