Example #1
0
def initMiniMap():
    if 'MiniMap' not in bge.logic.getCurrentScene().objects:
        return

    import Rasterizer
    height = Rasterizer.getWindowHeight()
    width = Rasterizer.getWindowWidth()
    # Compute position of miniMap viewport
    #left = int(width * 1/4)
    #bottom = int(height * 3/4)
    #right = int(width * 3/4)
    #top = int(height * 95/100)

    # Wide map (great for debug game)
    left = int(width * 3 / 100)
    bottom = int(height * 3 / 100)
    right = int(width * 97 / 100)
    top = int(height * 97 / 100)

    # set the viewport coordinates
    camMiniMap = bge.logic.getCurrentScene().objects['MiniMap']
    camMiniMap.setViewport(left, bottom, right, top)

    # move camera to position player
    myPlayer = bge.logic.getCurrentScene().objects['Player']
    camMiniMap.position[0] = myPlayer.position[0]
    camMiniMap.position[1] = myPlayer.position[1]
Example #2
0
def onMouse():
    Rasterizer.showMouse(True)
    cont = GameLogic.getCurrentController()
    mouse = cont.sensors["Mouse"]
    over = cont.sensors["Over"]

    if mouse.positive:
        hit = over.hitObject

        if hit is None: 
            return
        
        print(hit.name)
        print(hit.children)

        if hit.name in buildings:
            deselectAll()
            hit.children["Base01.Selected"].setVisible(True)
            infoPanelShow(hit)
            addUnit()
        else:
            if hit.name in units:
                deselectAll()
                hit.children["Unit0.Selected"].setVisible(True)
                cont.owner["selected"] = hit["id"]
                infoPanelShow(hit)
            else:
                for target in scene.objects:
                    if "Target" in target.name and target["id"] == cont.owner["selected"]:
                        target.localPosition = over.hitPosition
