コード例 #1
0
ファイル: GameSprite.cs プロジェクト: TobieD/Glide
 public GameSprite(string assetFile,RenderContext context)
 {
     //Load the texture
     m_AssetFile = assetFile;
     if(context !=null)
          m_Texture = context.Content.Load<Texture2D>(m_AssetFile);
 }
コード例 #2
0
ファイル: Background.cs プロジェクト: TobieD/Glide
 public override void DrawAsGUI(RenderContext context, float alpha = 1.0f,bool inWorld = false)
 {
     context.SpriteBatch.Begin(SpriteSortMode.Deferred, null, SamplerState.LinearWrap, null, null, null, WorldMatrix);
     //context.SpriteBatch.Begin();
     context.SpriteBatch.Draw(m_Texture, new Vector2(m_ViewPort.X,m_ViewPort.Y), m_Rect, Color.White, 0, PivotPoint, Zoom, SpriteEffects.None, 1);
     context.SpriteBatch.End();
 }
コード例 #3
0
ファイル: LevelManager.cs プロジェクト: TobieD/Glide
        public void GenerateLevel(int size,RenderContext context)
        {
            if (size <= 0)
                return;

            m_bIsThreading = true;

            int index = m_Level.Count();
            Level prev;
            prev = m_Level[index - 1];

            for (int i = 0; i < size; ++i)
            {
                //GetType of the random piece and instantiate it
                var newPiece= m_LevelList[m_RandGenerator.Next(1,m_AmountPieces)].GetType();
                var level = (Level)Activator.CreateInstance(newPiece,context);

                //level = ObjectCopier.Clone<Level>(m_LevelList[m_RandGenerator.Next(1, m_AmountPieces)]);
                ////Initialze the new Piece
                level.Initialize(context);

                level.Translate(new Vector2((prev.Position.X + (prev.Width * m_LevelOffset)), level.Position.Y));

                //previous level is current level
                prev = level;
                index++;

                ////Add it to the level
                m_Level.Add((level));
            }

            //Done Generating

            m_bIsThreading = false;
        }
コード例 #4
0
ファイル: MenuManager.cs プロジェクト: TobieD/Glide
        public void Draw(RenderContext context)
        {
            if(BackgroundScreen!= null)
                BackgroundScreen.DrawAsGUI(context);

            int i = 0;
            if (!m_bIsStarting)
            {
                m_CurrentTime = m_StartupTime * 2;
                foreach (KeyValuePair<ButtonName, GUIButton> button in m_MenuItems)
                {
                    float xPos = context.GraphicsDevice.Viewport.Width / 2 - button.Value.NewWidth / 2;
                    float yPos = context.GraphicsDevice.Viewport.Height / 2 + i * button.Value.NewHeight - 100;
                    button.Value.Translate(xPos, yPos);
                    button.Value.DrawAsGUI(context);
                    i++;
                }
            }

            if (m_bIsStarting && m_AlphaValue > 0)
            {
                if (SplashScreen != null)
                    SplashScreen.DrawAsGUI(context, m_AlphaValue / 255.0f);
            }
        }
コード例 #5
0
ファイル: LevelList.cs プロジェクト: TobieD/Glide
        public virtual void Update(RenderContext context, bool bThreading)
        {
            //update all models in the level
            foreach (GameModel model in m_Child.ToList<GameModel>())
            {

                if (!bThreading && !model.RigidBody.Enabled)
                {
                    model.RigidBody.Enabled = true;
                }

                //if it is a pick up, typecast it to a Pickup
                if(model.Name == "Pickup")
                {
                    var pickup = (Pickup)model;
                    if (pickup.isPickedUp)
                    {
                        //Do Pick up behaviour
                        pickup.OnPickup();

                        RemoveChild(pickup);
                        pickup = null;
                    }

                }

                model.Update();
            }
        }
