Exemple #1
0
        internal void Update(float msDelta, GraphicsDevice gd)
        {
            int aimFace = mFaceAimedAt;

//			mZoneDraw.Update(msDelta);

//			mMatLib.UpdateWVP(Matrix.Identity,
//				gd.GCam.View, gd.GCam.Projection, gd.GCam.Position);
            Vector3 startPos = mGD.GCam.Position;
            Vector3 endPos   = startPos + mGD.GCam.Forward * -2000f;
            Vector3 hitPos   = Vector3.Zero;
            bool    bHitLeaf = false;
            GFXFace HitFace  = null;
            int     faceIdx  = 0;

            if (mMap != null &&
                mMap.RayIntersectFace(startPos, endPos, 0, ref hitPos,
                                      ref bHitLeaf, ref HitFace, ref faceIdx))
            {
                mFaceAimedAt = faceIdx;
            }

            if (aimFace != mFaceAimedAt)
            {
                mST.ModifyStringText(mFonts[0], "Face Aimed At: " + mFaceAimedAt, "FaceAimedAt");
            }

            mST.Update(gd.DC);
            mSUI.Update(gd.DC);
        }
Exemple #2
0
        internal void Update(UpdateTimer time, List <Input.InputAction> actions)
        {
            mFrameCheck++;

            Vector3 startPos = mGD.GCam.Position;
            Vector3 endPos   = startPos + mGD.GCam.Forward * -2000f;

            float deltaMS  = time.GetUpdateDeltaMilliSeconds();
            float deltaSec = time.GetUpdateDeltaSeconds();

            //animate characters
            for (int i = 0; i < mCharacters.Count; i++)
            {
                Character c = mCharacters[i];

                c.Update(deltaSec);

                float totTime = mCharAnims.GetAnimTime(mAnims[mCurAnims[i]]);
                float strTime = mCharAnims.GetAnimStartTime(mAnims[mCurAnims[i]]);
                float endTime = totTime + strTime;

                mAnimTimes[i] += deltaSec;
                if (mAnimTimes[i] > endTime)
                {
                    mAnimTimes[i] = strTime + (mAnimTimes[i] - endTime);
                }

                c.Animate(mAnims[mCurAnims[i]], mAnimTimes[i]);

                mCBones[i] = (mCharToArch[c] as CharacterArch).GetBoneTransforms(mCharAnims.GetSkeleton());
            }

            //check for keys
            foreach (Input.InputAction act in actions)
            {
                if (act.mAction.Equals(Program.MyActions.NextCharacter))
                {
                    mCurChar++;
                    if (mCurChar >= mCharacters.Count)
                    {
                        mCurChar = 0;
                    }
                    UpdateCAStatus();
                }
                else if (act.mAction.Equals(Program.MyActions.NextStatic))
                {
                    mCurStatic++;
                    if (mCurStatic >= mMeshes.Count)
                    {
                        mCurStatic = 0;
                    }
                    UpdateStaticStatus();
                }
                else if (act.mAction.Equals(Program.MyActions.NextAnim))
                {
                    if (mCharacters.Count > 0)
                    {
                        mCurAnims[mCurChar]++;
                        if (mCurAnims[mCurChar] >= mAnims.Count)
                        {
                            mCurAnims[mCurChar] = 0;
                        }
                        UpdateCAStatus();
                    }
                }
                else if (act.mAction.Equals(Program.MyActions.IncreaseInvertInterval))
                {
                    mInvertInterval += InvertIncrement;
                    foreach (Character c in mCharacters)
                    {
                        c.AutoInvert(true, mInvertInterval);
                    }
                    UpdateInvertStatus();
                }
                else if (act.mAction.Equals(Program.MyActions.DecreaseInvertInterval))
                {
                    mInvertInterval -= InvertIncrement;
                    if (mInvertInterval < InvertIncrement)
                    {
                        mInvertInterval = InvertIncrement;
                    }
                    foreach (Character c in mCharacters)
                    {
                        c.AutoInvert(true, mInvertInterval);
                    }
                    UpdateInvertStatus();
                }
                else if (act.mAction.Equals(Program.MyActions.RandRotateStatic))
                {
                    if (mMeshes.Count > 0)
                    {
                        //make a random rotation
                        mMeshRotations[mCurStatic] = new Vector3(
                            Mathery.RandomFloatNext(mRand, 0, MathUtil.TwoPi),
                            Mathery.RandomFloatNext(mRand, 0, MathUtil.TwoPi),
                            Mathery.RandomFloatNext(mRand, 0, MathUtil.TwoPi));
                        UpdateStaticTransform(mCurStatic);
                    }
                }
                else if (act.mAction.Equals(Program.MyActions.RandScaleStatic))
                {
                    if (mMeshes.Count > 0)
                    {
                        //make a random scale
                        mMeshScales[mCurStatic] = new Vector3(
                            Mathery.RandomFloatNext(mRand, 0.25f, 5f),
                            Mathery.RandomFloatNext(mRand, 0.25f, 5f),
                            Mathery.RandomFloatNext(mRand, 0.25f, 5f));
                        UpdateStaticTransform(mCurStatic);
                    }
                }
            }

            mPartHit = null;
            mMeshHit = null;

            float bestDist = float.MaxValue;

            for (int i = 0; i < mMeshes.Count; i++)
            {
                StaticMesh sm = mMeshes[i];

                float?bHit = sm.RayIntersect(startPos, endPos, true);
                if (bHit != null)
                {
                    Mesh partHit = null;

                    bHit = sm.RayIntersect(startPos, endPos, true, out partHit);
                    if (bHit != null)
                    {
                        if (bHit.Value < bestDist)
                        {
                            bestDist = bHit.Value;
                            mPartHit = partHit;
                            mMeshHit = sm;
                        }
                    }
                }
            }

            if (mStaticMats != null)
            {
                mStaticMats.UpdateWVP(Matrix.Identity, mGD.GCam.View, mGD.GCam.Projection, mGD.GCam.Position);
            }
            if (mCharMats != null)
            {
                mCharMats.UpdateWVP(Matrix.Identity, mGD.GCam.View, mGD.GCam.Projection, mGD.GCam.Position);
            }

            mCPrims.Update(mGD.GCam, Vector3.Down);

            for (int i = 0; i < mCharacters.Count; i++)
            {
                Character c    = mCharacters[i];
                float?    bHit = c.RayIntersect(startPos, endPos);
                if (bHit != null)
                {
                    c.RayIntersectBones(startPos, endPos, false, out mCBone[i]);
                }
                else
                {
                    mCBone[i] = 0;
                }
            }

            if (mFrameCheck == 10)
            {
                mFrameCheck = 0;
                UpdateThreadStatus();
            }

            UpdatePosStatus();
            UpdateHitStatus();

            //this has to behind any text changes
            //otherwise the offsets will be messed up
            mST.Update(mGD.DC);
            mSUI.Update(mGD.DC);
        }
