Esempio n. 1
0
        public void Update(GameTime gameTime, Camera camera)
        {
            billboardEngine.Begin(camera.ViewMatrix);
            billboardEngine.AddBillboard(new Vector3(0.0f, 1.0f, 0.0f), Color.Honeydew, 0.01f);

            particleEffect.Update((float)gameTime.ElapsedGameTime.TotalSeconds, camera.ViewMatrix, Position, Vector3.Zero);
        }
Esempio n. 2
0
        public void Update(float time, Matrix cameraMatrix, Vector3 position)
        {
            emitParticles(position);

            billboardEngine.Begin(cameraMatrix);

            for (int i = 0; i <= numParticles; i++)
            {
                particles[i].remLifetime -= time;
                if (particles[i].remLifetime < 0.0f)
                {
                    numParticles--;
                    particles[i] = particles[numParticles];
                    i--;
                    continue;
                }

                float interpolation = particles[i].remLifetime / particles[i].totLifetime;
                particles[i].position += (previousPosition == Vector3.Zero? Vector3.Zero:(position - previousPosition)) + particles[i].velocity * time;
                Color color = Color.Lerp(particles[i].endColor, particles[i].startColor, interpolation);
                float size  = MathHelper.Lerp(particles[i].endsize, particles[i].startsize, interpolation);
                billboardEngine.AddBillboard(particles[i].position, color, size);
            }

            previousPosition = position;
        }
Esempio n. 3
0
        public void update(GameTime gameTime, BulletCollection bullets, Camera camera, Player p, Mission m)
        {
            //TODO

            clearMoveData();

            //Initialize BillboardEngine
            billboardEngine.Begin(camera.ViewMatrix);
            billboardEngine.AddBillboard(new Vector3(0.0f, 1.0f, 0.0f), Color.Transparent, 0.01f);

            for (int i = 0; i < Constants.CAP_NPCS; ++i)
            {
                NPC n = _content[i];

                if (!n.active)
                {
                    continue;
                }

                try
                {
                    bool k = n.update(gameTime, bullets, camera, p, m);
                    if (k)
                    {
                        float nx = n.position.X;
                        float nz = n.position.Z;
                        float tx = n.target.X;
                        float tz = n.target.Z;
                        int   TX = (int)Math.Round((-1 * tx + world.size - 1));
                        int   TZ = (int)Math.Round((-1 * tz + world.size - 1));
                        moveData[TX][TZ] = 255;

                        int X = (int)Math.Round((-1 * nx + world.size - 1));
                        int Z = (int)Math.Round((-1 * nz + world.size - 1));

                        if (n.kind == Constants.NPC_BOSS)
                        {
                            moveData[X][Z] = (byte)(i + 1);
                            for (int j = -1; j < 2; ++j)
                            {
                                for (int l = -1; l < 2; ++l)
                                {
                                    if (moveData[X + j][Z + l] == 0)
                                    {
                                        moveData[X + j][Z + l] = (byte)(i + 1);
                                    }
                                }
                            }
                        }
                        else
                        {
                            moveData[X][Z] = (byte)(i + 1);
                        }
                    }
                }
                catch (IndexOutOfRangeException)
                {
                    n.active = false;
                }
            }
        }
Esempio n. 4
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);
        }