The BGE Documentation

The BGE Documentation Team APOCALYPSE Guest Book Chinu3d 3D-pics Apocalypse screenshots Blog My Files Hot Stuff ! Scholar Rinascita

Exclusively for team APOCALYPSE...

These are some of the key resources for starting game programming in the BGE.

1. The gamekeys module:

   Home   

   Trees   

   Index   

   Help   

 

Module GameKeys

[frames | no frames]

Module GameKeys

Documentation for the GameKeys module.

This module holds key constants for the SCA_KeyboardSensor.

Alphabet keys

  • AKEY
  • BKEY
  • CKEY
  • DKEY
  • EKEY
  • FKEY
  • GKEY
  • HKEY
  • IKEY
  • JKEY
  • KKEY
  • LKEY
  • MKEY
  • NKEY
  • OKEY
  • PKEY
  • QKEY
  • RKEY
  • SKEY
  • TKEY
  • UKEY
  • VKEY
  • WKEY
  • XKEY
  • YKEY
  • ZKEY

Number keys

  • ZEROKEY
  • ONEKEY
  • TWOKEY
  • THREEKEY
  • FOURKEY
  • FIVEKEY
  • SIXKEY
  • SEVENKEY
  • EIGHTKEY
  • NINEKEY

Shift Modifiers

  • CAPSLOCKKEY
  • LEFTCTRLKEY
  • LEFTALTKEY
  • RIGHTALTKEY
  • RIGHTCTRLKEY
  • RIGHTSHIFTKEY
  • LEFTSHIFTKEY

Arrow Keys

  • LEFTARROWKEY
  • DOWNARROWKEY
  • RIGHTARROWKEY
  • UPARROWKEY

Numberpad Keys

  • PAD0
  • PAD1
  • PAD2
  • PAD3
  • PAD4
  • PAD5
  • PAD6
  • PAD7
  • PAD8
  • PAD9
  • PADPERIOD
  • PADSLASHKEY
  • PADASTERKEY
  • PADMINUS
  • PADENTER
  • PADPLUSKEY

Function Keys

  • F1KEY
  • F2KEY
  • F3KEY
  • F4KEY
  • F5KEY
  • F6KEY
  • F7KEY
  • F8KEY
  • F9KEY
  • F10KEY
  • F11KEY
  • F12KEY

Other Keys

  • ACCENTGRAVEKEY
  • BACKSLASHKEY
  • BACKSPACEKEY
  • COMMAKEY
  • DELKEY
  • ENDKEY
  • EQUALKEY
  • ESCKEY
  • HOMEKEY
  • INSERTKEY
  • LEFTBRACKETKEY
  • LINEFEEDKEY
  • MINUSKEY
  • PAGEDOWNKEY
  • PAGEUPKEY
  • PAUSEKEY
  • PERIODKEY
  • QUOTEKEY
  • RIGHTBRACKETKEY
  • RETKEY
  • SEMICOLONKEY
  • SLASHKEY
  • SPACEKEY
  • TABKEY

Example:

       # Set a connected keyboard sensor to accept F1
       import GameLogic
       import GameKeys
       
       co = GameLogic.getCurrentController()
       # 'Keyboard' is a keyboard sensor
       sensor = co.getSensor('Keyboard')
       sensor.setKey(GameKeys.F1KEY)

Example:

       # Do the all keys thing
       import GameLogic
       import GameKeys
 
       # status: these should be added to a module somewhere
       KX_NO_INPUTSTATUS = 0
       KX_JUSTACTIVATED = 1
       KX_ACTIVE = 2
       KX_JUSTRELEASED = 3
               
       co = GameLogic.getCurrentController()
       # 'Keyboard' is a keyboard sensor
       sensor = co.getSensor('Keyboard')
       keylist = sensor.getPressedKeys()
       for key in keylist:
               # key[0] == GameKeys.keycode, key[1] = status
               if key[1] == KX_JUSTACTIVATED:
                       if key[0] == GameKeys.WKEY:
                               # Activate Forward!
                       if key[0] == GameKeys.SKEY:
                               # Activate Backward!
                       if key[0] == GameKeys.AKEY:
                               # Activate Left!
                       if key[0] == GameKeys.DKEY:
                               # Activate Right!

   Home   

   Trees   

   Index   

   Help   

 

Generated by Epydoc 2.1 on Fri Aug 27 21:08:02 2004

http://epydoc.sf.net

 

 

2. The gamelogic module:

 

   Home   

   Trees   

   Index   

   Help   

 