コード例 #6
0
ファイル: GameModel.cs プロジェクト: TobieD/Glide
        public virtual void Draw(RenderContext renderContext)
        {
            var transforms = new Matrix[Model.Bones.Count];
            Model.CopyAbsoluteBoneTransformsTo(transforms);

            foreach (ModelMesh mesh in Model.Meshes)
            {
                foreach (BasicEffect effect in mesh.Effects)
                {
                    effect.EnableDefaultLighting();
                    effect.View = renderContext.Camera.View;
                    effect.Projection = renderContext.Camera.Projection;
                    effect.World = transforms[mesh.ParentBone.Index] * WorldMatrix;
                    effect.GraphicsDevice.BlendState = BlendState.NonPremultiplied;
                    effect.PreferPerPixelLighting = true;
                    effect.TextureEnabled = true;
                    effect.Texture = DiffuseTexture;
                    effect.SpecularColor = new Vector3(0.2f);
                    effect.SpecularPower = 100;
                    effect.Alpha = Alpha;
                }

                mesh.Draw();
            }
        }
コード例 #7
0
ファイル: LevelList.cs プロジェクト: TobieD/Glide
        public virtual void Initialize(RenderContext context)
        {
            IsInitialized = true;

            //Load All Possible Pickups here
            PickupPrefabList.AddPrefab(new PickupPrefab(context,PickupName.Health, "Model/Dynamic/Player_Model"));
        }
コード例 #8
0
ファイル: BaseCamera.cs プロジェクト: TobieD/Glide
        public BaseCamera(RenderContext renderContext)
        {
            float aspectRatio = renderContext.GraphicsDevice.Viewport.AspectRatio;

            //Projection = Matrix.CreateOrthographic(1280, 720, 0.1f, 300f);
            Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(90.0f),
                aspectRatio, 1.0f, 1500f);
        }
コード例 #9
0
ファイル: LevelManager.cs プロジェクト: TobieD/Glide
 //Draws all Levels in the list
 public void Draw3D(RenderContext context)
 {
     foreach (Level level in m_Level.ToList<Level>())
     {
         if (Math.Abs(context.Player.Position.X - level.Position.X) < context.ViewPortSize.X * 4)
          level.Draw3D(context);
     }
 }
コード例 #10
0
ファイル: GameSprite.cs プロジェクト: TobieD/Glide
        public virtual void DrawAsGUI(RenderContext context, float alpha = 1.0f,bool inWorld = false)
        {
            context.SpriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend);
            context.SpriteBatch.Draw(m_Texture, Position, DrawRect, Color.White * alpha, MathHelper.ToRadians(Rotation), Vector2.Zero, ObjectScale, Effect,1);
            context.SpriteBatch.End();

            context.Graphics.GraphicsDevice.DepthStencilState = DepthStencilState.Default;
        }
コード例 #11
0
ファイル: Player.cs プロジェクト: TobieD/Glide
 public void DisplaySettings(RenderContext context)
 {
     TextRenderer.DrawText("Mulitplier: " + m_Multplier +
                             "\nTurn Amount: " + m_TurnAmount +
                             "\nIncrement: " + m_CurrentIncrement +
                             "\nVelocity: " + m_Velocity +
                             "\nWindDirection: " + m_WindDirection
                             ,context.ViewPortSize.X * 0.75f, context.ViewPortSize.Y * 0.05f, Color.White, context);
 }
コード例 #12
0
ファイル: HealthBar.cs プロジェクト: TobieD/Glide
 public HealthBar(RenderContext context)
 {
     for (int i = 0; i < m_Amount; i++)
     {
         m_Health = new GameSprite("Textures/GUI/Health_GUI",context);
         m_Health.Scale(0.5f);
         m_HealthBar.Add(m_Health);
     }
 }
コード例 #13
0
ファイル: Background.cs プロジェクト: TobieD/Glide
 public void Update(RenderContext context, Vector2 playerDir)
 {
     //calculate distance to move image
     Vector2 dist = playerDir * m_Speed * (float)context.GameTime.ElapsedGameTime.TotalSeconds;
     m_Offset += dist;
     m_ViewPort = context.Graphics.GraphicsDevice.Viewport;
     //DrawRect = m_Rect;
     base.Update(context);
 }
