Exemple #1
0
def runBullet(cont):
	own = cont.owner
	collision = cont.sensors["Collision"]
	
	if collision.positive:
		
		if not "Damage" in own:
			own["Damage"] = DAMAGE_DEFAULT
		
		for obj in collision.hitObjectList:
			if "Life" in obj and obj["Life"] > 0 and own["Emitter"] != obj:
				obj["Life"] -= own["Damage"]
				if "Player" in obj:
					sound = bgf.playSfx("ShotHitMetal", buffer=True, is3D=True, refObj=obj, distMax=150)
					if sound is not None: sound.pitch = 1 + (random() * 0.5 - 0.25)
				else:
					blood = own.scene.addObject("BloodHit", own, 120)
					blood.worldPosition = obj.worldPosition
					# blood.localPosition.y += 3
					blood.localScale *= 2
					blood.alignAxisToVect(blood.getVectTo(own.scene.active_camera.worldPosition)[1], 2)
					sound = bgf.playSfx("ShotHit", buffer=True, is3D=True, refObj=obj, distMax=150)
					if sound is not None: sound.pitch = 1 + (random() * 0.5 - 0.25)
				
				own.endObject()
				return
Exemple #2
0
def runEnemy(cont):
    own = cont.owner
    always = cont.sensors["Always"]

    if always.status == bge.logic.KX_INPUT_JUST_ACTIVATED:
        own.childrenRecursive["Soldier"].replaceMesh("Soldier2")
        own.childrenRecursive["SoldierGun"].replaceMesh("AK47")

    if "Target" in own and own["Target"] is not None and not own[
            "Target"].invalid and own["Life"] > 0:
        if own.getDistanceTo(
                own["Target"]
        ) < ENEMY_FIRE_DISTANCE and own["FireTime"] > FIRE_TIME:
            own["FireTime"] = -FIRE_TIME
        if own["FireCooldown"] >= 0 and own["FireTime"] < 0:
            own["FireCooldown"] = -FIRE_COOLDOWN
            bullet = own.scene.addObject("HelicopterBullet", own,
                                         BULLET_LIFE_TIME)
            bullet["Emitter"] = own
            bullet.alignAxisToVect(
                bullet.getVectTo(own["Target"].worldPosition)[1], 1)
            bgf.playSfx("ShotHelicopter",
                        buffer=True,
                        is3D=True,
                        refObj=own,
                        distMax=SOUND_MAX_DISTANCE)
            own["Action"] = "Fire"

    processAnimation(cont, "Soldier", ANIMS=ANIMS)
    processTrack(cont)
    if own["FireTime"] > FIRE_TIME:
        processMovement(cont)
Exemple #3
0
def setPropsAlly(cont):
    own = cont.owner
    collision = cont.sensors["Collision"]
    ray = own.rayCast(own.worldPosition + Vector((0, 0, -1)), own, 1, "Ground")
    meshObj = own.childrenRecursive["Soldier"]
    meshGunObj = own.childrenRecursive["SoldierGun"]

    if collision.positive:
        if "Hostage" in collision.hitObject and not collision.hitObject["Free"]:
            collision.hitObject["Free"] = True
            bgf.playSfx("VoiceThankYou",
                        buffer=True,
                        is3D=True,
                        refObj=collision.hitObject,
                        distMax=SOUND_DISTANCE_MAX)

    if ray[0] is not None and not own["OnGround"]:
        own["OnGround"] = True
        meshObj.replaceMesh("Soldier1")
        meshGunObj.visible = True

    elif ray[0] is None and own["OnGround"]:
        own["OnGround"] = False
        meshObj.replaceMesh("SoldierParachute")
        meshGunObj.visible = False
Exemple #4
0
def runSoldier(cont):
    own = cont.owner
    always = cont.sensors["Always"]

    if always.positive:

        if always.status == bge.logic.KX_INPUT_JUST_ACTIVATED:
            pass

        if own.groupObject is not None:
            if "Enemy" in own.groupObject:
                own["Enemy"] = own.groupObject["Enemy"]

        if own["Life"] <= 0 and own[
                "Action"] != "Death" and not "VoiceDeath" in own:
            own["Action"] = "Death"
            if own["Enemy"]:
                globalDict["EnemiesKilled"] += 1
            own.sendMessage("UpdateText")
            own["VoiceDeath"] = bgf.playSfx("VoiceDeath",
                                            buffer=True,
                                            is3D=True,
                                            refObj=own,
                                            distMax=SOUND_DISTANCE_MAX)

        if own["Enemy"]:
            own["IsEnemy"] = True
            runEnemy(cont)

        else:
            own["IsAlly"] = True
            runAlly(cont)
Exemple #5
0
def runAlly(cont):
    own = cont.owner
    always = cont.sensors["Always"]

    if always.status == bge.logic.KX_INPUT_JUST_ACTIVATED:
        bgf.playSfx("VoiceYesSir",
                    buffer=True,
                    is3D=True,
                    refObj=own,
                    distMax=SOUND_DISTANCE_MAX)

    setPropsAlly(cont)

    if own["OnGround"]:
        processAnimation(cont, "Soldier", ANIMS=ANIMS)
        processTrack(cont)
        processMovement(cont)