Module GameLogic

[frames | no frames]

Module GameLogic

Documentation for the GameLogic Module.

There are only three importable modules in the game engine:

All the other modules are accessible through the methods in GameLogic.

See WhatsNew for updates, changes and new functionality in the Game Engine Python API.

Examples:

       # To get a controller:
       import GameLogic
       co = GameLogic.getCurrentController()
       
       # To get the game object associated with this controller:
       obj = co.getOwner()

KX_GameObject and KX_Camera or KX_Light methods are available depending on the type of object:

       # To get a sensor linked to this controller.
       # "sensorname" is the name of the sensor as defined in the Blender interface.
       # +---------------------+  +--------+
       # | Sensor "sensorname" +--+ Python +
       # +---------------------+  +--------+
       sens = co.getSensor("sensorname")
 
       # To get a list of all sensors:
       sensors = co.getSensors()

See the sensor's reference for available methods:

You can also access actuators linked to the controller:

       # To get an actuator attached to the controller:
       #                          +--------+  +-------------------------+
       #                          + Python +--+ Actuator "actuatorname" |
       #                          +--------+  +-------------------------+
       actuator = co.getActuator("actuatorname")
       
       # Activate an actuator
       GameLogic.addActiveActuator(actuator, True)

See the actuator's reference for available methods:

There are also methods to access the current KX_Scene:

       # Get the current scene
       scene = GameLogic.getCurrentScene()
       
       # Get the current camera
       cam = scene.active_camera

Matricies as used by the game engine are row major:

       matrix[row][col] = blah

KX_Camera has some examples using matricies.


Function Summary

 

addActiveActuator(actuator, activate)
Activates the given actuator.

SCA_PythonController

getCurrentController()
Gets the Python controller associated with this Python script.

KX_Scene

getCurrentScene()
Gets the current Scene.

 

getRandomFloat()
Returns a random floating point value in the range [0...1)

list [float], len(getSpectrum()) == 512

getSpectrum()
Returns a 512 point list from the sound card.

 

setGravity(gravity)
Sets the world gravity.

 

stopDSP()
Stops the sound driver using DSP effects.



Variable Summary

 

KKX_SOUNDACT_LOOPSTOP: See KX_SoundActuator

    Constants

 

KX_TRUE: True value used by some modules.

 

KX_FALSE: False value used by some modules.

    Property Sensor

 

KX_PROPSENSOR_EQUAL: Activate when the property is equal to the sensor value.

 

KX_PROPSENSOR_NOTEQUAL: Activate when the property is not equal to the sensor value.

 

KX_PROPSENSOR_INTERVAL: Activate when the property is between the specified limits.

 

KX_PROPSENSOR_CHANGED: Activate when the property changes

 

KX_PROPSENSOR_EXPRESSION: Activate when the expression matches

    Constraint Actuator

 

KX_CONSTRAINTACT_LOCX: See KX_ConstraintActuator

 

KX_CONSTRAINTACT_LOCY: See KX_ConstraintActuator

 

KX_CONSTRAINTACT_LOCZ: See KX_ConstraintActuator

 

KX_CONSTRAINTACT_ROTX: See KX_ConstraintActuator

 

KX_CONSTRAINTACT_ROTY: See KX_ConstraintActuator

 

KX_CONSTRAINTACT_ROTZ: See KX_ConstraintActuator

    IPO Actuator

 

KX_IPOACT_PLAY: See KX_IpoActuator

 

KX_IPOACT_PINGPONG: See KX_IpoActuator

 

KX_IPOACT_FLIPPER: See KX_IpoActuator

 

KX_IPOACT_LOOPSTOP: See KX_IpoActuator

 

KX_IPOACT_LOOPEND: See KX_IpoActuator

    Random Distributions

 

KX_RANDOMACT_BOOL_CONST: See SCA_RandomActuator

 

KX_RANDOMACT_BOOL_UNIFORM: See SCA_RandomActuator

 

KX_RANDOMACT_BOOL_BERNOUILLI: See SCA_RandomActuator

 

KX_RANDOMACT_INT_CONST: See SCA_RandomActuator

 

KX_RANDOMACT_INT_UNIFORM: See SCA_RandomActuator

 

KX_RANDOMACT_INT_POISSON: See SCA_RandomActuator

 

KX_RANDOMACT_FLOAT_CONST: See SCA_RandomActuator

 

KX_RANDOMACT_FLOAT_UNIFORM: See SCA_RandomActuator

 

KX_RANDOMACT_FLOAT_NORMAL: See SCA_RandomActuator

 