コード例 #14
0
ファイル: BackgroundManager.cs プロジェクト: TobieD/Glide
        public void DrawBefore(RenderContext context)
        {
            foreach (Background bg in m_Backgrounds)
            {
                if(bg.DrawBefore3D)
                     bg.DrawAsGUI(context);

            }
        }
コード例 #15
0
ファイル: Background.cs プロジェクト: TobieD/Glide
 public Background(string t, Vector2 s, float z,bool bFront, RenderContext context)
     : base("Textures/Background/"  + t,context)
 {
     //PivotPoint.Y -= Height/2;
     m_Speed = s;
     Zoom = z;
     m_ViewPort = context.Graphics.GraphicsDevice.Viewport; ;
     DrawBefore3D = bFront;
 }
コード例 #16
0
ファイル: HealthBar.cs プロジェクト: TobieD/Glide
 public void Draw(RenderContext context)
 {
     var width = m_Health.Width;
     int i = 0;
     foreach (GameSprite obj in m_HealthBar)
     {
         obj.Position = new Microsoft.Xna.Framework.Vector2(width * i, obj.Position.Y);
         obj.Draw(context);
         i++;
     }
 }
コード例 #17
0
ファイル: BaseCamera.cs プロジェクト: TobieD/Glide
        public void Update(RenderContext renderContext, Vector2 playerPos)
        {
            BuildViewMatrix();

            // Camera interpolates between current position and player position (smooth follow)

            Vector2 currentPos = new Vector2(Position.X, Position.Y);
            float lerpAmount = 0.05f;   // Adjust for faster / smoother following
            var lerpedPos = Vector2.Lerp(currentPos, playerPos, lerpAmount);
            Position = new Vector3(lerpedPos, Position.Z);
        }
コード例 #18
0
ファイル: GameSprite.cs プロジェクト: TobieD/Glide
        public virtual void DrawOverModel(RenderContext context, GameModel model)
        {
            var camera = context.Camera;
            Vector3 center = context.GraphicsDevice.Viewport.Project(new Vector3(model.Position,0), camera.Projection, camera.View, Matrix.Identity);
            Position = new Vector2(center.X - Width/2, center.Y - Height/2);

            context.SpriteBatch.Begin();
            context.SpriteBatch.Draw(m_Texture, Position, DrawRect, new Color(Color.R, Color.G, Color.B, 1.0f), MathHelper.ToRadians(Rotation), Vector2.Zero, ObjectScale, Effect, 1);
            context.SpriteBatch.End();

            context.Graphics.GraphicsDevice.DepthStencilState = DepthStencilState.Default;
        }
コード例 #19
0
ファイル: GameScene.cs プロジェクト: TobieD/Glide
       public void Initialize(RenderContext context)
       {
           //Create new savedata file if it doesn't exist yet
           if (!File.Exists(SaveDataFile))
           {
               SaveData data = new SaveData();
               data.HighestDistance = 0;

               XmlWriter.SaveScore(data, SaveDataFile);
           }
           SaveScore(); // actually loads the score

           isActive = true;

           m_ViewPort = context.GraphicsDevice.Viewport;

           //Load a font
           TextRenderer.SetFont(context.Content.Load<SpriteFont>("Font/Standard"));

           //Create player an set him at center of screen
           m_StartPos = new Vector2(context.ViewPortSize.X * 0.25f, context.ViewPortSize.Y * 0.25f);
           m_Player = new Player(context, m_StartPos);
           m_Player.Initialize(context);
           m_Player.Translate(m_StartPos);

           context.Player = m_Player;

           //Generate a random level
           m_LevelManager = new LevelManager();
           m_LevelManager.Initialize(context);

           //AddParalaxing backgrounds
           m_BgManager = new BackgroundManager(context);
           m_BgManager.AddBackgound(new Background("background", new Vector2(0, 0), 1.0f, false, context));
           m_BgManager.AddBackgound(new Background("1", new Vector2(60, 20), 1.0f, false, context));
           m_BgManager.AddBackgound(new Background("2", new Vector2(100, 70), 1, false, context));
           m_BgManager.AddBackgound(new Background("3", new Vector2(200, 40), 1, false, context));
           m_BgManager.AddBackgound(new Background("4", new Vector2(300, 50), 1, false, context));
           m_BgManager.AddBackgound(new Background("5", new Vector2(400, 200), 1, false, context));

           #if(DEBUG)
           m_MonoDebug = new DebugViewXNA(context.World);
           m_MonoDebug.AppendFlags(DebugViewFlags.DebugPanel);
           m_MonoDebug.DefaultShapeColor = Color.Red;
           m_MonoDebug.SleepingShapeColor = Color.LightGray;
           m_MonoDebug.LoadContent(context.GraphicsDevice, context.Content);
           #endif

           SoundManager.Play("Background", true);

           HitScreen = new GameSprite("Textures/GUI/hit", context);
           PickScreen = new GameSprite("Textures/GUI/pickupHit", context);
       }             