Exemple #6
0
def widget(cont):
	
	own = cont.owner
	
	lmb = cont.sensors["LMB"]
	mouseOver = cont.sensors["MouseOver"]
	always = cont.sensors["Always"]
	
	if own.groupObject is None:
		own.endObject()
		return
		
	if always.status == 1:
		if own.parent is None:
			own.setParent(own.groupObject)
		
		if "Checkbox" in own:
			checkbox(cont, True)
	
	processProperties(cont)
	
	# Mouse over
	if mouseOver.positive and not lmb.positive:
		own.color = bgf.database["Gui"]["Widget"]["ColorHover"]
		bgf.playSfx("MouseHover", buffer=True)
	
	# Mouse not over
	if not mouseOver.positive and not lmb.positive:
		own.color = bgf.database["Gui"]["Widget"]["ColorNormal"]
	
	# Mouse clicking
	if mouseOver.positive and lmb.positive and lmb.status == 1:
		own.color = bgf.database["Gui"]["Widget"]["ColorClick"]
		bgf.playSfx("MouseClick", buffer=True)
		
		if "Button" in own:
			button(cont)
		
		if "Checkbox" in own:
			checkbox(cont, False)
			button(cont)
Exemple #7
0
def processAim(cont):
    own = cont.owner
    mouseOverTargetArea = cont.sensors["MouseOverTargetArea"]
    targetObj = own.childrenRecursive["TargetObj"]

    if mouseOverTargetArea.positive:
        targetObj.worldPosition = mouseOverTargetArea.hitPosition
        targetObj.worldPosition.y = 0

        if own["Ammo"] > 0 and own[
                "FireCooldown"] >= 0 and own.worldPosition.z > targetObj.worldPosition.z and bgf.getInputStatus(
                    "KeyFire"):
            own["Ammo"] -= 1
            own["FireCooldown"] = -FIRE_COOLDOWN
            bullet = own.scene.addObject("HelicopterBullet", own,
                                         BULLET_LIFE_TIME)
            bullet.alignAxisToVect(
                bullet.getVectTo(targetObj.worldPosition)[1], 1)
            bullet["Emitter"] = own
            bgf.playSfx("ShotHelicopter",
                        buffer=True,
                        is3D=True,
                        refObj=own,
                        distMax=SOUND_MAX_DISTANCE)

        if own["Target"] is not None and "Hostage" in own[
                "Target"] and not own["Target"]["Free"] and globalDict[
                    "AlliesAlive"] > 0 and own["AllyCooldown"] >= 0 and not own[
                        "Landing"] and bgf.getInputStatus(
                            "KeyAlly", bge.logic.KX_INPUT_JUST_ACTIVATED):
            own["AllyCooldown"] = -ALLY_COOLDOWN
            globalDict["AlliesAlive"] -= 1
            ally = own.scene.addObject("SoldierCollision")
            ally.worldPosition = own.worldPosition
            ally["Target"] = own["Target"]
            ally["Enemy"] = False
            own.scene["Allies"].append(ally)
            own.sendMessage("UpdateText")
Exemple #8
0
def runHostageFree(cont):
	own = cont.owner
	free = own.childrenRecursive["Hostage"]
	tied = own.childrenRecursive["HostagePole"]
	
	tied.visible = False
	free.visible = True
		
	if own["Life"] <= 0 and own["Action"] != "Death" and not "VoiceDeath" in own:
		own["Action"] = "Death"
		own["VoiceDeath"] = bgf.playSfx("VoiceDeath", buffer=True, is3D=True, refObj=own, distMax=SOUND_DISTANCE_MAX)
	
	processAnimation(cont, "Hostage", ANIMS=ANIMS)
	processTrack(cont)
	processMovement(cont)
Exemple #9
0
def runHostageTied(cont):
	own = cont.owner
	free = own.childrenRecursive["Hostage"]
	tied = own.childrenRecursive["HostagePole"]
	
	tied.visible = True
	free.visible = False
	
	if own["Life"] <= 0 and not "VoiceDeath" in own:
		own["VoiceDeath"] = bgf.playSfx("VoiceDeath", buffer=True, is3D=True, refObj=own, distMax=SOUND_DISTANCE_MAX)
		own.endObject()
		return
	
	action = ANIMS["Tied"]
	tied.playAction("HostageTied", action[0], action[1], play_mode=action[2])
