示例#1
0
        public void update(NPCCollection npcs, Player p, Mission m, bool isMainMission = false)
        {
            if (!active) return;
            if (cooldown == 0)
            {
                Vector3 pos = new Vector3(Constants.MAP_SIZE - 2 * x - 1, 0, Constants.MAP_SIZE - 2 * z - 1);
                Vector3 dir = p.Position - pos;

                dir.Normalize();

                if (isMainMission && kind != Constants.NPC_BOSS)
                    npcs.generate(kind, pos, dir, m.level - 10);
                else npcs.generate(kind, pos, dir, m.level);

                if (rate == Constants.SPAWN_ONCE)
                    active = false;
                else
                    cooldown = new Random().Next((int)(maxCooldown * 0.6f), (int)(maxCooldown * 1.0f));
            }
            else cooldown = Math.Max(cooldown - 1, 0);
        }
示例#2
0
文件: Player.cs 项目: kayorga/3DSP
 public void getHit(Bullet b, Mission m)
 {
     if (invincibleTimer > 0)
         return;
     //RAW DAMAGE//
     int dmg = b.Strength;
     //////////////
     gotHit = true;
     health = Math.Max(health - dmg, 0);
     m.dmgIn += dmg;
     invincibleTimer = Constants.PLAYER_BULLET_INVINCIBILITY;
     hitDelay = maxHitDelay;
 }
示例#3
0
文件: World.cs 项目: kayorga/3DSP
        /// <summary>
        /// configures npc spawners to match the mission data
        /// </summary>
        public void setupSpawners(Mission m)
        {
            if (m.Kinds[0] == Constants.NPC_BOSS)
                spawners[0].setup(m.Kinds[0], Constants.SPAWN_ONCE);
            else
                spawners[0].setup(m.Kinds[0], Constants.SPAWN_INFINITE);

            for (int i = 1; i < m.Kinds.Length; i++)
                spawners[i].setup(m.Kinds[i], Constants.SPAWN_INFINITE);
        }
示例#4
0
文件: World.cs 项目: kayorga/3DSP
 public void update(NPCCollection npcs, Player p, Mission m, bool isMainMission = false)
 {
     foreach (NPCSpawner spawner in spawners)
         spawner.update(npcs, p, m, isMainMission);
 }
示例#5
0
        public bool update(GameTime gameTime, BulletCollection bullets, Camera camera, Player p, Mission m)
        {
            #region npc death
            //die and grant xp
            if (health <= 0 && !isDead)
            {
                int exp = (int)(XP * (float)level / (float)p.level);
                exp = Math.Min(exp, (int)(XP * 1.5f));
                exp = Math.Max(exp, 1);
                if (p.lv == 50)
                {
                    exp = 0;
                }
                else
                {
                    p.getEXP(exp);
                }
                m.update(kind, exp);
                isDead             = true;
                isHit              = false;
                hitTimer           = 0;
                explosion.Position = Position + new Vector3(0, 0.5f, 0);
                explosion.Initialize(camera);
            }

            //Explosion Update if NPC is down
            if (isDead && active)
            {
                hitTimer++;
                explosion.Update(gameTime, camera);
                if (hitTimer > 25)
                {
                    active = false;
                    isDead = false;
                    this.explosion.Clear();
                    dmgNumbers.Clear();
                    return(false);
                }
            }
            #endregion

            #region shoot

            //shoot if player is within shooting distance and not on cooldown
            if (playerDistance <= world.shootDistance && cooldown == 0)
            {
                cooldown = maxCooldn;
                Vector3 dir = (p.position - position);
                dir.Normalize();
                bullets.generate(false, position + dir, dir, 1, world.shootDistance * 2, strength, element);
                audio.playShoot(false);
            }

            if (cooldown > 0)
            {
                cooldown--;
            }
            #endregion

            #region move
            //if (moving)
            //move();
            //else



            if (!moving || !move())
            {
                {
                    pathFinder.setup(new Point((int)Math.Round((-1 * position.X + world.size - 1)), (int)Math.Round((-1 * position.Z + world.size - 1))), p);
                    target    = pathFinder.findPath(kind == Constants.NPC_BOSS);
                    newTarget = true;
                    direction = target - position;
                    if (direction.Length() != 0)
                    {
                        direction.Normalize();
                    }
                    moving = true;
                    //move();
                }
            }

            #endregion

            #region get hit billboard/dmg number
            //Hit Notification
            if (isHit)
            {
                hitTimer++;
                billboardEngine.AddBillboard(this.position + new Vector3(0, 2, 0), Color.Red, 1.5f);
                if (hitTimer == 70)
                {
                    isHit    = false;
                    hitTimer = 0;
                }
            }
            #endregion

            //Rotate Model
            double rotationAngle = Math.Acos((Vector3.Dot(direction, -1 * Vector3.UnitX)) / (direction.Length()));
            rotationAngle  = (p.Position.Z < this.Position.Z) ? rotationAngle * -1.0f : rotationAngle;
            rotationAngle += (this.kind == Constants.NPC_BOSS) ? Math.PI / 2 : -Math.PI / 2;
            model.Rotation = new Vector3(0, (float)(rotationAngle), 0);

            //Update PlayerDistance
            playerDistance = (p.Position - this.Position).Length();

            if (playerDistance < 4)
            {
                target    = position;
                direction = p.Position - this.Position;
            }

            return(true);
        }
示例#6
0
        public void getHit(Bullet b, Mission m)
        {
            if (!isDead && b.fromPlayer)
            {
                int dmg = b.Strength;

                Random ran = new Random();

                dmg = (byte)(ran.Next(9 * dmg, 11 * dmg) * 0.1f);

                float dmgModifier = 1;

                //apply weakness and resistance
                if (b.Element != Constants.ELM_NIL && b.Element == elWeakness)
                {
                    dmgModifier *= 1.5f;
                }
                else if (b.Element != Constants.ELM_NIL && b.Element == element)
                {
                    dmgModifier /= 1.5f;
                }

                if (b.Type != Constants.TYP_NIL && b.Type == typeWeakness)
                {
                    dmgModifier *= 1.5f;
                }
                else if (b.Type != Constants.TYP_NIL && b.Type == typeResistance)
                {
                    dmgModifier /= 1.5f;
                }

                dmg = (int)(dmg * dmgModifier);

                //apply crit chance and play hit sound
                bool crit = false;
                if (ran.Next(100) < 8)
                {
                    crit = true;
                    dmg *= 2;
                    audio.playCrit();
                }
                else
                {
                    audio.playNPCHit(dmgModifier);
                }

                //cap damage between 1 and health
                dmg = Math.Max(dmg, 1);
                dmg = Math.Min(dmg, health);

                //apply damage and add to dmg out
                health   -= dmg;
                m.dmgOut += dmg;

                //knockback effect
                Vector3 push = b.Direction;
                push.Normalize();
                this.position += push * 0.5f;
                moving         = false;
                //isHit = true;

                //add new dmg number for new dmg
                sbyte dx = (sbyte)(ran.Next(41) - 20);
                sbyte dy = (sbyte)(ran.Next(21) - 10);
                dmgNumbers.Add(new DmgNumber(dmg, crit, dx, dy));
            }
        }
示例#7
0
        public void update(GameTime gameTime, Camera camera, World world, NPCCollection npcs, Player p, Mission m)
        {
            if (!active)
            {
                return;
            }

            waveTime += gameTime.ElapsedGameTime;
            float dx = (float)Math.Sin(waveTime.Milliseconds);
            float dz = (float)Math.Cos(waveTime.Milliseconds);

            int factor = (int)Math.Ceiling(speed);

            float remainingSpeed = speed;
            float spd            = speed / (float)factor;

            for (int i = 0; i < factor; i++)
            {
                spd = Math.Min(spd, remainingSpeed);
                bool u = updateCycle(gameTime, camera, world, npcs, p, m, factor, spd, dx, dz);
                remainingSpeed -= spd;
                if (!u || remainingSpeed == 0)
                {
                    break;
                }
            }

            return;
        }
示例#8
0
        private bool updateCycle(GameTime gameTime, Camera camera, World world, NPCCollection npcs, Player p, Mission m, int factor, float spd, float dx, float dz)
        {
            position += spd * direction;
            if (type == Constants.TYP_WAV)
            {
                Vector3 cross = Vector3.Cross(direction, Vector3.Up);
                if (mirror)
                {
                    position -= 0.5f * cross * (float)Math.Sin(waveTime.Milliseconds * 200);
                }
                else
                {
                    position += 0.5f * cross * (float)Math.Sin(waveTime.Milliseconds * 200);
                }
                //position += 0.5f * Vector3.Up * (float)Math.Cos(waveTime.Milliseconds);
                //position.X += dx / factor;
                //position.Z += dz / factor;
            }

            distance += spd;

            bulletOb.Position = position;

            particleEffect.Update((float)gameTime.ElapsedGameTime.TotalSeconds, camera.ViewMatrix, position, direction);

            xTile = (byte)Math.Round(-1 * (position.X) + (Constants.MAP_SIZE - 1));
            zTile = (byte)Math.Round(-1 * (position.Z) + (Constants.MAP_SIZE - 1));

            if (collision(world) || collision(npcs, m) || collision(p, m) || distance > maxDist)
            {
                active = false;
                particleEffect.Clear();
                return(false);
            }
            return(true);
        }
示例#9
0
文件: NPC.cs 项目: kayorga/3DSP
        public void getHit(Bullet b, Mission m)
        {
            if (!isDead && b.fromPlayer)
            {
                int dmg = b.Strength;

                Random ran = new Random();

                dmg = (byte) (ran.Next(9*dmg, 11*dmg) * 0.1f);

                float dmgModifier = 1;

                //apply weakness and resistance
                if (b.Element != Constants.ELM_NIL && b.Element == elWeakness) dmgModifier *= 1.5f;
                else if (b.Element != Constants.ELM_NIL && b.Element == element) dmgModifier /= 1.5f;

                if (b.Type != Constants.TYP_NIL && b.Type == typeWeakness) dmgModifier *= 1.5f;
                else if (b.Type != Constants.TYP_NIL && b.Type == typeResistance) dmgModifier /= 1.5f;

                dmg = (int)(dmg * dmgModifier);

                //apply crit chance and play hit sound
                bool crit = false;
                if (ran.Next(100) < 8)
                {
                    crit = true;
                    dmg *= 2;
                    audio.playCrit();
                }
                else audio.playNPCHit(dmgModifier);

                //cap damage between 1 and health
                dmg = Math.Max(dmg, 1);
                dmg = Math.Min(dmg, health);

                //apply damage and add to dmg out
                health -= dmg;
                m.dmgOut += dmg;

                //knockback effect
                Vector3 push = b.Direction;
                push.Normalize();
                this.position += push * 0.5f;
                moving = false;
                //isHit = true;

                //add new dmg number for new dmg
                sbyte dx = (sbyte)(ran.Next(41) - 20);
                sbyte dy = (sbyte)(ran.Next(21) - 10);
                dmgNumbers.Add(new DmgNumber(dmg, crit, dx, dy));
            }
        }
示例#10
0
文件: NPC.cs 项目: kayorga/3DSP
        public bool update(GameTime gameTime, BulletCollection bullets, Camera camera, Player p, Mission m)
        {
            #region npc death
            //die and grant xp
            if (health <= 0 && !isDead)
            {
                int exp = (int)(XP * (float)level / (float)p.level);
                exp = Math.Min(exp,(int) (XP * 1.5f));
                exp = Math.Max(exp, 1);
                if (p.lv == 50) exp = 0;
                else p.getEXP(exp);
                m.update(kind, exp);
                isDead = true;
                isHit = false;
                hitTimer = 0;
                explosion.Position = Position + new Vector3(0, 0.5f, 0);
                explosion.Initialize(camera);
            }

            //Explosion Update if NPC is down
            if (isDead && active)
            {
                hitTimer++;
                explosion.Update(gameTime, camera);
                if (hitTimer > 25)
                {
                    active = false;
                    isDead = false;
                    this.explosion.Clear();
                    dmgNumbers.Clear();
                    return false;
                }
            }
            #endregion

            #region shoot

            //shoot if player is within shooting distance and not on cooldown
            if (playerDistance <= world.shootDistance && cooldown == 0)
            {
                cooldown = maxCooldn;
                Vector3 dir = (p.position - position);
                dir.Normalize();
                bullets.generate(false, position + dir, dir, 1, world.shootDistance * 2, strength, element);
                audio.playShoot(false);
            }

            if (cooldown > 0) cooldown--;
            #endregion

            #region move
            //if (moving)
                //move();
            //else

            if (!moving || !move())
            {
                {
                    pathFinder.setup(new Point((int)Math.Round((-1 * position.X + world.size - 1)), (int)Math.Round((-1 * position.Z + world.size - 1))), p);
                    target = pathFinder.findPath(kind == Constants.NPC_BOSS);
                    newTarget = true;
                    direction = target - position;
                    if (direction.Length() != 0) direction.Normalize();
                    moving = true;
                    //move();
                }
            }

            #endregion

            #region get hit billboard/dmg number
            //Hit Notification
            if (isHit)
            {
                hitTimer++;
                billboardEngine.AddBillboard(this.position + new Vector3(0, 2, 0), Color.Red, 1.5f);
                if (hitTimer == 70)
                {
                    isHit = false;
                    hitTimer = 0;
                }
            }
            #endregion

            //Rotate Model
            double rotationAngle = Math.Acos((Vector3.Dot(direction, -1 * Vector3.UnitX)) / (direction.Length()));
            rotationAngle = (p.Position.Z < this.Position.Z) ? rotationAngle * -1.0f : rotationAngle;
            rotationAngle += (this.kind == Constants.NPC_BOSS) ? Math.PI / 2 : -Math.PI / 2;
            model.Rotation = new Vector3(0, (float)(rotationAngle), 0);

            //Update PlayerDistance
            playerDistance = (p.Position - this.Position).Length();

            if (playerDistance < 4)
            {
                target = position;
                direction = p.Position - this.Position;
            }

            return true;
        }