コード例 #20
0
ファイル: TextRenderer.cs プロジェクト: TobieD/Glide
        public static void DrawText(string text, float x, float y,Color color, RenderContext context)
        {
            var pos =  new Vector2(x,y);
             Matrix mat = context.Camera.View ;
             MathHelp.WorldToScreen(pos,context);

               // Matrix translation = Matrix.CreateTranslation(new Vector3(pos.X, pos.Y, 0));

               //Open and close the spritebach
            context.SpriteBatch.Begin();
            context.SpriteBatch.DrawString(m_Font, text, pos, color, 0, Vector2.Zero, 1, SpriteEffects.None, 1.0f);
            context.SpriteBatch.End();
        }
コード例 #21
0
ファイル: Player.cs プロジェクト: TobieD/Glide
        public Player(RenderContext context, Vector2 originalPos)
            : base("PlayerV2")
        {
            m_Context = context;

            base.Name = "Player";
            base.m_AssetFile = "PlayerV2";
            m_OrginalPos = originalPos;

            //Create rigidBody
            RigidBody = BodyFactory.CreateRectangle(context.World, ConvertUnits.ToSimUnits(100), ConvertUnits.ToSimUnits(10), 1.0f);
            RigidBody.BodyType = BodyType.Dynamic;
            RigidBody.OnCollision += RigidBody_OnCollision;
            RigidBody.OnSeparation += RigidBody_OnSeparation;
            RigidBody.UserData = this; //Add this class as data for easy access in collision
            RigidBody.Restitution = 0.1f;
            RigidBody.FixedRotation = true;
            Depth = 0;

            //Chain Creation
            float scale = 1f;
            for (int i = 0; i < m_ChainCount; i++)
            {
                Chain piece = new Chain(context, scale);
                piece.Translate(originalPos);
                piece.Initialize(context);
                m_Chain.Add(piece);
            }
            for (int i = 0; i < m_NrOfChainPos ; i++)
            {
                m_ChainPositions.Add(Vector2.Zero);
                m_ChainRotations.Add(0f);
            }

            //Xml
            /*var xmlPlayerData = XmlLoader.Load<PlayerSettings>("PlayerSettings");
            m_Multplier = xmlPlayerData.multiplier;
            m_TurnAmount = xmlPlayerData.turnAmount;
            m_CurrentIncrement = xmlPlayerData.windIncrement;
            m_TwirlEffect = xmlPlayerData.toggleTwirl;
            if (xmlPlayerData.minWindSpeedX != -1) m_MinHorizontalWind = xmlPlayerData.minWindSpeedX;*/

            m_Velocity = Vector2.Zero;

            m_Flat = context.Content.Load<Model>("Model/m_PlayerV2");
            m_Curved = context.Content.Load<Model>("Model/m_PlayerV2");
            base.DiffuseTexture = context.Content.Load<Texture2D>("Textures/Models/D_PlayerV2");

            Scale(0.6f);
        }
