public GrenadeWeapon(Game game, Texture2D grenadeTexture2D) : base(game) { CurrentBulletsInCharger = 1; AllBullets = 5; TimeForRecharge = new TimeSpan(0, 0, 0, 2); Grenades = new Grenades(game, grenadeTexture2D, AllBullets); }
/// <summary> /// Adjusts the interactable state of buy buttons in the menus. If the player /// doesn't have enough money, the button will be not interactable. /// </summary> private void SetInteractableStateOfBuyButtons() { foreach (GameObject wepBuyMenu in listPersonalWepBuyMenuObjs) { for (int i = 0; i < wepBuyMenu.transform.childCount; i++) { GameObject buyButton = wepBuyMenu.transform.GetChild(i).gameObject; Button button = buyButton.GetComponent <Button>(); if (personalWeaponPrefabs.ContainsKey(buyButton.GetComponent <BuyWeaponButtonScript>().weaponName)) { Weapon wepToCheck = personalWeaponPrefabs[buyButton.GetComponent <BuyWeaponButtonScript>().weaponName].GetComponent <Weapon>(); if (wepToCheck.cost > currentMoney) { button.interactable = false; } else { button.interactable = true; } } else { Debug.Log("personalWeaponPrefabs does not contain an entry for: " + buyButton.GetComponent <BuyWeaponButtonScript>().weaponName); button.interactable = false; } } } for (int i = 0; i < grenadeObj.transform.childCount; i++) { GameObject buyButton = grenadeObj.transform.GetChild(i).gameObject; Button button = buyButton.GetComponent <Button>(); if (grenadePrefabs.ContainsKey(buyButton.GetComponent <BuyWeaponButtonScript>().weaponName)) { Grenades grenadeToCheck = grenadePrefabs[buyButton.GetComponent <BuyWeaponButtonScript>().weaponName].GetComponent <Grenades>(); if (grenadeToCheck.cost > currentMoney) { button.interactable = false; } else { button.interactable = true; } } else { Debug.Log("grenadePrefabs does not contain an entry for: " + buyButton.GetComponent <BuyWeaponButtonScript>().weaponName); button.interactable = false; } } /* this will be for the team menu stuff in the future * for (int i = 0; i < assaultRifleObj.transform.childCount; i++) * { * * }*/ }
public GuardMech(LevelState parentWorld, float initial_x, float initial_y) { position = new Vector2(initial_x, initial_y); melee_position = Vector2.Zero; dimensions = new Vector2(96, 120); velocity = new Vector2(0.8f, 0.0f); flame_position = Vector2.Zero; windup_timer = 0.0f; angle = 0.0f; turret_angle = angle; enemy_life = 75; disable_movement = false; disable_movement_time = 0.0f; enemy_found = false; change_direction_time = 0.0f; this.parentWorld = parentWorld; enemy_type = EnemyType.Guard; change_direction_time_threshold = 3000.0f; direction_facing = GlobalGameConstants.Direction.Right; prob_item_drop = 0.6; number_drop_items = 5; component = new MoveSearch(); mech_state = MechState.Moving; enemy_type = EnemyType.Guard; velocity_speed = 3.0f; entity_found = null; death = false; tank_hull_animation_time = 0.0f; explode_timer = 0.0f; rocket_angle = 0.0f; grenade = new Grenades(Vector2.Zero, 0.0f); walk_down = AnimationLib.loadNewAnimationSet("tankTurret"); current_skeleton = walk_down; current_skeleton.Animation = current_skeleton.Skeleton.Data.FindAnimation("idle"); current_skeleton.Skeleton.FlipX = false; animation_time = 0.0f; range_distance = 600.0f; tankAnim = AnimationLib.getFrameAnimationSet("tank"); tankDeadAnim = AnimationLib.getFrameAnimationSet("tankDead"); plasmaExplode = AnimationLib.getFrameAnimationSet("plasmaExplodeLong"); tankTurretDeadAnim = AnimationLib.getFrameAnimationSet("tankTurretDead"); rocketProjectile = AnimationLib.getFrameAnimationSet("rocketProjectile"); }
/// <summary> /// If the grenade in the slot that it should go in, is not currently taken, place this grenade obj there. /// Else do nothing with it. /// </summary> /// <param name="weaponToPickup"></param> private void PickupGrenade(GameObject grenadeToPickup) { Grenades grenadeInfo = grenadeToPickup.GetComponent <Grenades>(); for (int i = 0; i < GRENADE_COUNT; i++) { if (inventory[grenadeInfo.weaponSlot][i] == null) { PrepareWeaponForAddToPlayer(grenadeToPickup); inventory[grenadeInfo.weaponSlot][i] = grenadeToPickup; this.SendMessageUpwards("SetNonNullWeaponsFromInventory", SendMessageOptions.DontRequireReceiver); inventoryUi?.InventoryActionPerformed(); } } }
public GameObject findWeaponByID(int id) { int type = id / 100; GameObject weapon = null; switch (type) { case 01: for (int i = 0; i < secondaryGuns.Length; i++) { gun testGun = secondaryGuns[i].GetComponent <gun>(); if (testGun.id == id) { weapon = testGun.gameObject; break; } } break; case 02: for (int i = 0; i < primaryGuns.Length; i++) { gun testGun = primaryGuns[i].GetComponent <gun>(); if (testGun.id == id) { weapon = testGun.gameObject; break; } } break; case 03: for (int i = 0; i < Grenades.Length; i++) { Grenades testGun = Grenades[i].GetComponent <Grenades>(); if (testGun.grenadeID == id) { weapon = testGun.gameObject; break; } } break; } return(weapon); }
public ContentLoader_Grenades(Grenades grenade, StackLayout pageContent) { this.grenade = grenade; this.pageContent = pageContent; }
public override void update(GameTime currentTime) { float distance = float.MaxValue; if (disable_movement == true) { disable_movement_time += currentTime.ElapsedGameTime.Milliseconds; if (disable_movement_time > 300) { disable_movement = false; disable_movement_time = 0.0f; velocity = Vector2.Zero; } } else { switch (mech_state) { case MechState.Moving: current_skeleton.Animation = current_skeleton.Skeleton.Data.FindAnimation("idle"); tank_hull_animation_time += currentTime.ElapsedGameTime.Milliseconds; change_direction_time += currentTime.ElapsedGameTime.Milliseconds; if (enemy_found == false) { for (int i = 0; i < parentWorld.EntityList.Count; i++) { if (parentWorld.EntityList[i] == this || (parentWorld.EntityList[i] is Player && GameCampaign.PlayerAllegiance > 0.7)) { continue; } else if (parentWorld.EntityList[i].Enemy_Type != enemy_type && parentWorld.EntityList[i].Enemy_Type != EnemyType.NoType && parentWorld.EntityList[i].Death == false) { component.update(this, parentWorld.EntityList[i], currentTime, parentWorld); if (enemy_found) { entity_found = parentWorld.EntityList[i]; break; } } } } switch (direction_facing) { case GlobalGameConstants.Direction.Right: velocity = new Vector2(0.5f, 0f); dimensions = new Vector2(120, 96); angle = 0.0f; break; case GlobalGameConstants.Direction.Left: velocity = new Vector2(-0.5f, 0f); dimensions = new Vector2(120, 96); angle = (float)(Math.PI); break; case GlobalGameConstants.Direction.Up: velocity = new Vector2(0f, -0.5f); dimensions = new Vector2(96, 120); angle = (float)(-1 * Math.PI / 2); break; default: velocity = new Vector2(0.0f, 0.5f); dimensions = new Vector2(96, 120); angle = (float)(Math.PI / 2); break; } if (enemy_found) { distance = Vector2.Distance(CenterPoint, entity_found.CenterPoint); tank_hull_animation_time = 0.0f; if (Math.Abs(distance) < range_distance) { if (Math.Abs(distance) > 192 && Math.Abs(distance) < range_distance) { mech_state = MechState.Firing; } else { mech_state = MechState.MeleeWindUp; } } } int corner_check = 0; bool is_on_wall = false; while (corner_check != 4) { if (corner_check == 0) { is_on_wall = parentWorld.Map.hitTestWall(position); } else if (corner_check == 1) { is_on_wall = parentWorld.Map.hitTestWall(position + new Vector2(dimensions.X, 0)); } else if (corner_check == 2) { is_on_wall = parentWorld.Map.hitTestWall(position + new Vector2(0, dimensions.Y)); } else if (corner_check == 3) { is_on_wall = parentWorld.Map.hitTestWall(position + dimensions); } if (is_on_wall) { if (direction_facing == GlobalGameConstants.Direction.Right || direction_facing == GlobalGameConstants.Direction.Left) { dimensions = new Vector2(96, 120); if (Game1.rand.NextDouble() > 0.5) { direction_facing = GlobalGameConstants.Direction.Up; } else { direction_facing = GlobalGameConstants.Direction.Down; } } else { dimensions = new Vector2(120, 96); if (Game1.rand.NextDouble() > 0.5) { direction_facing = GlobalGameConstants.Direction.Right; } else { direction_facing = GlobalGameConstants.Direction.Left; } } break; } corner_check++; } break; case MechState.Firing: windup_timer += currentTime.ElapsedGameTime.Milliseconds; angle = (float)Math.Atan2(entity_found.CenterPoint.Y - current_skeleton.Skeleton.FindBone("muzzle").WorldY, entity_found.CenterPoint.X - current_skeleton.Skeleton.FindBone("muzzle").WorldX); distance = Vector2.Distance(position, entity_found.Position); velocity = Vector2.Zero; bool enemy_in_sight = parentWorld.Map.playerInSight(angle, distance, this, entity_found); if (Math.Abs(distance) > 600 || entity_found.Remove_From_List == true || enemy_in_sight) { mech_state = MechState.Moving; windup_timer = 0.0f; enemy_found = false; return; } else if (Math.Abs(distance) < 192) { windup_timer = 0.0f; mech_state = MechState.MeleeWindUp; } if (windup_timer > 2000) { if (grenade.active == false) { AudioLib.playSoundEffect("tankFire"); rocket_angle = (float)Math.Atan2(entity_found.CenterPoint.Y - current_skeleton.Skeleton.FindBone("muzzle").WorldY, entity_found.CenterPoint.X - current_skeleton.Skeleton.FindBone("muzzle").WorldX); current_skeleton.Animation = current_skeleton.Skeleton.Data.FindAnimation("attack"); grenade = new Grenades(new Vector2(current_skeleton.Skeleton.FindBone("muzzle").WorldX, current_skeleton.Skeleton.FindBone("muzzle").WorldY), angle); grenade.active = true; } } if (windup_timer > 2100) { windup_timer = 0.0f; current_skeleton.Animation = current_skeleton.Skeleton.Data.FindAnimation("idle"); } switch (direction_facing) { case GlobalGameConstants.Direction.Right: if (angle < -1 * Math.PI / 3.27) { direction_facing = GlobalGameConstants.Direction.Up; dimensions = new Vector2(96, 120); } else if (angle > Math.PI / 3.27) { direction_facing = GlobalGameConstants.Direction.Down; dimensions = new Vector2(96, 120); } break; case GlobalGameConstants.Direction.Left: if (angle < Math.PI / 1.44 && angle > Math.PI / 1.5) { direction_facing = GlobalGameConstants.Direction.Down; dimensions = new Vector2(96, 120); } else if (angle > -1 * Math.PI / 1.44 && angle < -1 * Math.PI / 1.5) { direction_facing = GlobalGameConstants.Direction.Up; dimensions = new Vector2(96, 120); } break; case GlobalGameConstants.Direction.Up: if (angle < -1 * Math.PI / 1.24) { direction_facing = GlobalGameConstants.Direction.Left; dimensions = new Vector2(120, 96); } else if (angle > -1 * Math.PI / 5.14) { direction_facing = GlobalGameConstants.Direction.Right; dimensions = new Vector2(120, 96); } break; default: if (angle < Math.PI / 5.14) { direction_facing = GlobalGameConstants.Direction.Right; dimensions = new Vector2(120, 96); //current_skeleton = walk_right; } else if (angle > Math.PI / 1.24) { direction_facing = GlobalGameConstants.Direction.Left; dimensions = new Vector2(120, 96); //current_skeleton = walk_right; } break; } break; case MechState.MeleeWindUp: windup_timer += currentTime.ElapsedGameTime.Milliseconds; angle = (float)Math.Atan2(entity_found.CenterPoint.Y - CenterPoint.Y, entity_found.CenterPoint.X - CenterPoint.X); if (windup_timer > 1000) { mech_state = MechState.Melee; windup_timer = 0.0f; melee_active = true; } switch (direction_facing) { case GlobalGameConstants.Direction.Right: if (angle < -1 * Math.PI / 3.27) { direction_facing = GlobalGameConstants.Direction.Up; dimensions = new Vector2(96, 120); //current_skeleton = walk_up; } else if (angle > Math.PI / 3.27) { direction_facing = GlobalGameConstants.Direction.Down; dimensions = new Vector2(96, 120); //current_skeleton = walk_down; } break; case GlobalGameConstants.Direction.Left: if (angle < Math.PI / 1.44 && angle > Math.PI / 1.5) { direction_facing = GlobalGameConstants.Direction.Down; dimensions = new Vector2(96, 120); //current_skeleton = walk_down; } else if (angle > -1 * Math.PI / 1.44 && angle < -1 * Math.PI / 1.5) { direction_facing = GlobalGameConstants.Direction.Up; dimensions = new Vector2(96, 120); //current_skeleton = walk_up; } break; case GlobalGameConstants.Direction.Up: if (angle < -1 * Math.PI / 1.24) { direction_facing = GlobalGameConstants.Direction.Left; dimensions = new Vector2(120, 96); //current_skeleton = walk_right; } else if (angle > -1 * Math.PI / 5.14) { direction_facing = GlobalGameConstants.Direction.Right; dimensions = new Vector2(120, 96); //current_skeleton = walk_right; } break; default: if (angle < Math.PI / 5.14) { direction_facing = GlobalGameConstants.Direction.Right; dimensions = new Vector2(120, 96); //current_skeleton = walk_right; } else if (angle > Math.PI / 1.24) { direction_facing = GlobalGameConstants.Direction.Left; dimensions = new Vector2(120, 96); //current_skeleton = walk_right; } break; } break; case MechState.Melee: //current_skeleton.Animation = current_skeleton.Skeleton.Data.FindAnimation("idle"); windup_timer += currentTime.ElapsedGameTime.Milliseconds; AudioLib.playTankFlameSoundEffect(true); Vector2 flame_displacement = Vector2.Zero; if (direction_facing == GlobalGameConstants.Direction.Left || direction_facing == GlobalGameConstants.Direction.Right) { flame_displacement = new Vector2(tankAnim.FrameDimensions.X / 2, 0); } else { flame_displacement = new Vector2(0, tankAnim.FrameDimensions.X / 2); } parentWorld.Particles.pushFlame(CenterPoint + ((direction_facing == GlobalGameConstants.Direction.Left || direction_facing == GlobalGameConstants.Direction.Up)?-1 * flame_displacement : flame_displacement), (float)((int)direction_facing * Math.PI / 2)); parentWorld.Particles.pushFlame(CenterPoint + ((direction_facing == GlobalGameConstants.Direction.Left || direction_facing == GlobalGameConstants.Direction.Up) ? -1 * flame_displacement : flame_displacement), (float)((int)direction_facing * Math.PI / 2)); switch (direction_facing) { case GlobalGameConstants.Direction.Right: melee_position = position + new Vector2(dimensions.X, melee_hitbox.Y / 4); break; case GlobalGameConstants.Direction.Left: melee_position = position + new Vector2(-1 * melee_hitbox.X, dimensions.Y / 4); break; case GlobalGameConstants.Direction.Up: melee_position = position + new Vector2(dimensions.X / 4, -1 * melee_hitbox.Y); break; default: melee_position = position + new Vector2(dimensions.X / 4, dimensions.Y); break; } foreach (Entity en in parentWorld.EntityList) { if (en == this) { continue; } else if (meleeHitTest(en)) { Vector2 direction = en.CenterPoint - CenterPoint; en.knockBack(direction, 3.5f, 10, this); } } velocity = Vector2.Zero; if (windup_timer > 1500) { windup_timer = 0.0f; melee_active = false; if (Math.Abs(distance) > 300 || entity_found.Remove_From_List) { enemy_found = false; mech_state = MechState.Moving; } else if (Math.Abs(distance) > 192 && Math.Abs(distance) < 300) { mech_state = MechState.Firing; } else { mech_state = MechState.MeleeWindUp; } AudioLib.stopTankFlameSoundEffect(); } break; case MechState.Reset: windup_timer = 0.0f; enemy_found = false; mech_state = MechState.Moving; break; case MechState.Death: death = true; explode_timer += currentTime.ElapsedGameTime.Milliseconds; velocity = Vector2.Zero; break; default: break; } } if (grenade.active) { grenade.update(parentWorld, currentTime, this); } if (enemy_life <= 0 && death == false) { AudioLib.stopFlameSoundEffect(); explode_timer += currentTime.ElapsedGameTime.Milliseconds; animation_time = 0.0f; death = true; mech_state = MechState.Death; velocity = Vector2.Zero; parentWorld.pushCoin(this); } Vector2 pos = new Vector2(position.X, position.Y); Vector2 nextStep = new Vector2(position.X + velocity.X, position.Y + velocity.Y); Vector2 finalPos = parentWorld.Map.reloactePosition(pos, nextStep, dimensions); position.X = finalPos.X; position.Y = finalPos.Y; animation_time += currentTime.ElapsedGameTime.Milliseconds / 1000f; current_skeleton.Animation.Apply(current_skeleton.Skeleton, animation_time, true); }
private void Update() { if (playerSc.isAlive) { line.transform.position = ActiveGun.GetComponent <gun>().tip.position; if (Input.GetButtonDown("Switch")) { switchWeapon(); } if (Input.GetButtonDown("Reload")) { ActiveGun.GetComponent <gun>().reload(); } if (Input.GetButton("Grenade")) { if (GrenadeHoldTime < grenadeMaxHoldTime) { GrenadeHoldTime += Time.deltaTime; } } if (Input.GetButtonUp("Grenade")) { Transform tip = ActiveGun.GetComponent <gun>().tip.transform; if (grenadeCount[ActiveGrenade % 300] > 0) { Grenades G = Instantiate(findWeaponByID(ActiveGrenade), tip.position, tip.rotation).GetComponent <Grenades>(); G.GrenadeAimTime = GrenadeHoldTime / grenadeMaxHoldTime; GrenadeHoldTime = 0; grenadeCount[ActiveGrenade % 300]--; } if (grenadeCount[ActiveGrenade % 300] < 1) { SwitchGrenade(); } } switch (firemode) { case 1: if (Input.GetButton("Fire1")) { shoot(); playerSc.isShooting = true; } else { playerSc.isShooting = false; } break; case 2: if (Input.GetButtonDown("Fire1")) { shoot(); playerSc.isShooting = true; } else { playerSc.isShooting = false; } break; } if (Input.GetButtonDown("SwitchGrenade")) { SwitchGrenade(); } } }
// Use this for initialization void Start() { source = Camera.main.GetComponent<AudioSource> (); PlayerCam = Camera.main.GetComponent<Camera>(); // Find the Camera's GameObject from its tag gameManager = Camera.main.GetComponent<GameMaster> (); gridManager = Camera.main.GetComponent<GridManager> (); isGrenades = GameObject.Find ("Grenades").GetComponent<Grenades> (); }
/// <summary> /// Function called anytime the full inventory and money UI need to be displayed for the player. /// </summary> public void InventoryActionPerformed() { inventoryAndMoneyPanel.SetActive(true); overallInventoryUI.SetActive(true); disappearTimer = inventoryDisappearTime; startDisappearingTimer = timeBeforeStartDisappearing; uiOpacity = 1.0f; playerMoneyText.text = "$" + playerManager.GetCurrentPlayerMoney(); foreach (string slot in inventorySlotNames) { if (slot == InventoryScript.GRENADES) { GameObject[] grenades = playerInventory.GetGrenades(); for (int i = 0; i < InventoryScript.GRENADE_COUNT; i++) { if (grenades[i] == null) { grenadePanelObj.transform.GetChild(i).gameObject.SetActive(false); } else { Grenades grenade = grenades[i].GetComponent <Grenades>(); grenadePanelObj.transform.GetChild(i).gameObject.SetActive(true); grenadePanelObj.transform.GetChild(i).gameObject.GetComponent <Image>().sprite = grenade.uiIcon; grenadePanelObj.transform.GetChild(i).gameObject.GetComponentInChildren <Text>().text = grenade.weaponName; } } } else { GameObject wepToGrabObj = playerInventory.GetWeapon(slot); if (slot == InventoryScript.PRIMARY) { //there is no weapon in that slot so turn it off if (wepToGrabObj == null) { primaryWepImageObj.SetActive(false); } else { Weapon wepToGrab = wepToGrabObj.GetComponent <Weapon>(); primaryWepImageObj.SetActive(true); primaryWepImageObj.GetComponent <Image>().sprite = wepToGrab.uiIcon; primaryWepImageObj.GetComponentInChildren <Text>().text = wepToGrab.weaponName; } } else if (slot == InventoryScript.SECONDARY) { //there is no weapon in that slot so turn it off if (wepToGrabObj == null) { secondaryWepImageObj.SetActive(false); } else { Weapon wepToGrab = wepToGrabObj.GetComponent <Weapon>(); secondaryWepImageObj.SetActive(true); secondaryWepImageObj.GetComponent <Image>().sprite = wepToGrab.uiIcon; secondaryWepImageObj.GetComponentInChildren <Text>().text = wepToGrab.weaponName; } } else if (slot == InventoryScript.KNIFE) { //there is no weapon in that slot so turn it off if (wepToGrabObj == null) { knifeImageObj.SetActive(false); } else { Weapon wepToGrab = wepToGrabObj.GetComponent <Weapon>(); knifeImageObj.SetActive(true); knifeImageObj.GetComponent <Image>().sprite = wepToGrab.uiIcon; knifeImageObj.GetComponentInChildren <Text>().text = wepToGrab.weaponName; } } else if (slot == InventoryScript.BOMB) { //there is no weapon in that slot so turn it off if (wepToGrabObj == null) { objectiveBombImageObj.SetActive(false); } else { Weapon wepToGrab = wepToGrabObj.GetComponent <Weapon>(); objectiveBombImageObj.SetActive(true); objectiveBombImageObj.GetComponent <Image>().sprite = wepToGrab.uiIcon; objectiveBombImageObj.GetComponentInChildren <Text>().text = wepToGrab.weaponName; } } } } SetUIOpacity(); }