Skip to content

Commit

Permalink
start moving to a more OOP paradigm
Browse files Browse the repository at this point in the history
  • Loading branch information
gandalf3 committed Dec 20, 2015
1 parent 45712ed commit b8763ed
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 2 deletions.
Binary file modified lonely_photon.blend
Binary file not shown.
71 changes: 71 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
from bge import logic, types
import utils

class Sentry(types.KX_GameObject):

def __init__(self, own):
self.cont = self.controllers[0]
# scene = logic.getCurrentScene()

self.target = self.scene.objects["player"]

self.fireRate = .1
self.range = 8

if not self.get("projectile", 0):
self.projectile_type = "standard_projectile"
else:
self.projectile_type = self["projectile"]

print(self.name, "using", self.projectile_type)

self.firenow = 0



def aim(self):

hit = self.rayCast(self.target, self, 0.0, "solid", 0, 1, 0)
if hit[0] == self.target:
self["cansee"] = True
self.alignAxisToVect(hit[2], 0, 1)
else:
self["cansee"] = False

return



def fire(self):

print("pow")
projectile = self.scene.addObject(self.projectile_type, self, 0)
projectile.worldOrientation = self.worldOrientation
projectile.setLinearVelocity((-20, 0, 0), True)

self.firenow = 0



def main(self):
self.aim()

print(self.firenow*logic.getTimeScale())
if self.firenow*logic.getTimeScale() >= 1:
self.fire()

self.firenow += 1*self.fireRate



class Projectile(types.KX_GameObject):

light_source = "standard_projectile_lamp"

def __init__(self, own):
self.cont = self.controllers[0]

self.light = self.scene.addObject(light_source)
self.light.setParent(self,0,0)


4 changes: 3 additions & 1 deletion player.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
import aud

sound = aud.Factory.file(logic.expandPath("//sound/Adventure Meme.mp3")).volume(.1).loop(-1)
music = aud.device().play(sound)
#music = aud.device().play(sound)

scene = logic.getCurrentScene()



def movement(movement_speed):
cont = logic.getCurrentController()
own = cont.owner
Expand Down
13 changes: 12 additions & 1 deletion sentry.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from bge import logic
from main import Sentry
import random
import math
import aud
import utils

laser_sound = aud.Factory.file(logic.expandPath("//sound/laser/laserfire01.ogg")).volume(.5)
laser_sound = aud.Factory.file(logic.expandPath("//sound/laser/laserfire01.ogg")).volume(.5).fadeout(0, .4)


def search():
Expand Down Expand Up @@ -42,3 +43,13 @@ def fire(direction):
projectile["sound_handler"] = aud.device().play(laser_sound)
if projectile.get("sound_handler", 0):
projectile["sound_handler"].pitch = logic.getTimeScale()

def main(cont):
own = cont.owner

if not "init" in own:
own["init"] = True
print("setup")
own = Sentry(own)

own.main()

0 comments on commit b8763ed

Please sign in to comment.