Ejemplo n.º 1
0
        public override void Fire()
        {
            base.Fire();

            if (Ammo > 0)
            {
                if (FireTimer <= 0)
                {
                    MainGame.soundInstances.Add(new SoundInstance(Content.GetSound("shotgunSfx.wav"), 1f, .2f, 3));

                    //Console.WriteLine("Bang");
                    Bullet b0 = new Bullet(Owner.UID, Owner.AimAngle, Owner.Core + Helper.PolarToVector2(28, Owner.AimAngle, 1, 1));
                    Bullet b1 = new Bullet(Owner.UID, Owner.AimAngle - .1f, Owner.Core + Helper.PolarToVector2(28, Owner.AimAngle, 1, 1));
                    Bullet b2 = new Bullet(Owner.UID, Owner.AimAngle + .1f, Owner.Core + Helper.PolarToVector2(28, Owner.AimAngle, 1, 1));

                    Gui.CrosshairFireExpand = .75f;
                    MainGame.dm.Projectiles.Add(b0);
                    MainGame.dm.Projectiles.Add(b1);
                    MainGame.dm.Projectiles.Add(b2);
                    MainGame.Camera.Center += Helper.PolarToVector2(3.5f * MainGame.rand.Next(2, 3), Owner.AimAngle + (float)Math.PI, 1, 1);
                    ((ClientPlayer)Owner).holdDistance = -10f;
                    MainGame.dm.GameObjects.Add(new GunSmoke(Owner.Core + Helper.PolarToVector2(32, Owner.AimAngle, 1, 1) + (Owner.Velocity), Owner.AimAngle));
                    MainGame.dm.GameObjects.Add(new GunFlash(Owner.Core + Helper.PolarToVector2(32, Owner.AimAngle, 1, 1) + (Owner.Velocity), Owner.AimAngle));
                    Ammo--;

                    if (Ammo == 0)
                        if (ReloadTimer < 0)
                            ReloadTimer = ReloadSpeed;

                    FireTimer = FireSpeed;
                    MainGame.dm.Mailman.SendBulletCreate(b0);
                    MainGame.dm.Mailman.SendBulletCreate(b1);
                    MainGame.dm.Mailman.SendBulletCreate(b2);
                }
            }
            else
            {
                MainGame.soundInstances.Add(new SoundInstance(Content.GetSound("dryFireSfx.wav"), 1f, .1f, 3));
                if (ReloadTimer < 0)
                    ReloadTimer = 70;
            }
        }
Ejemplo n.º 2
0
        private void HandleBulletCreate(Bullet b, long uid)
        {
            Actor shooter = ((Actor)dm.GetPlayerWithUID(uid));
            MainGame.dm.Projectiles.Add(b);

            MainGame.dm.GameObjects.Add(new GunSmoke(shooter.Core + Helper.PolarToVector2(32, shooter.AimAngle, 1, 1) + (shooter.Velocity), shooter.AimAngle));
            MainGame.dm.GameObjects.Add(new GunFlash(shooter.Core + Helper.PolarToVector2(32, shooter.AimAngle, 1, 1) + (shooter.Velocity), shooter.AimAngle));
        }