KX_RANDOMACT_FLOAT_NEGATIVE_EXPONENTIAL: See SCA_RandomActuator

    Action Actuator

 

KX_ACTIONACT_PLAY: See BL_ActionActuator

 

KX_ACTIONACT_FLIPPER: See BL_ActionActuator

 

KX_ACTIONACT_LOOPSTOP: See BL_ActionActuator

 

KX_ACTIONACT_LOOPEND: See BL_ActionActuator

 

KX_ACTIONACT_PROPERTY: See BL_ActionActuator

    Sound Actuator

 

KX_SOUNDACT_PLAYSTOP: See KX_SoundActuator

 

KX_SOUNDACT_PLAYEND: See KX_SoundActuator

 

KX_SOUNDACT_LOOPEND: See KX_SoundActuator

 

KX_SOUNDACT_LOOPBIDIRECTIONAL: See KX_SoundActuator

 

KX_SOUNDACT_LOOPBIDIRECTIONAL_STOP: See KX_SoundActuator



Function Details

 

addActiveActuator(actuator, activate)

Activates the given actuator.

Parameters:

actuator
           (type=SCA_IActuator)

activate - whether to activate or deactivate the given actuator.
           (type=boolean)

 

getCurrentController()

Gets the Python controller associated with this Python script.

Returns:

SCA_PythonController

 

getCurrentScene()

Gets the current Scene.

Returns:

KX_Scene

 

getRandomFloat()

Returns a random floating point value in the range [0...1)

 

getSpectrum()

Returns a 512 point list from the sound card. This only works if the fmod sound driver is being used.

Returns:

list [float], len(getSpectrum()) == 512

 

setGravity(gravity)

Sets the world gravity.

Parameters:

gravity
           (type=list [fx, fy, fz])

 

stopDSP()

Stops the sound driver using DSP effects.

Only the fmod sound driver supports this. DSP can be computationally expensive.



Variable Details

 

KX_TRUE

True value used by some modules.

 

KX_FALSE

False value used by some modules.

 

KX_PROPSENSOR_EQUAL

Activate when the property is equal to the sensor value.

 

KX_PROPSENSOR_NOTEQUAL

Activate when the property is not equal to the sensor value.

 

KX_PROPSENSOR_INTERVAL

Activate when the property is between the specified limits.

 

KX_PROPSENSOR_CHANGED

Activate when the property changes

 

KX_PROPSENSOR_EXPRESSION

Activate when the expression matches

 

KX_CONSTRAINTACT_LOCX

See KX_ConstraintActuator

 

KX_CONSTRAINTACT_LOCY

See KX_ConstraintActuator

 

KX_CONSTRAINTACT_LOCZ

See KX_ConstraintActuator

 

KX_CONSTRAINTACT_ROTX

See KX_ConstraintActuator

 

KX_CONSTRAINTACT_ROTY

See KX_ConstraintActuator

 

KX_CONSTRAINTACT_ROTZ

See KX_ConstraintActuator

 

KX_IPOACT_PLAY

See KX_IpoActuator

 

KX_IPOACT_PINGPONG

See KX_IpoActuator

 

KX_IPOACT_FLIPPER

See KX_IpoActuator

 

KX_IPOACT_LOOPSTOP

See KX_IpoActuator

 

KX_IPOACT_LOOPEND

See KX_IpoActuator

 

KX_RANDOMACT_BOOL_CONST

See SCA_RandomActuator

 

KX_RANDOMACT_BOOL_UNIFORM

See SCA_RandomActuator

 

KX_RANDOMACT_BOOL_BERNOUILLI

See SCA_RandomActuator

 

KX_RANDOMACT_INT_CONST

See SCA_RandomActuator

 

KX_RANDOMACT_INT_UNIFORM

See SCA_RandomActuator

 

KX_RANDOMACT_INT_POISSON

See SCA_RandomActuator

 

KX_RANDOMACT_FLOAT_CONST

See SCA_RandomActuator

 

KX_RANDOMACT_FLOAT_UNIFORM

See SCA_RandomActuator

 

KX_RANDOMACT_FLOAT_NORMAL

See SCA_RandomActuator

 

KX_RANDOMACT_FLOAT_NEGATIVE_EXPONENTIAL

See SCA_RandomActuator

 

KX_ACTIONACT_PLAY

See BL_ActionActuator

 

KX_ACTIONACT_FLIPPER

See BL_ActionActuator

 

KX_ACTIONACT_LOOPSTOP

