Esempio n. 1
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;
            }
        }
Esempio n. 2
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;
            }
        }