Example #1
0
        public void Draw(GameTime gameTime, Camera camera)
        {
            // Oppdater shaderen (world settes for hver plakat)
            effect.View = camera.View;
            effect.Projection = camera.Projection;

            // Løp gjennom alle plakater
            foreach (Instance instance in instances)
            {
                // ISROT for plakaten settes i World
                Matrix rotation = Matrix.CreateRotationY(instance.rotY);
                Matrix translation = Matrix.CreateTranslation(instance.Position);
                effect.World = rotation * translation;

                // Tegn forsiden
                foreach (EffectPass pass in effect.CurrentTechnique.Passes)
                {
                    pass.Apply();
                    device.DrawUserIndexedPrimitives(PrimitiveType.TriangleStrip, vertices, 0, vertices.Length, indices, 0, 2, VertexPositionTexture.VertexDeclaration);
                }

                // Tegner også plakaten på baksiden ved å beregne world-matrisa på nytt.
                rotation = Matrix.CreateRotationY(instance.rotY - MathHelper.Pi);
                effect.World = rotation * translation;

                foreach (EffectPass pass in effect.CurrentTechnique.Passes)
                {
                    pass.Apply();
                    device.DrawUserIndexedPrimitives(PrimitiveType.TriangleStrip, vertices, 0, vertices.Length, indices, 0, 2, VertexPositionTexture.VertexDeclaration);
                }

            }
        }
Example #2
0
 public static Camera CameraOrtho(Vector3 position, float scale, float aspect)
 {
     Camera cam = new Camera();
     cam.Transform.Rotation = new Quaternion(0, 0, 1, 0);
     cam.Transform.Position = new Vector3(position.X, position.Y, 1000);
     cam.Transform.Scale = new Vector3(1, 1, 1);
     cam.Aspect = aspect;
     cam.Scale = scale;
     cam.Orthographic = true;
     cam.ZNear = -10000f;
     cam.ZFar = 10000f;
     return cam;
 }
Example #3
0
File: Track.cs Project: Biskus/rush
        public void Draw(GameTime gameTime, Camera camera)
        {
            // WVP til shaderen.
            effect.World = world;
            effect.View = camera.View;
            effect.Projection = camera.Projection;

            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Apply();
                device.DrawUserIndexedPrimitives(PrimitiveType.TriangleStrip, vertices, 0, vertices.Length, indices, 0, 2, VertexPositionTexture.VertexDeclaration);
            }
        }
Example #4
0
        public void Draw(GameTime gameTime, Camera camera)
        {
            // Sett opp world-matrisa
            world = scale * position;

            // Parametre til shaderen.
            effect.Parameters["xAmbient"].SetValue(0.5f);
            effect.Parameters["xView"].SetValue(camera.View);
            effect.Parameters["xProjection"].SetValue(camera.Projection);
            effect.Parameters["xWorld"].SetValue(world);
            effect.Parameters["xLightDirection"].SetValue(Vector3.Normalize(new Vector3(-0.5f, -1, 0)));

            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Apply();
                device.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, vertices, 0, vertices.Length, indices, 0, indices.Length / 3, VertexPositionColorNormal.VertexDeclaration);

            }
        }
Example #5
0
        public void Draw(Camera camera, Model mesh)
        {
            transforms = new Matrix[mesh.Bones.Count];
            mesh.CopyAbsoluteBoneTransformsTo(transforms);

            foreach (var singleMesh in mesh.Meshes)
            {
                // This is where the mesh orientation is set, as well as our camera and projection.
                foreach (BasicEffect effect in singleMesh.Effects)
                {
                    effect.EnableDefaultLighting();

                    effect.View = camera.ViewMatrix;
                    effect.Projection = camera.ProjectionMatrix;

                    effect.World = transforms[singleMesh.ParentBone.Index] * Matrix.CreateScale(objectArrangement.Scale) *
                        Matrix.CreateRotationY(MathHelper.ToRadians(objectArrangement.Rotation.Y))
                        * Matrix.CreateTranslation(objectArrangement.Position);
                }

                singleMesh.Draw();
            }
        }
Example #6
0
        void DrawLight(int idx, RenderObjects renderObjects, SpotLight light, Matrix4 m, Matrix4 projectionMatrix, Matrix4 invViewMatrix, Camera camera, float zNear)
        {
            using (RenderStateBinder binder = device.ChangeRenderState())
            {
                device.RenderState.DepthWrite = true;
                device.RenderState.DepthTest = true;
                device.RenderState.ColorWrite = false;
                device.RenderState.FrontFace = FrontFaceDirection.CCW;
                device.RenderState.PolygonOffset = true;
                device.RenderState.PolygonOffsetFactor = 0.0f;
                device.RenderState.PolygonOffsetUnits = -1.0f;
                device.ApplyRenderState();

                shadow_fb.SetTexture2D(FramebufferAttachment.DepthAttachment, 0, shadow_texture);
                device.SetFramebuffer(shadow_fb);

                device.Clear(BufferMask.DepthBuffer);

                device.SetShader(generate_shadowmap);

                device.SetMatrix(MatrixModeEnum.Projection, light.ProjectionMatrix);
                renderObjects(light.ViewMatrix);
            }

            device.SetFramebuffer(lighting_fb);
            device.SetMatrix(MatrixModeEnum.Projection, projectionMatrix);

            using (RenderStateBinder binder = device.ChangeRenderState())
            {
                device.SetShader(deferred_spotlight);
                deferred_spotlight.GetSampler("color_texture").Set(color_texture);
                deferred_spotlight.GetSampler("normal_texture").Set(normal_texture);
                deferred_spotlight.GetSampler("depth_texture").Set(depth_texture);
                deferred_spotlight.GetSampler("shadow_texture").Set(shadow_texture);

                deferred_spotlight.GetUniform("buffer_range").Set(1.0f / device.Width, 1.0f / device.Height);
                deferred_spotlight.GetUniform("ndc_to_view").Set(m);

                deferred_spotlight.GetUniform("shadow_matrix").Set(invViewMatrix * light.ShadowMatrix);
                deferred_spotlight.GetUniform("light_params").Set(light.Ambient, light.Diffuse, light.Specular, light.Shininess);
                deferred_spotlight.GetUniform("light_params2").Set(light.Length2, light.AngleParam1, light.AngleParam2, light.Exponent);
                deferred_spotlight.GetUniform("light_position").Set(Vector3.TransformPosition(light.Position, camera.ViewMatrix));
                deferred_spotlight.GetUniform("light_direction").Set(Vector3.TransformVector(light.Direction, camera.ViewMatrix));
                deferred_spotlight.GetUniform("light_color").Set(light.Color);

                device.SetVertexBuffer(spot_light_VB, 0);
                device.SetIndexBuffer(spot_light_IB);

                device.SetMatrix(MatrixModeEnum.ModelView, light.WorldMatrix * camera.ViewMatrix);

                bool inside = false;
                Vector3 p = (camera.Position + camera.ZAxis * zNear) - light.Position;
                float dot = Vector3.Dot(p, light.Direction);
                if (dot > 0.0f || dot < light.Length)
                {
                    float cosBeta = dot / p.Length;
                    if (cosBeta > Degrees.Cos(light.Angle + 5))
                    {
                        inside = true;
                    }
                }

                device.RenderState.DepthWrite = false;
                device.RenderState.Blend = true;
                device.RenderState.BlendingFuncDst = BlendingFactorDest.One;
                device.RenderState.BlendingFuncSrc = BlendingFactorSrc.One;

                if (inside)
                {
                    device.RenderState.FrontFace = FrontFaceDirection.CCW;
                    device.RenderState.DepthFunction = DepthFunction.GEqual;
                    device.RenderState.StencilTest = false;
                    device.ApplyRenderState();

                    device.DrawElements(BeginMode.TriangleStrip, 0, spot_light_primitives);
                }
                else
                {
                    if (has_stencil)
                    {
                        device.RenderState.FrontFace = FrontFaceDirection.CW;
                        device.RenderState.ColorWrite = false;
                        device.RenderState.DepthFunction = DepthFunction.Less;
                        device.RenderState.StencilTest = true;
                        device.RenderState.StencilFunc = StencilFunction.Always;
                        device.RenderState.StencilFail = StencilOpEnum.Keep;
                        device.RenderState.StencilZFail = StencilOpEnum.Keep;
                        device.RenderState.StencilZPass = StencilOpEnum.Replace;
                        device.RenderState.StencilFuncReference = idx;
                        device.ApplyRenderState();

                        device.DrawElements(BeginMode.TriangleStrip, 0, spot_light_primitives);

                        device.RenderState.FrontFace = FrontFaceDirection.CCW;
                        device.RenderState.ColorWrite = true;
                        device.RenderState.DepthFunction = DepthFunction.GEqual;
                        device.RenderState.StencilFunc = StencilFunction.Equal;
                        device.RenderState.StencilZPass = StencilOpEnum.Keep;
                        device.RenderState.StencilFuncReference = idx;
                        device.ApplyRenderState();

                        device.DrawElements(BeginMode.TriangleStrip, 0, spot_light_primitives);
                    }
                    else
                    {
                        device.RenderState.FrontFace = FrontFaceDirection.CW;
                        device.RenderState.DepthFunction = DepthFunction.Less;
                        device.RenderState.StencilTest = false;
                        device.ApplyRenderState();

                        device.DrawElements(BeginMode.TriangleStrip, 0, spot_light_primitives);
                    }
                }
            }
        }
Example #7
0
 private void ResizeGame(int mod)
 {
     Data.Windowsize += mod;
     if (Data.Windowsize <= 160)
         Data.Windowsize = 176;
     graphics.PreferredBackBufferWidth = Data.Windowsize;
     graphics.PreferredBackBufferHeight = Data.Windowsize;
     graphics.ApplyChanges();
     this.camera = new Camera(graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight);
     this.camera.Zoom = (float)(Data.Windowsize / 256f);
 }
Example #8
0
        public void DrawLights(RenderObjects renderObjects, List<Light> lights, Matrix4 projectionMatrix, float zNear, Camera camera)
        {
            if (lights.Count == 0)
            {
                return;
            }

            Matrix4 invProjectionMatrix = Matrix4.Invert(projectionMatrix);
            Matrix4 invViewMatrix = Matrix4.Invert(camera.ViewMatrix);

            Matrix4 m =
                    new Matrix4(
                        new Vector4(2.0f, 0.0f, 0.0f, 0.0f),
                        new Vector4(0.0f, 2.0f, 0.0f, 0.0f),
                        new Vector4(0.0f, 0.0f, 2.0f, 0.0f),
                        new Vector4(-1.0f, -1.0f, -1.0f, 1.0f))
                  * invProjectionMatrix;

            int idx = 0;
            foreach (Light light in lights)
            {
                idx++;

                if (light is SpotLight)
                {
                    DrawLight(idx, renderObjects, (SpotLight)light, m, projectionMatrix, invViewMatrix, camera, zNear);
                }
                else // light is PointLight
                {
                    DrawLight(idx, renderObjects, (PointLight)light, m, projectionMatrix, invViewMatrix, camera, zNear);
                }
            }
        }
Example #9
0
 private void Load()
 {
     Data.Load(); ;
     int blocks = (Data.BlockPerLevel + (Data.Levels / 10) * 25) * Data.Levels;
     map = new Map(Data.LastSeed, Data.BlockPerLevel + blocks, Data.Levels);
     Data.NextMaps.Clear();
     player = new Player();
     camera = new Camera(graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight);
     Data.Levels++;
 }