Example #3
0
def rotate(contr):
    """ Read the movements of the mouse and apply them
        as a rotation to the camera. """
    # get the object this script is attached to
    camera = contr.owner

    # Get sensor named Mouse
    mouse = contr.sensors['Mouse']

    if mouse.positive:
        # get width and height of game window
        width = Rasterizer.getWindowWidth()
        height = Rasterizer.getWindowHeight()

        # get mouse movement from function
        move = mouse_move(camera, mouse, width, height)

        # set mouse sensitivity
        sensitivity = camera['Sensitivity']

        # Amount, direction and sensitivity
        leftRight = move[0] * sensitivity
        upDown = move[1] * sensitivity

        # set the values
        camera.applyRotation( [0.0, 0.0, leftRight], 0 )
        camera.applyRotation( [upDown, 0.0, 0.0], 1 )

        # Center mouse in game window
        # Using the '//' operator (floor division) to produce an integer result
        Rasterizer.setMousePosition(width//2, height//2)
	def mouseLook(self):
		if self.mouselook_blocked:	return
		x = (0.5-G.mouse.position[0])*self.sensitivity
		y = (G.mouse.position[1]-0.5)*self.sensitivity
		if abs(x) < 0.01 and abs(y) < 0.01:
			return
		
		if self.mblur:
			strength = abs(x)+abs(y)
			if strength > 0.2:
				print(strength)
				strength = min(strength*2,0.8)
				Rasterizer.enableMotionBlur(strength)
				self.mblur_ticks = 0
			elif self.mblur_ticks > 120:
				Rasterizer.disableMotionBlur()
			else:	self.mblur_ticks += 1
		
		self.rotateOb(self.box, x, (0,0,1))
		
		pot_rotX = self.head_rotX + math.degrees(y)
		if abs(pot_rotX) < self.cam_cap:
			self.head_rotX = pot_rotX
			if self.up_down_enabled:
				anim.armature['UpDown'] = -pot_rotX+90
			self.rotateOb(self.head, y, (-1,0,0))
		
		#Reset cursor
		G.mouse.position = 0.5,0.5
Example #5
0
def centerCursor(controller, gameScreen, Rasterizer):

    # extract width and height from gameScreen
    width = gameScreen[0]
    height = gameScreen[1]

    # Get sensor named MouseLook
    mouse = controller.sensors["MouseLook"]

    # get cursor position
    pos = mouse.position

    # if cursor needs to be centered
    if pos != [width / 2, height / 2]:

        # Center mouse in game window
        Rasterizer.setMousePosition(width / 2, height / 2)

    # already centered.  Turn off actuators
    else:
        # Get the actuators
        act_LeftRight = controller.actuators["LeftRight"]
        act_UpDown = controller.actuators["UpDown"]

        # turn off the actuators
        controller.deactivate(act_LeftRight)
        controller.deactivate(act_UpDown)
Example #6
0
def gameWindow(Rasterizer):

    # get width and height of game window
    width = Rasterizer.getWindowWidth()
    height = Rasterizer.getWindowHeight()

    return (width, height)
def mouse_input() :
	"""mouse_input() gere les entrées de la souris et déplace la camera et le joueur en fonction.
	Cette fonction est parametrée par les champs du fichier config.py dans le meme repertoire
	Ce callback est appele par le spawn du premier joueur
	"""
	cont = bge.logic.getCurrentController()
	own = cont.owner
	sens = cont.sensors[0]

	if _click(sens, config.interact.take) and first_player.getInteractor() : # l'utilisateur doit cliquer pour ramasser l'objet
		obj = first_player.getInteractor()
		if "interact" in obj:
			first_player.click()
		elif "item" in obj:
			first_player.take()

	if _click(sens, config.interact.itemaction1):
		first_player.actionItem(1)
	if _click(sens, config.interact.itemaction2):
		first_player.actionItem(2)
	if _click(sens, config.interact.itemaction3):
		first_player.actionItem(3)
	
	global mx, my, first_player, headcam, boxrotz
	mx += sens.position[0] - WIN_MIDDLE_X
	my += sens.position[1] - WIN_MIDDLE_Y
	x = (mx)*config.mouse.sensibility
	y = (my)*config.mouse.sensibility

	first_player.lookAt(mathutils.Euler((0, y, -x)))

	Rasterizer.setMousePosition(WIN_MIDDLE_X, WIN_MIDDLE_Y)
def mouse_input():
    """mouse_input() gere les entrées de la souris et déplace la camera et le joueur en fonction.
	Cette fonction est parametrée par les champs du fichier config.py dans le meme repertoire
	Ce callback est appele par le spawn du premier joueur
	"""
    cont = bge.logic.getCurrentController()
    own = cont.owner
    sens = cont.sensors[0]

    if _click(sens, config.interact.take) and first_player.getInteractor(
    ):  # l'utilisateur doit cliquer pour ramasser l'objet
        obj = first_player.getInteractor()
        if "interact" in obj:
            first_player.click()
        elif "item" in obj:
            first_player.take()

    if _click(sens, config.interact.itemaction1):
        first_player.actionItem(1)
    if _click(sens, config.interact.itemaction2):
        first_player.actionItem(2)
    if _click(sens, config.interact.itemaction3):
        first_player.actionItem(3)

    global mx, my, first_player, headcam, boxrotz
    mx += sens.position[0] - WIN_MIDDLE_X
    my += sens.position[1] - WIN_MIDDLE_Y
    x = (mx) * config.mouse.sensibility
    y = (my) * config.mouse.sensibility

    first_player.lookAt(mathutils.Euler((0, y, -x)))

    Rasterizer.setMousePosition(WIN_MIDDLE_X, WIN_MIDDLE_Y)
Example #9
0
    def mouseLook(self):
        if self.mouselook_blocked: return
        x = (0.5 - G.mouse.position[0]) * self.sensitivity
        y = (G.mouse.position[1] - 0.5) * self.sensitivity
        if abs(x) < 0.01 and abs(y) < 0.01:
            return

        if self.mblur:
            strength = abs(x) + abs(y)
            if strength > 0.2:
                print(strength)
                strength = min(strength * 2, 0.8)
                Rasterizer.enableMotionBlur(strength)
                self.mblur_ticks = 0
            elif self.mblur_ticks > 120:
                Rasterizer.disableMotionBlur()
            else:
                self.mblur_ticks += 1

        self.rotateOb(self.box, x, (0, 0, 1))

        pot_rotX = self.head_rotX + math.degrees(y)
        if abs(pot_rotX) < self.cam_cap:
            self.head_rotX = pot_rotX
            if self.up_down_enabled:
                anim.armature['UpDown'] = -pot_rotX + 90
            self.rotateOb(self.head, y, (-1, 0, 0))

        #Reset cursor
        G.mouse.position = 0.5, 0.5
Example #10
0
def init():
    loadCursorObjs()
    defaultCursor = Cursor(ARROW_POINTER)
    defaultCursor.setAsDefault()
    defaultCursor.use()

    R.setMousePosition(int(R.getWindowWidth() / 2),
                       int(R.getWindowHeight() / 2))
Example #11
0
def screenshot():
    Rasterizer.makeScreenshot("shot#")
        
    
    
    
        
        
    
Example #12
0
 def generate_images(self):
     self.pointIndex, self.zVals, self.rasterizeParams = Rasterizer.rasterizeOrtho(
         StandardBody.pointCloud,
         self.xvec,
         self.yvec,
         self.mmPerPix,
         pzThrow=self.zclip)
     self.smoothedPointIndex = Rasterizer.smoothRaster(
         self.pointIndex, self.zVals)
     self.image = Rasterizer.colorizeRaster(self.pointIndex)
     self.smoothedImage = Rasterizer.colorizeRaster(self.smoothedPointIndex)
Example #13
0
def hand_control(contr):
    """ Move the hand following the mouse

    Use the movement of the mouse to determine the rotation
    for the IK arm (right arm) """
    # get the object this script is attached to
    human = contr.owner
    scene = GameLogic.getCurrentScene()
    target = scene.objects['IK_Target_Empty.R']

    # set mouse sensitivity
    sensitivity = human['Sensitivity']

    # If the manipulation mode is inactive, do nothing
    if not human['Manipulate']:
        return
 
    # Get sensor named Mouse
    mouse = contr.sensors['Mouse']

    if mouse.positive:
        # get width and height of game window
        width = Rasterizer.getWindowWidth()
        height = Rasterizer.getWindowHeight()

        # get mouse movement from function
        move = mouse_move(human, mouse, width, height)

        # Amount, direction and sensitivity
        left_right = move[0] * sensitivity
        up_down = move[1] * sensitivity

        target.applyMovement([0.0, left_right, 0.0], True)
        target.applyMovement([0.0, 0.0, up_down], True)

        # Reset mouse position to the centre of the screen
        # Using the '//' operator (floor division) to produce an integer result
        Rasterizer.setMousePosition(width//2, height//2)

    # Get sensors for mouse wheel
    wheel_up = contr.sensors['Wheel_Up']
    wheel_down = contr.sensors['Wheel_Down']

    if wheel_up.positive:
        front = 50.0 * sensitivity
        target.applyMovement([front, 0.0, 0.0], True)

    if wheel_down.positive:
        back = -50.0 * sensitivity
        target.applyMovement([back, 0.0, 0.0], True)
Example #14
0
def screamHopelesslyUntilGodComesBack():
	Rasterizer.showMouse(1)

	controller = bge.logic.getCurrentController();
	owner = controller.owner;
	scene = bge.logic.getCurrentScene();
	objects = scene.objects;
	
	bge.logic.LibLoad('//bluestar.blend','Scene',async=True).onFinish = loadBlend;
	bge.logic.LibLoad('//blackstar.blend','Scene',async=True).onFinish = loadBlend;
	scene.objects["Camera"].position = [0,0,9];

	import GameLogic as g;
	g.objectSelected = None;
Example #15
0
def centerCursor(controller, gameScreen, Rasterizer):
    # just centre the cursor
    width = gameScreen[0]
    height = gameScreen[1]
    mouse = controller.sensors["MouseLook"]
    pos = mouse.position
    if pos != [width / 2, height / 2]:
        Rasterizer.setMousePosition(math.floor(width / 2),
                                    math.floor(height / 2))
    else:
        # I deactivate the actuators. I am not sure why I have to do this....
        act_LeftRight = controller.actuators["LeftRight"]
        controller.deactivate(act_LeftRight)
        act_GoBack = controller.actuators["GoBack"]
        controller.deactivate(act_GoBack)
Example #16
0
    def setPlayers():
        import Rasterizer

        # menu leaves mouse on
        if ID == 0: Rasterizer.showMouse(False)

        playcount = conf['PLAYER_COUNT']

        if playcount != 1 and playcount != 2:
            cont.activate('set_camera')
            return True
        if ID != 0 and ID != 1:
            print("Unsupported number of players, running anyway")
            cont.activate('set_camera')
            return True

        # Single player game. no tricks
        if playcount == 1:
            if ID == 0:
                pass
            else:
                return False

        elif playcount == 2:

            # Split screen
            own_camera.useViewport = True

            w = Rasterizer.getWindowWidth()
            h = Rasterizer.getWindowHeight()
            if ID == 0:
                # Vert
                #own_camera.setViewport(0, h/2, w, h)
                # Hoz
                own_camera.setViewport(0, 0, int(w / 2), h)
            if ID == 1:
                # Vert
                #own_camera.setViewport(0, 0, w, h/2)
                # Hoz
                own_camera.setViewport(int(w / 2), 0, w, h)

        if not WITHOUT_CAMERA:
            cont.activate('set_camera')

        return True
Example #17
0
	def setPlayers():
		import Rasterizer
		
		# menu leaves mouse on
		if ID==0: Rasterizer.showMouse(False)
		
		playcount = conf['PLAYER_COUNT']
		
		if playcount != 1 and playcount != 2:
			cont.activate('set_camera')
			return True
		if ID != 0 and ID != 1:
			print("Unsupported number of players, running anyway")
			cont.activate('set_camera')
			return True
		
		# Single player game. no tricks
		if playcount == 1:
			if ID == 0:
				pass
			else:
				return False
		
		elif playcount == 2:

			# Split screen
			own_camera.useViewport = True
			
			w = Rasterizer.getWindowWidth()
			h = Rasterizer.getWindowHeight()
			if ID == 0:
				# Vert
				#own_camera.setViewport(0, h/2, w, h) 
				# Hoz
				own_camera.setViewport(0, 0, int(w/2), h)
			if ID == 1:
				# Vert
				#own_camera.setViewport(0, 0, w, h/2) 
				# Hoz
				own_camera.setViewport(int(w/2), 0, w, h) 
		
		if not WITHOUT_CAMERA:
			cont.activate('set_camera')
		
		return True
Example #18
0
    def look(self):
        cont = bge.logic.getCurrentController()
        mouse = cont.sensors['playerMouse']

        if 'x' not in self.playerCamera:
            self.playerCamera['x'] = math.pi / 2
            self.playerCamera['y'] = math.pi / 6
            x = R.getWindowWidth() // 2
            y = R.getWindowHeight() // 2
            self.playerCamera['size'] = (x, y)

        xpos = self.playerCamera['size'][0]
        ypos = self.playerCamera['size'][1]
        x = (xpos - mouse.position[0]) * self.SENSITIVITY
        y = (ypos - mouse.position[1]) * self.SENSITIVITY

        R.setMousePosition(xpos, ypos)

        self.playerCamera['x'] += x
        self.playerCamera['y'] += y

        #corelation of x(z) angle
        if self.playerCamera['x'] > 2 * math.pi:
            self.playerCamera['x'] -= 2 * math.pi
        if self.playerCamera['x'] < 0:
            self.playerCamera['x'] += 2 * math.pi
        #corelation of y(x) angle
        if self.playerCamera['y'] > math.pi / 2:
            self.playerCamera['y'] = math.pi / 2
        if self.playerCamera['y'] < -math.pi / 2:
            self.playerCamera['y'] = -math.pi / 2

        x = -self.playerCamera['y'] + math.pi / 2
        y = self.playerCamera['x'] + math.pi / 2

        v = mathu.Vector((-x, -math.pi, y))
        w = mathu.Vector((0, 0, (y - math.pi)))

        self.playerCamera.localOrientation = v
        x = self.playerBody.position[0]
        y = self.playerBody.position[1]
        z = self.playerBody.position[2] + 0.7
        self.playerCamera.worldPosition = [x, y, z]
        #print(self.playerCamera.localOrientation)
        self.playerBody.localOrientation = w
Example #19
0
	def look(self):
		cont = bge.logic.getCurrentController()
		mouse = cont.sensors['playerMouse']

		if 'x' not in self.playerCamera:
			self.playerCamera['x'] = math.pi / 2
			self.playerCamera['y'] = math.pi / 6
			x = R.getWindowWidth() // 2
			y = R.getWindowHeight() // 2
			self.playerCamera['size'] = (x,y)

		xpos = self.playerCamera['size'][0]
		ypos = self.playerCamera['size'][1]
		x = (xpos - mouse.position[0])*self.SENSITIVITY
		y = (ypos - mouse.position[1])*self.SENSITIVITY

		R.setMousePosition(xpos,ypos)

		self.playerCamera['x'] += x
		self.playerCamera['y'] += y

		#corelation of x(z) angle
		if self.playerCamera['x'] > 2 * math.pi:
			self.playerCamera['x'] -= 2*math.pi
		if self.playerCamera['x'] < 0:
			self.playerCamera['x'] += 2*math.pi
		#corelation of y(x) angle
		if self.playerCamera['y'] > math.pi / 2:
			self.playerCamera['y'] = math.pi / 2
		if self.playerCamera['y'] < -math.pi / 2:
			self.playerCamera['y'] = -math.pi / 2

		x = -self.playerCamera['y'] + math.pi / 2
		y = self.playerCamera['x'] + math.pi / 2

		v = mathu.Vector((-x,-math.pi,y))
		w = mathu.Vector((0,0,(y-math.pi)))

		self.playerCamera.localOrientation = v
		x = self.playerBody.position[0]
		y = self.playerBody.position[1]
		z = self.playerBody.position[2]+0.7
		self.playerCamera.worldPosition = [x,y,z]
		#print(self.playerCamera.localOrientation)
		self.playerBody.localOrientation = w
Example #20
0
def set(c):
    """ Sets the mouse position using the Rasterizer library. Requires that the
		calling object has the properties: mouse_x and mouse_y set to enable the
		position setting.
	"""
    print("client.mouse.set")

    # Make sure the mouse_x and mouse_y properties are set and are int's
    o = c.owner
    try:
        # Get the coordinates
        mouse_x = o.get("mouse_x")
        mouse_y = o.get("mouse_y")

        # Set the pointer to these coords
        Rasterizer.setMousePosition(mouse_x, mouse_y)
    except:
        return
def Main():

    # get the window dimensions
    import Rasterizer
    width = Rasterizer.getWindowWidth()
    height = Rasterizer.getWindowHeight()

    # get the current scene
    scene = bge.logic.getCurrentScene()
    # and use it to get a list of the objects in the scene
    objList = scene.objects
    # get the two player cameras, called cam1 and cam2
    playermaincam = objList["Camera"]

    # set player viewports with player1 at the right, player 2 at the left
    playermaincam.setViewport(0, 0, width, height)

    # finally, we turn on the use of both viewports
    playermaincam.useViewport = True
Example #22
0
def main():
    try:
        conf = GameLogic.globalDict['CONFIG']
    except:
        conf = GameLogic.globalDict['CONFIG'] = {}

    def confdef(opt, value):
        if opt not in conf:
            conf[opt] = value

    confdef('PLAYER_COUNT', 1)
    confdef('GRAPHICS_DETAIL', 2)  # 2 == high
    confdef('GRAPHICS_GLSL', 1)  # toggle

    # Keys

    # P1
    confdef('KEY_UP_P1', GameKeys.UPARROWKEY)
    confdef('KEY_DOWN_P1', GameKeys.DOWNARROWKEY)
    confdef('KEY_LEFT_P1', GameKeys.LEFTARROWKEY)
    confdef('KEY_RIGHT_P1', GameKeys.RIGHTARROWKEY)

    # P2
    confdef('KEY_UP_P2', GameKeys.WKEY)
    confdef('KEY_DOWN_P2', GameKeys.SKEY)
    confdef('KEY_LEFT_P2', GameKeys.AKEY)
    confdef('KEY_RIGHT_P2', GameKeys.DKEY)

    # P1
    confdef('KEY_JUMP_P1', GameKeys.MKEY)
    confdef('KEY_THROW_P1', GameKeys.SPACEKEY)
    confdef('KEY_ACTION_P1', GameKeys.NKEY)

    # P2
    confdef('KEY_JUMP_P2', GameKeys.GKEY)
    confdef('KEY_THROW_P2', GameKeys.JKEY)
    confdef('KEY_ACTION_P2', GameKeys.HKEY)

    #
    import Rasterizer
    Rasterizer.showMouse(True)
def setup_overlay():
    scene = bge.logic.getCurrentScene()
    camera = scene.objects["Camera"]
    #first_player.overlay = scene
    w = Rasterizer.getWindowWidth()
    h = Rasterizer.getWindowHeight()
    top = scene.objects["top side"]
    bottom = scene.objects["bottom side"]
    right = scene.objects["right side"]
    left = scene.objects["left side"]

    camera.setViewport(0, 0, w, h)  # n'a pas d'effet

    if w >= h:
        x = ((top.localPosition.z - bottom.localPosition.z) / h * w) / 2
        right.localPosition.x = x
        left.localPosition.x = -x
    elif h > w:
        z = ((right.localPosition.x - left.localPosition.x) / w * h) / 2
        top.localPosition.z = z
        bottom.localPosition.z = -z
def setup_overlay() :
	scene = bge.logic.getCurrentScene()
	camera = scene.objects["Camera"]
	#first_player.overlay = scene
	w = Rasterizer.getWindowWidth()
	h = Rasterizer.getWindowHeight()
	top = scene.objects["top side"]
	bottom = scene.objects["bottom side"]
	right = scene.objects["right side"]
	left = scene.objects["left side"]

	camera.setViewport(0, 0, w, h)   # n'a pas d'effet
	
	if w >= h :
		x = ((top.localPosition.z-bottom.localPosition.z)/h * w)/2
		right.localPosition.x = x
		left.localPosition.x = -x
	elif h > w :
		z = ((right.localPosition.x-left.localPosition.x)/w * h)/2
		top.localPosition.z = z
		bottom.localPosition.z = -z
Example #25
0
    def shifter(self):
        mouse = self.cont.sensors['mouse']
        if 'x' not in self.camera:
            self.camera['x'] = 0.0
            x = R.getWindowWidth() // 2
            y = R.getWindowHeight() // 2
            self.camera['size'] = (x, y)

        xpos = self.camera['size'][0]
        ypos = self.camera['size'][1]

        R.setMousePosition(xpos, ypos)
        x = float(xpos - mouse.position[0]) * self.SENSITIVITY

        self.camera['x'] += x
        if self.camera['x'] > 8.5:
            self.camera['x'] = 8.5
        if self.camera['x'] < -8.5:
            self.camera['x'] = -8.5

        z = self.camera.position[2]
        self.camera.position[0] = -self.camera['x']
	def shifter(self):
		mouse = self.cont.sensors['mouse']
		if 'x' not in self.camera:
			self.camera['x'] = 0.0
			x = R.getWindowWidth() // 2
			y = R.getWindowHeight() // 2
			self.camera['size'] = (x,y)

		xpos = self.camera['size'][0]
		ypos = self.camera['size'][1]

		R.setMousePosition(xpos,ypos)
		x = float(xpos - mouse.position[0])*self.SENSITIVITY
		
		self.camera['x'] += x
		if self.camera['x'] > 8.5:
			self.camera['x'] = 8.5
		if self.camera['x'] < -8.5:
			self.camera['x'] = -8.5

		
		z = self.camera.position[2]
		self.camera.position[0] = -self.camera['x']
Example #27
0
def enable(c):
    """ Enable the mouse pointer and at the same time sets the mouse to the our
		center of the screen. Does not require any properties.
	"""
    print("client.mouse.enable")
    # Set the mouse to the default position
    try:
        Rasterizer.setMousePosition(Rasterizer.getWindowWidth() / 2, Rasterizer.getWindowHeight() / 2)
    except:
        pass

        # Enable the mouse
    Rasterizer.showMouse(True)
Example #28
0
import Rasterizer
Rasterizer.showMouse(1)
Example #29
0
import Rasterizer
Rasterizer.showMouse(0)
Example #30
0
def menu_activate(cont, own, item_ob, items):
    '''
	use same syntax as portals for scenes and/or blendfiles
	see frank.blend -> frank_portal text for similar script
	'''

    globalDict = GameLogic.globalDict
    portal_ob = item_ob  # just so we can use copied script

    # incase the portal was set before
    # we dont want to use an invalid value
    try:
        del globalDict['PORTAL_OBNAME']
    except:
        pass

    try:
        del globalDict['PORTAL_SCENENAME']
    except:
        pass

    blend_name = scene_name = target_name = ''

    if 'portal' in portal_ob:  # check for a spesific object
        target_name = portal_ob['portal']

    if 'portal_blend' in portal_ob:
        blend_name = portal_ob[
            'portal_blend']  # No way to check if this really matches up to a scene

    if 'portal_scene' in portal_ob:
        scene_name = portal_ob[
            'portal_scene']  # No way to check if this really matches up to a scene

    if blend_name:
        # todo, allow blend AND scene switching. at the moment can only do blend switching.
        set_blend_actu = cont.actuators['portal_blend']
        set_blend_actu.fileName = blend_name

        try:
            del globalDict['PLAYER_ID']  # regenerate ID's on restart
        except:
            pass

        if target_name:
            globalDict['PORTAL_OBNAME'] = 'OB' + target_name

        if scene_name:
            globalDict['PORTAL_SCENENAME'] = scene_name

        cont.activate(set_blend_actu)
        '''
		SPECIAL CASE - Set GLSL 
		'''
        import Rasterizer
        if GameLogic.globalDict['CONFIG']['GRAPHICS_GLSL']:
            Rasterizer.setMaterialMode(2)  # use GLSL textures
        else:
            Rasterizer.setMaterialMode(0)  # texface

    elif scene_name:
        # portal_ob
        set_scene_actu = cont.actuators['portal_scene']
        set_scene_actu.scene = scene_name

        try:
            del globalDict['PLAYER_ID']  # regenerate ID's on restart
        except:
            pass

        if target_name:
            globalDict['PORTAL_OBNAME'] = 'OB' + target_name

        cont.activate(set_scene_actu)
    else:
        # Not a portal

        conf = GameLogic.globalDict['CONFIG']

        if 'trigger' in item_ob:
            # This should have its own logic thats activated on trigger.
            # print("trigger", item_ob.name)
            item_ob['trigger'] = True

            # Configuration spesific
        elif 'toggle' in item_ob:
            item_ob['toggle'] = not item_ob['toggle']

            if 'conf_key' in item_ob:
                conf[item_ob['conf_key']] = item_ob['toggle']

        elif 'radio' in item_ob:
            conf_key = item_ob['conf_key']

            for ob in items:
                if ob.get('conf_key') == conf_key:
                    print(ob.name)
                    ob['enabled'] = 0

            item_ob['enabled'] = 1
            conf[item_ob['conf_key']] = item_ob[
                'radio']  # The index of this radio
Example #31
0
def start(controller):
    Rasterizer.showMouse(True)
Example #32
0
def main():
    print("------------ Player script start :p")

    cont = bge.logic.getCurrentController()
    scene = bge.logic.getCurrentScene()
    player = cont.owner

    keyboard = bge.logic.keyboard
    mouse = bge.logic.mouse
    cam = scene.objects.get("Camera")

    ground_sensor = cont.sensors["touch_ground"]
    #print(bge.types.KX_TouchSensor(ground_sensor).hitObject)
    #print(ground_sensor.status == bge.logic.KX_SENSOR_ACTIVE)

    # mouse look
    # apply rotation and reset mouse position
    mouseX = mouse.position[0] * -1
    mouseY = mouse.position[1] * -1
    w = bge.render.getWindowWidth()
    h = bge.render.getWindowHeight()
    w2 = math.ceil(w / 2)
    h2 = math.ceil(h / 2)

    moveX = mouseX + 0.5
    moveY = mouseY + 0.5

    moveY *= MOUSE_SENS
    moveX *= MOUSE_SENS

    print("mouse.position[0]: ", mouseX)
    print("w2: ", w2)
    print("moveX: ", moveX, " moveY: ", moveY)

    cam.applyRotation([moveY, 0, 0], True)
    player.applyRotation([0, 0, moveX], True)
    Rasterizer.setMousePosition(w2, h2)

    player_vel = player.getLinearVelocity(True)

    # controls
    k = bge.logic.KX_INPUT_ACTIVE

    # crouching
    if k == keyboard.events[bge.events.LEFTCTRLKEY]:
        player.localScale.z = 0.9
    else:
        player.localScale.z = 1.8

    # if touching ground
    if ground_sensor.hitObject != None:
        if keyboard.events[bge.events.COMMAKEY] == k:
            if player_vel[1] < PLAYER_MAX_SPEED:
                player.applyForce([0, 80, 0], True)
        if keyboard.events[bge.events.OKEY] == k:
            if player_vel[1] > -PLAYER_MAX_SPEED:
                player.applyForce([0, -80, 0], True)
        if keyboard.events[bge.events.AKEY] == k:
            if player_vel[0] > -PLAYER_MAX_SPEED:
                player.applyForce([-80, 0, 0], True)
        if keyboard.events[bge.events.EKEY] == k:
            if player_vel[0] < PLAYER_MAX_SPEED:
                player.applyForce([80, 0, 0], True)
        if keyboard.events[bge.events.SPACEKEY] == k:
            if player_vel[0] < PLAYER_MAX_SPEED:
                player.applyForce([0, 0, 160], True)
Example #33
0
def showMouse():
    Rasterizer.showMouse(1)
Example #34
0
import bge
import Rasterizer

Rasterizer.showMouse(False)

def main():
    cont = bge.logic.getCurrentController()

    # The KX_GameObject that owns this controller.
    own = cont.owner

    # for scripts that deal with spacial logic
    own_pos = own.worldPosition

    # Some example functions, remove to write your own script.
    # check for a positive sensor, will run on any object without errors.
    print("Logic info for KX_GameObject", own.name)
    input = False

    for sens in cont.sensors:
        # The sensor can be on another object, we may want to use it
        own_sens = sens.owner
        print("    sensor:", sens.name, end=" ")
        if sens.positive:
            print("(true)")
            input = True
        else:
            print("(false)")

    for actu in cont.actuators:
        # The actuator can be on another object, we may want to use it
Example #35
0
import Rasterizer
Rasterizer.showMouse(0)

import Rasterizer as r
r.showMouse(1)
Example #37
0
import Rasterizer
cont = GameLogic.getCurrentController()
player = cont.getOwner()
mousemove = cont.getSensor('mousemove')

Rasterizer.showMouse(0)

player.mouseX = mousemove.getXPosition()
player.mouseY = mousemove.getYPosition()
player.moveX = 0.0
player.moveY = 0.0

shoulderipo = cont.getActuator('shoulderipo')
playerrot = cont.getActuator('playerrot')
shoulder = shoulderipo.getOwner()
player.deltaMouseX =  player.mouseX - (Rasterizer.getWindowWidth() / 2)
player.deltaMouseY = player.mouseY - (Rasterizer.getWindowHeight() / 2)
player.moveX= (player.deltaMouseX - player.moveX) * player.mousefilter
player.moveY= (player.deltaMouseY - player.moveY) * player.mousefilter

player.rot -= (player.moveX * player.sensitivity)
shoulder.pitch -= (player.moveY * player.sensitivity)
GameLogic.addActiveActuator(playerrot, 1)
GameLogic.addActiveActuator(shoulderipo, 1)
	
Rasterizer.setMousePosition(Rasterizer.getWindowWidth() / 2, Rasterizer.getWindowHeight() / 2)
Example #38
0
    owner = cont.owner
    acts = [act for act in cont.actuators if
            not act.name.startswith('-') and act.action]
    check_defects(owner, acts)

    # all properties must be set to the face mesh.
    # TODO: p26 is copied on the 'jaw' bone too, use the one from face mesh.
    G.server[FACE].set_available_AUs([n[1:] for n in owner.getPropertyNames()])

    # ok, startup
    G.initialized = True	
    G.setMaxLogicFrame(1)       # relative to rendering
    G.setLogicTicRate(MAX_FPS)
    import Rasterizer
#    Rasterizer.enableMotionBlur( 0.65)
    Rasterizer.setBackgroundColor([.0, .0, .0, 1.0])
    print "Material mode:", ['TEXFACE_MATERIAL','MULTITEX_MATERIAL ','GLSL_MATERIAL '][Rasterizer.getMaterialMode()]
    G.last_update_time = time.time()    
    return cont

def update(faceServer, time_diff):
    """
    """
    global INFO_PERIOD

    cont = G.getCurrentController()
    eyes_done = False

    # threaded server is thread-safe
    for au, value in faceServer.update(time_diff):
        if au[0] == '6':        # XXX: yes, 6 is an eye prefix (do better ?)
Example #39
0
def main():
	Rasterizer.showMouse(1)
Example #40
0
    def setGfxQuality():
        import Rasterizer
        # return
        # Only to this once
        if ID != 0:
            return

        conf = GameLogic.globalDict['CONFIG']

        if conf['GRAPHICS_DETAIL'] == 0:
            print("\tconfig: setting deytail low")
            Rasterizer.setGLSLMaterialSetting("lights", 1)
            Rasterizer.setGLSLMaterialSetting("shaders", 0)
            Rasterizer.setGLSLMaterialSetting("shadows", 0)
            Rasterizer.setGLSLMaterialSetting("ramps", 0)
            Rasterizer.setGLSLMaterialSetting("nodes", 0)
            Rasterizer.setGLSLMaterialSetting("extra_textures", 1)
        elif conf['GRAPHICS_DETAIL'] == 1:
            print("\tconfig: setting deytail med")
            Rasterizer.setGLSLMaterialSetting("lights", 1)
            Rasterizer.setGLSLMaterialSetting("shaders", 0)
            Rasterizer.setGLSLMaterialSetting("shadows", 0)
            Rasterizer.setGLSLMaterialSetting("ramps", 1)
            Rasterizer.setGLSLMaterialSetting("nodes", 0)
            Rasterizer.setGLSLMaterialSetting("extra_textures", 1)
        else:  # high quality
            print("\tconfig: setting deytail high")
            Rasterizer.setGLSLMaterialSetting("lights", 1)
            Rasterizer.setGLSLMaterialSetting("shaders", 1)
            Rasterizer.setGLSLMaterialSetting("shadows", 1)
            Rasterizer.setGLSLMaterialSetting("ramps", 1)
            Rasterizer.setGLSLMaterialSetting("nodes", 1)
            Rasterizer.setGLSLMaterialSetting("extra_textures", 1)
Example #41
0
def gameWindow(Rasterizer):
    # get the size of the screen
    width = Rasterizer.getWindowWidth()
    height = Rasterizer.getWindowHeight()
    return (width, height)
def main():
    Rasterizer.showMouse(1)
Example #43
0
import bge
import Rasterizer

Rasterizer.showMouse(False)


def main():
    cont = bge.logic.getCurrentController()

    # The KX_GameObject that owns this controller.
    own = cont.owner

    # for scripts that deal with spacial logic
    own_pos = own.worldPosition

    # Some example functions, remove to write your own script.
    # check for a positive sensor, will run on any object without errors.
    print("Logic info for KX_GameObject", own.name)
    input = False

    for sens in cont.sensors:
        # The sensor can be on another object, we may want to use it
        own_sens = sens.owner
        print("    sensor:", sens.name, end=" ")
        if sens.positive:
            print("(true)")
            input = True
        else:
            print("(false)")

    for actu in cont.actuators:
Example #44
0
import Rasterizer as r

r.showMouse(True)
import bge, Rasterizer

# Frequently used variables
curScene = bge.logic.getCurrentScene()
curCont = bge.logic.getCurrentController()
scenes = bge.logic.getSceneList()
text = bge.logic.globalDict["Text"]

# Get the objects
inventoryView = curScene.objects["InventoryView"]
inventoryBackground = curScene.objects["InventoryBackground"]
inventoryItem = curScene.objects["InventoryItem"]

# Add the mouse pointer if needed
Rasterizer.showMouse(True)

inventoryItem.resolution = 4
inventoryItem["Text"] = scenes[0].objects["Player"]["Inventory"]
Example #46
0
def hideMouse():
    Rasterizer.showMouse(0)
def initGUI():
	R.showMouse(1)
	G.UIScene = G.getCurrentScene()
Example #48
0
def initGUI():
    R.showMouse(1)
    G.UIScene = G.getCurrentScene()
Example #49
0
import GameLogic 
import Rasterizer 

#init stuff, show mouse
if not hasattr(GameLogic,'init'):
    GameLogic.init = 1
    Rasterizer.showMouse(1)

# load controller, set sensors
py = GameLogic.getCurrentController()
always,move,click = py.sensors

# load target "Cube"
obj = GameLogic.getCurrentScene().getObjectList()["Rouge"]
    
# find mouse    
if move.positive:
    pos = move.getHitPosition()
    
    # set "Cube" at mouse position on click
    if click.positive:
        obj.setPosition(pos)
Example #50
0
def disable(c):
    """ Disable the mouse pointer by hiding the pointer. Does not require any of
		the properties.
	"""
    print("client.mouse.disable")
    Rasterizer.showMouse(False)
Example #51
0
	def setGfxQuality():
		import Rasterizer
		# return
		# Only to this once
		if ID != 0:
			return
		
		
		
		conf = GameLogic.globalDict['CONFIG']
		
		if conf['GRAPHICS_DETAIL'] == 0:
			print("\tconfig: setting deytail low")
			Rasterizer.setGLSLMaterialSetting("lights", 1)
			Rasterizer.setGLSLMaterialSetting("shaders", 0)
			Rasterizer.setGLSLMaterialSetting("shadows", 0)
			Rasterizer.setGLSLMaterialSetting("ramps", 0)
			Rasterizer.setGLSLMaterialSetting("nodes", 0)
			Rasterizer.setGLSLMaterialSetting("extra_textures", 1)
		elif conf['GRAPHICS_DETAIL'] == 1:
			print("\tconfig: setting deytail med")
			Rasterizer.setGLSLMaterialSetting("lights", 1)
			Rasterizer.setGLSLMaterialSetting("shaders", 0)
			Rasterizer.setGLSLMaterialSetting("shadows", 0)
			Rasterizer.setGLSLMaterialSetting("ramps", 1)
			Rasterizer.setGLSLMaterialSetting("nodes", 0)
			Rasterizer.setGLSLMaterialSetting("extra_textures", 1)
		else: # high quality
			print("\tconfig: setting deytail high")
			Rasterizer.setGLSLMaterialSetting("lights", 1)
			Rasterizer.setGLSLMaterialSetting("shaders", 1)
			Rasterizer.setGLSLMaterialSetting("shadows", 1)
			Rasterizer.setGLSLMaterialSetting("ramps", 1)
			Rasterizer.setGLSLMaterialSetting("nodes", 1)
			Rasterizer.setGLSLMaterialSetting("extra_textures", 1)
Example #52
0
# Import Rasterizer 
import Rasterizer

# Show mouse 
Rasterizer.showMouse(True)
Example #53
0
import bge
import GameLogic
import Rasterizer

gameWidth = Rasterizer.getWindowWidth()
gameHeight = Rasterizer.getWindowHeight()

directionXAxis = -1
directionYAxis = -1

controller = bge.logic.getCurrentController()
owner = controller.owner
parent = owner.parent
mouse = controller.sensors['Mouse']

Rasterizer.setMousePosition(int(gameWidth/2), int(gameHeight/2))

sensitivity = 0.0020

mousePositionX = mouse.position[0] - gameWidth/2
mousePositionY = mouse.position[1] - gameHeight/2

# fix mouse drift on subpixel positions
if mousePositionX == -0.5:
    mousePositionX = 0
if mousePositionY == -0.5:
    mousePositionY = 0

rotXAxis = (mousePositionX * directionXAxis) * sensitivity
rotYAxis = (mousePositionY * directionYAxis) * sensitivity
Example #54
0
	def draw(self):
		cam = bge.logic.getCurrentScene().active_camera
		
		self.position[2] += self.speed
		
		# Get some viewport info
		view_buf = bgl.Buffer(bgl.GL_INT, 4)
		bgl.glGetIntegerv(bgl.GL_VIEWPORT, view_buf)
		view = view_buf[:]

		if 0:
			# Save the state
			bgl.glPushAttrib(bgl.GL_ALL_ATTRIB_BITS)

			# Disable depth test so we always draw over things
			bgl.glDisable(bgl.GL_DEPTH_TEST)

			# Disable lighting so everything is shadless
			bgl.glDisable(bgl.GL_LIGHTING)

			# Unbinding the texture prevents BGUI frames from somehow picking up on
			# color of the last used texture
			bgl.glBindTexture(bgl.GL_TEXTURE_2D, 0)

			# Make sure we're using smooth shading instead of flat
			bgl.glShadeModel(bgl.GL_SMOOTH)


		# Calculate x and y
		screen_coord = cam.getScreenPosition(self.position)
		x = screen_coord[0] * ras.getWindowWidth()
		y = ras.getWindowHeight() - (screen_coord[1] * ras.getWindowHeight())
		
		# Check to make sure the position isn't behind the camera
		if not cam.pointInsideFrustum(self.position):
			return
	
		# Calculate scale
		distance = cam.getDistanceTo(self.position)
		if 1000 - distance > 0:
			scale = (1000 - distance) / 1000
		else:
			scale = 0

		# Setup the matrices
		bgl.glMatrixMode(bgl.GL_PROJECTION)
		bgl.glPushMatrix()
		bgl.glLoadIdentity()
		bgl.gluOrtho2D(0, view[2], 0, view[3])
		bgl.glMatrixMode(bgl.GL_MODELVIEW)
		bgl.glPushMatrix()
		bgl.glLoadIdentity()
		
		# Center the x
		text_width, text_height = blf.dimensions(self.fontid, self.text)
		x -= text_width / 2

			
		# Draw the font if large enough
		if scale:
			blf.size(self.fontid, int(self.pt_size*scale), 72)
			blf.position(self.fontid, x, y, 0)
			blf.draw(self.fontid, self.text)
			
		# Reset the state
		bgl.glPopMatrix()
		bgl.glMatrixMode(bgl.GL_PROJECTION)
		bgl.glPopMatrix()
Example #55
0
# Get controller
controller = GameLogic.getCurrentController()

# Get sensor named Mouse
mouse = controller.getSensor("Mouse")

# Get the actuators
rotLeftRight = controller.getActuator("LookLeftRight")
rotUpDown = controller.getActuator("LookUpDown")


############################## Need the size of the game window

import Rasterizer

width = Rasterizer.getWindowWidth()
height = Rasterizer.getWindowHeight()


############################### Get the mouse movement

def mouseMove():

    # distance moved from screen center
    #x = width/2 - mouse.getXPosition()
    #y = height/2 - mouse.getYPosition()
    x = width/2 - mouse.position[0]
    y = height/2 - mouse.position[1]

    # intialize mouse so it doesn't jerk first time
    if hasattr(GameLogic, 'init') == False:
Example #56
0
def main():
    print("------------ Player script start :p")

    cont = bge.logic.getCurrentController()
    scene = bge.logic.getCurrentScene()
    player = cont.owner
    
    keyboard = bge.logic.keyboard
    mouse = bge.logic.mouse
    cam = scene.objects.get("Camera") 
    
    ground_sensor = cont.sensors["touch_ground"]
    #print(bge.types.KX_TouchSensor(ground_sensor).hitObject)
    #print(ground_sensor.status == bge.logic.KX_SENSOR_ACTIVE)

    # mouse look
    # apply rotation and reset mouse position
    mouseX = mouse.position[0] * -1
    mouseY = mouse.position[1] * -1
    w = bge.render.getWindowWidth()
    h = bge.render.getWindowHeight()
    w2 = math.ceil(w/2)
    h2 = math.ceil(h/2)

    moveX = mouseX + 0.5
    moveY = mouseY + 0.5

    moveY *= MOUSE_SENS
    moveX *= MOUSE_SENS
    
    print("mouse.position[0]: ", mouseX)
    print("w2: ", w2)
    print("moveX: ",moveX, " moveY: ", moveY)

    cam.applyRotation([moveY, 0, 0], True)
    player.applyRotation([0, 0, moveX], True)
    Rasterizer.setMousePosition(w2, h2)
    
    player_vel = player.getLinearVelocity(True)

    # controls
    k = bge.logic.KX_INPUT_ACTIVE
    
    # crouching
    if k == keyboard.events[bge.events.LEFTCTRLKEY]:
        player.localScale.z = 0.9
    else:
        player.localScale.z = 1.8
        
    # if touching ground
    if ground_sensor.hitObject != None:
        if keyboard.events[bge.events.COMMAKEY] == k:
            if player_vel[1] < PLAYER_MAX_SPEED:
                player.applyForce([0,80,0], True)
        if keyboard.events[bge.events.OKEY] == k:
            if player_vel[1] > -PLAYER_MAX_SPEED:
                player.applyForce([0,-80,0], True)
        if keyboard.events[bge.events.AKEY] == k:
            if player_vel[0] > -PLAYER_MAX_SPEED:
                player.applyForce([-80,0,0], True)
        if keyboard.events[bge.events.EKEY] == k:
            if player_vel[0] < PLAYER_MAX_SPEED:
                player.applyForce([80,0,0], True)
        if keyboard.events[bge.events.SPACEKEY] == k:
            if player_vel[0] < PLAYER_MAX_SPEED:
                player.applyForce([0,0,160], True)
def record():
    global rec_i
    scr = Rasterizer.makeScreenshot("/tmp/game_"+str('%04d' % rec_i)+".jpg")
    rec_i+=1