コード例 #22
0
ファイル: MenuManager.cs プロジェクト: TobieD/Glide
        public void Update(RenderContext context)
        {
            float deltaTime = (float)context.GameTime.ElapsedGameTime.Milliseconds / 100.0f;

            foreach (KeyValuePair<string, GUIButton> button in m_MenuItems)
            {
                button.Value.Update(context);
            }
            ButtonBehaviour(context);

            m_CurrentTime += deltaTime;
            if (m_CurrentTime > m_StartupTime)
                 FadeOut(deltaTime);
        }
コード例 #23
0
ファイル: Particle.cs プロジェクト: TobieD/Glide
        public void Update(float dt,RenderContext context,GameModel model)
        {
            //Project onto a model
            var camera = context.Camera;
            Vector3 center = context.GraphicsDevice.Viewport.Project(new Vector3(model.Position, 0), camera.Projection, camera.View, Matrix.Identity);
            Position = new Vector2(center.X, center.Y);

            Velocity += Acceleration * dt;
            Position += Velocity * dt;

            //Position.Y += 120 * dt;

            Rotation += RotSpeed * dt;
            TimeSinceStart += dt;
        }
コード例 #24
0
ファイル: GUIButton.cs プロジェクト: TobieD/Glide
        public new void Update(RenderContext context)
        {
            // Reset the clicked boolean
            IsClicked = false;

            //Get States
            m_MouseState = Mouse.GetState();
            KeyboardState keystate = Keyboard.GetState();
            var padState = context.PadState;

            // Fancy conversions
            var mousePoint = new Point(m_MouseState.X, m_MouseState.Y);
            m_HitRect.X = (int)ConvertUnits.ToDisplayUnits((float)Position.X);
            m_HitRect.Y = (int)ConvertUnits.ToDisplayUnits((float)Position.Y);

            //With Mouse( when no PadState is connected
            if (!padState.IsConnected && m_HitRect.Contains(mousePoint))
            {
                //On Mouse Click
                if (m_OldMouseState.LeftButton == ButtonState.Pressed && m_MouseState.LeftButton == ButtonState.Released)
                {
                    IsClicked = true;
                    SoundManager.Play("ButtonClick");
                }

                SelectButton(true);
            }

            //Changing of texture of selected button
            if(m_IsSelected)
            {
                if (padState.IsButtonDown(Buttons.Start) || keystate.IsKeyDown(Keys.Enter) && m_OldState.IsKeyUp(Keys.Enter))
                    IsClicked = true;
                m_Texture = m_HoverTexture;
            }
            else if (!m_HitRect.Contains(mousePoint) || !m_IsSelected)
            {
                m_Texture = m_NormalTexture;
            }

            //Set Old states
            m_OldMouseState = m_MouseState;
            m_OldState = keystate;

            //SoundManager.Stop("ButtonClick");

            base.Update(context);
        }
コード例 #25
0
ファイル: MenuManager.cs プロジェクト: TobieD/Glide
        public void Draw(RenderContext context)
        {
            context.SpriteBatch.Begin(SpriteSortMode.FrontToBack, BlendState.NonPremultiplied);

            int i = 0;
            foreach (KeyValuePair<string, GUIButton> button in m_MenuItems)
            {

                 button.Value.Translate(m_Position.X - button.Value.Width / 2, m_Position.Y + i * (button.Value.Height * 1.25f) );
                 button.Value.Draw(context);
                 i++;
            }

            if (m_bIsStarting && m_AlphaValue > 0)
                 SplashScreen.Draw(context,m_AlphaValue/255.0f);

            context.SpriteBatch.End();
        }
コード例 #26
0
ファイル: GUIButton.cs プロジェクト: TobieD/Glide
        public GUIButton(string assetFile, string hoverTextureFile, ButtonName name, RenderContext context)
            : base(assetFile, context)
        {
            Scale(m_Scalefactor);

            m_NormalTextureFile = assetFile;
            m_HoverTextureFile = hoverTextureFile;
            m_NormalTexture = m_Texture;
            m_HoverTexture = context.Content.Load<Texture2D>(m_HoverTextureFile);

            BtnName = name;

            float w = (float)Width * m_Scalefactor;
            float h = (float)Height * m_Scalefactor;
            NewWidth = (int)w;
            NewHeight = (int)h;

            IsClicked = false;
            m_HitRect = new Rectangle((int)Position.X, (int)Position.Y, NewWidth, NewHeight);
        }
