Пример #1
0
def shooter():
    strategyKey = StrategyKey()

    cont = bge.logic.getCurrentController()
    own = cont.owner

    scene = logic.getCurrentScene()
    gun = None
    gunPlayer = None
    # gun = scene.objects["AK.004"]
    for gobj in scene.objects:
        if gobj.name == "ClientGun":
            gun = gobj
        elif gobj.name == "Lowpoly..002":
            gunPlayer = gobj

        elif gobj.name == "player1":
            orientationPlayer = gobj

        elif gobj.name == "character":
            orientation = gobj

        elif gobj.name == "player_mesh_basic_Client":
            healthMonitor = gobj

    if gun:
        keyPressed = strategyKey.keyDown

        fireCommand = FireCommand(gun)
        aimCommand = AimCommand(gun)

        target = getThreat(scene, gun)
        hud(healthMonitor["healt"], gun)
        endGame(healthMonitor["healt"])
        # print(orientation.health)

        if keyPressed(events.SPACEKEY):
            fireCommand.execute()

        if target:
            aimCommand.execute(target.worldPosition)

        else:
            gun.worldOrientation = orientation.worldOrientation
            # pass
            # fix aim

    if gunPlayer:
        # keyPressed = strategyKey.keyDown

        fireCommand = FireCommand(gunPlayer)
        aimCommand = AimCommand(gunPlayer)

        target = getThreat(scene, gunPlayer)

        if target:
            fireCommand.execute()
            aimCommand.execute(target.worldPosition)
        else:
            gunPlayer.worldOrientation = orientationPlayer.worldOrientation
Пример #2
0
def enemyShooter():
    #strategyKey = StrategyKey()
    
    cont = bge.logic.getCurrentController()
    own = cont.owner
    
    scene = logic.getCurrentScene()
    gun = None
    guns = list()
    #gun = scene.objects["AK.004"]
    for gobj in scene.objects:
            if "AK" in gobj.name:
                #print(gobj.name)                
                guns.append(gobj) 
    
    if guns:
        #keyPressed = strategyKey.keyDown
        for gun in guns:
            fireCommand = FireCommand(gun)
            aimCommand = AimCommand(gun)
            
            target = getThreat(scene,gun)
                
            #if keyPressed(events.SPACEKEY):                                  
            if target:            
                aimCommand.execute(target.worldPosition)
                fireCommand.execute()
Пример #3
0
class Enemy(base.Hope):
    
    def __init__(self, own):
        super().__init__(own)
        
        self.sen = self.cont.sensors
        self.action = self.cont.actuators
        
        self.sense_range = 20
        self.target = None                               
        
        for child in self.children:
            if "AK" in child.name:
                self.weapon = child
            elif "enemy_armature" in child.name:
                self.arm = child
        
        #for child in self.children:
            #if "enemy_armature" in child.name:
                #self.arm = child
                
        self.fireCommand = FireCommand(self.weapon)
        self.aimCommand = AimCommand(self.weapon) 
        
    def getThreat(self):
        
        for gobj in self.scene.objects:
            if "player" in gobj.name:
                delta = gobj.worldPosition - self.worldPosition
                if delta.magnitude < self.sense_range:                    
                    return gobj
    
    def rotation(self):
        self.target = self.getThreat()
        AI = self.action["path"]
        
        if self.target:
            self.aimAt(self.target.worldPosition)
            self.aimCommand.execute(self.target.worldPosition)
            self.fireCommand.execute()
            AI.target = self.target.name 
            self.cont.activate(AI)
                  
        else:
            newTarget = self.getThreat()
            
    def collision(self):
        
        sound = self.action["Sound"]
        self.health = self.arm.children[0]["healt"]
        
        if(self.health <= 50):
            self.cont.activate(sound)
            
        if(self.health<0):
            print("Enemy dead")
            
            #wait time
            self.endObject()#cont.activate(death)
