Пример #1
0
  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)
Пример #2
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)
Пример #3
0
	def test_render_front(self):
		soya.set_root_widget(self.blue_camera)
		soya.render()
		screenshot = soya.screenshot()
		self.assertEquals(screenshot.getpixel((0,0)), (0, 0, 255))

		soya.set_root_widget(self.red_camera)
		soya.render()
		screenshot = soya.screenshot()
		self.assertEquals(screenshot.getpixel((0,0)),(255, 0, 0))
Пример #4
0
	def test_render_back_read(self):
		"""Test that rendering made without switching back buffer are accessible with screenshot"""
		# Screenshot in front buffer
		soya.set_root_widget(self.blue_camera)
		soya.render()
		screenshot = soya.screenshot()
		self.assertEquals(screenshot.getpixel((0,0)),(0, 0, 255))

		# Screenshot in back buffer
		soya.set_root_widget(self.red_camera)
		soya.render(swap_buffer=False)
		screenshot = soya.screenshot(use_back_buffer=True)
		self.assertEquals(screenshot.getpixel((0,0)),(255, 0, 0))
Пример #5
0
	def test_render_does_not_alter(self):
		"""Test that rendering in the back buffer doesn't alter the front one."""
		# Screenshot in front buffer
		soya.set_root_widget(self.blue_camera)
		soya.render()

		# Screenshot in back buffer
		soya.set_root_widget(self.red_camera)
		soya.render(swap_buffer=False)

		# Front buffer didn't changed
		screenshot = soya.screenshot()
		self.assertEquals(screenshot.getpixel((0,0)),(0, 0, 255))

		# Everything still work fine
		soya.set_root_widget(self.blue_camera)
		soya.render()
		screenshot = soya.screenshot()
		self.assertEquals(screenshot.getpixel((0,0)),(0, 0, 255))
Пример #6
0
 def make_screenshot(self):
     filename = 'canta_' + str(time.strftime('%S' +'%H'+'%M'+'_'+'%d'+'-'+'%h'+'-'+'%Y'))+'.jpeg'
     soya.screenshot().save(os.path.join(os.path.dirname(sys.argv[0]), filename))
Пример #7
0
		
		for event in soya.MAIN_LOOP.events:
			
			if event[0] == soya.sdlconst.MOUSEMOTION:
				self.mouse_pos = camera.coord2d_to_3d(event[1], event[2], -15.0)
				self.move(self.mouse_pos)
				
green = soya.Material(); green.diffuse = (0.0, 1.0, 0.0, 1.0)

Cursor(scene, soya.cube.Cube(None, green).to_model())

# Adds a light.

light = soya.Light(scene)
light.set_xyz(0.0, 0.2, 1.0)

# Creates a camera.

camera = soya.Camera(scene)
camera.set_xyz(0.0, 0.0, 4.0)
camera.fov = 100.0
soya.set_root_widget(camera)


# Main loop
try:
	soya.MainLoop(scene).main_loop()
except:
	soya.render(); soya.screenshot().resize((320, 240)).save(os.path.join(os.path.dirname(sys.argv[0]), "results", os.path.basename(sys.argv[0])[:-3] + ".jpeg"))