Example #10
0
 private void NextLevel()
 {
     while (Data.NextMaps.Count == 0)
         Thread.Sleep(100);
     map = Data.NextMaps.Dequeue();
     player = new Player();
     camera = new Camera(graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight);
     this.camera.Zoom = (float)(Data.Windowsize / 256f);
     Data.Levels++;
 }
Example #11
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here

            base.Initialize();
            Data.SetNull();
            graphics.PreferredBackBufferWidth = Data.Windowsize;
            graphics.PreferredBackBufferHeight = Data.Windowsize;
            graphics.ApplyChanges();
            this.camera = new Camera(graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight);
            this.player = new Player();
        }
Example #12
0
 /// <summary>
 /// Allows the game to run logic such as updating the world,
 /// checking for collisions, gathering input, and playing audio.
 /// </summary>
 /// <param name="gameTime">Provides a snapshot of timing values.</param>
 protected override void Update(GameTime gameTime)
 {
     #region unpausable Logic
     this.UpdatePause();
     KeyboadInput(gameTime);
     #endregion
     #region pausable Logic
     if (!pause)
     {
         player.Update(gameTime);
         camera.Update(player.Position, 32, 64, 64, 64);
         World.Update(gameTime);
         if (gameTime.TotalGameTime.TotalMilliseconds - last >= 150)
         {
             last = gameTime.TotalGameTime.TotalMilliseconds;
             if (!map.OnPath(player.Hitbox))
             {
                 player = new Player();
                 map.RecalcBuffer();
                 camera = new Camera(graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight);
                 this.camera.Zoom = (float)(Data.Windowsize / 256f);
                 Data.Death++;
             }
         }
         if (map.restart)
         {
             NextLevel();
         }
     }
     #endregion
     base.Update(gameTime);
     oks = Keyboard.GetState();
 }
Example #13
0
        public void Draw(GameTime gameTime, Camera camera)
        {
            // En ørliten rotasjon per frame gir en fin effekt av at det blåser. Det passer teksturen
            // på skyboksen veldig godt.
            // World-matrisen oppdateres med denne rotasjonen hver gang Posisjons-property settes.
            // Dette gjøres fra CarGame-klassen, når skybox får samme koordinater som kameraet.
            rotY -= 0.0001f;
            rotY = rotY % MathHelper.TwoPi;
            rotation = Matrix.CreateRotationY(rotY);

            // WVP til BasicEffect-objektet.
            effect.World = world;
            effect.View = camera.View;
            effect.Projection = camera.Projection;

            int textureID = 0;
            foreach (int[] list in indices)
            {
                // Tegn hver side med riktig tekstur
                effect.Texture = textures[textureID++];
                foreach (EffectPass pass in effect.CurrentTechnique.Passes)
                {
                    pass.Apply();
                    device.DrawUserIndexedPrimitives(PrimitiveType.TriangleStrip, vertices, 0, vertices.Length, list, 0, 2, VertexPositionTexture.VertexDeclaration);
                }

            }
        }
Example #14
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base. Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            LoadConfigFile();
            graphics.PreferredBackBufferWidth = GameConstants.HorizontalGameResolution;
            graphics.PreferredBackBufferHeight = GameConstants.VerticalGameResolution;

            graphics.IsFullScreen = GameConstants.IsGameInFullScreen;
            IsMouseVisible = GameConstants.IsMouseVisible;
            graphics.ApplyChanges();

            kinectData = new KinectData();
            camera = new Camera(graphics);

            if (kinectData.IsKinectConnected)
            {
                try
                {
                    kinectData.KinectSensor.AllFramesReady += KinectAllFramesReady;
                    kinectData.KinectSensor.SkeletonStream.Enable();
                    kinectData.KinectSensor.Start();
                }
                catch
                {

                }
            }

            mainMenu = new MainMenu(this) {IsGameInMenuMode = true};
            kinectPlayer = new KinectPlayer(new Vector3(GameConstants.FirstPlatformPosition + (GameConstants.RowLength/2)*GameConstants.SpaceBetweenPlatforms,GameConstants.PlatformGroundLevel,GameConstants.BeginningOfBoardPositionZ));

            platformList = new List<Platform>();
            platformGenerator=new PlatformCollection();

            TargetElapsedTime = TimeSpan.FromSeconds(1.0f / GameConstants.GameUpdatesPerSecond);

            PreparePlatformsForNewGame();

            base.Initialize();
        }