See BL_ActionActuator

 

KX_ACTIONACT_LOOPEND

See BL_ActionActuator

 

KX_ACTIONACT_PROPERTY

See BL_ActionActuator

 

KX_SOUNDACT_PLAYSTOP

See KX_SoundActuator

 

KX_SOUNDACT_PLAYEND

See KX_SoundActuator

 

KX_SOUNDACT_LOOPEND

See KX_SoundActuator

 

KX_SOUNDACT_LOOPBIDIRECTIONAL

See KX_SoundActuator

 

KX_SOUNDACT_LOOPBIDIRECTIONAL_STOP

See KX_SoundActuator

 

KKX_SOUNDACT_LOOPSTOP

See KX_SoundActuator



   Home   

   Trees   

   Index   

   Help   

 

Generated by Epydoc 2.1 on Fri Aug 27 21:08:03 2004

http://epydoc.sf.net

 

 

 

 

3. The rasterizer module: 

 

 

   Home   

   Trees   

   Index   

   Help   

 

Module Rasterizer

[frames | no frames]

Module Rasterizer

Documentation for the Rasterizer module.

Example Uses an SCA_MouseSensor, and two KX_ObjectActuators to implement MouseLook:

       # To use a mouse movement sensor "Mouse" and a 
       # motion actuator to mouse look:
       import Rasterizer
       import GameLogic
 
       # SCALE sets the speed of motion
       SCALE=[1, 0.5]
       
       co = GameLogic.getCurrentController()
       obj = co.getOwner()
       mouse = co.getSensor("Mouse")
       lmotion = co.getActuator("LMove")
       wmotion = co.getActuator("WMove")
       
       # Transform the mouse coordinates to see how far the mouse has moved.
       def mousePos():
               x = (Rasterizer.getWindowWidth()/2 - mouse.getXPosition())*SCALE[0]
               y = (Rasterizer.getWindowHeight()/2 - mouse.getYPosition())*SCALE[1]
               return (x, y)
       
       pos = mousePos()
       
       # Set the amount of motion: X is applied in world coordinates...
       lmotion.setTorque(0.0, 0.0, pos[0], False)
       # ...Y is applied in local coordinates
       wmotion.setTorque(-pos[1], 0.0, 0.0, True)
       
       # Activate both actuators
       GameLogic.addActiveActuator(lmotion, True)
       GameLogic.addActiveActuator(wmotion, True)
       
       # Centre the mouse
       Rasterizer.setMousePosition(Rasterizer.getWindowWidth()/2, Rasterizer.getWindowHeight()/2)

Function Summary

 

enableVisibility(visible)
Doesn't really do anything...

integer

getWindowHeight()
Gets the height of the window (in pixels)

integer

getWindowWidth()
Gets the width of the window (in pixels)

 

makeScreenshot(filename)
Writes a screenshot to the given filename.

 

setBackgroundColor(rgba)
Sets the window background colour.

 

setMistColor(rgb)
Sets the mist colour.

 

setMistEnd(end)
Sets the mist end value.

 

setMistStart(start)
Sets the mist start value.

 

setMousePosition(x, y)
Sets the mouse cursor position.

 

showMouse(visible)
Enables or disables the operating system mouse cursor.



Function Details

 

enableVisibility(visible)

Doesn't really do anything...

 

getWindowHeight()

Gets the height of the window (in pixels)

Returns:

integer

 

getWindowWidth()

Gets the width of the window (in pixels)

Returns:

integer

 

makeScreenshot(filename)

Writes a screenshot to the given filename.

Parameters:

filename
           (type=string)

 

setBackgroundColor(rgba)

Sets the window background colour.

Parameters:

rgba
           (type=list [r, g, b, a])

 

setMistColor(rgb)

Sets the mist colour.

Parameters:

rgb
           (type=list [r, g, b])

 

setMistEnd(end)

Sets the mist end value. Objects further away from this will be coloured solid with the colour set by setMistColor().

Parameters:

end
           (type=float)

 

setMistStart(start)

Sets the mist start value. Objects further away than start will have mist applied to them.

Parameters:

start
           (type=float)

 

setMousePosition(x, y)

Sets the mouse cursor position.

Parameters:

x
           (type=integer)

y
           (type=integer)

 

showMouse(visible)

Enables or disables the operating system mouse cursor.

Parameters:

visible
           (type=boolean)



   Home   

   Trees   

   Index   

   Help   

 

Generated by Epydoc 2.1 on Fri Aug 27 21:08:01 2004

http://epydoc.sf.net