Пример #8
0
    def begin_round(self):
        global j1, j2, pend, scene, pole, ball, grabScreens, frNum
        global pauseState
        damping = 0.1

        if (pauseState == 1):
            self.next()
            return

        # Calls the super implementation.
        soya.World.begin_round(self)
        #~ print(j1.getFeedback(), "#", j2.getFeedback()) # (force1, torque1, force2, torque2) : ((0.0, 332.9216613769531, -257.0126647949219), (180.77870178222656, 0.0, 0.0), (0.0, 1.0, 0.0), (0.0, 0.0, 1.0)) ..... (((0.0, 426.10772705078125, -1055.581298828125), (-5704.71435546875, 0.0, 0.0), (1.1854985008187952e-42, 2.312142466135948e-43, 9.164491956684304e-43), (1.4461400151832112e-42, 7.777206477002735e-43, 7.903323338791968e-43)), '#', ((0.0, 173.71861267089844, -6280.154296875), (-96.6642074584961, 0.0, 0.0), (0.0, -173.71861267089844, 6280.154296875), (-504.1296081542969, 0.0, 0.0)))

        self.j1f = j1.getFeedback()
        self.j2f = j2.getFeedback()
        frc1 = self.j2f[0]  #[0]
        # note - vector should be referenced to scene, NOT pend,
        #   for the damping to work!
        dampvect = Vector(scene, -damping * frc1[0], -damping * frc1[1],
                          -damping * frc1[2])
        pend.add_force(dampvect)
        #~ j1fp = j1.getFeedback() # same as j1f
        #~ print(frc1, "#", j1fp[0])
        self.dj1fp = Vector(scene, frc1[0], frc1[1], frc1[2]) + dampvect
        #~ print(frc1, "#", self.dj1fp)

        #~ print(bp)
        #~ frep=bp+0.1*self.dj1fp # float required; no parse
        #~ frep=bp.add_mul_vector(0.1, self.dj1fp) # awful
        #~ frep=bp+self.dj1fp.__mul__(0.000001) # ??
        #~ frep=Vector(ball,0,0,2) # ref to ball don't seem to matter!
        # AH - for these kind of transform with convert_to, should have Point, not Vector!
        # frcpball coord syst: 2 units in each direction, moved 1 unit along x so as not to be hidden by ball
        movx = 0
        if (self.coordViewState == 0):
            self.bp = ball.position().add_vector(soya.Vector(ball, movx, 0, 0))
            self.bp1 = self.bp
            self.bp2 = self.bp1
        if (self.coordViewState == 1):
            movx = 1
            self.bp = ball.position().add_vector(soya.Vector(ball, movx, 0, 0))
            self.bp1 = self.bp
            self.bp2 = self.bp1
        elif (self.coordViewState == 2):
            movx = 1
            self.bp = ball.position().add_vector(soya.Vector(ball, movx, 0, 0))
            self.bp1 = ball.position().add_vector(soya.Vector(ball, 2, 0, 1))
            self.bp2 = self.bp1
        elif (self.coordViewState == 3):
            movx = 1
            self.bp = ball.position().add_vector(soya.Vector(ball, movx, 0, 0))
            self.bp1 = ball.position().add_vector(soya.Vector(ball, 2, 0, 1))
            self.bp2 = ball.position().add_vector(soya.Vector(ball, 3, 0, 2))

        self.bp1b = self.bp1.copy().add_vector(soya.Vector(ball, -0.5, 0, 0))

        self.frepx = Point(ball, 2 + movx, 0, 0)
        self.frepy = Point(ball, movx, 2, 0)
        self.frepz = Point(ball, movx, 0, 2)
        self.frepx.convert_to(scene)
        self.frepy.convert_to(scene)
        self.frepz.convert_to(scene)

        # scaled so they're approx the same
        scale_grav = scene.gravity.__mul__(0.5)
        scale_dfor = self.dj1fp.__mul__(0.03)
        self.epg = self.bp1 + scale_grav
        self.epfor = self.bp2 + scale_dfor

        tp = Vector(ball, 2, 0,
                    0)  # convert_to must go separate! can be vector
        tp.convert_to(scene)  # IN PLACE
        grav_lx = self.vecProjectionAontoB(scale_grav, tp)
        tp = Vector(ball, 0, 2, 0)
        tp.convert_to(scene)
        grav_ly = self.vecProjectionAontoB(scale_grav, tp)
        tp = Vector(ball, 0, 0, 2)
        tp.convert_to(scene)
        grav_lz = self.vecProjectionAontoB(scale_grav, tp)
        self.epgx = self.bp1 + grav_lx
        self.epgy = self.bp1 + grav_ly
        self.epgz = self.bp1 + grav_lz

        tp = Vector(ball, 2, 0, 0)
        tp.convert_to(scene)
        dfor_lx = self.vecProjectionAontoB(scale_dfor, tp)
        tp = Vector(ball, 0, 2, 0)
        tp.convert_to(scene)
        dfor_ly = self.vecProjectionAontoB(scale_dfor, tp)
        tp = Vector(ball, 0, 0, 2)
        tp.convert_to(scene)
        dfor_lz = self.vecProjectionAontoB(scale_dfor, tp)
        self.epforx = self.bp2 + dfor_lx
        self.epfory = self.bp2 + dfor_ly
        self.epforz = self.bp2 + dfor_lz

        tp = Vector(scene, 2, 0, 0)
        grav_lz_mx = self.vecProjectionAontoB(grav_lz, tp)
        tp = Vector(scene, 0, 2, 0)
        grav_lz_my = self.vecProjectionAontoB(grav_lz, tp)
        tp = Vector(scene, 0, 0, 2)
        grav_lz_mz = self.vecProjectionAontoB(grav_lz, tp)
        self.epglzx = self.bp1b + grav_lz_mx
        self.epglzy = self.bp1b + grav_lz_my
        self.epglzz = self.bp1b + grav_lz_mz

        if (grabScreens):
            frNum += 1
            tfname = "/dev/shm/soya-pend%05d.png" % (frNum)
            soya.screenshot(filename=tfname, use_back_buffer=False)
Пример #9
0
 def make_screenshot(self):
     """Take a screenshot and save it to data/screenshots.
     """
     soya.screenshot().save(os.path.join(self.app_dir, 'canta_' \
         + str(time.strftime('%S' +'%H'+'%M'+'_'+'%d'+'-'+'%h'+'-'+'%Y')) \
         + '.jpeg'))
Пример #10
0
 def make_screenshot(self):
     filename = 'canta_' + str(
         time.strftime('%S' + '%H' + '%M' + '_' + '%d' + '-' + '%h' + '-' +
                       '%Y')) + '.jpeg'
     soya.screenshot().save(
         os.path.join(os.path.dirname(sys.argv[0]), filename))
Пример #11
0
 def make_screenshot(self):
     """Take a screenshot and save it to data/screenshots.
     """
     soya.screenshot().save(os.path.join(self.app_dir, 'canta_' \
         + str(time.strftime('%S' +'%H'+'%M'+'_'+'%d'+'-'+'%h'+'-'+'%Y')) \
         + '.jpeg'))