Example #15
0
        void DrawLight(int idx, RenderObjects renderObjects, PointLight light, Matrix4 m, Matrix4 projectionMatrix, Matrix4 invViewMatrix, Camera camera, float zNear)
        {
            using (RenderStateBinder binder = device.ChangeRenderState())
            {
                device.RenderState.DepthWrite = true;
                device.RenderState.DepthTest = true;
                device.RenderState.ColorWrite = false;
                device.RenderState.FrontFace = FrontFaceDirection.CCW;
                device.RenderState.PolygonOffset = true;
                device.RenderState.PolygonOffsetFactor = -1.0f;
                device.RenderState.PolygonOffsetUnits = -1.0f;
                device.ApplyRenderState();

                device.SetShader(generate_dp_shadowmap);

                Vector3[,] direction = new Vector3[6, 2]
                {
                    { -Vector3.UnitX, Vector3.UnitY },
                    { Vector3.UnitX, Vector3.UnitY },
                    { -Vector3.UnitY, -Vector3.UnitZ },
                    { Vector3.UnitY, Vector3.UnitZ },
                    { -Vector3.UnitZ, Vector3.UnitY },
                    { Vector3.UnitZ, Vector3.UnitY },
                };

                TextureTarget[] targets = new TextureTarget[6]
                {
                    TextureTarget.TextureCubeMapPositiveX,
                    TextureTarget.TextureCubeMapNegativeX,
                    TextureTarget.TextureCubeMapPositiveY,
                    TextureTarget.TextureCubeMapNegativeY,
                    TextureTarget.TextureCubeMapPositiveZ,
                    TextureTarget.TextureCubeMapNegativeZ,
                };

                device.SetMatrix(MatrixModeEnum.Projection, Matrix4.Perspective(90.0f, 1.0f, Light.zNear, light.Radius));
                device.SetFramebuffer(shadow_fb);

                for (int i = 0; i < 6; i++)
                {
                    shadow_fb.SetTextureCubeMap(FramebufferAttachment.DepthAttachment, targets[i], 0, shadow_texture_cube);
                    device.Clear(BufferMask.DepthBuffer);

                    Matrix4 lightViewMatrix = Matrix4.LookAt(light.Position, light.Position + direction[i, 0], direction[i, 1]);

                    renderObjects(lightViewMatrix);
                }

                //// front
                //shadow_fb.SetTexture2D(FramebufferAttachment.DepthAttachment, 0, shadow_texture[1]);
                //device.SetFramebuffer(shadow_fb);
                //device.Clear(BufferMask.DepthBuffer);

                //generate_dp_shadowmap.GetUniform("direction").Set(1.0f);

                //Vector3 pos = light.Position;// -new Vector3(0.0f, 0.0f, 0.02f);
                //Matrix4 lightViewMatrix = Matrix4.LookAt(pos, pos + Vector3.UnitZ, Vector3.UnitY);

                //renderObjects(lightViewMatrix);

                //// back
                //shadow_fb.SetTexture2D(FramebufferAttachment.DepthAttachment, 0, shadow_texture[2]);
                //device.Clear(BufferMask.DepthBuffer);

                //generate_dp_shadowmap.GetUniform("direction").Set(-1.0f);

                //pos = light.Position;// -new Vector3(0.0f, 0.0f, 0.02f);
                //lightViewMatrix = Matrix4.LookAt(pos, pos + Vector3.UnitZ, Vector3.UnitY);
                //renderObjects(lightViewMatrix);
            }

            device.SetFramebuffer(lighting_fb);
            device.SetMatrix(MatrixModeEnum.Projection, projectionMatrix);

            using (RenderStateBinder binder = device.ChangeRenderState())
            {
                device.SetShader(deferred_pointlight);
                deferred_pointlight.GetSampler("color_texture").Set(color_texture);
                deferred_pointlight.GetSampler("normal_texture").Set(normal_texture);
                deferred_pointlight.GetSampler("depth_texture").Set(depth_texture);
                //deferred_pointlight.GetSampler("shadowFront_texture").Set(shadow_texture[1]);
                //deferred_pointlight.GetSampler("shadowBack_texture").Set(shadow_texture[2]);
                deferred_pointlight.GetSampler("shadow_texture").Set(shadow_texture_cube);

                deferred_pointlight.GetUniform("buffer_range").Set(1.0f / device.Width, 1.0f / device.Height);

                deferred_pointlight.GetUniform("ndc_to_view").Set(m);

                device.SetVertexBuffer(point_light_VB, 0);
                device.SetIndexBuffer(point_light_IB);

                deferred_pointlight.GetUniform("shadow_matrix").Set(invViewMatrix);
                deferred_pointlight.GetUniform("light_params").Set(light.Ambient, light.Diffuse, light.Specular, light.Shininess);
                deferred_pointlight.GetUniform("light_position").Set(Vector3.TransformPosition(light.Position, camera.ViewMatrix));
                deferred_pointlight.GetUniform("light_positionW").Set(light.Position);
                deferred_pointlight.GetUniform("light_radius2").Set(light.Radius2);
                deferred_pointlight.GetUniform("light_color").Set(light.Color);
                deferred_pointlight.GetUniform("depth_param1").Set(light.DepthParam1);
                deferred_pointlight.GetUniform("depth_param2").Set(light.DepthParam2);

                device.SetMatrix(MatrixModeEnum.ModelView, light.WorldMatrix * camera.ViewMatrix);

                Vector3 p = camera.Position - light.Position;

                device.RenderState.DepthWrite = false;
                device.RenderState.Blend = true;
                device.RenderState.BlendingFuncDst = BlendingFactorDest.One;
                device.RenderState.BlendingFuncSrc = BlendingFactorSrc.One;

                if (p.Length < light.Radius + 2.0f * zNear)
                {
                    device.RenderState.FrontFace = FrontFaceDirection.CCW;
                    device.RenderState.DepthFunction = DepthFunction.GEqual;
                    device.RenderState.StencilTest = false;
                    device.ApplyRenderState();

                    device.DrawElements(BeginMode.TriangleStrip, 0, point_light_primitives);
                }
                else
                {
                    if (has_stencil)
                    {
                        device.RenderState.FrontFace = FrontFaceDirection.CW;
                        device.RenderState.ColorWrite = false;
                        device.RenderState.DepthFunction = DepthFunction.Less;
                        device.RenderState.StencilTest = true;
                        device.RenderState.StencilFunc = StencilFunction.Always;
                        device.RenderState.StencilFail = StencilOpEnum.Keep;
                        device.RenderState.StencilZFail = StencilOpEnum.Keep;
                        device.RenderState.StencilZPass = StencilOpEnum.Replace;
                        device.RenderState.StencilFuncReference = idx;
                        device.ApplyRenderState();

                        device.DrawElements(BeginMode.TriangleStrip, 0, point_light_primitives);

                        device.RenderState.FrontFace = FrontFaceDirection.CCW;
                        device.RenderState.ColorWrite = true;
                        device.RenderState.DepthFunction = DepthFunction.GEqual;
                        device.RenderState.StencilFunc = StencilFunction.Equal;
                        device.RenderState.StencilZPass = StencilOpEnum.Keep;
                        device.RenderState.StencilFuncReference = idx;
                        device.ApplyRenderState();

                        device.DrawElements(BeginMode.TriangleStrip, 0, point_light_primitives);
                    }
                    else
                    {
                        device.RenderState.FrontFace = FrontFaceDirection.CW;
                        device.RenderState.DepthFunction = DepthFunction.Less;
                        device.RenderState.StencilTest = false;
                        device.ApplyRenderState();

                        device.DrawElements(BeginMode.TriangleStrip, 0, point_light_primitives);
                    }
                }
            }
        }
