Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Player Object Ref
- # http://www.blender.org/api/blender_python_api_2_65_release/bge.types.html#bge.types.KX_GameObject
- # More info
- # http://www.cgmasters.net/free-tutorials/python-scripting/
- import bge
- from mathutils import Vector
- import mytools
- import aud
- device = aud.device()
- sndPlrJump = aud.Factory.file(
- bge.logic.expandPath("//assets/music/smb_jump-small.wav"))
- p = bge.constraints.getCharacter('player_avatar')
- cont = bge.logic.getCurrentController()
- obj = cont.owner
- keyboard = bge.logic.keyboard
- INPUT_ACTIVATED = bge.logic.KX_INPUT_JUST_ACTIVATED
- INPUT_ACTIVE = bge.logic.KX_INPUT_ACTIVE
- INPUT_RELEASED = bge.logic.KX_INPUT_JUST_RELEASED
- INPUT_NONE = bge.logic.KX_INPUT_NONE
- # input status ref http://www.blender.org/api/blender_python_api_2_60_6/bge.logic.html
- if keyboard.events[bge.events.IKEY] == INPUT_ACTIVATED:
- print('Object', dir(p))
- print('onGround?', p.onGround)
- print('Gravity', p.gravity)
- print('health:', obj['health']) # works
- print('speed:', obj['speed'])
- if keyboard.events[bge.events.HKEY] == INPUT_ACTIVATED:
- # NOTE TO SELF
- # It may be more efficient to enable/disable the overlay scene
- # rather than each object in it. However, this is a good
- # learnign example for interacting with other scene objects.
- scene = mytools.getScene(bge.logic.getSceneList(), 'game_world_level_1')
- player_hud = mytools.getScene(bge.logic.getSceneList(), 'player_hud')
- # Example of getting a single objects from a scene
- # player_hud.objects['health_bar_1'].setVisible(toggleVisable())
- for obj in player_hud.objects:
- print(obj)
- obj.setVisible(mytools.toggleVisable(obj))
- if keyboard.events[bge.events.JKEY] == INPUT_ACTIVATED:
- scene = mytools.getScene(bge.logic.getSceneList(), 'game_world_level_1')
- player_hud = mytools.getScene(bge.logic.getSceneList(), 'player_hud')
- for obj in player_hud.objects:
- print(obj)
- obj.setVisible(mytools.toggleVisable(obj))
- sensor = cont.sensors["key_input"]
- for key,status in sensor.events:
- if status == bge.logic.KX_INPUT_JUST_ACTIVATED:
- if key == bge.events.DKEY:
- if p.walkDirection[0] < 0:
- p.walkDirection = obj.orientation*Vector((0.0, 0.0, 0.0))
- if p.walkDirection[0] < obj['maxSpeed']:
- p.walkDirection += obj.orientation*Vector((obj['speed'] , 0.0, 0.0))
- print('moving right', p.walkDirection[0])
- if key == bge.events.AKEY:
- if p.walkDirection[0] > 0:
- p.walkDirection = obj.orientation*Vector((0.0, 0.0, 0.0))
- if p.walkDirection[0] > -obj['maxSpeed']:
- p.walkDirection += obj.orientation*Vector((-obj['speed'] , 0.0, 0.0))
- print('moving left', p.walkDirection[0])
- if key == bge.events.SPACEKEY:
- print('moving jump')
- p.jump()
- sndPlrJump = sndPlrJump.pitch(1)
- device.play(sndPlrJump)
- #obj['health'] += -1
- if status == bge.logic.KX_INPUT_JUST_RELEASED:
- if key == bge.events.AKEY:
- if p.walkDirection[0] < 0:
- p.walkDirection = obj.orientation*Vector((0.0, 0.0, 0.0))
- if key == bge.events.DKEY:
- if p.walkDirection[0] > 0:
- p.walkDirection = obj.orientation*Vector((0.0, 0.0, 0.0))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement