Beispiel #1
0
 public void Draw(GameTime gameTime, Map map)
 {
     Vector2 pos = map.GetTile(Position);
     map.spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend, null, null, null, null, map.parent.Cam.Transformation);
     Textures.Arial15.DrawText(map.spriteBatch, PlayerId.ToString(), pos, Color.Yellow);
     map.spriteBatch.End();
 }
Beispiel #2
0
 public void Draw(GameTime gameTime, Map map)
 {
     map.parent.spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.NonPremultiplied, null, null, null, null, map.parent.Cam.Transformation);
     switch (Type)
     {
         case ItemType.Rocket:
             map.parent.spriteBatch.Draw(Textures.BazookaItem, map.GetTile(Position), Color.White);
             break;
         case ItemType.Fuel:
             map.parent.spriteBatch.Draw(Textures.ChainsawItem, map.GetTile(Position), Color.White);
             break;
         case ItemType.Healthpack:
             map.parent.spriteBatch.Draw(Textures.HealthItem, map.GetTile(Position), Color.White);
             break;
         case ItemType.Launcher:
             map.parent.spriteBatch.Draw(Textures.LauncherItem, map.GetTile(Position), Color.White);
             break;
         case ItemType.Ammo:
             map.parent.spriteBatch.Draw(Textures.MachinegunItem, map.GetTile(Position), Color.White);
             break;
         case ItemType.Shotgun:
             map.parent.spriteBatch.Draw(Textures.ShotgunItem, map.GetTile(Position), Color.White);
             break;
         default:
             Textures.Arial15.DrawText(map.spriteBatch, Type.ToString(), map.GetTile(Position), Color.White);
             break;
     }
     map.parent.spriteBatch.End();
 }
        public void LoadMap()
        {
            map = null;
            string file = Path.Combine(Content.RootDirectory, cbn.MapName + ".mpc");

            if (!File.Exists(file))
            {
                WebClient wc = new WebClient();
                wc.DownloadFile(new Uri(cbn.MapServerUrl + "/" + cbn.MapName + "/" + cbn.MapName + ".mpc"), file);
            }

            File.Copy(file, file + ".rar", true);
            using (var stream = File.Open(file + ".rar", FileMode.Open, FileAccess.Write))
            {
                stream.Seek(0, SeekOrigin.Begin);
                stream.WriteByte(0x52);
                stream.WriteByte(0x61);
                stream.WriteByte(0x72);
                stream.Flush();
            }
            using (var arc = RarArchive.Open(file + ".rar"))
            {
                foreach (var f in arc.Entries)
                {

                    //using (var stream = f.OpenEntryStream())
                    //{
                    //    int read = 0;
                    //    byte[] buffer = new byte[(int)f.Size];
                    //    while (read < buffer.Length)
                    //    {
                    //        read += stream.Read(buffer, read, (int)f.Size - read);
                    //    }
                    //    Debugger.Break();
                    //}
                    using (var ffs = File.OpenWrite(Path.Combine(Content.RootDirectory, f.FilePath)))
                    {
                        f.WriteTo(ffs);
                        ffs.Flush();
                    }
                    if (Path.GetExtension(f.FilePath).ToLower().Equals(".pxi"))
                    {
                        DotPxi.ConvertToBitmap(Path.Combine(Content.RootDirectory, f.FilePath));
                    }
                }
            }

            map = new Map(this, cbn.MapName);
            map.LoadContent(Content);
            prevMapCRC = cbn.MapCRC;
        }
Beispiel #4
0
        public void Draw(GameTime gameTime, Map map)
        {
            map.parent.spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.NonPremultiplied, null, null, null, null, map.parent.Cam.Transformation);
            Vector2 pos = map.GetTile(Position);

            if (Team == 2)
            {
                map.parent.spriteBatch.Draw(Textures.PlayerPistol2, pos, null, Color.White, DegreeToRadian(Angle), new Vector2(Textures.PlayerPistol2.Width / 2, Textures.PlayerPistol2.Height / 2), 1, SpriteEffects.None, 0);
            }
            else
            {
                map.parent.spriteBatch.Draw(Textures.PlayerPistol1, pos, null, Color.White, DegreeToRadian(Angle), new Vector2(Textures.PlayerPistol1.Width / 2, Textures.PlayerPistol1.Height / 2), 1, SpriteEffects.None, 0);
            }
            Textures.Arial15.DrawText(map.spriteBatch, this.Name + " " + Health, pos + new Vector2(0, Textures.PlayerPistol1.Height), Color.Yellow);
            map.spriteBatch.End();
        }
