Skip to content

Commit

Permalink
actually create external .py files ;)
Browse files Browse the repository at this point in the history
  • Loading branch information
gandalf3 committed Dec 18, 2015
1 parent 8069b25 commit 734808e
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 0 deletions.
48 changes: 48 additions & 0 deletions player.py
Original file line number Diff line number Diff line change
@@ -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)

29 changes: 29 additions & 0 deletions sentry.py
Original file line number Diff line number Diff line change
@@ -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)
9 changes: 9 additions & 0 deletions utils.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 734808e

Please sign in to comment.