private void ProcessPlayerPacket(string[] split, ref int i) { int id = Convert.ToInt32(split[i++]); float ping = float.Parse(split[i++]); int health = Convert.ToInt32(split[i++]); int armour = Convert.ToInt32(split[i++]); Vector3 org = new Vector3( float.Parse(split[i++], System.Globalization.CultureInfo.InvariantCulture) , float.Parse(split[i++], System.Globalization.CultureInfo.InvariantCulture) , float.Parse(split[i++], System.Globalization.CultureInfo.InvariantCulture) ); Vector3 vel = new Vector3( float.Parse(split[i++], System.Globalization.CultureInfo.InvariantCulture) , float.Parse(split[i++], System.Globalization.CultureInfo.InvariantCulture) , float.Parse(split[i++], System.Globalization.CultureInfo.InvariantCulture) ); Vector3 rot = new Vector3( float.Parse(split[i++], System.Globalization.CultureInfo.InvariantCulture) , float.Parse(split[i++], System.Globalization.CultureInfo.InvariantCulture) , float.Parse(split[i++], System.Globalization.CultureInfo.InvariantCulture) ); WEAPONTYPE activeWeapon = (WEAPONTYPE)float.Parse(split[i], System.Globalization.CultureInfo.InvariantCulture); UpdatePlayer(id, ping, health, armour, org, vel, rot, activeWeapon); }
// when a player attacks public Projectile AddProjectile(Player shooter, Vector3 dest, string projName, WEAPONTYPE weapon) { ProjectileInfo.PROJECTILE projType = ProjectileInfo.Weapons[weapon]; Projectile proj = (Projectile)ProjectileScenes[projType].Instance(); this.AddChild(proj); _projectiles.Add(proj); Peer p = _game.Network.PeerList.Where(e => e.ID == shooter.ID).SingleOrDefault(); float ping = 0f; if (p != null) { ping = IsNetworkMaster() ? p.Ping : 0f; } proj.Init(shooter, dest.Normalized(), weapon, _game); proj.Velocity *= proj.Speed; if (proj is HandGrenade h) { h.Visible = false; shooter.PrimingGren = h; } proj.Name = projName.Replace("\"", "").Length > 0 ? projName : shooter.ID + "!" + proj.Name; // godot inserts @ signs and numbers to non unique names that can happen due to sync issues // it also currently doesn't allow you to manually insert them, so server sets wrong name! and sends back wrong name! // great architecture! // if this is too slow we need to track unique projectile count on client and set that as name, but i worry about uniqueness still proj.Name = proj.Name.Replace("@", ""); return(proj); }
protected void ChangeWeapon(WEAPONTYPE w, GameObject weapon) // 무기 장착 함수 { if (Weapon_Obj != null) { Destroy(Weapon_Obj); } weapontype = w; switch (w) { case WEAPONTYPE.BOW: bLongDistAtk = true; UsingWeaponTR = BowTR; UsingAni.runtimeAnimatorController = BowAni; break; case WEAPONTYPE.GUN: bLongDistAtk = true; UsingWeaponTR = GunTR; UsingAni.runtimeAnimatorController = GunAni; break; case WEAPONTYPE.SWORD: bLongDistAtk = false; UsingWeaponTR = SwordTR; UsingAni.runtimeAnimatorController = SwordAni; break; } Weapon_Obj = Instantiate(weapon) as GameObject; Weapon_Obj.transform.SetParent(UsingWeaponTR); Weapon_Obj.transform.position = UsingWeaponTR.position; Weapon_Obj.transform.rotation = UsingWeaponTR.rotation; }
public override void Init(Player shooter, Vector3 vel, WEAPONTYPE weapon, Game game) { base.Init(shooter, vel, weapon, game); _damage = 10; _debuffLength = 5; _grenadeType = WEAPONTYPE.FLASH; }
//constructor for bulletclass, each bullet is an object and takes a initial position, position of mouse, increment amount, rotation direction and what kind of gun its fired from public BulletClass(Vector3 position, Vector3 mousePosition, Vector3 increment, float rotation, WEAPONTYPE bulletFromWhatWeapon) { this.position = position + new Vector3(0f, 0.9f, 0f); this.mousePosition = mousePosition + new Vector3(0f, 0.9f, 0f); this.increment = increment; this.rotation = rotation; this.bulletFromWhatWeapon = bulletFromWhatWeapon; boundingBox = new BoundingBox(); if (bulletFromWhatWeapon == WEAPONTYPE.AK47) //if bullet is from ak47 { boundingBox.Max = new Vector3(0.05f, 0.9f, 0.05f); // + (increment * 0.5f) boundingBox.Min = new Vector3(-0.05f, 0.8f, -0.05f); // + (increment * 0.5f) bulletDmg = 30; //amount of damage it does do person bulletWallDmg = 5; //amount of damage it does to wall } if (bulletFromWhatWeapon == WEAPONTYPE.SHOTGUN) //if bullet is from shotgun { boundingBox.Max = position + new Vector3(0.05f, 0.9f, 0.05f) + (increment * 5); boundingBox.Min = position + new Vector3(-0.05f, 0.8f, -0.05f) + (increment * 5); bulletDmg = 10; bulletWallDmg = 10; } if (bulletFromWhatWeapon == WEAPONTYPE.GRENADE) //if bullet is from grenade { boundingBox.Max = position + new Vector3(0.05f, 0.9f, 0.05f); boundingBox.Min = position + new Vector3(-0.05f, 0.8f, -0.05f); bulletDmg = 51; bulletWallDmg = 150; } }
public WeaponClass(Game game, WEAPONTYPE weaponType, Vector3 modelPosition) : base(game) { this.modelPosition = modelPosition; this.weaponType = weaponType; //based on input weapon type, will set its weapon attributes to different things if (weaponType == WEAPONTYPE.AK47) { weaponModel = game.Content.Load <Model>("gunAK47"); weaponAmmoInWeapon = 30; weaponMagSize = 30; weaponMaxAmmo = 120; weaponROF = 100; //rounds per second reloadTime = 4000; //3 seconds for mag } if (weaponType == WEAPONTYPE.SHOTGUN) { weaponModel = game.Content.Load <Model>("gunPumpShotgun"); weaponAmmoInWeapon = 7; weaponMagSize = 7; weaponMaxAmmo = 42; weaponROF = 1000; //1 round per 2 seconds reloadTime = 1500; //1.5 seconds per shell } if (weaponType == WEAPONTYPE.GRENADE) { weaponModel = game.Content.Load <Model>("gunGrenade"); weaponAmmoInWeapon = 1; weaponMagSize = 1; weaponMaxAmmo = 3; weaponROF = 5000; //1 grenade per 5 seconds reloadTime = 5000; } }
// FIXME - only h/a of owning player public void UpdatePlayer(int id, float ping, float health, float armour, Vector3 org, Vector3 velo , Vector3 rot, WEAPONTYPE activeWeapon) { Peer p = PeerList.Where(p2 => p2.ID == id).First(); p.Ping = ping; p.Player.SetServerState(org, velo, rot, health, armour, activeWeapon); }
public void load() { switch (m_Player) { case PLAYER.P1: m_PlayerName = GameManager.m_Instance.m_Player1.name; m_Player = GameManager.m_Instance.m_Player1.player; m_AttackSpeed = GameManager.m_Instance.m_Player1.attackSpeed; m_Score = GameManager.m_Instance.m_Player1.score; m_Gold = GameManager.m_Instance.m_Player1.gold; //m_Health = GameManager.m_Instance.m_Player1.health; //m_MaxHealth = GameManager.m_Instance.m_Player1.maxHealth; m_WeaponID = GameManager.m_Instance.m_Player1.weaponID; m_LastLocation = GameManager.m_Instance.m_Player1.lastLocation; m_Controller = GameManager.m_Instance.m_Player1.m_Controller; break; case PLAYER.P2: m_PlayerName = GameManager.m_Instance.m_Player2.name; m_Player = GameManager.m_Instance.m_Player2.player; m_AttackSpeed = GameManager.m_Instance.m_Player2.attackSpeed; m_Score = GameManager.m_Instance.m_Player2.score; m_Gold = GameManager.m_Instance.m_Player2.gold; //m_Health = GameManager.m_Instance.m_Player2.health; //m_MaxHealth = GameManager.m_Instance.m_Player2.maxHealth; m_WeaponID = GameManager.m_Instance.m_Player2.weaponID; m_LastLocation = GameManager.m_Instance.m_Player2.lastLocation; m_Controller = GameManager.m_Instance.m_Player2.m_Controller; break; case PLAYER.P3: m_PlayerName = GameManager.m_Instance.m_Player3.name; m_Player = GameManager.m_Instance.m_Player3.player; m_AttackSpeed = GameManager.m_Instance.m_Player3.attackSpeed; m_Score = GameManager.m_Instance.m_Player3.score; m_Gold = GameManager.m_Instance.m_Player3.gold; //m_Health = GameManager.m_Instance.m_Player3.health; //m_MaxHealth = GameManager.m_Instance.m_Player3.maxHealth; m_WeaponID = GameManager.m_Instance.m_Player3.weaponID; m_LastLocation = GameManager.m_Instance.m_Player3.lastLocation; m_Controller = GameManager.m_Instance.m_Player3.m_Controller; break; case PLAYER.P4: m_PlayerName = GameManager.m_Instance.m_Player4.name; m_Player = GameManager.m_Instance.m_Player4.player; m_AttackSpeed = GameManager.m_Instance.m_Player4.attackSpeed; m_Score = GameManager.m_Instance.m_Player4.score; m_Gold = GameManager.m_Instance.m_Player4.gold; //m_Health = GameManager.m_Instance.m_Player4.health; //m_MaxHealth = GameManager.m_Instance.m_Player4.maxHealth; m_WeaponID = GameManager.m_Instance.m_Player4.weaponID; m_LastLocation = GameManager.m_Instance.m_Player4.lastLocation; m_Controller = GameManager.m_Instance.m_Player4.m_Controller; break; } }
public override void Init(Player shooter, Vector3 vel, WEAPONTYPE weapon, Game game) { base.Init(shooter, vel, weapon, game); _damage = 50; _grenadeType = WEAPONTYPE.SHOCK; _shockArea = GetNode("CSGMesh/Area") as Area; _shockArea.Connect("body_entered", this, "on_Shock_Entered"); _shockArea.Connect("body_exited", this, "on_Shock_Exited"); }
public override void Init(Player shooter, Vector3 vel, WEAPONTYPE weapon, Game game) { _particleResource = "res://Scenes/Weapons/RocketExplosion.tscn"; _areaOfEffect = true; _areaOfEffectRadius = 5; base.Init(shooter, vel, weapon, game); _moveType = MOVETYPE.BOUNCE; _maxLifeTime = 2.5f; }
public override void Init(Player shooter, Vector3 vel, WEAPONTYPE weapon, Game game) { _particleResource = "res://Scenes/Weapons/RocketExplosion.tscn"; base.Init(shooter, vel, weapon, game); _areaOfEffectRadius = 10f; _moveType = MOVETYPE.BOUNCE; _areaOfEffect = true; _speed = 40; _verticalSpeed = 20; }
public Player(Game game, GraphicsDeviceManager graphics, Vector3 startingPosition, SpriteBatch spriteBatch, WEAPONTYPE weapon1, WEAPONTYPE weapon2) : base(game) { this.spriteBatch = spriteBatch; modelPosition = startingPosition + new Vector3(2.0f, 0.0f, -2.0f); //moving the player's starting position //loading the models for the player, the player has separate head, torso and limbs modelTorso = game.Content.Load <Model>("personCubeTorso"); modelHead = game.Content.Load <Model>("personCubeHead"); modelArmL = game.Content.Load <Model>("personCubeArm"); modelArmR = game.Content.Load <Model>("personCubeArm"); modelLegL = game.Content.Load <Model>("personCubeLeg"); modelLegR = game.Content.Load <Model>("personCubeLeg"); //loading sound effects for various weapons sfxAk47Shot = game.Content.Load <SoundEffect>("SFX/sfxAK47gunshot"); sfxAk47Charge = game.Content.Load <SoundEffect>("SFX/sfxAK47charge"); sfxMoss500Shot = game.Content.Load <SoundEffect>("SFX/sfxMoss500gunshot"); sfxMoss500pump = game.Content.Load <SoundEffect>("SFX/sfxMoss500pump"); sfxWeaponSwitch = game.Content.Load <Song>("SFX/sfxWeaponSwitch"); sfxWeaponDryFire = game.Content.Load <Song>("SFX/sfxDryFire"); //the offsets for each limb, relative to 0, 0, 0 torsoOffset = new Vector3(0, 0.4f, 0); headOffset = new Vector3(0, 1.0f, 0); armLeftOffset = new Vector3(-0.25f, 0.9f, 0); armRightOffSet = new Vector3(0.25f, 0.9f, 0); legLeftOffset = new Vector3(-0.11f, 0.4f, 0); legRightOffset = new Vector3(0.11f, 0.4f, 0); //new effect for debug drawing boxEffect = new BasicEffect(game.GraphicsDevice); //bounding box, first is min, second is max bulletCollisionBox = new BoundingBox(bulletColBoxMin, bulletColBoxMax); bulletList = new List <BulletClass>(); //bounding boxes for each axis boundingBoxXNeg = new BoundingBox(bbXNMin, bbXNMax); boundingBoxXPos = new BoundingBox(bbXPMax, bbXNMax); boundingBoxZNeg = new BoundingBox(bbZNMin, bbZNMax); boundingBoxZPos = new BoundingBox(bbZPMin, bbZPMax); currWeapon = weapon1; //the player will spawn with the first weapon weaponSwitchTo = weapon1; weaponClass1 = new WeaponClass(game, weapon1, modelPosition); //weapon class will load weapon model based on WEAPONTYPE weaponClass2 = new WeaponClass(game, weapon2, modelPosition); weaponClass3 = new WeaponClass(game, WEAPONTYPE.GRENADE, modelPosition); game.Components.Add(weaponClass1); game.Components.Add(weaponClass2); game.Components.Add(weaponClass3); }
void PlayerInit(/*PLAYERTYPE p_type, */ WEAPONTYPE w_type, float movespeed, int hp, int fullhp, bool moveaccess, bool dmgacces) { //SGameMng.I.PlayerType = p_type; _PlayerWeaponType = w_type; //direction = PLAYERDIRECT.DONTMOVE; _fMoveSpeed = movespeed; _nPlayerHp = hp; _nFullHp = fullhp; _bMoveAccess = moveaccess; _bDmgAccess = dmgacces; WeaponSetting(_PlayerWeaponType); }
private void UseHandGrenade(IMPULSE imp, PlayerCmd pCmd) { if (PrimingGren != null) { ThrowGren(pCmd.attackDir); } else { int grenCount = 0; switch (imp) { case IMPULSE.GRENONE: grenCount = _gren1Count; break; case IMPULSE.GRENTWO: grenCount = _gren2Count; break; } if (grenCount > 0) { // play timer if (this.ID == _game.Network.ID && _grenTimer != null) { _grenTimer.Play(); } WEAPONTYPE grenType = WEAPONTYPE.NONE; switch (imp) { case IMPULSE.GRENONE: _gren1Count -= 1; grenType = _gren1Type; break; case IMPULSE.GRENTWO: _gren2Count -= 1; grenType = _gren2Type; break; } Projectile proj = _game.World.ProjectileManager.AddProjectile(this, pCmd.attackDir, pCmd.projName, grenType); // FIXME - need projnames to be an array, shooting + gren on same frame pCmd.projName = proj.Name; } else { PrintGrenCount(imp); } } }
public override void Init(Player shooter, Vector3 vel, WEAPONTYPE weapon, Game game) { _particleResource = "res://Scenes/Weapons/RocketExplosion.tscn"; _areaOfEffect = true; base.Init(shooter, vel, weapon, game); _areaOfEffectRadius = 500; _damage = 500; _moveType = MOVETYPE.NONE; _maxLifeTime = 256f; game.World.MoveToFloor(this); }
public Weapon(string _name, int _value, int _weight, ITEMTYPE _itemType, float _physicalDamage, float _energyDamage, float _range, float _attackSpeed, float _resetSpeed, float _energyCost, float _heatCost, WEAPONTYPE _weaponType, bool _twoHanded) : base(_name, _value, _weight, _itemType) { PhysicalDamage = _physicalDamage; EnergyDamage = _energyDamage; Range = _range; AttackSpeed = _attackSpeed; ResetSpeed = _resetSpeed; EnergyCost = _energyCost; HeatCost = _heatCost; WeaponType = _weaponType; TwoHanded = _twoHanded; }
public Weapon( string _name, int _value, int _weight, ITEMTYPE _itemType, float _physicalDamage, float _energyDamage, float _range, float _attackSpeed, float _resetSpeed, float _energyCost, float _heatCost, WEAPONTYPE _weaponType, bool _twoHanded) : base(_name, _value, _weight, _itemType) { PhysicalDamage = _physicalDamage; EnergyDamage = _energyDamage; Range = _range; AttackSpeed = _attackSpeed; ResetSpeed = _resetSpeed; EnergyCost = _energyCost; HeatCost = _heatCost; WeaponType = _weaponType; TwoHanded = _twoHanded; }
virtual public void Init(Player shooter, Vector3 vel, WEAPONTYPE weapon, Game game) { _game = game; this.AddCollisionExceptionWith(shooter); Transform t = this.GlobalTransform; t.origin = shooter.Head.GlobalTransform.origin; this.GlobalTransform = t; Velocity = vel; this.LookAt(vel * 1000, _game.World.Up); _playerOwner = shooter; _moveType = MOVETYPE.FLY; Weapon = weapon; _damage = shooter.ActiveWeapon.Damage; _speed = shooter.ActiveWeapon.Speed; _particleScene = (PackedScene)ResourceLoader.Load(_particleResource); }
private void PrintGrenCount(IMPULSE imp) { int grenCount = 0; WEAPONTYPE grenType = WEAPONTYPE.NONE; switch (imp) { case IMPULSE.GRENONE: grenCount = _gren1Count; grenType = _gren1Type; break; case IMPULSE.GRENTWO: grenCount = _gren2Count; grenType = _gren2Type; break; } Console.Print("You have " + grenCount + " " + grenType + "s left."); }
public EnemyNpc(Game game, Vector3 modelPosition, WEAPONTYPE weapon) : base(game) { this.modelPosition = modelPosition; //loading the models for the player, the player has separate head, torso and limbs modelTorso = game.Content.Load <Model>("personCubeTorso"); modelHead = game.Content.Load <Model>("personCubeHead"); modelArmL = game.Content.Load <Model>("personCubeArm"); modelArmR = game.Content.Load <Model>("personCubeArm"); modelLegL = game.Content.Load <Model>("personCubeLeg"); modelLegR = game.Content.Load <Model>("personCubeLeg"); modelDead = game.Content.Load <Model>("personCubeDead"); sfxAk47Shot = game.Content.Load <SoundEffect>("SFX/sfxAK47gunshot"); sfxAk47Charge = game.Content.Load <SoundEffect>("SFX/sfxAK47charge"); sfxMoss500Shot = game.Content.Load <SoundEffect>("SFX/sfxMoss500gunshot"); sfxMoss500pump = game.Content.Load <SoundEffect>("SFX/sfxMoss500pump"); //offsetting where the limbs and stuff are torsoOffset = new Vector3(0, 0.4f, 0); headOffset = new Vector3(0, 1.0f, 0); armLeftOffset = new Vector3(-0.25f, 0.9f, 0); armRightOffSet = new Vector3(0.25f, 0.9f, 0); legLeftOffset = new Vector3(-0.11f, 0.4f, 0); legRightOffset = new Vector3(0.11f, 0.4f, 0); //bounding box, first is min, second is max bulletCollisionBox = new BoundingBox(bulletColBoxMin, bulletColBoxMax); bulletList = new List <BulletClass>(); //bullet list //the bounding boxes for collision detection boundingBoxXNeg = new BoundingBox(bbXNMin, bbXNMax); boundingBoxXPos = new BoundingBox(bbXPMax, bbXNMax); boundingBoxZNeg = new BoundingBox(bbZNMin, bbZNMax); boundingBoxZPos = new BoundingBox(bbZPMin, bbZPMax); weaponClass1 = new WeaponClass(game, weapon, modelPosition); //weapon class will load weapon model based on WEAPONTYPE game.Components.Add(weaponClass1); }
// TODO - combine/fix via get/set? don't need double checks at the least private void SetActiveWeapon(WEAPONTYPE weaponType) { if (weaponType != WEAPONTYPE.NONE) { if (Weapon1 != null && weaponType == Weapon1.WeaponType) { ActiveWeapon = Weapon1; } else if (Weapon2 != null && weaponType == Weapon2.WeaponType) { ActiveWeapon = Weapon2; } else if (Weapon3 != null && weaponType == Weapon3.WeaponType) { ActiveWeapon = Weapon3; } else if (Weapon4 != null && weaponType == Weapon4.WeaponType) { ActiveWeapon = Weapon4; } } }
public void AddDebuff(Player attacker, WEAPONTYPE wt, float debuffLength) { switch (wt) { case WEAPONTYPE.NAPALM: case WEAPONTYPE.FLAMETHROWER: case WEAPONTYPE.CONCUSSION: case WEAPONTYPE.FLASH: Debuffs.Add(new Debuff { Type = wt, TimeLeft = debuffLength, Owner = this, Attacker = attacker }); break; case WEAPONTYPE.SYRINGE: if (attacker.Team != this.Team) { // enemy, infect Debuffs.Add(new Debuff { Type = wt, TimeLeft = debuffLength, Owner = this, Attacker = attacker }); } else { // friend, heal if (attacker.SyringeHealTime <= _game.World.GameTime) { _currentHealth = _maxHealth + 50; attacker.SyringeHealTime = _game.World.GameTime + 5; } } break; } }
public void ChooseRewards() { EventSystem.current.currentSelectedGameObject.GetComponent <Button>().interactable = false; GameObject chosenWeapon = EventSystem.current.currentSelectedGameObject.GetComponent <Reward>().m_Reward; WEAPONTYPE weaponID = chosenWeapon.GetComponent <WeaponID>().m_WeaponType; switch (m_PickCounter) { case 0: GameManager.m_Instance.m_Player1.weaponID = weaponID; Debug.Log("Player 1 weapon set as " + chosenWeapon.name); m_PickRewardText.text = "Choose reward: " + m_Second.ToString(); break; case 1: GameManager.m_Instance.m_Player2.weaponID = weaponID; Debug.Log("Player 2 weapon set as " + chosenWeapon.name); m_PickRewardText.text = "Choose reward: " + m_Third.ToString(); break; case 2: GameManager.m_Instance.m_Player3.weaponID = weaponID; Debug.Log("Player 3 weapon set as " + chosenWeapon.name); m_PickRewardText.text = "Choose reward: " + m_Fourth.ToString(); break; case 3: Debug.Log("Player 4 weapon set as " + chosenWeapon.name); GameManager.m_Instance.m_Player4.weaponID = weaponID; PickNewLevel(); Debug.Log("Rewards Given Out"); break; } m_PickCounter++; }
private void ProcessProjectilePacket(string[] split, ref int i) { string pName = split[i++]; string pID = split[i++]; WEAPONTYPE weapon = (WEAPONTYPE)Convert.ToInt16(split[i++]); Vector3 porg = new Vector3( float.Parse(split[i++], System.Globalization.CultureInfo.InvariantCulture) , float.Parse(split[i++], System.Globalization.CultureInfo.InvariantCulture) , float.Parse(split[i++], System.Globalization.CultureInfo.InvariantCulture) ); Vector3 pvel = new Vector3( float.Parse(split[i++], System.Globalization.CultureInfo.InvariantCulture) , float.Parse(split[i++], System.Globalization.CultureInfo.InvariantCulture) , float.Parse(split[i++], System.Globalization.CultureInfo.InvariantCulture) ); Vector3 prot = new Vector3( float.Parse(split[i++], System.Globalization.CultureInfo.InvariantCulture) , float.Parse(split[i++], System.Globalization.CultureInfo.InvariantCulture) , float.Parse(split[i], System.Globalization.CultureInfo.InvariantCulture) ); _game.World.ProjectileManager.AddNetworkedProjectile(pName, pID, porg, pvel, prot, weapon); }
public void WeaponSetting(WEAPONTYPE WeaponType) { if (WeaponType.Equals(WEAPONTYPE.MELEE_WEAPON)) { switch (_PlayerMeleeWeapon) { case MELEEWEAPON.TOOTH_PICK: MeleeWeaponSetting("현재무기 : 이쑤시개", WEAPONRATING.NORMAL, 4, 0.3f); break; case MELEEWEAPON.CLUB: MeleeWeaponSetting("현재무기 : 클럽", WEAPONRATING.NORMAL, 6, 0.5f); break; case MELEEWEAPON.STONE_SPEAR: MeleeWeaponSetting("현재무기 : 돌창", WEAPONRATING.NORMAL, 7, 0.5f); break; case MELEEWEAPON.VINE_WHIP: MeleeWeaponSetting("현재무기 : 넝쿨채찍", WEAPONRATING.NORMAL, 6, 0.4f); break; case MELEEWEAPON.WOOD_SHIELD: MeleeWeaponSetting("현재무기 : 나무방패", WEAPONRATING.NORMAL, 4, 0.6f); break; case MELEEWEAPON.SPIRAL_SWORD: MeleeWeaponSetting("현재무기 : 나선검", WEAPONRATING.RARE, 9, 0.5f); break; case MELEEWEAPON.RIGHT_SWORD_LEFT_SHILED: MeleeWeaponSetting("현재무기 : 오른쪽엔 검 왼쪽엔 방패", WEAPONRATING.RARE, 9, 0.5f); break; case MELEEWEAPON.KOLA: MeleeWeaponSetting("현재무기 : Kola", WEAPONRATING.RARE, 11, 0.4f); break; case MELEEWEAPON.RAPIER: MeleeWeaponSetting("현재무기 : 레이피어", WEAPONRATING.RARE, 8, 0.2f); break; case MELEEWEAPON.FORK: MeleeWeaponSetting("현재무기 : 포크", WEAPONRATING.UNIQUE, 14, 0.4f); break; case MELEEWEAPON.SEALED_KEY: MeleeWeaponSetting("현재무기 : 봉인된 열쇠", WEAPONRATING.UNIQUE, 17, 0.3f); break; case MELEEWEAPON.MASTER_KEY: MeleeWeaponSetting("현재무기 : 마스터키", WEAPONRATING.LEGEND, 35, 0.3f); break; case MELEEWEAPON.GAUNTLET: MeleeWeaponSetting("현재무기 : ??? 건틀릿", WEAPONRATING.UNKNOWN, 6, 0.4f); break; case MELEEWEAPON.SMALL_KEY: MeleeWeaponSetting("현재무기 : ??? 작은 열쇠", WEAPONRATING.UNKNOWN, 6, 0.5f); break; } } else if (WeaponType.Equals(WEAPONTYPE.RANGED_WEAPON)) { switch (_PlayerRangedWeapon) { case RANGEDWEAPON.TEST_GUN: RangedWeaponSetting("현재무기 : TestGun", WEAPONRATING.NORMAL, 30, 30, 5.0f, 1, 0.1f); break; case RANGEDWEAPON.WOOD_SLINGSHOT: RangedWeaponSetting("현재무기 : 나무새총", WEAPONRATING.NORMAL, 15, 90, 1.0f, 3, 0.4f); break; case RANGEDWEAPON.WOOD_BOW: RangedWeaponSetting("현재무기 : 나무활", WEAPONRATING.NORMAL, 10, 100, 1.3f, 4, 0.6f); break; case RANGEDWEAPON.STING: RangedWeaponSetting("현재무기 : 독침", WEAPONRATING.NORMAL, 15, 100, 0.8f, 3, 0.4f); break; case RANGEDWEAPON.BOOMERANG: RangedWeaponSetting("현재무기 : 부메랑", WEAPONRATING.NORMAL, 1, 1, 1.0f, 5, 1.0f); break; case RANGEDWEAPON.SEEDING: RangedWeaponSetting("현재무기 : 씨뿌리기", WEAPONRATING.NORMAL, 15, 80, 1.0f, 4, 0.4f); break; case RANGEDWEAPON.FIRE_BIRD: RangedWeaponSetting("현재무기 : 불새", WEAPONRATING.RARE, 10, 100, 1.2f, 6, 0.6f); break; case RANGEDWEAPON.FIRE_LOCK: RangedWeaponSetting("현재무기 : 화승총", WEAPONRATING.RARE, 5, 60, 1.7f, 9, 1.0f); break; case RANGEDWEAPON.CHAKRAM: RangedWeaponSetting("현재무기 : 차크람", WEAPONRATING.RARE, 10, 80, 0.8f, 8, 0.6f); break; case RANGEDWEAPON.NAILGUN: RangedWeaponSetting("현재무기 : 네일건", WEAPONRATING.RARE, 25, 120, 1.0f, 7, 0.4f); break; case RANGEDWEAPON.SHILED_PISTOL: RangedWeaponSetting("현재무기 : 쉴드피스톨", WEAPONRATING.UNIQUE, 20, 120, 1.0f, 10, 0.5f); break; case RANGEDWEAPON.GENTLEMAN_UMBRELLA: RangedWeaponSetting("현재무기 : 신사 우산", WEAPONRATING.UNIQUE, 20, 100, 0.7f, 8, 0.4f); break; case RANGEDWEAPON.THREE_SIX_NINE: RangedWeaponSetting("현재무기 : 369", WEAPONRATING.UNIQUE, 6, 93, 1.3f, 6, 0.5f); break; case RANGEDWEAPON.FLAX_GUN: RangedWeaponSetting("현재무기 : Flax Gun", WEAPONRATING.UNIQUE, 15, 150, 1.2f, 9, 0.3f); break; case RANGEDWEAPON.END_OF_THE_CENTURY_GAUNTLET: RangedWeaponSetting("현재무기 : 세기말 건틀릿", WEAPONRATING.LEGEND, 6, 60, 1.5f, 22, 2.0f); break; } } }
public override void Init(Player shooter, Vector3 vel, WEAPONTYPE weapon, Game game) { base.Init(shooter, vel, weapon, game); _damage = 100; _grenadeType = WEAPONTYPE.FRAG; }
public Weapon(string name, WEAPONTYPE weapontype, MATERIAL material) : base("weapon." + name, TOOLTYPE.WEAPON, material) { }
private Weapon SetupWeapon(WEAPONTYPE weapon) { Weapon weap = null; switch (weapon) { case WEAPONTYPE.SYRINGE: weap = new Syringe(); break; case WEAPONTYPE.AXE: weap = new Axe(); break; case WEAPONTYPE.SHOTGUN: weap = new Shotgun(); break; case WEAPONTYPE.SUPERSHOTGUN: weap = new SuperShotgun(); break; case WEAPONTYPE.NAILGUN: weap = new NailGun(); break; case WEAPONTYPE.SUPERNAILGUN: weap = new SuperNailGun(); break; case WEAPONTYPE.GRENADELAUNCHER: weap = new GrenadeLauncher(); break; case WEAPONTYPE.PIPEBOMBLAUNCHER: weap = new PipebombLauncher(); break; case WEAPONTYPE.ROCKETLAUNCHER: weap = new RocketLauncher(); break; case WEAPONTYPE.MINIGUN: weap = new Minigun(); break; case WEAPONTYPE.INCENDIARYCANNON: weap = new IncendiaryCannon(); break; case WEAPONTYPE.FLAMETHROWER: weap = new Flamethrower(); break; case WEAPONTYPE.NONE: default: break; } if (weap != null) { weap.Init(_game); weap.Spawn(this, nameof(weap)); } return(weap); }
public override void Update(GameTime gameTime) { //delta = gameTime.ElapsedGameTime.Milliseconds; MouseState mouseState = Mouse.GetState(); KeyboardState keyPress = Keyboard.GetState(); //rotation angle for the entire player model //how I learned to use Atan2: https://stackoverflow.com/questions/13694003/rotating-an-image-towards-the-mouses-current-position if (!playerIsDead) //only update player rotation movement if player is not dead { rotAngle = (float)Math.Atan2(-mousePosition.X, -mousePosition.Z); } //updating collision bounding boxs bulletCollisionBox.Min = modelPosition + bulletColBoxMin; bulletCollisionBox.Max = modelPosition + bulletColBoxMax; //updating collision bounding boxs boundingBoxXNeg.Min = modelPosition + bbXNMin; boundingBoxXNeg.Max = modelPosition + bbXNMax; boundingBoxXPos.Min = modelPosition + bbXPMin; boundingBoxXPos.Max = modelPosition + bbXPMax; boundingBoxZNeg.Min = modelPosition + bbZNMin; boundingBoxZNeg.Max = modelPosition + bbZNMax; boundingBoxZPos.Min = modelPosition + bbZPMin; boundingBoxZPos.Max = modelPosition + bbZPMax; //rotation angles for the limbs #region leg rotations float legAngle = 0f; legAngle = prevLegRotAngle; if (legAngle < MAXLEGANGLE && legForward == true && isMoving) //if leg is moving forwards and can move forwards { prevLegRotAngle += LEGANGLEPERTICK * delta; } else if (legAngle > MAXLEGANGLE) //if leg can't move forwards anymore { legForward = false; //leg is now moving backwards } if (legAngle > -MAXLEGANGLE && legForward == false && isMoving) //if leg is moving backwards and can move backwards { prevLegRotAngle -= LEGANGLEPERTICK * delta; } else if (legAngle < -MAXLEGANGLE) //if leg can't move backwards anymore { legForward = true; //leg is now moving forwards } if (!isMoving) { prevLegRotAngle = 0f; } #endregion #region head movement float headAngle = 0f; headAngle = prevHeadRotAngle; if (headAngle < MAXHEADANGLE && headLimit && !isMoving) //if head has not reached limit of rotation to one side, and char is not moving { prevHeadRotAngle += HEADANGLEPERTICK * delta; } else if (headAngle > MAXHEADANGLE) { headLimit = false; } if (headAngle > -MAXHEADANGLE && !headLimit && !isMoving) { prevHeadRotAngle -= HEADANGLEPERTICK * delta; } else if (headAngle < -MAXHEADANGLE) { headLimit = true; } if (isMoving) //if character is moving, stop head rotation { prevHeadRotAngle = 0f; } #endregion #region arm movement float armAngle = 0f; armAngle = prevArmRotAngle; if (armAngle < MAXARMANGLE && armUp) { prevArmRotAngle += ARMANGLEPERTICK * delta; } else if (armAngle > MAXARMANGLE) { armUp = false; } if (armAngle > -MAXARMANGLE && !armUp) { prevArmRotAngle -= ARMANGLEPERTICK * delta; } else if (armAngle < -MAXARMANGLE) { armUp = true; } #endregion //weapon 1 model position, camera matrix, rotation weaponClass1.WeaponPosition = modelPosition; //moving weapon based on player model weaponClass1.CameraViewMatrix = cameraViewMatrix; //moving weapon camera based on player model weaponClass1.WeaponRotation = rotAngle; weaponClass1.DiffuseVector = DiffuseVector; weaponClass1.LightingDirection = LightingDirection; weaponClass1.SpecularVector = SpecularVector; //weapon 2 model position, camera matrix, rotation weaponClass2.WeaponPosition = modelPosition; //moving weapon based on player model weaponClass2.CameraViewMatrix = cameraViewMatrix; //moving weapon camera based on player model weaponClass2.WeaponRotation = rotAngle; weaponClass2.DiffuseVector = DiffuseVector; weaponClass2.LightingDirection = LightingDirection; weaponClass2.SpecularVector = SpecularVector; //weapon 3 model position, camera matrix, rotation weaponClass3.WeaponPosition = modelPosition; //moving weapon based on player model weaponClass3.CameraViewMatrix = cameraViewMatrix; //moving weapon camera based on player model weaponClass3.WeaponRotation = rotAngle; weaponClass3.DiffuseVector = DiffuseVector; weaponClass3.LightingDirection = LightingDirection; weaponClass3.SpecularVector = SpecularVector; //changing which weapon the player holds based on which 1-3 key is pressed if (keyPress.IsKeyDown(Keys.D1)) { MediaPlayer.Play(sfxWeaponSwitch); weaponSwitchTo = weaponClass1.WeaponType; reloadWeapon = false; } else if (keyPress.IsKeyDown(Keys.D2)) { MediaPlayer.Play(sfxWeaponSwitch); weaponSwitchTo = weaponClass2.WeaponType; reloadWeapon = false; } else if (keyPress.IsKeyDown(Keys.D3)) { MediaPlayer.Play(sfxWeaponSwitch); weaponSwitchTo = weaponClass3.WeaponType; reloadWeapon = false; } //changing which weapon the player holds based on current mouse wheel scroll position if (mouseState.ScrollWheelValue > previousScrollWheelValue) { MediaPlayer.Play(sfxWeaponSwitch); if (currWeapon == weaponClass1.WeaponType) { weaponSwitchTo = weaponClass3.WeaponType; } else if (currWeapon == weaponClass2.WeaponType) { weaponSwitchTo = weaponClass1.WeaponType; } else { weaponSwitchTo = weaponClass2.WeaponType; } reloadWeapon = false; } if (mouseState.ScrollWheelValue < previousScrollWheelValue) { MediaPlayer.Play(sfxWeaponSwitch); if (currWeapon == weaponClass1.WeaponType) { weaponSwitchTo = weaponClass2.WeaponType; } else if (currWeapon == weaponClass2.WeaponType) { weaponSwitchTo = weaponClass3.WeaponType; } else { weaponSwitchTo = weaponClass1.WeaponType; } reloadWeapon = false; } previousScrollWheelValue = mouseState.ScrollWheelValue; #region logic for weapon switching //weapon switching logic, when one weapon is selected, all other weapons are disabled and invisible. current player held weapon attributes also change if (currWeapon == weaponClass1.WeaponType) { weaponClass1.Enabled = true; weaponClass1.Visible = true; weaponClass2.Enabled = false; weaponClass2.Visible = false; weaponClass3.Enabled = false; weaponClass3.Visible = false; currWeaponAmmoInWeapon = weaponClass1.WeaponAmmoInWeapon; currWeaponAmmoTotal = weaponClass1.WeaponMaxAmmo; currWeaponMagSize = weaponClass1.WeaponMagSize; currWeaponROF = weaponClass1.WeaponROF; if (!reloadWeapon) { currWeaponReloadTime = weaponClass1.WeaponReloadTime; } if (weaponSwitchTo == weaponClass2.WeaponType) { weaponClass1.Enabled = false; weaponClass1.Visible = false; weaponClass2.Enabled = true; weaponClass2.Visible = true; weaponClass3.Enabled = false; weaponClass3.Visible = false; weaponClass1.WeaponAmmoInWeapon = currWeaponAmmoInWeapon; weaponClass1.WeaponMaxAmmo = currWeaponAmmoTotal; weaponClass1.WeaponMagSize = currWeaponMagSize; currWeaponAmmoInWeapon = weaponClass2.WeaponAmmoInWeapon; currWeaponAmmoTotal = weaponClass2.WeaponMaxAmmo; currWeaponMagSize = weaponClass2.WeaponMagSize; currWeaponROF = weaponClass2.WeaponROF; currWeaponReloadTime = weaponClass2.WeaponReloadTime; } else if (weaponSwitchTo == weaponClass3.WeaponType) { weaponClass1.Enabled = false; weaponClass1.Visible = false; weaponClass2.Enabled = false; weaponClass2.Visible = false; weaponClass3.Enabled = true; if (weaponClass3.WeaponAmmoInWeapon != 0) { weaponClass3.Visible = true; } weaponClass1.WeaponAmmoInWeapon = currWeaponAmmoInWeapon; weaponClass1.WeaponMaxAmmo = currWeaponAmmoTotal; weaponClass1.WeaponMagSize = currWeaponMagSize; currWeaponAmmoInWeapon = weaponClass3.WeaponAmmoInWeapon; currWeaponAmmoTotal = weaponClass3.WeaponMaxAmmo; currWeaponMagSize = weaponClass3.WeaponMagSize; currWeaponROF = weaponClass3.WeaponROF; currWeaponReloadTime = weaponClass3.WeaponReloadTime; } } else if (currWeapon == weaponClass2.WeaponType) { weaponClass2.Enabled = true; weaponClass2.Visible = true; weaponClass1.Enabled = false; weaponClass1.Visible = false; weaponClass3.Enabled = false; weaponClass3.Visible = false; currWeaponAmmoInWeapon = weaponClass2.WeaponAmmoInWeapon; currWeaponAmmoTotal = weaponClass2.WeaponMaxAmmo; currWeaponMagSize = weaponClass2.WeaponMagSize; currWeaponROF = weaponClass2.WeaponROF; if (!reloadWeapon) { currWeaponReloadTime = weaponClass2.WeaponReloadTime; } if (weaponSwitchTo == weaponClass1.WeaponType) { weaponClass1.Enabled = true; weaponClass1.Visible = true; weaponClass2.Enabled = false; weaponClass2.Visible = false; weaponClass3.Enabled = false; weaponClass3.Visible = false; weaponClass2.WeaponAmmoInWeapon = currWeaponAmmoInWeapon; weaponClass2.WeaponMaxAmmo = currWeaponAmmoTotal; weaponClass2.WeaponMagSize = currWeaponMagSize; currWeaponAmmoInWeapon = weaponClass1.WeaponAmmoInWeapon; currWeaponAmmoTotal = weaponClass1.WeaponMaxAmmo; currWeaponMagSize = weaponClass1.WeaponMagSize; currWeaponROF = weaponClass1.WeaponROF; currWeaponReloadTime = weaponClass1.WeaponReloadTime; } else if (weaponSwitchTo == weaponClass3.WeaponType) { weaponClass1.Enabled = false; weaponClass1.Visible = false; weaponClass2.Enabled = false; weaponClass2.Visible = false; weaponClass3.Enabled = true; if (weaponClass3.WeaponAmmoInWeapon != 0) { weaponClass3.Visible = true; } weaponClass2.WeaponAmmoInWeapon = currWeaponAmmoInWeapon; weaponClass2.WeaponMaxAmmo = currWeaponAmmoTotal; weaponClass2.WeaponMagSize = currWeaponMagSize; currWeaponAmmoInWeapon = weaponClass3.WeaponAmmoInWeapon; currWeaponAmmoTotal = weaponClass3.WeaponMaxAmmo; currWeaponMagSize = weaponClass3.WeaponMagSize; currWeaponROF = weaponClass3.WeaponROF; currWeaponReloadTime = weaponClass3.WeaponReloadTime; } } else if (currWeapon == weaponClass3.WeaponType) { weaponClass3.Enabled = true; if (weaponClass3.WeaponAmmoInWeapon != 0) { weaponClass3.Visible = true; } weaponClass2.Enabled = false; weaponClass2.Visible = false; weaponClass1.Enabled = false; weaponClass1.Visible = false; currWeaponAmmoInWeapon = weaponClass3.WeaponAmmoInWeapon; currWeaponAmmoTotal = weaponClass3.WeaponMaxAmmo; currWeaponMagSize = weaponClass3.WeaponMagSize; currWeaponROF = weaponClass3.WeaponROF; if (!reloadWeapon) { currWeaponReloadTime = weaponClass3.WeaponReloadTime; } if (weaponSwitchTo == weaponClass1.WeaponType) { weaponClass1.Enabled = true; weaponClass1.Visible = true; weaponClass2.Enabled = false; weaponClass2.Visible = false; weaponClass3.Enabled = false; weaponClass3.Visible = false; weaponClass3.WeaponAmmoInWeapon = currWeaponAmmoInWeapon; weaponClass3.WeaponMaxAmmo = currWeaponAmmoTotal; weaponClass3.WeaponMagSize = currWeaponMagSize; currWeaponAmmoInWeapon = weaponClass1.WeaponAmmoInWeapon; currWeaponAmmoTotal = weaponClass1.WeaponMaxAmmo; currWeaponMagSize = weaponClass1.WeaponMagSize; currWeaponROF = weaponClass1.WeaponROF; currWeaponReloadTime = weaponClass1.WeaponReloadTime; } else if (weaponSwitchTo == weaponClass2.WeaponType) { weaponClass1.Enabled = false; weaponClass1.Visible = false; weaponClass2.Enabled = true; weaponClass2.Visible = true; weaponClass3.Enabled = false; weaponClass3.Visible = false; weaponClass3.WeaponAmmoInWeapon = currWeaponAmmoInWeapon; weaponClass3.WeaponMaxAmmo = currWeaponAmmoTotal; weaponClass3.WeaponMagSize = currWeaponMagSize; currWeaponAmmoInWeapon = weaponClass2.WeaponAmmoInWeapon; currWeaponAmmoTotal = weaponClass2.WeaponMaxAmmo; currWeaponMagSize = weaponClass2.WeaponMagSize; currWeaponROF = weaponClass2.WeaponROF; currWeaponReloadTime = weaponClass2.WeaponReloadTime; } } currWeapon = weaponSwitchTo; #endregion if (keyPress.IsKeyDown(Keys.R) && currWeaponAmmoTotal > 0) //player can manually trigger reloading of weapon, if weapon is switched during reloading, will reset reload timer { reloadWeapon = true; if (currWeapon == WEAPONTYPE.AK47) { currWeaponAmmoInWeapon = 0; weaponClass1.WeaponAmmoInWeapon = 0; } } //if left mouse button is held down, means player is shooting if (mouseState.LeftButton == ButtonState.Pressed) { //this is used as interrupt for how fast bullet cam fire timeLastBullet += gameTime.ElapsedGameTime.Milliseconds; if (currWeapon == WEAPONTYPE.AK47) { if (timeLastBullet > 100 && currWeaponAmmoInWeapon > 0) //&& weaponClass1.WeaponAmmoInWeapon > 0 { Random random = new Random(); double offSetAmount = 0.25; //the amount to offset the mouse position //calculating the offset for X and Z float offsetX = (float)(random.NextDouble() * (((mousePosition.X * offSetAmount)) - ((mousePosition.X * offSetAmount)) + ((mousePosition.X * offSetAmount)))); float offsetZ = (float)(random.NextDouble() * (((mousePosition.Z * offSetAmount)) - ((mousePosition.Z * offSetAmount)) + ((mousePosition.Z * offSetAmount)))); offsetX += mousePosition.X; //applying offset to X and Z offsetZ += mousePosition.Z; float rotAngleOffset = (float)Math.Atan2(-offsetX, -offsetZ); //calculating the bullet angle based off of the offset Vector3 bulletIncrement = new Vector3((offsetX * 10) - offsetX, 0, (offsetZ * 10) - offsetZ); //amount to increment bullet per update by bulletIncrement.Normalize(); //adding bullet to bullet list, bullet appears based on current position and etc bulletList.Add(new BulletClass(weaponClass1.WeaponPosition, mousePosition, bulletIncrement * 0.5f, rotAngleOffset, weaponClass2.WeaponType)); //adding new bullet to bulletList currWeaponAmmoInWeapon = weaponClass1.WeaponAmmoInWeapon--; //subtracting ammo in weapon per bullet fired timeLastBullet = 0; sfxAk47Shot.Play(); //play sound effect for ak47 } else if (currWeaponAmmoInWeapon == 0 && currWeaponAmmoTotal > 0) //if ammo is not greater than 0, means gun has run out of bullet { reloadWeapon = true; } else if (currWeaponAmmoInWeapon == 0 && currWeaponAmmoTotal == 0 && !isDryFiring) { MediaPlayer.Play(sfxWeaponDryFire); isDryFiring = true; } } if (currWeapon == WEAPONTYPE.SHOTGUN) // && weaponClass2.WeaponAmmoInWeapon > 0 { Random random = new Random(); if (timeLastBullet > 1000 && ROFInterrupt <= 0 && currWeaponAmmoInWeapon > 0) { double offSetAmountX = 0.5; //the amount to offset the mouse position double offSetAmountZ = 0.5; //these 4 if statements will adjust the amount of x and z offsets for the shotgun spread, this is needed as the offset //is randomly generated based on a set amount from the mouse position, and will change based on the current mouse x and y position if (mousePosition.X > -1.5 && mousePosition.X < 1.5) { offSetAmountX = 3; } if (mousePosition.Z > -1.5 && mousePosition.Z < 1.5) { offSetAmountZ = 3; } if (mousePosition.X > -0.5 && mousePosition.X < 0.5) { offSetAmountX = 10; } if (mousePosition.Z > -0.5 && mousePosition.Z < 0.5) { offSetAmountZ = 10; } for (int i = 0; i < 7; i++) //this for loop will add 7 bullets to the bulletList every time the shotgun is fired { //calculating the offset for X and Z float offsetX = (float)(random.NextDouble() * (((mousePosition.X * offSetAmountX)) - ((mousePosition.X * offSetAmountX)) + ((mousePosition.X * offSetAmountX)))); float offsetZ = (float)(random.NextDouble() * (((mousePosition.Z * offSetAmountZ)) - ((mousePosition.Z * offSetAmountZ)) + ((mousePosition.Z * offSetAmountZ)))); offsetX += mousePosition.X; //applying offset to X and Z offsetZ += mousePosition.Z; float rotAngleOffset = (float)Math.Atan2(-offsetX, -offsetZ); //calculating the bullet angle based off of the offset Vector3 bulletIncrement = new Vector3((offsetX * 10) - offsetX, 0, (offsetZ * 10) - offsetZ); //amount to increment bullet per update by bulletIncrement.Normalize(); bulletList.Add(new BulletClass(weaponClass2.WeaponPosition, mousePosition, bulletIncrement * 0.3f, rotAngleOffset, weaponClass2.WeaponType)); //adding new bullet to bulletList } currWeaponAmmoInWeapon = weaponClass2.WeaponAmmoInWeapon--; //subtracting ammo in weapon per bullet fired timeLastBullet = 0; //if fired, set to 0 ROFInterrupt = 1000; //if fired, set the weapon reload time, which is 1 second sfxMoss500Shot.Play(); } else if (currWeaponAmmoInWeapon == 0 && currWeaponAmmoTotal > 0) //if ammo is not greater than 0, means gun has run out of bullet { reloadWeapon = true; } else if (reloadWeapon == true) { ROFInterrupt -= gameTime.ElapsedGameTime.Milliseconds; } else if (currWeaponAmmoInWeapon == 0 && currWeaponAmmoTotal == 0 && !isDryFiring) { MediaPlayer.Play(sfxWeaponDryFire); isDryFiring = true; } } if (currWeapon == WEAPONTYPE.GRENADE) { if (currWeaponAmmoInWeapon != 0 && timeLastBullet >= 5000 && grenadeInterrupt <= 0) { //getting direction vector between mouse and player position grenadeIncrement = new Vector3(mousePosition.X * 10 - modelPosition.X, 0f, mousePosition.Z * 10 - modelPosition.Z); grenadeIncrement.Normalize(); //normalizing for increment vector grenadeIncrement *= 0.3f; //grenade move speed grenadeInitialPosition = weaponClass3.WeaponPosition; bulletList.Add(new BulletClass(weaponClass3.WeaponPosition, mousePosition, grenadeIncrement, rotAngle, weaponClass3.WeaponType)); currWeaponAmmoInWeapon = weaponClass3.WeaponAmmoInWeapon--; timeLastBullet = 0; //if fired, set to 0 grenadeInterrupt = 5000; //if fired, set the weapon reload time, which is 5 seconds weaponClass3.Visible = false; } else if (currWeaponAmmoInWeapon == 0 && currWeaponAmmoTotal > 0) //if ammo is not greater than 0, means gun has run out of bullet { reloadWeapon = true; } else { grenadeInterrupt -= gameTime.ElapsedGameTime.Milliseconds; } } } else { if (currWeapon == WEAPONTYPE.AK47) //interrupt for ak bullet fire rate { timeLastBullet = 100; } if (currWeapon == WEAPONTYPE.SHOTGUN) //interrupt for shotgun fire rate { timeLastBullet = 1000; if (ROFInterrupt <= 0) { timeLastBullet = 1000; } else { ROFInterrupt -= gameTime.ElapsedGameTime.Milliseconds; //subtracting from time until shotgun can be fired again } } if (currWeapon == WEAPONTYPE.GRENADE) { timeLastBullet = 5000; if (grenadeInterrupt <= 0) { timeLastBullet = 5000; } else { grenadeInterrupt -= gameTime.ElapsedGameTime.Milliseconds; //subtracting from time until shotgun can be fired again } } isDryFiring = false; } if (reloadWeapon) //if bool for weapon reload is true { if (currWeaponReloadTime <= 0) //if current reload time is less than or equal to zero, this is how long it takes for weapon to reload { if (currWeaponAmmoTotal > 0) //of there are ammo left for the weapon { if (currWeapon == WEAPONTYPE.AK47) //if weapon is ak-47 { currWeaponAmmoInWeapon = currWeaponMagSize; weaponClass1.WeaponAmmoInWeapon = currWeaponAmmoInWeapon; currWeaponAmmoTotal -= currWeaponAmmoInWeapon; weaponClass1.WeaponMaxAmmo = currWeaponAmmoTotal; reloadWeapon = false; sfxAk47Charge.Play(); } if (currWeapon == WEAPONTYPE.SHOTGUN && currWeaponAmmoInWeapon < 7 && mouseState.LeftButton != ButtonState.Pressed) //if weapon is shotgun { currWeaponAmmoInWeapon++; weaponClass2.WeaponAmmoInWeapon++; currWeaponAmmoTotal--; weaponClass2.WeaponMaxAmmo--; currWeaponReloadTime = weaponClass2.WeaponReloadTime; sfxMoss500pump.Play(); } else if (currWeaponAmmoInWeapon == 7) { reloadWeapon = false; } if (currWeapon == WEAPONTYPE.GRENADE) //if weapon is grenade { currWeaponAmmoInWeapon++; weaponClass3.WeaponAmmoInWeapon++; currWeaponAmmoTotal--; weaponClass3.WeaponMaxAmmo--; currWeaponReloadTime = weaponClass3.WeaponReloadTime; reloadWeapon = false; weaponClass3.Visible = true; } } } else { currWeaponReloadTime -= gameTime.ElapsedGameTime.Milliseconds; //decrementing the reload time, guns will be reloaded when relaod time reaches zero } } //if there are no ammo in the current weapon, and there is no ammo left to reload if (currWeaponAmmoInWeapon == 0 && currWeaponAmmoTotal == 0) { outOfAmmo = true; } else { outOfAmmo = false; } //if player health is less than 0, player is dead, set player hp to 0 for visuals if (playerHealth <= 0) { playerIsDead = true; playerHealth = 0; } base.Update(gameTime); }
public void SetupClass() { // remove old weapon nodes for readd Delete(_weapon1); Delete(_weapon2); Delete(_weapon3); Delete(_weapon4); // TODO - maybe one day use reflection to clean this up or do types properly switch (PlayerClass) { case PLAYERCLASS.NONE: break; case PLAYERCLASS.SCOUT: _maxHealth = Scout.Health; _maxArmour = Scout.Armour; _weapon1 = SetupWeapon(Scout.Weapon1); _weapon2 = SetupWeapon(Scout.Weapon2); _weapon3 = SetupWeapon(Scout.Weapon3); _weapon4 = SetupWeapon(Scout.Weapon4); ActiveWeapon = _weapon1; _moveSpeed = Scout.MoveSpeed; _gren1Type = Scout.Gren1Type; _gren2Type = Scout.Gren2Type; _gren1Count = Scout.MaxGren1; _gren2Count = Scout.MaxGren2; break; case PLAYERCLASS.SNIPER: break; case PLAYERCLASS.SOLDIER: _maxHealth = Soldier.Health; _maxArmour = Soldier.Armour; _weapon1 = SetupWeapon(Soldier.Weapon1); _weapon2 = SetupWeapon(Soldier.Weapon2); _weapon3 = SetupWeapon(Soldier.Weapon3); _weapon4 = SetupWeapon(Soldier.Weapon4); ActiveWeapon = _weapon1; _moveSpeed = Soldier.MoveSpeed; _gren1Type = Soldier.Gren1Type; _gren2Type = Soldier.Gren2Type; _gren1Count = Soldier.MaxGren1; _gren2Count = Soldier.MaxGren2; break; case PLAYERCLASS.DEMOMAN: _maxHealth = Demoman.Health; _maxArmour = Demoman.Armour; _weapon1 = SetupWeapon(Demoman.Weapon1); _weapon2 = SetupWeapon(Demoman.Weapon2); _weapon3 = SetupWeapon(Demoman.Weapon3); _weapon4 = SetupWeapon(Demoman.Weapon4); ActiveWeapon = _weapon1; _moveSpeed = Demoman.MoveSpeed; _gren1Type = Demoman.Gren1Type; _gren2Type = Demoman.Gren2Type; _gren1Count = Demoman.MaxGren1; _gren2Count = Demoman.MaxGren2; break; case PLAYERCLASS.MEDIC: _maxHealth = Medic.Health; _maxArmour = Medic.Armour; _weapon1 = SetupWeapon(Medic.Weapon1); _weapon2 = SetupWeapon(Medic.Weapon2); _weapon3 = SetupWeapon(Medic.Weapon3); _weapon4 = SetupWeapon(Medic.Weapon4); ActiveWeapon = _weapon1; _moveSpeed = Medic.MoveSpeed; _gren1Type = Medic.Gren1Type; _gren2Type = Medic.Gren2Type; _gren1Count = Medic.MaxGren1; _gren2Count = Medic.MaxGren2; break; case PLAYERCLASS.HWGUY: _maxHealth = HWGuy.Health; _maxArmour = HWGuy.Armour; _weapon1 = SetupWeapon(HWGuy.Weapon1); _weapon2 = SetupWeapon(HWGuy.Weapon2); _weapon3 = SetupWeapon(HWGuy.Weapon3); _weapon4 = SetupWeapon(HWGuy.Weapon4); ActiveWeapon = _weapon1; _moveSpeed = HWGuy.MoveSpeed; _gren1Type = HWGuy.Gren1Type; _gren2Type = HWGuy.Gren2Type; _gren1Count = HWGuy.MaxGren1; _gren2Count = HWGuy.MaxGren2; break; case PLAYERCLASS.PYRO: _maxHealth = Pyro.Health; _maxArmour = Pyro.Armour; _weapon1 = SetupWeapon(Pyro.Weapon1); _weapon2 = SetupWeapon(Pyro.Weapon2); _weapon3 = SetupWeapon(Pyro.Weapon3); _weapon4 = SetupWeapon(Pyro.Weapon4); ActiveWeapon = _weapon1; _moveSpeed = Pyro.MoveSpeed; _gren1Type = Pyro.Gren1Type; _gren2Type = Pyro.Gren2Type; _gren1Count = Pyro.MaxGren1; _gren2Count = Pyro.MaxGren2; break; case PLAYERCLASS.SPY: break; case PLAYERCLASS.ENGINEER: break; } }
public void SetServerState(Vector3 org, Vector3 velo, Vector3 rot, float health, float armour, WEAPONTYPE weaponType) { _serverState.Origin = org; _serverState.Velocity = velo; _serverState.Rotation = rot; _currentHealth = health; _currentArmour = armour; SetActiveWeapon(weaponType); if (!PlayerControlled) { this._mesh.Rotation = rot; } }
public override void _PhysicsProcess(float delta) { if (_weapon1 != null) { _weapon1.PhysicsProcess(delta); } if (_weapon2 != null) { _weapon2.PhysicsProcess(delta); } if (_weapon3 != null) { _weapon3.PhysicsProcess(delta); } if (_weapon4 != null) { _weapon4.PhysicsProcess(delta); } _predictedState = _serverState; if (pCmdQueue.Count == 0) { pCmdQueue.Add( new PlayerCmd { //snapshot = this.Peer.LastSnapshot + 1, snapshot = 0, playerID = ID, move_forward = 0, move_right = 0, move_up = 0, aim = new Basis(), cam_angle = 0, rotation = _predictedState.Rotation, attack = 0 } ); } else { pCmdQueue.Sort((x, y) => x.snapshot.CompareTo(y.snapshot)); } Transform t = GlobalTransform; t.origin = _predictedState.Origin; // by this point it's a new serverstate GlobalTransform = t; // TODO - implement medic aura health give foreach (PlayerCmd pCmd in pCmdQueue) { if (!PlayerControlled && IsNetworkMaster()) { _mesh.Rotation = pCmd.rotation; } if (pCmd.snapshot <= Peer.LastSnapshot) { continue; } Peer.LastSnapshot = pCmd.snapshot; switch (MoveType) { case MOVETYPE.DEAD: DeadProcess(pCmd, delta); break; case MOVETYPE.SPECTATOR: SpectatorProcess(pCmd, delta); break; case MOVETYPE.NONE: case MOVETYPE.NORMAL: NormalProcess(pCmd, delta); break; default: Console.ThrowPrint("No movement type set"); break; } } this.ProcessMovement(delta); if (IsNetworkMaster()) { WEAPONTYPE wt = (ActiveWeapon == null) ? WEAPONTYPE.NONE : ActiveWeapon.WeaponType; SetServerState(_predictedState.Origin, _predictedState.Velocity, _predictedState.Rotation, _currentHealth, _currentArmour, wt); } else { // FIXME - stop resending commands after trying 3 times _game.Network.SendPMovement(1, ID, pCmdQueue); } TrimCmdQueue(); }