Beispiel #5
0
        public void Update(GameTime gameTime, Map map)
        {
            PrevPos = Position;
            // Nopeus riippuu siitä millä aseella se on ammuttu
            var speed = Weapon.WeaponList[WeaponFrom].BulletSpeed;
            if (!Moved)
            {
                Moved = true;
                speed = 0;
            }
            // Jos ammus on ammuttu singolla niin tehdään savuvana
            if (WeaponFrom == WeaponType.Bazooka)
            {
                //If InScreen(ObjectX(bullet\obj), ObjectY(bullet\obj), 100) = True Then
                //    expl.EXPL_ANIMS = New(EXPL_ANIMS)
                //    expl\x      = ObjectX(bullet\obj)
                //    expl\y      = ObjectY(bullet\obj)
                //    expl\frame  = 0
                //    expl\tStamp = Timer()
                //    expl\frames = 16
                //    expl\img    = IMG_SMOKEANIM
                //    expl\w      = 20
                //    expl\h      = 20
                //EndIf
            }
            var RotationAngle = MathHelper.ToRadians(Angle);
            Vector2 direction = new Vector2((float)Math.Cos(RotationAngle),
                                    (float)Math.Sin(RotationAngle));
            direction.Normalize();
            Position += direction * speed;

            //UpdateGame2()
            //bx# = ObjectX(bullet\obj)
            //by# = ObjectY(bullet\obj)
            var hit = false;

            // Jos on ammuttu kranaatinlaukaisimella niin tutkitaan aikaviive
            if (WeaponFrom == WeaponType.Launcher)
            {
                if (ShotTime + 1000 < gameTime.TotalGameTime.Milliseconds)
                {
                    hit = true;
                }
            }

            // Osuiko seinään tai meniko kartalta ulos
            if (!hit && map.IsWall(Position) || !map.InMap(Position) || WeaponFrom == WeaponType.Chainsaw)
            {
                hit = true;
                //            bounce = False
                //            If bullet\weapon = WPN_LAUNCHER Then bounce = True
                // Osui seinään tai meni ulos
                //PlayGameSound(aWeapon(bullet\weapon, WPNF_HITSOUND), bx, by)
                //// Jos ammus oli singosta niin luodaan räjähdysanimaatio
                //If bullet\weapon = WPN_BAZOOKA Or bullet\weapon = WPN_LAUNCHER Then
                //    If InScreen(bx, by, 200) = True Then
                //        expl.EXPL_ANIMS = New(EXPL_ANIMS)
                //        expl\x      = bx
                //        expl\y      = by
                //        expl\frame  = 0
                //        expl\tStamp = Timer()
                //        expl\frames = 16
                //        expl\img    = IMG_EXPLOSION1
                //        expl\w      = 128
                //        expl\h      = 128
                //    EndIf
                //Else
                //    // Kipinöinti seinälle jos ammus on jostain muusta kuin singosta
                //    Sparking(bx, by)
                //EndIf
                //            If bounce = False Then hit = True
                // Kimmotus
                //            If bounce = True Then
                //                // Tutkitaan ammuksen suuntaa ja törmäyskulmaa ja niiden perusteella
                //                // asetetaan uusi suunta koska ammus kimpoaa seinästä.
                //                a# = CollisionAngle(bullet\obj, 1)
                //                ba# = ObjectAngle(bullet\obj)
                //                vx# = -Cos(ba)
                //                vy# = Sin(ba)
                //                If a = 0 And vx > 0 Then vx = vx * -1
                //                If a = 180 And vx < 0 Then vx = vx * -1
                //                If a = 90 And vy < 0 Then vy = vy * -1
                //                If a = 270 And vy > 0 Then vy = vy * -1
                //                //If a = 0 Or a = 180 Then vx = vx * -1
                //                //If a = 90 Or a = 270 Then vy = vy * -1
                //                a = GetAngle(vx, vy, 0, 0)
                //                RotateObject bullet\obj, a
                //                MoveObject bullet\obj, 10
                //            EndIf
            }
            if (WeaponFrom == WeaponType.Chainsaw)
            {
                hit = true;
            }

            if (hit)
            {
                Remove = true;
            }
        }