Example #16
0
        protected override void Initialize()
        {
            // Initier GraphicsDeviceManager og -Device
            InitGraphics();

            // Svært viktig funksjonskall
            Window.Title = "Bilspill - Karaktergivende Oppgave - Ole Petter W. Andersen";

            // Sett opp kamera
            camera = new Camera(cameraPosition, Vector3.Zero, new Vector3(0, 1, 0),
                (float)graphics.GraphicsDevice.Viewport.Width /
                (float)graphics.GraphicsDevice.Viewport.Height);

            base.Initialize();
        }
Example #17
0
        public void Update(List <Platform> platformList, Camera camera)
        {
            WaitForPlatformEnd(platformList);

            switch (currentStance)
            {
                case GameConstants.PlayerStance.GameStartCountDown:
                    if (!newGameCounter.IsRunning)
                    {
                        newGameCounter.Start();
                    }
                    else
                    {
                        if (GameConstants.NewGameCountdownTime - newGameCounter.Elapsed.Seconds <= 0)
                        {
                            lastStance = GameConstants.PlayerStance.Idle;
                            currentStance = GameConstants.PlayerStance.Idle;
                        }

                    }
                    break;

                case GameConstants.PlayerStance.Idle:
                    UpdateProgressBarWidth();
                    CheckPlayerOnPlatformPosition(platformList);
                    break;

                case GameConstants.PlayerStance.IdleJump:
                    PerformIdleJump();
                    break;

                case GameConstants.PlayerStance.Jump:
                    PerformJump();
                    break;

                case GameConstants.PlayerStance.SideJump:
                    PerformIdleJump();
                    PerformHorizontalJump();
                    break;

                case GameConstants.PlayerStance.JumpReady:
                    UpdateProgressBarWidth();
                    break;

                case GameConstants.PlayerStance.SideJumpReady:
                    UpdateProgressBarWidth();
                    break;

            }
        }
