def begin_round(self):
		soya.Camera.begin_round(self)
		events = soya.MAIN_LOOP.events
		
		for evenement in soya.coalesce_motion_event(events) :
			# mouvement de la souris
			if  evenement[0] == soya.sdlconst.MOUSEMOTION  and (evenement[1] != self.get_screen_width()/2 and evenement[2] != self.get_screen_height()/2):
				left = (evenement[1] - self.get_screen_width()/2) * (self.mouse_sensivity-1) + evenement[1]
				top = (evenement[2] - self.get_screen_height()/2) * (self.mouse_sensivity-1) + evenement[2]
				self.look_at(self.coord2d_to_3d( left, top ))
				soya.set_mouse_pos(self.get_screen_width()/2,self.get_screen_height()/2)
		
		for event in events:
			if event[0] == soya.sdlconst.KEYDOWN:
				if   event[1] == soya.sdlconst.K_UP:     self.speed.z = -1.0
				elif event[1] == soya.sdlconst.K_DOWN:   self.speed.z =  1.0
				elif event[1] == soya.sdlconst.K_LEFT:   self.speed.x = -1.0
				elif event[1] == soya.sdlconst.K_RIGHT:  self.speed.x =  1.0
				elif event[1] == soya.sdlconst.K_SPACE:  self.speed.y =  1.0
				elif event[1] == soya.sdlconst.K_LCTRL:  self.speed.y =  -1.0
				elif event[1] == soya.sdlconst.K_q:      soya.MAIN_LOOP.stop()
				elif event[1] == soya.sdlconst.K_ESCAPE: soya.MAIN_LOOP.stop()
				elif event[1] == soya.sdlconst.K_RETURN:
					self.set_xyz(0,0,70),
					self.look_at(Point(self.parent,0,0,0))
			elif 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.speed.x = 0.0
				elif event[1] == soya.sdlconst.K_RIGHT:  self.speed.x = 0.0
				elif event[1] == soya.sdlconst.K_SPACE:  self.speed.y = 0.0
				elif event[1] == soya.sdlconst.K_LCTRL:  self.speed.y = 0.0
			elif event[0] == soya.sdlconst.MOUSEBUTTONDOWN:
				self.laser_on = True
				self.laser.visible = True
				if event[1] == soya.sdlconst.BUTTON_RIGHT:
					self.laser_power=100000
					self.single_blast = True
					self.laser.color=(0,0.4,1,0.9)
			elif event[0] == soya.sdlconst.MOUSEBUTTONUP:
				self.laser_on = False
				self.laser.visible = False
				
		if self.laser_on:
			if self.laser_on:
				self.laser.move(self.laser_pos)
				self.laser.look_at(self.laser_vector)
			result = self.parent.raypick(self.laser_pos, self.laser_vector)
			if result:
				impact,normal = result
				#apply force
				target = impact.parent
				target.add_force(self.laser_vector*self.laser_power,impact)
				
				l = sqrt(self.laser_power/1000.)
				nl = int(sqrt(l))
				#create particle
				# first corresponding to the dust of the planet
				s = soya.Smoke(self.parent,nb_particles=12*nl)
				s.move(impact)
				s.removable = True
				s.set_colors(target.dust_color+(0.5,),target.dust_color+(0,))
				s.set_sizes((0.3, 0.3), (0.7, 0.7))
				s.life = 1
				#second the lazer beam
				s = soya.Smoke(self.parent,nb_particles=12*nl)
				s.move(impact)
				s.removable = True
				s.life = 0.4*l
				s.speed = 1
				s.set_colors((0.121569,0.431373,0.792157,0.8),(0.121569,0.431373,0.792157,0.5+l/20.))
				s.set_sizes((0.2, 0.2), (0, 0))
Esempio n. 2
0
 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)
Esempio n. 3
0
 def _assert_in_out(self, input, expected):
     output = coalesce_motion_event(input)
     self.assertEquals(output, expected)