Beispiel #6
0
        public void Update(GameTime gameTime, Map map)
        {
            if (Vector2.Distance(Position, NextPosition) > 20)
            {
                Position = NextPosition;
            }
            NextPosition = Position;
            byte pickedItem = 0;
            if (Health > 0)
            {
                var newPos = Position;

                if (map.parent.keyboardState.IsKeyDown(Keys.A))
                {
                    newPos.X -= 4;
                }

                if (map.parent.keyboardState.IsKeyDown(Keys.D))
                {
                    newPos.X += 4;
                }

                if (map.parent.keyboardState.IsKeyDown(Keys.W))
                {
                    newPos.Y += 4;
                }

                if (map.parent.keyboardState.IsKeyDown(Keys.S))
                {
                    newPos.Y -= 4;
                }
                if (!map.IsWall(newPos))
                {
                    Position = newPos;
                }
                Vector2 pos = map.parent.Cam.MouseCursorInWorld - map.GetTile(Position);
                this.Angle = RadianToDegree(Math.Atan2(pos.Y, pos.X));
                while (Angle > 360)
                {
                    Angle -= 360;
                }
                //Camera.Location = Position;
                map.parent.Cam.Pos = map.GetTile(Position);
                HasAmmo = 1;

                foreach (var i in map.parent.cbn.Items.Values)
                {
                    if (this.Bounding.Intersects(i.Bounding))
                    {
                        pickedItem = i.Id;
                        break;
                    }
                }

                if (map.parent.mouseState.LeftButton == ButtonState.Pressed && !lastPressed)
                {
                    Weapon w = Weapon.WeaponList[(WeaponType)HeldWeapon];
                    // Tarkastetaan, onko panoksia
                    //ammoExists = False
                    //If aWeapon(player\weapon, WPNF_AMMO) > 0 Then ammoExists = True
                    //// Tutkitaan voidaanko lähettää tieto ampumisesta
                    //shootNow = 0
                    //If (MouseDown(1) = True Or KeyDown(cbKeySpace) = True) And (player\weapon<>WPN_PISTOL Or gNotShotYet = True) And gConsoleMode = False And gDevConsole = False And gSessionComplete = False And player\spawnTime = 0 And player\team <> 0 Then
                    //    // Onko ase latingissa
                    //    If player\lastShoot + aWeapon(player\weapon, WPNF_RELOADTIME) < Timer() And player\health > 0 Then
                    //        // Onko ammuksia
                    //        If aWeapon(player\weapon, WPNF_AMMO) > 0 Or aWeapon(player\weapon, WPNF_AMMO_MAX) = 0 Then
                    //            // Latingissa on, vähennetään ammuksia
                    //            aWeapon(player\weapon, WPNF_AMMO) = aWeapon(player\weapon, WPNF_AMMO) - 1
                    //            aWeaponAmmos(player\weapon) = aWeapon(player\weapon, WPNF_AMMO) * 3
                    //            player\lastShoot = Timer()
                    //            shootNow = True
                    //        Else
                    //            PlayGameSound(SND_EMPTY, ObjectX(player\obj), ObjectY(player\obj))
                    //            player\lastShoot = Timer()
                    //        EndIf
                    //        gNotShotYet = False // Ammuttiin jo. Pistoolit eivät ammu ennen kuin klikkaa uudestaan
                    //    EndIf
                    //EndIf

                }
            }
            lastPressed = map.parent.mouseState.LeftButton == ButtonState.Pressed;

            if (gameTime.TotalGameTime - map.parent.lastUpdate > TimeSpan.FromMilliseconds(100))
            {
                map.parent.cbn.UpdatePlayer(lastPressed ? (byte)1 : (byte)0, pickedItem);
                map.parent.lastUpdate = gameTime.TotalGameTime;
            }
        }