示例#11
0
文件: Bullet.cs 项目: kayorga/3DSP
        private bool updateCycle(GameTime gameTime, Camera camera, World world, NPCCollection npcs, Player p, Mission m, int factor, float spd, float dx, float dz)
        {
            position += spd * direction;
            if (type == Constants.TYP_WAV)
            {
                Vector3 cross = Vector3.Cross(direction, Vector3.Up);
                if (mirror)
                    position -= 0.5f * cross * (float)Math.Sin(waveTime.Milliseconds * 200);
                else
                    position += 0.5f * cross * (float)Math.Sin(waveTime.Milliseconds*200);
                //position += 0.5f * Vector3.Up * (float)Math.Cos(waveTime.Milliseconds);
                //position.X += dx / factor;
                //position.Z += dz / factor;
            }

            distance += spd;

            bulletOb.Position = position;

            particleEffect.Update((float)gameTime.ElapsedGameTime.TotalSeconds, camera.ViewMatrix, position, direction);

            xTile = (byte)Math.Round(-1 * (position.X) + (Constants.MAP_SIZE - 1));
            zTile = (byte)Math.Round(-1 * (position.Z) + (Constants.MAP_SIZE - 1));

            if (collision(world) || collision(npcs, m) || collision(p, m) || distance > maxDist)
            {
                active = false;
                particleEffect.Clear();
                return false;
            }
            return true;
        }
示例#12
0
文件: Bullet.cs 项目: kayorga/3DSP
 //bullet - player collision
 private bool collision(Player p, Mission m)
 {
     if (!fromPlayer && xTile == p.xTile && zTile == p.zTile)
     {
         p.getHit(this, m);
         return true;
     }
     return false;
 }
示例#13
0
文件: Bullet.cs 项目: kayorga/3DSP
 //bullet - npc collision
 private bool collision(NPCCollection npcs, Mission m)
 {
     byte tile = npcs.npcMoveData[xTile][zTile];
     if (tile != 0 && tile != 255)
     {
         if (fromPlayer) npcs[tile - 1].getHit(this, m);
         return true;
     }
     return false;
 }
示例#14
0
文件: Bullet.cs 项目: kayorga/3DSP
        public void update(GameTime gameTime, Camera camera, World world, NPCCollection npcs, Player p, Mission m)
        {
            if (!active) return;

            waveTime += gameTime.ElapsedGameTime;
            float dx = (float)Math.Sin(waveTime.Milliseconds);
            float dz = (float)Math.Cos(waveTime.Milliseconds);

            int factor = (int) Math.Ceiling(speed);

            float remainingSpeed = speed;
            float spd = speed / (float)factor;

            for (int i = 0; i < factor; i++)
            {
                spd = Math.Min(spd, remainingSpeed);
                bool u = updateCycle(gameTime, camera, world, npcs, p, m, factor, spd, dx, dz);
                remainingSpeed -= spd;
                if (!u || remainingSpeed == 0) break;
            }

            return;
        }
示例#15
0
 public void update(GameTime gameTime, Camera camera, World world, NPCCollection npcs, Player p, Mission m)
 {
     for (int i = 0; i < Constants.CAP_BULLETS; i++)
     {
         _content[i].update(gameTime, camera, world, npcs, p, m);
     }
 }