Ejemplo n.º 3
0
        private void HandleAGameMessage(NetIncomingMessage msg)
        {
            string messageType = msg.ReadString();

            switch (messageType)
            {
                case "LIFE":
                    long UID_LIFE = msg.ReadInt64();
                    int hp = msg.ReadInt32();
                    HandleLifeMessage(UID_LIFE, hp);
                    break;

                case "NAME":
                    long UID_NAME = msg.ReadInt64();
                    string newName = msg.ReadString();
                    HandleNameMessage(UID_NAME, newName);
                    break;

                case "POS": //Update a player's position
                    long UID_POS = msg.ReadInt64();
                    float xPos = msg.ReadFloat();
                    float yPos = msg.ReadFloat();
                    int facing = msg.ReadInt32();
                    float aimAngle = msg.ReadFloat();
                    HandlePosMessage(UID_POS, xPos, yPos, facing, aimAngle);
                    break;

                case "JOIN": //Add a player
                    long UID_JOIN = msg.ReadInt64();
                    HandleJoinMessage(UID_JOIN);
                    break;

                case "CHAT": //Add chat
                    long UID_CHAT = msg.ReadInt64();
                    string message = msg.ReadString();
                    HandleChatMessage(UID_CHAT, message);
                    break;

                case "PART": //Remove a player
                    long UID_PART = msg.ReadInt64();
                    HandlePartMessage(UID_PART);
                    break;

                case "INFO": //Recieved when server has completed sending all newbie initialization
                    break;
                case "BULLET":
                    long UID_BULLET = msg.ReadInt64();
                    float xBULLET = msg.ReadFloat();
                    float yBULLET = msg.ReadFloat();
                    float BULLETangle = msg.ReadFloat();
                    Bullet b = new Bullet(UID_BULLET, BULLETangle, new Vector2f(xBULLET, yBULLET));
                    HandleBulletCreate(b, UID_BULLET);
                    break;
                case "RESPAWN":
                    long UID_RESPAWN = msg.ReadInt64();
                    HandleRespawnMessage(UID_RESPAWN);
                    break;
                case "COIN":
                    //long UID_COIN = msg.ReadInt64();
                    float xCOIN = msg.ReadFloat();
                    float yCOIN = msg.ReadFloat();
                    int countCOIN = msg.ReadInt32();

                    HandleCoinCreate(countCOIN, xCOIN, yCOIN);

                    break;
                case "SWITCHWEAPON":
                    long UID_WEPSWITCH = msg.ReadInt64();
                    int WEAPONID = msg.ReadInt32();
                    HandleNetPlayerWeaponSwitch(UID_WEPSWITCH, WEAPONID);
                    break;
                case "KILLER":
                    long UID_VICTIM = msg.ReadInt64();
                    long UID_KILLER = msg.ReadInt64();
                    HandleKillerMessage(UID_VICTIM, UID_KILLER);
                    break;
                case "LOOT":
                    Console.WriteLine("LOOT Recieved");
                    int LOOTseed = msg.ReadInt32();
                    Console.WriteLine(LOOTseed);
                    Random rand = new Random(LOOTseed);
                    MainGame.dm.GameObjects.Add(new TreasureBox(new Vector2f(rand.Next(40, 1600), 180)));
                    break;
                case "EMOTE":
                    long UID_EMOTE = msg.ReadInt64();
                    string EMOTE_TYPE = msg.ReadString();
                    MainGame.dm.GameObjects.Add(new EmoteBubble(EMOTE_TYPE, MainGame.dm.GetPlayerWithUID(UID_EMOTE))); ;
                    break;
                case "BOMB":
                    long UID_EXPLOSIVE = msg.ReadInt64();
                    float xEXP = msg.ReadFloat();
                    float yEXP = msg.ReadFloat();
                    float EXPangle = msg.ReadFloat();
                    BombInstance bomb = new BombInstance(UID_EXPLOSIVE, EXPangle, new Vector2f(xEXP, yEXP));
                    HandleBombCreate(bomb, UID_EXPLOSIVE);
                    break;
                case "TIME":
                    float TIME_MESSAGE = msg.ReadFloat();
                    HandleTimeMessage(TIME_MESSAGE);
                    break;
                case "MODEL":
                    Console.WriteLine("Model");
                    long UID_MODEL = msg.ReadInt64();
                    string MODEL_STR = msg.ReadString();
                    Console.WriteLine(MODEL_STR);
                    HandleModel(UID_MODEL, MODEL_STR);
                    break;
                case "GOLDCOUNT":
                    long UID_GOLDCOUNT = msg.ReadInt64();
                    int goldCount = msg.ReadInt32();
                    HandleGoldCountMessage(UID_GOLDCOUNT, goldCount);
                    break;
                case "LANDMINE":
                    long UID_MINEOWNER = msg.ReadInt64();
                    float xMINE = msg.ReadFloat();
                    float yMINE = msg.ReadFloat();
                    int MINE_ID = msg.ReadInt32();
                    HandleLandMineMessage(UID_MINEOWNER, xMINE, yMINE, MINE_ID);
                    break;
                case "LANDMINE_TRIGGER":
                    int LANDMINEID = msg.ReadInt32();
                    HandleLandMineTriggerMessage(LANDMINEID);
                    break;
                case "GENERATOR":
                    long UID_GENOWNER = msg.ReadInt64();
                    float xGEN = msg.ReadFloat();
                    float yGEN = msg.ReadFloat();
                    int type = msg.ReadInt32();
                    DateTime when = new DateTime(msg.ReadInt64());
                    HandleGeneratorMessage(xGEN, yGEN, type, when);
                    break;
                default:
                    Console.WriteLine("Unrecognized Game Message Recieved: {0}\n{1}", msg.ToString(), messageType);
                    break;
            }
        }
Ejemplo n.º 4
0
 public void SendBulletCreate(Bullet b)
 {
     NetOutgoingMessage outGoingMessage = client.CreateMessage();
     outGoingMessage.Write("BULLET");
     outGoingMessage.Write(b.Pos.X);
     outGoingMessage.Write(b.Pos.Y);
     outGoingMessage.Write(b.Angle);
     client.SendMessage(outGoingMessage, NetDeliveryMethod.ReliableOrdered);
 }