Example #18
0
        public void Draw(SpriteBatch spriteBatch, SpriteFont font,Camera camera)
        {
            progressBarBackground.DrawByRectangle(spriteBatch);
            nyanSprite.DrawByRectangle(spriteBatch);
            if (currentModel == null) currentModel = modelUp;  // brzydkie ale tak musi byc :/ błąd z asynchronicznym Draw
            modelPosition.Draw(camera, currentModel);
            spriteBatch.Begin();
            spriteBatch.DrawString(font, "Points : "+ ScoreInCurrentGame.ToString(), new Vector2(GameConstants.HorizontalGameResolution/200, GameConstants.VerticalGameResolution/100), Color.Yellow, 0, Vector2.Zero,3, SpriteEffects.None, 1);
            //spriteBatch.DrawString(font, stateString, new Vector2(GameConstants.HorizontalGameResolution*0.95f, GameConstants.VerticalGameResolution / 100), Color.Yellow, 0, Vector2.Zero, 3, SpriteEffects.None, 1);
            spriteBatch.Draw(progressBarTextures[progressBarTextureType],progressBarRectangle,Color.White);
            spriteBatch.End();

            progressBarFrame.DrawByRectangle(spriteBatch);

            switch (currentStance)
            {
                case GameConstants.PlayerStance.GameStartCountDown:
                    spriteBatch.Begin();
                    spriteBatch.DrawString(font, (GameConstants.NewGameCountdownTime - newGameCounter.Elapsed.Seconds).ToString(), new Vector2(GameConstants.HorizontalGameResolution / 2, GameConstants.VerticalGameResolution / 10), Color.Yellow, 0, Vector2.Zero, 2, SpriteEffects.None, 1);
                    spriteBatch.End();
                    break;
            }
        }
 private void Awake()
 {
     Component = GetComponentInChildren <Camera>();
 }