Пример #4
0
class Player(base.Hope):
    def __init__(self, own):
        
        super().__init__(own)        
        self.sen = self.cont.sensors
        self.action = self.cont.actuators
        
        self.sense_range = 25
        self.enemy = None
        
        self.weapon = self.children[1]
        
        self.fireCommand = FireCommand(self.weapon)
        self.aimCommand = AimCommand(self.weapon)
        
        for child in self.children:
            if "player_armature" in child.name:
                self.arm = child
        
        #animation = self.arm.actuators["Action"]        
        #print(self.arm.children[0]["healt"])
        
        
        #self.hud()
        #self.weapon.range = 25
        #self.user = self["user"]
        
    def movement(self):
        keyPressed = strategyKey.keyDown                               
            
        if keyPressed(events.WKEY):
            speed = 0.4
            movement = Vector((0,speed,0))
            #self.arm.controller[0].activate(animation)
            self.applyMovement(movement, True)
            
        elif keyPressed(events.SKEY):            
            movement = Vector((0,-self.speed,0))
            self.applyMovement(movement, True)                                                       
        else:
            pass
        
    def straif(self):
        keyPressed = strategyKey.keyDown
        if keyPressed(events.QKEY):            
            rotation = Vector((-self.speed,0,0))           
            self.applyMovement(rotation, True)    
            
        elif keyPressed(events.EKEY):
            rotation = Vector((self.speed,0,0))
            self.applyMovement(rotation, True) 
        
    def rotation(self):
        keyPressed = strategyKey.keyDown                
        #playerCam = logic.getCurrentScene().objects['Camera']
    
        if keyPressed(events.AKEY):
            rotation = Vector((0,0,0.1))
            self.applyRotation(rotation, True)
                        
        elif keyPressed(events.DKEY):
            rotation = Vector((0,0,-0.1))
            self.applyRotation(rotation, True)
                                  
    
    def shooting(self):
        keyPressed = strategyKey.keyDown
        
        if keyPressed(events.SPACEKEY):
            self.fireCommand.execute()
    
    def reload(self):
        keyPressed = strategyKey.keyDown
        if keyPressed(events.RKEY):
            timer = Timer(2, self.weapon.reload)
            #print("Reloading")
            timer.start()
            
        #pass
        #keyPressed = strategyKey.keyDown
        # impliment weapon switch                        
                
    def hurting(self):
        keyPressed = strategyKey.keyTouch
        self.health = self.arm.children[0]["healt"] 
        #self.health = self["healt"]
        
        if keyPressed(events.HKEY):
            #self.health = self.health - 50.0
            print(self.health)  
            
        if(self.health<0):
            #passp
            logic.restartGame()
            #pass
            #print("DEAD")   
            
    def hud(self):
        sceneList = logic.getSceneList()
        #displayAmmo = None
        #print(sceneList[1])
        try:
            if(sceneList):#.objects["Ammo.001"]
                displayAmmo = sceneList[1].objects["Ammo.001"]
                displayHealth = sceneList[1].objects["Health.001"]
                displayAmmo.text = str(self.weapon.ammo)
                displayHealth.text = str(self.health)            
        except:
            pass#print("No")        
        #print(displayAmmo)
        #pass
        
    def getThreat(self):
        #threats = list()
        
        for gobj in self.scene.objects:
            if "enemy_mesh" in gobj.name:
                delta = gobj.worldPosition - self.worldPosition
                if delta.magnitude < self.sense_range:                    
                    return gobj
                
    def aimAtEnemy(self):
        self.target = self.getThreat()
        
        if self.target:            
            self.aimCommand.execute(self.target.worldPosition)                        
        else:
            self.weapon.worldOrientation = self.worldOrientation               
Пример #5
0
class PlayerClient(base.Hope):
    def __init__(self,own):
        
        self.speed = 0.1
        self.user = self["user"]
        #self.weapon = self.children[0]
        
        for child in self.children:
            if "AK" in child.name:
                self.weapon = child
            elif "player_armature" in child.name:
                self.arm = child
        
        self.sense_range = 25
        self.enemy = None
        
        self.fireCommand = FireCommand(self.weapon)
        self.aimCommand = AimCommand(self.weapon)
        
    def movement(self):
        keyPressed = self.user.keyboard.keyDown            
        
        if keyPressed(events.WKEY):
            speed = 0.2
            movement = Vector((0,speed,0))
            #self.arm.controller[0].activate(animation)
            self.applyMovement(movement, True)
            
        elif keyPressed(events.SKEY):
            movement = Vector((0,-self.speed,0))
            self.applyMovement(movement, True)                                                       
        else:
            pass
        
    def straif(self):
        keyPressed = self.user.keyboard.keyDown
        if keyPressed(events.QKEY):
            rotation = Vector((-self.speed,0,0))           
            self.applyMovement(rotation, True)    
            
        elif keyPressed(events.EKEY):
            rotation = Vector((self.speed,0,0))
            self.applyMovement(rotation, True)
            
    def rotation(self):
        keyPressed = self.user.keyboard.keyDown                
        #playerCam = logic.getCurrentScene().objects['Camera']
    
        if keyPressed(events.AKEY):
            rotation = Vector((0,0,0.07))
            self.applyRotation(rotation, True)
                        
        elif keyPressed(events.DKEY):
            rotation = Vector((0,0,-0.07))
            self.applyRotation(rotation, True)
        
    def fire(self):
        keyPressed = self.user.keyboard.keyDown
        
        if keyPressed(events.SPACEKEY):
            self.fireCommand.execute()
            #self.weapon.fire()
            
    def getThreat(self):
        #threats = list()
        
        for gobj in self.scene.objects:
            if "enemy_mesh" in gobj.name:
                delta = gobj.worldPosition - self.worldPosition
                if delta.magnitude < self.sense_range:                    
                    return gobj
                
    def aimAtEnemy(self):
        self.target = self.getThreat()
        
        if self.target:            
            self.aimCommand.execute(self.target.worldPosition)                        
        else:
            self.weapon.worldOrientation = self.worldOrientation 
            
    def hurting(self):
        self.health = self.arm.children[0]["healt"] 
            
        if(self.health<-250):
            self.endObject()
            pass