コード例 #27
0
ファイル: Level0.cs プロジェクト: TobieD/Glide
        public override void Initialize(RenderContext context)
        {
            Piece side = PiecePrefabList.GetPrefab(Collision.Col2,"Side");
            side.Rotate(0, 0, -90);
            side.Translate(-200, 750);
            side.Scale(1f, 1,1);
            AddChild(side);

            Piece ground = PiecePrefabList.GetPrefab(Collision.Col5,"Ground");
            ground.Translate(-200, ground.Position.Y);
            AddChild(ground);

            //lots of volcanos at the begining of the level
            for (int i = 0; i < 1; ++i)
            {
                AddVolcano(ground.Height, ground.Position.Y, context);
            }

            Width = (int)ground.Width * 0.85f;
        }
コード例 #28
0
ファイル: LevelManager.cs プロジェクト: TobieD/Glide
        public void Generate(int size, RenderContext context)
        {
            m_Context = context;

            m_Worker = new BackgroundWorker();

            m_Worker.WorkerReportsProgress = true;
            m_Worker.WorkerSupportsCancellation = true;

            m_Worker.DoWork += bgw_DoWork; //Work Event
            m_Worker.RunWorkerCompleted += m_Worker_RunWorkerCompleted;

            //Event that is run in the background;
            Console.WriteLine("Opening new Thread");
            m_Worker.RunWorkerAsync(size);

            m_Worker.CancelAsync();

            m_Worker.Dispose();
        }
コード例 #29
0
ファイル: Ground.cs プロジェクト: TobieD/Glide
        public GroundPrefab(RenderContext context, Collision name, string modelFile, string collisionFile)
        {
            Name = name;

            if (m_Model == null)
            {
                m_Model = context.Content.Load<Model>(modelFile);
                Console.WriteLine("Load Model");
            }

            if (m_Body == null)
            {
                //Load the texture
                m_Texture = context.Content.Load<Texture2D>(collisionFile);
                BodyFromTexture.CreateBodyFromImage(ref m_Body, context.Game, context.World, m_Texture);
                m_Body.UserData = new Vector2(m_Texture.Width, m_Texture.Height);
                m_Body.BodyType = BodyType.Static;
                m_Body.Enabled = false;
                Console.WriteLine("Load Collision Body of Ground");
            }
        }
コード例 #30
0
ファイル: Player.cs プロジェクト: TobieD/Glide
        public Player(string assetFile, RenderContext context, Vector2 originalPos)
            : base(assetFile, "Textures/Collision/c_Piece1", context)
        {
            m_OrginalPos = originalPos;
            //Create rigidBody
            RigidBody = BodyFactory.CreateRectangle(context.World, ConvertUnits.ToSimUnits(20), ConvertUnits.ToSimUnits(10), 1.0f);
            RigidBody.BodyType = BodyType.Dynamic;
            RigidBody.OnCollision += RigidBody_OnCollision;
            RigidBody.OnSeparation +=RigidBody_OnSeparation;
            RigidBody.UserData = this;
            RigidBody.Restitution = 0.1f;
            Depth = -200;

            //Xml
            var xmlPlayerData = XmlLoader.Load<PlayerSettings>("PlayerSettings");
            m_Multplier = xmlPlayerData.multiplier;
            m_TurnAmount = xmlPlayerData.turnAmount;
            m_CurrentIncrement = xmlPlayerData.windIncrement;

            m_Velocity = Vector2.Zero;
        }
コード例 #31
0
 public abstract void Create(RenderContext context);
コード例 #32
0
 public override void Create(RenderContext context)
 {
     throw new NotImplementedException();
 }
コード例 #33
0
ファイル: BackgroundManager.cs プロジェクト: TobieD/Glide
 public BackgroundManager(RenderContext context)
 {
 }