def begin_round(self): MenuIdler.begin_round(self) # wait for any keystroke to advance onto the menu for e in soya.process_event(): if e[0]==sdlconst.KEYDOWN and e[3]!=0: stateMachine.state='menu'
def begin_round(self): soya.Body.begin_round(self) if self.stopping: soya.MAIN_LOOP.stop() for event in soya.process_event(): if event[0] == soya.sdlconst.QUIT: soya.MAIN_LOOP.stop() elif event[0] == soya.sdlconst.KEYDOWN: direction = { KEY_A: LEFT, KEY_D: RIGHT, KEY_W: UP, KEY_S: DOWN, KEY_SPACE: NEUTRAL }.get(event[1], NEUTRAL) if not self.rotating: self.turn_to(direction) # if not self.rotating: # self.rotating = True # self.angle = 0.0 # #self.move = True # check where we are and adjust the speed vector and position if # neccessairy if self.x < self.left or self.x > self.right: self.speed.x = -self.speed.x if self.x < self.left: self.x = self.left elif self.x > self.right: self.x = self.right if self.y < self.bottom or self.y > self.top: self.speed.y = -self.speed.y if self.y < self.bottom: self.y = self.bottom elif self.y > self.top: self.y = self.top
def begin_round(self): global PAUSE, STOP, FPS soya.Camera.begin_round(self) for event in soya.process_event(): if event[0] == soya.sdlconst.KEYDOWN: if event[1] == soya.sdlconst.K_w: self.speed.z = -0.5 elif event[1] == soya.sdlconst.K_s: self.speed.z = 0.5 elif event[1] == soya.sdlconst.K_e: self.rotation_x_speed = 1.0 elif event[1] == soya.sdlconst.K_q: self.rotation_x_speed = -1.0 elif event[1] == soya.sdlconst.K_a: self.rotation_y_speed = 1.0 elif event[1] == soya.sdlconst.K_d: self.rotation_y_speed = -1.0 elif event[1] == soya.sdlconst.K_q: STOP = True elif event[1] == soya.sdlconst.K_ESCAPE: STOP = True elif event[1] == soya.sdlconst.K_SPACE: PAUSE = not PAUSE elif event[1] == soya.sdlconst.K_PLUS: FPS += 1 elif event[1] == soya.sdlconst.K_MINUS: FPS -= 1 else: print event[1] if event[0] == soya.sdlconst.KEYUP: if event[1] == soya.sdlconst.K_w: self.speed.z = 0.0 elif event[1] == soya.sdlconst.K_s: self.speed.z = 0.0 elif event[1] == soya.sdlconst.K_e: self.rotation_x_speed = 0.0 elif event[1] == soya.sdlconst.K_q: self.rotation_x_speed = 0.0 elif event[1] == soya.sdlconst.K_a: self.rotation_y_speed = 0.0 elif event[1] == soya.sdlconst.K_d: self.rotation_y_speed = 0.0
def next(self): jump = 0 fire = 0 for event in soya.process_event(): if event[0] == sdlconst.KEYDOWN: if (event[1] == sdlconst.K_q) or (event[1] == sdlconst.K_ESCAPE): stateMachine.change_state('menu') elif event[1] == sdlconst.K_LSHIFT: jump = 1 elif event[1] == sdlconst.K_SPACE: fire = 1 elif event[1] == sdlconst.K_F1: soya.screenshot().save(os.path.join(os.path.dirname(sys.argv[0]), "results", os.path.basename(sys.argv[0])[:-3] + ".jpg")) elif event[1] == sdlconst.K_LEFT: self.left_key_down = 1 elif event[1] == sdlconst.K_RIGHT: self.right_key_down = 1 elif event[1] == sdlconst.K_UP: self.up_key_down = 1 elif event[1] == sdlconst.K_DOWN: self.down_key_down = 1 elif event[0] == sdlconst.KEYUP: if event[1] == sdlconst.K_LEFT: self.left_key_down = 0 elif event[1] == sdlconst.K_RIGHT: self.right_key_down = 0 elif event[1] == sdlconst.K_UP: self.up_key_down = 0 elif event[1] == sdlconst.K_DOWN: self.down_key_down = 0 if jump: return Action(ACTION_JUMP) if fire: return Action(ACTION_FIRE) return self.action_table.get((self.left_key_down, self.right_key_down, self.up_key_down, self.down_key_down), self.default_action)
def begin_round(self): soya.Body.begin_round(self) # go through the events: for event in soya.process_event(): # key pressed: if event[0] == soya.sdlconst.KEYDOWN: # [ARROW UP] - no action: for observed_event in self.observed_events: if event[1] == observed_event['type']: if observed_event['args'] is not None: observed_event['action'](observed_event['args']) else: observed_event['action']() break else: if event[1] == soya.sdlconst.K_RSHIFT \ or event[1] == soya.sdlconst.K_LSHIFT: self.shift = True elif event[1] == soya.sdlconst.K_RCTRL \ or event[1] == soya.sdlconst.K_LCTRL: self.ctrl = True elif event[1] == soya.sdlconst.K_RALT \ or event[1] == soya.sdlconst.K_LALT: self.alt = True elif event[0] == soya.sdlconst.KEYUP: if event[1] == soya.sdlconst.K_RSHIFT \ or event[1] == soya.sdlconst.K_LSHIFT: self.shift = False elif event[1] == soya.sdlconst.K_RCTRL \ or event[1] == soya.sdlconst.K_LCTRL: self.ctrl = False elif event[1] == soya.sdlconst.K_RALT \ or event[1] == soya.sdlconst.K_LALT: self.alt = False
def next(self): jump = 0 fire = 0 #print "running controllers next method" for event in soya.process_event(): if event[0] == sdlconst.KEYDOWN: if (event[1] == sdlconst.K_q) or (event[1] == sdlconst.K_ESCAPE): clientplayer.state = 'menu' elif event[1] == sdlconst.K_LSHIFT: jump = 1 elif event[1] == sdlconst.K_SPACE: fire = 1 elif event[1] == sdlconst.K_F1: soya.screenshot().save(os.path.join(os.path.dirname(sys.argv[0]), "results", os.path.basename(sys.argv[0])[:-3] + ".jpg")) elif event[1] == sdlconst.K_LEFT: self.left_key_down = 1 elif event[1] == sdlconst.K_RIGHT: self.right_key_down = 1 elif event[1] == sdlconst.K_UP: self.up_key_down = 1 elif event[1] == sdlconst.K_DOWN: self.down_key_down = 1 elif event[0] == sdlconst.KEYUP: if event[1] == sdlconst.K_LEFT: self.left_key_down = 0 elif event[1] == sdlconst.K_RIGHT: self.right_key_down = 0 elif event[1] == sdlconst.K_UP: self.up_key_down = 0 elif event[1] == sdlconst.K_DOWN: self.down_key_down = 0 #if jump: return Action(ACTION_JUMP) #if fire: return Action(ACTION_FIRE) return (self.left_key_down, self.right_key_down, self.up_key_down, self.down_key_down, jump, fire)
def begin_round(self): soya.Body.begin_round(self) if self.stopping: soya.MAIN_LOOP.stop() for event in soya.process_event(): if event[0] == soya.sdlconst.QUIT: soya.MAIN_LOOP.stop() elif event[0] == soya.sdlconst.KEYDOWN: direction = {KEY_A : LEFT, KEY_D : RIGHT, KEY_W : UP, KEY_S : DOWN, KEY_SPACE : NEUTRAL}.get(event[1], NEUTRAL) if not self.rotating: self.turn_to(direction) # if not self.rotating: # self.rotating = True # self.angle = 0.0 # #self.move = True # check where we are and adjust the speed vector and position if # neccessairy if self.x < self.left or self.x > self.right: self.speed.x = -self.speed.x if self.x < self.left: self.x = self.left elif self.x > self.right: self.x = self.right if self.y < self.bottom or self.y > self.top: self.speed.y = -self.speed.y if self.y < self.bottom: self.y = self.bottom elif self.y > self.top: self.y = self.top
def begin_round(self): global PAUSE, STOP, FPS soya.Camera.begin_round(self) for event in soya.process_event(): if event[0] == soya.sdlconst.KEYDOWN: if event[1] == soya.sdlconst.K_w : self.speed.z = -0.5 elif event[1] == soya.sdlconst.K_s : self.speed.z = 0.5 elif event[1] == soya.sdlconst.K_e : self.rotation_x_speed = 1.0 elif event[1] == soya.sdlconst.K_q : self.rotation_x_speed = -1.0 elif event[1] == soya.sdlconst.K_a : self.rotation_y_speed = 1.0 elif event[1] == soya.sdlconst.K_d : self.rotation_y_speed = -1.0 elif event[1] == soya.sdlconst.K_q : STOP = True elif event[1] == soya.sdlconst.K_ESCAPE: STOP = True elif event[1] == soya.sdlconst.K_SPACE : PAUSE = not PAUSE elif event[1] == soya.sdlconst.K_PLUS : FPS += 1 elif event[1] == soya.sdlconst.K_MINUS : FPS -= 1 else: print event[1] if event[0] == soya.sdlconst.KEYUP: if event[1] == soya.sdlconst.K_w : self.speed.z = 0.0 elif event[1] == soya.sdlconst.K_s : self.speed.z = 0.0 elif event[1] == soya.sdlconst.K_e : self.rotation_x_speed = 0.0 elif event[1] == soya.sdlconst.K_q : self.rotation_x_speed = 0.0 elif event[1] == soya.sdlconst.K_a : self.rotation_y_speed = 0.0 elif event[1] == soya.sdlconst.K_d : self.rotation_y_speed = 0.0
def rotate(self): if self.active: self.cube.rotate_y(5.0) self.render() events = soya.process_event() self.cancel = self.dialog.after(50, self.rotate)
def begin_round(self): soya.Body.begin_round(self) for event in soya.process_event(): event_type = event[0] if event_type == soya.sdlconst.KEYDOWN: key, modifier = event[1:] if key == soya.sdlconst.K_UP: self.tilt_forward = True print "tilt forward", self.tilt_x elif key == soya.sdlconst.K_DOWN: self.tilt_backward = True print "tilt back", self.tilt_x elif key == soya.sdlconst.K_LEFT: self.tilt_left = True print "tilt left", self.tilt_z elif key == soya.sdlconst.K_RIGHT: self.tilt_right = True print "tilt right", self.tilt_z elif key == soya.sdlconst.K_q: soya.MAIN_LOOP.stop() elif key == soya.sdlconst.K_ESCAPE: soya.MAIN_LOOP.stop() elif event_type == soya.sdlconst.KEYUP: key, modifier = event[1:] if key == soya.sdlconst.K_UP: self.tilt_forward = False print "end tilt forward" elif key == soya.sdlconst.K_DOWN: self.tilt_backward = False print "end tilt back" elif key == soya.sdlconst.K_LEFT: self.tilt_left = False print "end tilt left" elif key == soya.sdlconst.K_RIGHT: self.tilt_right = False print "end tilt right" elif event_type == soya.sdlconst.QUIT: soya.MAIN_LOOP.stop() elif event_type == soya.sdlconst.MOUSEMOTION: # Need to figure out how far from 0 we went print "mouse movement", event else: print "unhandled event:", event
def begin_round(self): WidgetedIdler.begin_round(self) for e in soya.process_event(): self.input.process_event(e) reactor.iterate() if realm.server.state != 'game': stateMachine = realm.server.state
def begin_round(self): MenuIdler.begin_round(self) # pass all events to the choicelist for e in soya.process_event(): self.choicelist.process_event(e) if clientplayer.state != 'menu': stateMachine.change_state(clientplayer.state)
def begin_round(self): MenuIdler.begin_round(self) # wait for any keystroke to advance onto the menu for e in soya.process_event(): if e[0]==sdlconst.KEYDOWN and e[3]!=0: clientplayer.state='menu' if clientplayer.state != 'intro': stateMachine.change_state(clientplayer.state)
def begin_round(self): global MOUSE_WHEEL global KEY,callback_round, MOUSE_X, MOUSE_Y, MOUSE_BUTTON,MOUSE_BUTTONUP, mainloop soya.Body.begin_round(self) array_events = [] if pyworlds_engine == "soya": array_events = soya.process_event() elif pyworlds_engine == "pudding": import soya.pudding as pudding # Use mainloop.events instead of pudding.process_event() : # array_events = pudding.process_event() array_events = mainloop.events for ev1 in MOUSE_BUTTONUP: if MOUSE_BUTTON.has_key(ev1): del MOUSE_BUTTON[ev1] MOUSE_BUTTONUP = [] for event in array_events: if event[0] == soya.sdlconst.KEYDOWN: if event[1] == soya.sdlconst.K_ESCAPE: soya.MAIN_LOOP.stop() else: KEY[event[1]]=event[:] elif event[0] == sdlconst.KEYUP: if event[1] in KEY: del KEY[event[1]] elif event[0] == sdlconst.QUIT: soya.MAIN_LOOP.stop() elif event[0] == soya.sdlconst.MOUSEBUTTONDOWN: MOUSE_BUTTON[event[1]]=event[:] MOUSE_X = event[2] MOUSE_Y = event[3] a,b,c,d = MOUSE_BUTTON[event[1]] if a == 5 and (b==4 or b==5): MOUSE_WHEEL = b elif event[0] == soya.sdlconst.MOUSEBUTTONUP: #print "Up: ",MOUSE_BUTTON[event[1]] MOUSE_BUTTONUP.append(event[1]) #if MOUSE_BUTTON.has_key(event[1]): # del MOUSE_BUTTON[event[1]] MOUSE_X = event[2] MOUSE_Y = event[3] elif event[0] == soya.sdlconst.MOUSEMOTION: MOUSE_X = event[1] MOUSE_Y = event[2] if callback_round: callback_round()
def compute_action(self): for event in soya.process_event(): if event[0] == sdlconst.KEYDOWN: if (event[1] == sdlconst.K_q) or (event[1] == sdlconst.K_ESCAPE): soya.MAIN_LOOP.stop() elif event[1] == sdlconst.K_UP: self.plan_action(Action(self, ACTION_MOVE_FORWARD)) elif event[1] == sdlconst.K_DOWN: self.plan_action(Action(self, ACTION_MOVE_BACKWARD)) elif event[1] == sdlconst.K_LEFT: self.plan_action(Action(self, ACTION_TURN_LEFT)) elif event[1] == sdlconst.K_RIGHT: self.plan_action(Action(self, ACTION_TURN_RIGHT)) elif event[0] == sdlconst.KEYUP: if event[1] == sdlconst.K_UP: self.plan_action(Action(self, ACTION_STOP_MOVING)) elif event[1] == sdlconst.K_DOWN: self.plan_action(Action(self, ACTION_STOP_MOVING)) elif event[1] == sdlconst.K_LEFT: self.plan_action(Action(self, ACTION_STOP_TURNING)) elif event[1] == sdlconst.K_RIGHT: self.plan_action(Action(self, ACTION_STOP_TURNING))
def begin_round(self): WidgetedIdler.begin_round(self) # just send all events to the input for e in soya.process_event(): self.input.process_event(e) reactor.iterate() #print realm.server.state for player in players: if player.isstatechanged == 1: realm.server.state = "game" if realm.server.state != 'lobby': stateMachine.change_state(realm.server.state)
def generate_action(self): for event in soya.process_event(): if event[0] == sdlconst.KEYDOWN: if (event[1] == sdlconst.K_q) or (event[1] == sdlconst.K_ESCAPE): soya.MAIN_LOOP.stop() elif event[1] == sdlconst.K_UP: self.send_action(ACTION_MOVE_FORWARD) elif event[1] == sdlconst.K_DOWN: self.send_action(ACTION_MOVE_BACKWARD) elif event[1] == sdlconst.K_LEFT: self.send_action(ACTION_TURN_LEFT) elif event[1] == sdlconst.K_RIGHT: self.send_action(ACTION_TURN_RIGHT) elif event[1] == sdlconst.K_LSHIFT: self.send_action(ACTION_JUMP) elif event[0] == sdlconst.KEYUP: if event[1] == sdlconst.K_UP: self.send_action(ACTION_STOP_MOVING) elif event[1] == sdlconst.K_DOWN: self.send_action(ACTION_STOP_MOVING) elif event[1] == sdlconst.K_LEFT: self.send_action(ACTION_STOP_TURNING) elif event[1] == sdlconst.K_RIGHT: self.send_action(ACTION_STOP_TURNING)
def begin_round(self): # just send all events to the input for e in soya.process_event(): self.input.process_event(e) #iterate the twisted reator so it can process all its stuff if clientplayer.isconnected != 0: reactor.iterate() if clientplayer.generalmsg !='': self.text.append_line(clientplayer.generalmsg) clientplayer.generalmsg ='' if clientplayer.state != 'lobby': stateMachine.change_state(clientplayer.state)
def begin_round(self): soya.Body.begin_round(self) for event in soya.process_event(): if event[0] == soya.sdlconst.KEYDOWN: if event[1] == soya.sdlconst.K_UP: self.speed.z = -1.2 elif event[1] == soya.sdlconst.K_DOWN: self.speed.z = 0.1 elif event[1] == soya.sdlconst.K_LEFT: self.rotation_y_speed = 10.0 elif event[1] == soya.sdlconst.K_RIGHT: self.rotation_y_speed = -10.0 elif event[1] == soya.sdlconst.K_q: soya.MAIN_LOOP.stop() elif event[1] == soya.sdlconst.K_ESCAPE: soya.MAIN_LOOP.stop() if event[0] == soya.sdlconst.KEYUP: if event[1] == soya.sdlconst.K_UP: self.speed.z = 0.0 elif event[1] == soya.sdlconst.K_DOWN: self.speed.z = 0.0 elif event[1] == soya.sdlconst.K_LEFT: self.rotation_y_speed = 0.0 elif event[1] == soya.sdlconst.K_RIGHT: self.rotation_y_speed = 0.0 self.rotate_y(self.rotation_y_speed)
def begin_round(self): for event in soya.process_event(): if self.event_filter(event): pass elif event[0] == sdlconst.QUIT: self.stop() elif event[0] == sdlconst.VIDEORESIZE: self.resize() elif event[0] == sdlconst.KEYDOWN: self.on_key_down(event) elif event[0] == sdlconst.KEYUP: self.on_key_up(event) elif event[0] == sdlconst.MOUSEBUTTONDOWN: self.on_mouse_button_down(event) elif event[0] == sdlconst.MOUSEBUTTONUP: self.on_mouse_button_up(event) elif event[0] == sdlconst.MOUSEMOTION: self.on_mouse_motion(event) # lblRotInfo.text="%.2f %.2f %.2f %.2f %.2f" % (camera.x,camera.y,camera.z,self.rotx,self.roty) soya.Idler.begin_round(self)
def next(self): """Returns the next action""" jump = 0 for event in soya.process_event(): if event[0] == sdlconst.KEYDOWN: if (event[1] == sdlconst.K_q) or (event[1] == sdlconst.K_ESCAPE): sys.exit() # Quit the game elif event[1] == sdlconst.K_LSHIFT: # Shift key is for jumping # Contrary to other action, jump is only performed once, at the beginning of # the jump. jump = 1 elif event[1] == sdlconst.K_LEFT: self.left_key_down = 1 elif event[1] == sdlconst.K_RIGHT: self.right_key_down = 1 elif event[1] == sdlconst.K_UP: self.up_key_down = 1 elif event[1] == sdlconst.K_DOWN: self.down_key_down = 1 elif event[0] == sdlconst.KEYUP: if event[1] == sdlconst.K_LEFT: self.left_key_down = 0 elif event[1] == sdlconst.K_RIGHT: self.right_key_down = 0 elif event[1] == sdlconst.K_UP: self.up_key_down = 0 elif event[1] == sdlconst.K_DOWN: self.down_key_down = 0 if jump: return Action(ACTION_JUMP) # People saying that Python doesn't have switch/select case are wrong... # Remember this if you are coding a fighting game ! return Action({ (0, 0, 1, 0) : ACTION_ADVANCE, (1, 0, 1, 0) : ACTION_ADVANCE_LEFT, (0, 1, 1, 0) : ACTION_ADVANCE_RIGHT, (1, 0, 0, 0) : ACTION_TURN_LEFT, (0, 1, 0, 0) : ACTION_TURN_RIGHT, (0, 0, 0, 1) : ACTION_GO_BACK, (1, 0, 0, 1) : ACTION_GO_BACK_LEFT, (0, 1, 0, 1) : ACTION_GO_BACK_RIGHT, }.get((self.left_key_down, self.right_key_down, self.up_key_down, self.down_key_down), ACTION_WAIT))
def begin_round(self): super(GUIManager, self).begin_round() #process events for event in soya.process_event(): self.check_quit(event)
def begin_round(self): soya.Camera.begin_round(self) # Processes the events for event in soya.process_event(): if event[0] == soya.sdlconst.KEYDOWN: if (event[1] == soya.sdlconst.K_h): self.text_displayer.set_text(" h : show this help\n r : restart \n q : quit\n ") elif (event[1] == soya.sdlconst.K_r): os.system("./git3k&") sys.exit() elif (event[1] == soya.sdlconst.K_q) or (event[1] == soya.sdlconst.K_ESCAPE): sys.exit() elif event[1] == soya.sdlconst.K_LEFT: self.left_key_down = 1 elif event[1] == soya.sdlconst.K_RIGHT: self.right_key_down = 1 elif event[1] == soya.sdlconst.K_UP: self.up_key_down = 1 elif event[1] == soya.sdlconst.K_DOWN: self.down_key_down = 1 elif event[1] == soya.sdlconst.K_PAGEDOWN: self.down_key_page_down = 1 elif event[1] == soya.sdlconst.K_PAGEUP: self.down_key_page_up = 1 elif event[0] == soya.sdlconst.KEYUP: if event[1] == soya.sdlconst.K_LEFT: self.left_key_down = 0 elif event[1] == soya.sdlconst.K_RIGHT: self.right_key_down = 0 elif event[1] == soya.sdlconst.K_UP: self.up_key_down = 0 elif event[1] == soya.sdlconst.K_DOWN: self.down_key_down = 0 elif event[1] == soya.sdlconst.K_PAGEDOWN: self.down_key_page_down = 0 elif event[1] == soya.sdlconst.K_PAGEUP: self.down_key_page_up = 0 elif event[1] == soya.sdlconst.K_KP_PLUS: self.proportion += 0.1 elif event[1] == soya.sdlconst.K_KP_MINUS: self.proportion -= 0.1 elif event[0] == soya.sdlconst.MOUSEBUTTONDOWN: if event[1] == soya.sdlconst.BUTTON_RIGHT: self.move = 1 elif event[1] == soya.sdlconst.BUTTON_MIDDLE: point = self.coord2d_to_3d(event[2], event[3], -5.0) point.convert_to(self.parent) self.points_to.y = point.y self.points_to.x = point.x self.rotate = 1 elif event[1] == soya.sdlconst.BUTTON_WHEELUP: self.add_vector(soya.Vector(self, 0.0,0.0,-10.0)) elif event[1] == soya.sdlconst.BUTTON_WHEELDOWN: self.add_vector(soya.Vector(self, 0.0,0.0,10.0)) elif event[0] == soya.sdlconst.MOUSEBUTTONUP: if event[1] == soya.sdlconst.BUTTON_RIGHT: self.move = 0 elif event[1] == soya.sdlconst.BUTTON_MIDDLE: self.rotate = 0 elif event[0] == soya.sdlconst.MOUSEMOTION: if self.move == 1: self.add_vector(soya.Vector(self, - event[3]/10.0, event[4]/10.0, 0.0)) elif self.rotate == 1: self.add_vector(soya.Vector(self, event[3], -event[4], 0.0)) self.look_at(self.points_to) else: mouse = self.coord2d_to_3d(event[1], event[2]) result = self.parent.raypick(self, self.vector_to(mouse)) if result: impact, normal = result if type(impact.parent) == GitOverrides.Commit3D or \ type(impact.parent) == GitOverrides.BranchLabel or \ type(impact.parent) == GitOverrides.TagLabel or \ type(impact.parent) == GitOverrides.RemoteLabel: if self.old_impact and impact != self.old_impact: self.old_impact.unselect() impact.parent.select() self.text_displayer.set_text(impact.parent.description()) self.old_impact = impact.parent elif self.old_impact: self.old_impact.unselect() self.old_impact = None if (self.left_key_down == 1): self.x -= self.proportion if (self.right_key_down == 1): self.x += self.proportion if (self.up_key_down == 1): self.y += self.proportion if (self.down_key_down == 1): self.y -= self.proportion if (self.down_key_page_down == 1): self.z += self.proportion if (self.down_key_page_up == 1): self.z -= self.proportion
def begin_roundzz(self): soya.Camera.begin_round(self) # go through the events: for event in soya.process_event(): # key pressed: if event[0] == soya.sdlconst.KEYDOWN: #print self.x, self.y, self.z # [ARROW UP] - move forward: if event[1] == soya.sdlconst.K_UP or event[ 1] == soya.sdlconst.K_w: if self.debug: print 'DEBUG: MovableCamera - key pressed - [ARROW UP]' self.speed.z = -0.2 # [ARROW DOWN] - move backward: elif event[1] == soya.sdlconst.K_DOWN or event[ 1] == soya.sdlconst.K_s: if self.debug: print 'DEBUG: MovableCamera - key pressed - [ARROW DOWN]' self.speed.z = 0.2 # [ARROW LEFT] - turn left: elif event[1] == soya.sdlconst.K_LEFT or event[ 1] == soya.sdlconst.K_a: if self.debug: print 'DEBUG: MovableCamera - key pressed - [ARROW LEFT]' self.rotation_y_speed = 1.5 # [ARROW RIGHT] - turn right: elif event[1] == soya.sdlconst.K_RIGHT or event[ 1] == soya.sdlconst.K_d: if self.debug: print 'DEBUG: MovableCamera - key pressed - [ARROW RIGHT]' self.rotation_y_speed = -1.5 # [s] - take a screenshot: elif event[1] == soya.sdlconst.K_s: if self.debug: print 'DEBUG: UserInputManager - key pressed - [s]' self.make_screenshot() # [t] - toggle wireframe: elif event[1] == soya.sdlconst.K_t: if self.debug: print 'DEBUG: UserInputManager - key pressed - [t]' soya.toggle_wireframe() # [q] - quit: elif event[1] == soya.sdlconst.K_q: if self.debug: print 'DEBUG: MovableCamera - key pressed - [q]' soya.MAIN_LOOP.stop() # [ESC] - quit: elif event[1] == soya.sdlconst.K_ESCAPE: if self.debug: print 'DEBUG: MovableCamera - key pressed - [ESCAPE]' soya.MAIN_LOOP.stop() # [o] - look up: elif event[1] == soya.sdlconst.K_o: if self.debug: print 'DEBUG: MovableCamera - key pressed - [o]' self.rotation_x_speed = 1.0 # [k] - look down: elif event[1] == soya.sdlconst.K_k: if self.debug: print 'DEBUG: MovableCamera - key pressed - [k]' self.rotation_x_speed = -1.0 # [k] - look down: elif event[1] == soya.sdlconst.K_r: if self.debug: print 'DEBUG: MovableCamera - key pressed - [r]' self.make_screenshot() # key released: if event[0] == soya.sdlconst.KEYUP: # [ARROW UP] - stop motion: if event[1] == soya.sdlconst.K_UP or event[ 1] == soya.sdlconst.K_w: self.speed.z = 0.0 # [ARROW DOWN] - stop motion: elif event[1] == soya.sdlconst.K_DOWN or event[ 1] == soya.sdlconst.K_s: self.speed.z = 0.0 # [ARROW LEFT] - stop motion: elif event[1] == soya.sdlconst.K_LEFT or event[ 1] == soya.sdlconst.K_a: self.rotation_y_speed = 0.0 # [ARROW RIGHT] - stop motion: elif event[1] == soya.sdlconst.K_RIGHT or event[ 1] == soya.sdlconst.K_d: self.rotation_y_speed = 0.0 # [o] - look up: elif event[1] == soya.sdlconst.K_o: self.rotation_x_speed = 0.0 # [k] - look down: elif event[1] == soya.sdlconst.K_k: self.rotation_x_speed = 0.0
def begin_round(self): self.events = soya.process_event() tofu.MainLoop.begin_round(self)
def auto_render(self): for event in soya.coalesce_motion_event(soya.process_event()): self.on_event(event) self.render() self.cancel = self.dialog.after(150, self.auto_render)
def get_events(self): return soya.process_event()
def begin_roundzz(self): soya.Camera.begin_round(self) # go through the events: for event in soya.process_event(): # key pressed: if event[0] == soya.sdlconst.KEYDOWN: #print self.x, self.y, self.z # [ARROW UP] - move forward: if event[1] == soya.sdlconst.K_UP or event[1] == soya.sdlconst.K_w: if self.debug: print 'DEBUG: MovableCamera - key pressed - [ARROW UP]' self.speed.z = -0.2 # [ARROW DOWN] - move backward: elif event[1] == soya.sdlconst.K_DOWN or event[1] == soya.sdlconst.K_s: if self.debug: print 'DEBUG: MovableCamera - key pressed - [ARROW DOWN]' self.speed.z = 0.2 # [ARROW LEFT] - turn left: elif event[1] == soya.sdlconst.K_LEFT or event[1] == soya.sdlconst.K_a: if self.debug: print 'DEBUG: MovableCamera - key pressed - [ARROW LEFT]' self.rotation_y_speed = 1.5 # [ARROW RIGHT] - turn right: elif event[1] == soya.sdlconst.K_RIGHT or event[1] == soya.sdlconst.K_d: if self.debug: print 'DEBUG: MovableCamera - key pressed - [ARROW RIGHT]' self.rotation_y_speed = -1.5 # [s] - take a screenshot: elif event[1] == soya.sdlconst.K_s: if self.debug: print 'DEBUG: UserInputManager - key pressed - [s]' self.make_screenshot() # [t] - toggle wireframe: elif event[1] == soya.sdlconst.K_t: if self.debug: print 'DEBUG: UserInputManager - key pressed - [t]' soya.toggle_wireframe() # [q] - quit: elif event[1] == soya.sdlconst.K_q: if self.debug: print 'DEBUG: MovableCamera - key pressed - [q]' soya.MAIN_LOOP.stop() # [ESC] - quit: elif event[1] == soya.sdlconst.K_ESCAPE: if self.debug: print 'DEBUG: MovableCamera - key pressed - [ESCAPE]' soya.MAIN_LOOP.stop() # [o] - look up: elif event[1] == soya.sdlconst.K_o: if self.debug: print 'DEBUG: MovableCamera - key pressed - [o]' self.rotation_x_speed = 1.0 # [k] - look down: elif event[1] == soya.sdlconst.K_k: if self.debug: print 'DEBUG: MovableCamera - key pressed - [k]' self.rotation_x_speed = -1.0 # [k] - look down: elif event[1] == soya.sdlconst.K_r: if self.debug: print 'DEBUG: MovableCamera - key pressed - [r]' self.make_screenshot() # key released: if event[0] == soya.sdlconst.KEYUP: # [ARROW UP] - stop motion: if event[1] == soya.sdlconst.K_UP or event[1] == soya.sdlconst.K_w: self.speed.z = 0.0 # [ARROW DOWN] - stop motion: elif event[1] == soya.sdlconst.K_DOWN or event[1] == soya.sdlconst.K_s: self.speed.z = 0.0 # [ARROW LEFT] - stop motion: elif event[1] == soya.sdlconst.K_LEFT or event[1] == soya.sdlconst.K_a: self.rotation_y_speed = 0.0 # [ARROW RIGHT] - stop motion: elif event[1] == soya.sdlconst.K_RIGHT or event[1] == soya.sdlconst.K_d: self.rotation_y_speed = 0.0 # [o] - look up: elif event[1] == soya.sdlconst.K_o: self.rotation_x_speed = 0.0 # [k] - look down: elif event[1] == soya.sdlconst.K_k: self.rotation_x_speed = 0.0
def begin_round(self): MenuIdler.begin_round(self) # just send all events to the input for e in soya.process_event(): self.input.process_event(e)
def begin_round(self): MenuIdler.begin_round(self) # pass all events to the choicelist for e in soya.process_event(): self.choicelist.process_event(e)
def begin_round(self): soya.World.begin_round(self) for event in soya.process_event(): # Mouse down initiates the dragdrop. # key pressed: if event[0] == soya.sdlconst.KEYDOWN: #print self.x, self.y, self.z # [ARROW UP] - move forward: if event[1] == soya.sdlconst.K_UP or event[1] == soya.sdlconst.K_w: self.cam.speed.z = -0.2 # [ARROW DOWN] - move backward: elif event[1] == soya.sdlconst.K_DOWN or event[1] == soya.sdlconst.K_s: self.cam.speed.z = 0.2 # [ARROW LEFT] - turn left: elif event[1] == soya.sdlconst.K_LEFT or event[1] == soya.sdlconst.K_a: self.cam.rotation_y_speed = 1.5 # [ARROW RIGHT] - turn right: elif event[1] == soya.sdlconst.K_RIGHT or event[1] == soya.sdlconst.K_d: self.cam.rotation_y_speed = -1.5 # [s] - take a screenshot: #elif event[1] == soya.sdlconst.K_s: # self.make_screenshot() # [b] - toggle wireframe: elif event[1] == soya.sdlconst.K_b: soya.toggle_wireframe() # [q] - quit: #elif event[1] == soya.sdlconst.K_q: # soya.MAIN_LOOP.stop() # [ESC] - quit: elif event[1] == soya.sdlconst.K_ESCAPE: soya.MAIN_LOOP.stop() # [p] - look up: elif event[1] == soya.sdlconst.K_p: self.cam.rotation_x_speed = 1.0 # [l] - look down: elif event[1] == soya.sdlconst.K_l: self.cam.rotation_x_speed = -1.0 #TODO: [x] - save world: #elif event[1] == soya.sdlconst.K_x: # self.save() # [e] - rotate world: elif event[1] == soya.sdlconst.K_e: self.rotation_y_speed = 1.5 # [r] - rotate world: elif event[1] == soya.sdlconst.K_r: self.rotation_y_speed = -1.5 # [u] - reset camera position: elif event[1] == soya.sdlconst.K_u: self.cam.set_xyz(0.0, 0.0, 15.0) self.cam.look_at_y(self.point) # [o] - rotate world: elif event[1] == soya.sdlconst.K_o: self.rotation_x_speed = 1.5 # [k] - rotate world: elif event[1] == soya.sdlconst.K_k: self.rotation_x_speed = -1.5 # key released: elif event[0] == soya.sdlconst.KEYUP: # [ARROW UP] - stop motion: if event[1] == soya.sdlconst.K_UP or event[1] == soya.sdlconst.K_w: self.cam.speed.z = 0.0 # [ARROW DOWN] - stop motion: elif event[1] == soya.sdlconst.K_DOWN or event[1] == soya.sdlconst.K_s: self.cam.speed.z = 0.0 # [ARROW LEFT] - stop motion: elif event[1] == soya.sdlconst.K_LEFT or event[1] == soya.sdlconst.K_a: self.cam.rotation_y_speed = 0.0 # [ARROW RIGHT] - stop motion: elif event[1] == soya.sdlconst.K_RIGHT or event[1] == soya.sdlconst.K_d: self.cam.rotation_y_speed = 0.0 # [p] - stop looking up: elif event[1] == soya.sdlconst.K_p or event[1] == soya.sdlconst.K_l: self.cam.rotation_x_speed = 0.0 elif event[1] == soya.sdlconst.K_e or event[1] == soya.sdlconst.K_r: self.rotation_y_speed = 0.0 # [o/k] - stop rotate world: elif event[1] == soya.sdlconst.K_o or event[1] == soya.sdlconst.K_k: self.rotation_x_speed = 0.0 elif event[0] == soya.sdlconst.MOUSEBUTTONDOWN: # The event give us the 2D mouse coordinates in pixel. The camera.coord2d_to_3d # convert these 2D pixel coordinates into a soy.Point object. mouse = self.cam.coord2d_to_3d(event[2], event[3]) # Performs a raypicking, starting at the camera and going toward the mouse. # The vector_to method returns the vector between 2 positions. # This raypicking grabs anything that is under the mouse. Raypicking returns # None if nothing is encountered, or a (impact, normal) tuple, where impact is the # position of the impact and normal is the normal vector at this position. # The object encountered is impact.parent ; here, we don't need the normal. result = self.raypick(self.cam, self.cam.vector_to(mouse)) if result: self.impact, normal = result self.dragdroping = self.impact.parent # Converts impact into the camera coordinate system, in order to get its Z value. # camera.coord2d_to_3d cannot choose a Z value for you, so you need to pass it # as a third argument (it defaults to -1.0). Then, we computes the old mouse # position, which has the same Z value than impact. self.impact.convert_to(self.cam) self.old_mouse = self.cam.coord2d_to_3d(event[2], event[3], self.impact.z) # Mouse up ends the dragdrop. elif event[0] == soya.sdlconst.MOUSEBUTTONUP: self.dragdroping = None # Mouse motion moves the dragdroping object, if there is one. elif event[0] == soya.sdlconst.MOUSEMOTION: if self.dragdroping: # Computes the new mouse position, at the same Z value than impact. new_mouse = self.cam.coord2d_to_3d(event[1], event[2], self.impact.z) # Translates dragdroping by a vector starting at old_mouse and ending at # new_mouse. self.dragdroping.add_vector(self.old_mouse.vector_to(new_mouse)) # Store the current mouse position. self.old_mouse = new_mouse
def begin_round(self): soya.Body.begin_round(self) # Loops over all Soya / SDL events. # Each event is a tuple ; the first value indicates the event type and the other # values depend on the type. The following event types exist : # - (KEYDOWN, keysym, modifier) where keysym is the key's code (a K_* constant) # and modifier is a flag combining some of the MOD_* constant (to test the presence # of a modifier, do e.g. for left shift: modifier & soya.sdlconst.MOD_LSHIFT). # - (KEYUP, keysym, modifier) # - (MOUSEMOTION, x, y, xrel, yrel) where x and y are the mouse coordinates (in # pixel) ; xrel and yrel are the relative mouse coordinates (the difference since # next mouse motion event). # - (MOUSEBUTTONDOWN, button, x, y) where button is the mouse button number and # x and y are the mouse coordinates. Mouse buttons are : # - 1 : left # - 2 : middle # - 3 : right # - 4 : roll up # - 5 : roll down # - (MOUSEBUTTONUP, button, x, y) # - (JOYAXISMOTION, axis, value) XXX # - (JOYBUTTONDOWN, button) XXX # - (VIDEORESIZE, new_width, new_height) for event in soya.process_event(): # Checks for key down (press) events. if event[0] == soya.sdlconst.KEYDOWN: # The up and down arrows set the caterpillar speed to a negative or positive value. if event[1] == soya.sdlconst.K_UP: self.speed.z = -0.2 elif event[1] == soya.sdlconst.K_DOWN: self.speed.z = 0.1 # The left and right arrow modify the rotation speed. elif event[1] == soya.sdlconst.K_LEFT: self.rotation_y_speed = 10.0 elif event[1] == soya.sdlconst.K_RIGHT: self.rotation_y_speed = -10.0 # Pressing the escape or 'q' key will exit the main_loop mainloop, and thus terminate # the program. soya.MAIN_LOOP.stop() is the right way to end your application, and # causes the MainLoop.main_loop() method to return. elif event[1] == soya.sdlconst.K_q: soya.MAIN_LOOP.stop() elif event[1] == soya.sdlconst.K_ESCAPE: soya.MAIN_LOOP.stop() # Checks for key up (release) events. elif event[0] == soya.sdlconst.KEYUP: # When up or down arrows are released, the speed is set to zero. if event[1] == soya.sdlconst.K_UP: self.speed.z = 0.0 elif event[1] == soya.sdlconst.K_DOWN: self.speed.z = 0.0 # When left or right arrows are released, the rotation speed is set to zero. elif event[1] == soya.sdlconst.K_LEFT: self.rotation_y_speed = 0.0 elif event[1] == soya.sdlconst.K_RIGHT: self.rotation_y_speed = 0.0 elif event[0] == soya.sdlconst.QUIT: soya.MAIN_LOOP.stop() # Do the rotation. self.rotate_y(self.rotation_y_speed)
def begin_round(self): soya.World.begin_round(self) #process events for event in soya.process_event(): self.check_quit(event)