Exemple #3
0
        //if running on a fixed timestep, this might be called
        //more often with a smaller delta time than RenderUpdate()
        internal void Update(UpdateTimer time, List <Input.InputAction> actions, PlayerSteering ps)
        {
            //Thread.Sleep(30);

            float secDelta = time.GetUpdateDeltaSeconds();

            mZone.ClearPushableVelocities(secDelta);

            //update model movers
            foreach (Component c in mBModelMovers)
            {
                c.Update(time);
            }

            Vector3 pos         = Vector3.Zero;
            bool    bGroundMove = false;

            UInt32 contents = mPCamMob.GetWorldContents();

            if (mbFly)
            {
                pos = UpdateFly(secDelta, actions, ps);
            }
            else if (Misc.bFlagSet(contents, (UInt32)GameContents.Lava) ||
                     Misc.bFlagSet(contents, (UInt32)GameContents.Water) ||
                     Misc.bFlagSet(contents, (UInt32)GameContents.Slime))
            {
                pos = UpdateSwimming(secDelta, actions, ps);
            }
            else
            {
                pos = UpdateGround(secDelta, actions, ps, out bGroundMove);

                //flip ground move as it returns as a jump bool
                bGroundMove = !bGroundMove;
            }

            UpdateMiscKeys(actions, ps);
            UpdateDynamicLights(actions);

            Vector3 camPos  = Vector3.Zero;
            Vector3 endPos  = pos;
            float   msDelta = time.GetUpdateDeltaMilliSeconds();

            mPCamMob.Move(endPos, msDelta, false, mbFly,
                          bGroundMove, true, out endPos, out camPos);

            //check resulting move against triggers / pickups
            if (!mbFly)
            {
                foreach (Trigger t in mTriggers)
                {
                    t.BoxTriggerCheck(mPCamMob, mPCamMob.GetBounds(),
                                      pos, endPos, msDelta);
                }
                foreach (ConvexVolume cv in mPickUpCVs)
                {
                    if (!cv.Active)
                    {
                        continue;
                    }
                    if (cv.SphereMotionIntersects(PlayerBoxWidth, pos, endPos))
                    {
                        PickUpThing(cv);
                        cv.StateChange(ConvexVolume.State.Active, 0);
                    }
                }
            }


            //check a slightly expanded box to see if any interactives are being touched
            mModelsHit.Clear();
            if (!mbFly)
            {
                if (mZone.TraceStaticBoxVsModels(mFatBox, endPos, mModelsHit))
                {
                    //do stuff
                    foreach (int model in mModelsHit)
                    {
                        foreach (BModelMover bmm in mBModelMovers)
                        {
                            if (bmm.GetModelIndex() == model)
                            {
                                bmm.StateChange(BModelMover.States.Forward, 1);
                                bmm.StateChange(BModelMover.States.Moving, 1);
                            }
                        }
                    }
                }
            }

            //check pvs against entities
            mVisibleSMC.Clear();
            foreach (StaticMeshComp smc in mStaticComps)
            {
                Vector3 smPos = smc.mMat.TranslationVector;

                if (mZone.IsVisibleFrom(endPos, smPos))
                {
                    mVisibleSMC.Add(smc);

                    //update the entity
                    smc.mOwner.Update(time);
                }
            }

            mGD.GCam.Update(camPos, ps.Pitch, ps.Yaw, ps.Roll);

            if (!mbFly)
            {
                if (mPCamMob.IsOnGround())
                {
                    //kill downward velocity so previous
                    //falling momentum doesn't contribute to
                    //a new jump
                    if (mCamVelocity.Y < 0f)
                    {
                        mCamVelocity.Y = 0f;
                    }
                }
                if (mPCamMob.IsBadFooting())
                {
                    //reduce downward velocity to avoid
                    //getting stuck in V shaped floors
                    if (mCamVelocity.Y < 0f)
                    {
                        mCamVelocity.Y -= (StumbleFriction * mCamVelocity.Y * secDelta);
                    }
                }
            }

            mPB.Update(mGD.DC, time.GetUpdateDeltaMilliSeconds());

            mAudio.Update(mGD.GCam);

            mST.ModifyStringText(mFonts[0], "ModelOn: " + mPCamMob.GetModelOn() + " : "
                                 + (int)mGD.GCam.Position.X + ", "
                                 + (int)mGD.GCam.Position.Y + ", "
                                 + (int)mGD.GCam.Position.Z + " (F)lyMode: " + mbFly
                                 + (mPCamMob.IsBadFooting()? " BadFooting!" : "")
                                 + " ModelsHit: " + mModelsHit.Count, "PosStatus");

            mST.Update(mGD.DC);
            mUI.Update(mGD.DC);
        }
