Previous Thread  Next Thread

chat icon Having trouble with mouse!

xintoc

Posted: Wed Oct 30, 2002 11:31 am
Joined: 29 Oct 2002
Posts: 18
How to add this script to mouse, I need some kind of a tutorial for it!


from GameLogic import *
from Rasterizer import *

Cont = getCurrentController()
Own = Cont.getOwner()
Sens = Cont.getSensors()
Sensor = Sens[0]

Height = getWindowHeight()/2
Width = getWindowWidth()/2

# get current mouse position
Xpos = Sensor.getXPosition()
Ypos = Sensor.getYPosition()

# get actuators
RightMove = Cont.getActuator("Right")
LeftMove = Cont.getActuator("Left")
UpMove = Cont.getActuator("Up")
DownMove = Cont.getActuator("Down")


# check positions relative to old position
# Mouse going right
if (Xpos > Width):
# Move right
XDiff = Xpos - Width
RightMove.setDRot(0,(XDiff /Own.move/2),0,1)
addActiveActuator(RightMove,1)

# Mouse going left
if (Xpos < Width):
# Move left
XDiff = Xpos - Width
LeftMove.setDRot(0,(XDiff/Own.move/2),0,1)
addActiveActuator(LeftMove,1)

# Mouse going up
if (Ypos < Height):
# Move up
YDiff = Ypos - Height
UpMove.setDRot((YDiff/Own.move/2),0,0,1)
addActiveActuator(UpMove,1)

# Mouse going down
if (Ypos > Height):
# Move down
YDiff = Ypos - Height
DownMove.setDRot((YDiff/Own.move/2),0,0,1)
addActiveActuator(DownMove,1)



# Shut off all actuator movements
addActiveActuator(LeftMove,0)
addActiveActuator(DownMove,0)
addActiveActuator(RightMove,0)
addActiveActuator(UpMove,0)

# Set the mouse to the center of the game screen
setMousePosition(Width,Height)
Reply with quote


xintoc

Posted: Wed Oct 30, 2002 11:31 am
Joined: 29 Oct 2002
Posts: 18
Or this python:

from GameLogic import *
from Rasterizer import *

Cont = getCurrentController()
Own = Cont.getOwner()
Sens = Cont.getSensors()
Sensor = Sens[0]

Height = getWindowHeight()/2
Width = getWindowWidth()/2

# get current mouse position
Xpos = Sensor.getXPosition()
Ypos = Sensor.getYPosition()

# get actuators
RightMove = Cont.getActuator("Rechts")
LeftMove = Cont.getActuator("Links")
UpMove = Cont.getActuator("Auf")
DownMove = Cont.getActuator("Ab")


# check positions relative to old position
# Mouse going right
if (Xpos > Width):
# Move right
XDiff = Xpos - Width
RightMove.setDRot(0,0,(XDiff /Own.move),1)
addActiveActuator(RightMove,1)

# Mouse going left
if (Xpos < Width):
# Move left
XDiff = Xpos - Width
LeftMove.setDRot(0,0,(XDiff/Own.move),1)
addActiveActuator(LeftMove,1)

# Mouse going up
if (Ypos < Height):
# Move up
YDiff = Ypos - Height
UpMove.setDRot((YDiff/Own.move),0,0,1)
addActiveActuator(UpMove,1)

# Mouse going down
if (Ypos > Height):
# Move down
YDiff = Ypos - Height
DownMove.setDRot((YDiff/Own.move),0,0,1)
addActiveActuator(DownMove,1)



# Shut off all actuator movements
addActiveActuator(LeftMove,0)
addActiveActuator(DownMove,0)
addActiveActuator(RightMove,0)
addActiveActuator(UpMove,0)

# Set the mouse to the center of the game screen
setMousePosition(Width,Height)

Last edited by xintoc on Wed Oct 30, 2002 11:34 am; edited 1 time in total
Reply with quote


xintoc

Posted: Wed Oct 30, 2002 11:33 am
Joined: 29 Oct 2002
Posts: 18
Code:
from GameLogic import *
from Rasterizer import *

Cont = getCurrentController()
Own = Cont.getOwner()
Sens = Cont.getSensors()
Sensor = Sens[0]

Height = getWindowHeight()/2
Width = getWindowWidth()/2

# get current mouse position
Xpos = Sensor.getXPosition()
Ypos = Sensor.getYPosition()

# get actuators
RightMove = Cont.getActuator("Rechts")
LeftMove = Cont.getActuator("Links")
UpMove = Cont.getActuator("Auf")
DownMove = Cont.getActuator("Ab")


# check positions relative to old position
# Mouse going right
if (Xpos > Width):
   # Move right
   XDiff = Xpos - Width
   RightMove.setDRot(0,0,(XDiff /Own.move),1)
   addActiveActuator(RightMove,1)

# Mouse going left
if (Xpos < Width):
   # Move left
   XDiff = Xpos - Width
   LeftMove.setDRot(0,0,(XDiff/Own.move),1)
   addActiveActuator(LeftMove,1)

# Mouse going up
if (Ypos < Height):
   # Move up
   YDiff = Ypos - Height
   UpMove.setDRot((YDiff/Own.move),0,0,1)
   addActiveActuator(UpMove,1)

# Mouse going down
if (Ypos > Height):
   # Move down
   YDiff = Ypos - Height
   DownMove.setDRot((YDiff/Own.move),0,0,1)
   addActiveActuator(DownMove,1)



# Shut off all actuator movements
addActiveActuator(LeftMove,0)
addActiveActuator(DownMove,0)
addActiveActuator(RightMove,0)
addActiveActuator(UpMove,0)

# Set the mouse to the center of the game screen
setMousePosition(Width,Height)
Reply with quote


 
Jump to:  
Powered by phpBB © 2001, 2005 phpBB Group