Hello,
First of all i didnt know where to place this so i hope i am at the right location here.
Ok my problem, i am following a tutorial for basic movement/schooting/hitting things.
(its called: Introduction to Scripting in the Blender Game Engine - part 2 )
Its as simple as the video everything is correct but i cant get the color to work.
i can move it, shoot balls, move object when pushing it, all things works exept the color and the hp part (when hp is low, color of the object change).
Can anyone help me out with this?
Here is the script:
obstacleScript
import bge
def main():
cont = bge.logic.getCurrentController()
obstacle = cont.owner
keyboard = bge.logic.keyboard
scene = bge.logic.getCurrentScene()
if 'hp' not in obstacle:
start(obstacle)
obstacle.color = (1, obstacle['hp'], obstacle['hp'], 1)
if obstacle['hp'] <= 0:
die(obstacle, scene)
def start(obstacle):
obstacle['hp'] = 1
def die(obstacle, scene):
#expl = scene.addObject("ExplosionSound", obstacle.name, 60)
#expl.actuators["Sound"].startSound()
obstacle.endObject()
main()
playerScript
import bge
def main():
cont = bge.logic.getCurrentController()
poppetje = cont.owner
keyboard = bge.logic.keyboard
scene = bge.logic.getCurrentScene()
Movspeed = 0.08
Rotspeed = 0.08
kogelsnelheid = 1000
if bge.logic.KX_INPUT_ACTIVE == keyboard.events[bge.events.UPARROWKEY]:
#vooruit
poppetje.applyMovement((0, Movspeed, 0), True)
if bge.logic.KX_INPUT_ACTIVE == keyboard.events[bge.events.DOWNARROWKEY]:
#Achteruit
poppetje.applyMovement((0, -Movspeed, 0), True)
if bge.logic.KX_INPUT_ACTIVE == keyboard.events[bge.events.LEFTARROWKEY]:
#links
poppetje.applyRotation((0, 0, Rotspeed), True)
if bge.logic.KX_INPUT_ACTIVE == keyboard.events[bge.events.RIGHTARROWKEY]:
#Rechts
poppetje.applyRotation((0, 0, -Rotspeed), True)
if bge.logic.KX_INPUT_ACTIVE == keyboard.events[bge.events.SPACEKEY]:
#omhoog
poppetje.applyMovement((0, 0, 0.1), True)
#kogel afschieten
if bge.logic.KX_INPUT_JUST_ACTIVATED == keyboard.events[bge.events.LEFTCTRLKEY]:
kogel = scene.addObject("kogel", "kogellocatie", 240)
kogel.applyForce ((0, kogelsnelheid, 0), True)
kogel.color = (1, 0, 0, 1)
main()
bulletscript
import bge
def main():
cont = bge.logic.getCurrentController()
kogel = cont.owner
keyboard = bge.logic.keyboard
scene = bge.logic.getCurrentScene()
touch = cont.sensors['Touch']
hit = touch.positive
damage = 0.4
if 'active' not in kogel:
start(kogel)
if hit and kogel['active'] == True:
print(touch.hitObject.name)
kogel['active'] = False
kogel.color = (1, 1, 1, 1)
touch.hitObject['hp'] -= damage
def start(kogel):
kogel['active'] = True
main()