Exemple #10
0
def setProps(cont):
    own = cont.owner
    always = cont.sensors["Always"]
    mouseOver = cont.sensors["MouseOver"]
    collision = cont.sensors["Collision"]

    if always.status == bge.logic.KX_INPUT_JUST_ACTIVATED:
        own["Life"] = globalDict["Life"]
        own["Ammo"] = globalDict["Ammo"]
        own["Fuel"] = globalDict["Fuel"]
        own["FuelCooldown"] = -bgf.database["Default"]["FuelCooldown"]

    globalDict["Life"] = bgf.clamp(own["Life"], 0,
                                   bgf.database["Game"]["Life"])
    globalDict["Fuel"] = bgf.clamp(own["Fuel"], 0,
                                   bgf.database["Game"]["Fuel"])
    globalDict["Ammo"] = own["Ammo"] if own["Ammo"] > 0 else 0

    if own["FuelCooldown"] >= 0:
        own["FuelCooldown"] = -bgf.database["Default"]["FuelCooldown"]
        own["Fuel"] -= 1

    own.scene["Player"] = own
    if not "Allies" in own.scene:
        own.scene["Allies"] = [own]

    if collision.positive and own["OnGround"]:
        for obj in collision.hitObjectList:
            if "Life" in obj and obj["Life"] > 0:
                if "Target" in obj and obj["Target"] == own \
                and ("Enemy" in obj and not obj["Enemy"] \
                or "Hostage" in obj and obj["Free"]):
                    if "Enemy" in obj:
                        globalDict["AlliesAlive"] += 1
                        own.scene["Allies"].remove(obj)
                    elif "Hostage" in obj:
                        globalDict["HostagesSaved"] += 1
                    obj.endObject()
        own.sendMessage("UpdateText")

    if mouseOver.positive:
        own["Target"] = mouseOver.hitObject
        if "Enemy" in mouseOver.hitObject:
            if mouseOver.hitObject["Enemy"]:
                globalDict["TargetType"] = "Enemy"
            else:
                globalDict["TargetType"] = "Ally"
        elif "Hostage" in mouseOver.hitObject:
            globalDict["TargetType"] = "Ally"
        else:
            globalDict["TargetType"] = "None"
            own["Target"] = None
    else:
        globalDict["TargetType"] = "None"
        own["Target"] = None

    # Key status
    keyLeft = bgf.getInputStatus("KeyLeft", 2)
    keyRight = bgf.getInputStatus("KeyRight", 2)
    keyUp = bgf.getInputStatus("KeyUp", 2)
    keyDown = bgf.getInputStatus("KeyDown", 2)
    keyPause = bgf.getInputStatus("KeyPause", 1)

    if not globalDict["Paused"]:

        if keyPause:
            if "SoundHelicopter" in own:
                own["SoundHelicopter"].stop()
            globalDict["Paused"] = True
            own.sendMessage("ContextPause")
            return

        if not "SoundHelicopter" in own or "SoundHelicopter" in own and own[
                "SoundHelicopter"].status != aud.AUD_STATUS_PLAYING:
            sound = bgf.playSfx("Helicopter",
                                buffer=True,
                                is3D=True,
                                refObj=own,
                                distMax=SOUND_MAX_DISTANCE)
            if sound is not None:
                own["SoundHelicopter"] = sound
                own["SoundHelicopter"].loop_count = -1

        if "SoundHelicopter" in own and not globalDict["Paused"]:
            own["SoundHelicopter"].location = own.worldPosition

        aud.device().listener_location = own.scene.active_camera.worldPosition
        aud.device(
        ).listener_orientation = own.scene.active_camera.worldOrientation.to_quaternion(
        )

    ray = own.rayCast(own.worldPosition - Vector((0, 0, 1)), own.worldPosition,
                      LANDING_DISTANCE, "Ground", 1, True)

    own["Landing"] = True if ray[0] is not None else False
    if own["Landing"]:
        own["OnGround"] = True if own.getDistanceTo(ray[1]) < 1.3 else False

    # Left and right keys
    if keyLeft and not keyRight:
        own["DirectionH"] = "Left"
        own["Move"] = True
        if own["MoveH"] > -1:
            own["MoveH"] -= MOVE_ACCEL

    elif not keyLeft and keyRight:
        own["DirectionH"] = "Right"
        own["Move"] = True
        if own["MoveH"] < 1:
            own["MoveH"] += MOVE_ACCEL

    elif not keyLeft and not keyRight or keyLeft and keyRight:
        own["Move"] = False
        if own["MoveH"] < 0:
            own["MoveH"] += MOVE_ACCEL
        if own["MoveH"] > 0:
            own["MoveH"] -= MOVE_ACCEL

    # Up and down keys
    if keyUp and not keyDown:
        own["DirectionV"] = "Up"
        if own["MoveV"] < 1:
            own["MoveV"] += MOVE_ACCEL

    elif not keyUp and keyDown:
        own["DirectionV"] = "Down"
        if own["MoveV"] > -1:
            own["MoveV"] -= MOVE_ACCEL

    elif not keyUp and not keyDown or keyUp and keyDown:
        own["DirectionV"] = "Center"
        if own["MoveV"] < 0:
            own["MoveV"] += MOVE_ACCEL
        if own["MoveV"] > 0:
            own["MoveV"] -= MOVE_ACCEL

    # Avoid sliding
    own["MoveV"] = round(own["MoveV"], 3)
    own["MoveH"] = round(own["MoveH"], 3)