Exemple #4
0
        public void Update(GameTime gameTime)
        {
            ui_but_back.Update(gameTime);
            if (ui_but_back.getIsButtonBackPressed())
            {
                ui_but_back.setIsButtonBackPressed(false);
                isBackPressed = true;
            }
            if (gameLogic.getNumRocks() <= 0)
            {
                gameLogic.incrementWave();
                ui_wave_NUMS.UpdateValues("WAVE: " + gameLogic.getWave());
                numberOfRocks = 10;
                invulnTimer   = 0.0f;
                gameLogic.SetNumberOfRocks(numberOfRocks);
                for (int i = 0; i < numberOfRocks; i++)
                {
                    my_rocks.Add(new Planetoids(graphicsDeviceMain));
                }
            }
            timeSinceShot += (float)gameTime.ElapsedGameTime.TotalSeconds;
            Vector2 debug_direction = character.getDirection();
            //Console.WriteLine(debug_direction);
            //Trenutno stanje tipkovnice
            KeyboardState state = Keyboard.GetState();

            updateGameParralax(state, gameTime);
            //Preverim kontrole igralca, preverim, ali gre igralec skozi
            updateGameRocksCollision(gameTime);
            if (gameLogic.getPlayerHP() > 0)
            {
                if (!character.getIsAlive())
                {
                    respawnTimer += (float)gameTime.ElapsedGameTime.TotalSeconds;
                }
                else
                {
                    character.checkControls(state, screenWidth, screenHeight, my_rocks);
                    //Posodabljanje metkov, v primeru da metrki ne letijo jih posodabljam z ladjo
                    updateGameBullets(state);
                }
                if (respawnTimer >= 1.0f)
                {
                    invulnTimer = 0.0f;
                    gameLogic.setPlayerHp(-1);
                    ui_playerHP_NUMS.UpdateValues("x " + gameLogic.getPlayerHP());
                    ui_playerHP = new ScreenUI(graphicsDeviceMain, screenWidth - 100, 40, (int)gameLogic.getPlayerHP());
                    //Console.WriteLine("beep respawn");
                    character.setPosition(new Vector2(screenWidth / 2, screenHeight / 2));
                    respawnTimer = 0;
                    character.setIsAlive(true);
                    foreach (Projectile p in my_bullets)
                    {
                        p.RefreshProjectile();
                    }
                }
            }
            //Posodabljanje parallax backgrounda
            //Posodabljanje kolizij in kamnov
            npc_testing.UpdateAI(character, gameTime);
            //ufo_testing.UpdateAI(character, gameTime);
            ui_score_NUMS.UpdateValues(gameLogic.getScore().ToString());
            ui_rocks_REMAIN.UpdateValues(gameLogic.getNumRocks().ToString());
            invulnTimer += (float)gameTime.ElapsedGameTime.TotalSeconds;
        }