diff --git a/player.py b/player.py new file mode 100644 index 0000000..5cac245 --- /dev/null +++ b/player.py @@ -0,0 +1,48 @@ +from bge import logic, events +import utils + + +def movement(movement_speed): + cont = logic.getCurrentController() + own = cont.owner + + keyboard = logic.keyboard + ACTIVE = logic.KX_INPUT_ACTIVE + + movement = own.getLinearVelocity() + + # forward + if keyboard.events[events.WKEY] == ACTIVE: + movement[1] = movement_speed + + # backward + if keyboard.events[events.SKEY] == ACTIVE: + movement[1] = -movement_speed + + # left + if keyboard.events[events.AKEY] == ACTIVE: + movement[0] = -movement_speed + + # right + if keyboard.events[events.DKEY] == ACTIVE: + movement[0] = movement_speed + + own.setLinearVelocity(movement) + +def main(): + cont = logic.getCurrentController() + own = cont.owner + + movement_speed = 20 + + velocity = own.getLinearVelocity() + speed = utils.velocity2speed(velocity) + timescale = utils.clamp(speed/movement_speed, .05, 1) + + own['timescale'] = timescale + own['speed'] = speed + if timescale != logic.getTimeScale(): + logic.setTimeScale(timescale) + + movement(movement_speed) + \ No newline at end of file diff --git a/sentry.py b/sentry.py new file mode 100644 index 0000000..29c3c54 --- /dev/null +++ b/sentry.py @@ -0,0 +1,29 @@ +from bge import logic +from random import random + +def search(): + cont = logic.getCurrentController() + own = cont.owner + + scene = logic.getCurrentScene() + target = scene.objects["player"] + + hit = own.rayCast(target, own, 0.0, "player", 0, 0, 0) + + print(hit) + if hit != (None, None, None): + own["cansee"] = True + if random() < .1: + fire(hit[2]) + else: + own["cansee"] = False + +def fire(direction): + cont = logic.getCurrentController() + own = cont.owner + + scene = logic.getCurrentScene() + + projectile = scene.addObject("standard_projectile", own, 0) + projectile.worldOrientation = direction + projectile.setLinearVelocity((5, 0, 0), True) \ No newline at end of file diff --git a/utils.py b/utils.py new file mode 100644 index 0000000..5fb8b22 --- /dev/null +++ b/utils.py @@ -0,0 +1,9 @@ + +def clamp(value, min_value=0, max_value=1): + return max(min(value, max_value), min_value) + +def velocity2speed(velocity): + speed = 0 + for i in velocity: + speed += abs(i) + return speed \ No newline at end of file