-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
actually create external .py files ;)
- Loading branch information
Showing
3 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |