示例#1
1
        /*private static GraphicsContext graphics;

        public static void Main (string[] args)
        {
            Initialize ();

            while (true) {
                SystemEvents.CheckEvents ();
                Update ();
                Render ();
            }
        }

        public static void Initialize ()
        {
            // Set up the graphics system
            graphics = new GraphicsContext ();
        }

        public static void Update ()
        {
            // Query gamepad for current state
            var gamePadData = GamePad.GetData (0);
        }

        public static void Render ()
        {
            // Clear the screen
            graphics.SetClearColor (0.0f, 0.0f, 0.0f, 0.0f);
            graphics.Clear ();

            // Present the screen
            graphics.SwapBuffers ();
        }*/
        public static void Main(string[] args)
        {
            //JP: initialize GameEngine2D singletion that handles loop
            Director.Initialize();
            //JP: New 2D scene (graph) container (and camera alignment to orthogonal view
            Scene scene = new Scene();
            scene.Camera.SetViewFromViewport();
            //JP: Get width and height to local variables (optimization)
            var width = Director.Instance.GL.Context.GetViewport().Width;
            var height = Director.Instance.GL.Context.GetViewport().Height;
            //JP: Create new image
            Image img = new Image(ImageMode.Rgba, new ImageSize(width,height),
                                  new ImageColor(255,0,0,0));
            img.DrawText("Dream-Gin",
                         new ImageColor(255,0,0,255),
                         new Font(FontAlias.System,170,FontStyle.Regular),
                         new ImagePosition(0,150));
            //JP: Create hax0r frame buffer and add our img to it's buffer (and consequently kill img content)
            Texture2D texture = new Texture2D(width,height,false,
                                              PixelFormat.Rgba);
            texture.SetPixels(0,img.ToBuffer());
            img.Dispose();
            //JP: Texture info needed for SpriteUV
            TextureInfo ti = new TextureInfo();
            ti.Texture = texture;
            //JP: Add ti to SpriteUV
            SpriteUV sprite = new SpriteUV();
            sprite.TextureInfo = ti;
            //JP: resize sprite and center
            sprite.Quad.S = ti.TextureSizef;
            sprite.CenterSprite();
            sprite.Position = scene.Camera.CalcBounds().Center;
            //JP: Add to Scene
            scene.AddChild(sprite);
            //JP: execute loop shit
            Director.Instance.RunWithScene(scene, true);

            bool gameOver = false;

            while(!gameOver)
            {
                Sce.PlayStation.HighLevel.GameEngine2D.Director.Instance.Update();
                if(Input2.GamePad.GetData(0).Left.Release)
                {
                    sprite.Rotate(Sce.PlayStation.HighLevel.GameEngine2D.Base.Math.Deg2Rad(90));
                }
                if(Input2.GamePad0.Right.Release)
                {
                    sprite.Rotate(Sce.PlayStation.HighLevel.GameEngine2D.Base.Math.Deg2Rad(-90));
                }
                if((Sce.PlayStation.Core.Input.GamePad.GetData(0).Buttons & GamePadButtons.Up) == GamePadButtons.Up)
                {
                    sprite.Quad.S = new Vector2(sprite.Quad.S.X += 10.0f,sprite.Quad.S.Y += 10.0f);
                    sprite.CenterSprite();
                }
                if((Sce.PlayStation.Core.Input.GamePad.GetData(0).Buttons & GamePadButtons.Down) == GamePadButtons.Down)
                {
                    sprite.Quad.S = new Vector2(sprite.Quad.S.X -= 10.0f,sprite.Quad.S.Y -= 10.0f);
                    sprite.CenterSprite();
                }
                if(Input2.GamePad0.Circle.Press == true)
                    gameOver = true;

                Sce.PlayStation.HighLevel.GameEngine2D.Director.Instance.Render();
                Sce.PlayStation.HighLevel.GameEngine2D.Director.Instance.GL.Context.SwapBuffers();
                Sce.PlayStation.HighLevel.GameEngine2D.Director.Instance.PostSwap();
            }

            Director.Terminate();
        }
示例#2
0
        public void Render( Texture2D texture, Scene scene)
        {
            TextureInfo ti1 = new TextureInfo();

            //if(flip)
                ti1.Texture = texture;
            //	else
            //		ti1.Texture = texture1;

               		SpriteUV sprite1 = new SpriteUV();
               		sprite1.TextureInfo = ti1;

               		if(type==0)
            sprite1.Quad.S = ti1.TextureSizef.Multiply(.3f);

            if(type==1)
            sprite1.Quad.S = ti1.TextureSizef.Multiply(.05f);

               		sprite1.CenterSprite();
               		sprite1.Position = position;// scene.Camera.CalcBounds().Center;

            sprite1.Rotate(-rotation);//*Sce.PlayStation.HighLevel.GameEngine2D.Base.Math.Pi/180);

               		scene.AddChild(sprite1);
        }
示例#3
0
        public void Render(Scene scene)
        {
            TextureInfo ti1 = new TextureInfo();

            ti1.Texture = texture;

               		SpriteUV sprite1 = new SpriteUV();
               		sprite1.TextureInfo = ti1;

               		sprite1.Quad.S = ti1.TextureSizef.Multiply(multipier);
               		sprite1.CenterSprite();
               		sprite1.Position = position;// scene.Camera.CalcBounds().Center;

            sprite1.Rotate(-rotationAngle);//*Sce.PlayStation.HighLevel.GameEngine2D.Base.Math.Pi/180);

               		scene.AddChild(sprite1);
        }
示例#4
0
        public void Render(Scene scene, int width, int height)
        {
            Image img1 = new Image(ImageMode.Rgba, new ImageSize(width/5,height/10),
                             new ImageColor(255,0,0,0));
               		img1.DrawText(RotationAngle.ToString()+" "+currentAngle.ToString(),
                    new ImageColor(0,0,255,255),
                    new Font(FontAlias.System,20,FontStyle.Regular),
                    new ImagePosition(0,0));

               		Texture2D texture1 = new Texture2D(width/5,height/10,false,
                                         PixelFormat.Rgba);
               		texture1.SetPixels(0,img1.ToBuffer());
               		img1.Dispose();

               		TextureInfo ti1 = new TextureInfo();

            //			if(timer.Milliseconds()>100){
            //				flip = !flip;
            //				timer.Reset();
            //			}

              		//if(flip) {
                ti1.Texture = shipTexture;
                //flip= !flip;
            //	}
            //	else {

            //		ti1.Texture = shipTexture1;
                //flip = !flip;

            //	}

            //	else
            //		ti1.Texture = texture1;

               		SpriteUV sprite1 = new SpriteUV();
               		sprite1.TextureInfo = ti1;

               		sprite1.Quad.S = ti1.TextureSizef.Multiply(.3f);
               		sprite1.CenterSprite();
               		sprite1.Position = position;// scene.Camera.CalcBounds().Center;

            sprite1.Rotate(-RotationAngle);//*Sce.PlayStation.HighLevel.GameEngine2D.Base.Math.Pi/180);

               		scene.AddChild(sprite1);
        }
示例#5
-1
        public static void Main(string[] args)
        {
            Director.Initialize();

            //Initialize ();

            Scene scene = new Scene();
            scene.Camera.SetViewFromViewport();

            var width = Director.Instance.GL.Context.GetViewport().Width;
            var height = Director.Instance.GL.Context.GetViewport().Height;

            /* Color Matrix Values
             * Unfortunately C# doesn't allow the regular #define usage,
             * See: The #define directive cannot be used to declare constant values
             * as is typically done in C and C++. Constants in C# are best defined as static members of a
             * class or struct. If you have several such constants, consider creating a separate "Constants"
             * class to hold them.
             *
             */
            const int RED = 255;
            const int BLUE = 0;
            const int GREEN = 0;
            const int ALPHA = 0;

            Image img = new Image(ImageMode.Rgba, new ImageSize(width, height), new ImageColor(RED,GREEN,BLUE,ALPHA));

            img.DrawText("Hello World", new ImageColor(RED,GREEN,BLUE,ALPHA+255),
            new Font(FontAlias.System,170,FontStyle.Regular), new ImagePosition(0,150));

            Texture2D texture = new Texture2D(width,height,false,PixelFormat.Rgba);
            texture.SetPixels(0,img.ToBuffer());
            img.Dispose();

            TextureInfo ti = new TextureInfo();
            ti.Texture = texture;

            SpriteUV sprite = new SpriteUV();
            sprite.TextureInfo = ti;

            sprite.Quad.S = ti.TextureSizef;
            sprite.CenterSprite();
            sprite.Position = scene.Camera.CalcBounds().Center;

            scene.AddChild(sprite);

            /* Important: The second argument 'true' defines that the Scene processing would be done manually,
             * So in this case, we would like to do the following ourselves:
             * Update();	-- Tells us to move to the next frame.
             * Render();	-- Draws the next frame.
             * SwapBuffers(); -- Swaps what the Render() drew in the previous frame. {Hence happens after the render}
             * PostSwap(); -- Tells us that we've finished with SwapBuffer();
             * */

            Director.Instance.RunWithScene(scene, true);

            bool gameOver = false;

            while(!gameOver)
            {
                Sce.PlayStation.HighLevel.GameEngine2D.Director.Instance.Update();
                // Rotate Left: Preferred Method to Rotate, although not so smooth.
                /*
                if(Input2.GamePad.GetData(0).Left.Release)
                {
                    sprite.Rotate(Sce.PlayStation.HighLevel.GameEngine2D.Base.Math.Deg2Rad(1));
                }
                */

                /*
                 * AWWx1 to do rotation per interrupt.
                 if(Input2.GamePad0.Left.Release)
                 {
                 	sprite.Rotate(Sce.PlayStation.HighLevel.GameEngine2D.Base.Math.Deg2Rad(90));
                 }
                 */

                // AWWx2 to do rotation per interrupt, with bitwise comparison.
                // Interesting Fact, doing a bitwise comparison does a continous rendering. So doing it 1 degree at a time smoothens it out.
                // Smoothness = 1/InputDegree.
                if((Sce.PlayStation.Core.Input.GamePad.GetData(0).Buttons & GamePadButtons.Left) == GamePadButtons.Left)
                {
                    sprite.Rotate(Sce.PlayStation.HighLevel.GameEngine2D.Base.Math.Deg2Rad(1.0f));
                }

                // Rotate Right
                // Notice that this is NOT continous as compared to the Left Rotate.
                if(Input2.GamePad.GetData(0).Right.Release)
                {
                    sprite.Rotate(Sce.PlayStation.HighLevel.GameEngine2D.Base.Math.Deg2Rad(-90));
                }

                // Scale Up by a factor of 1/10th.
                if((Sce.PlayStation.Core.Input.GamePad.GetData(0).Buttons & GamePadButtons.Up) == GamePadButtons.Up)
                {
                    sprite.Quad.S = new Vector2(sprite.Quad.S.X += 10.0f, sprite.Quad.S.Y += 10.0f);
                    sprite.CenterSprite();
                }

                // Scale Down by a factor of 1/10th.
                if((Sce.PlayStation.Core.Input.GamePad.GetData(0).Buttons & GamePadButtons.Down) == GamePadButtons.Down)
                {
                    sprite.Quad.S = new Vector2(sprite.Quad.S.X -= 10.0f, sprite.Quad.S.Y -= 10.0f);
                    sprite.CenterSprite();
                }

                // Exit if Circle is Pressed.
             	if(Input2.GamePad0.Circle.Press == true)
                {
                    gameOver = true;
                }

                Sce.PlayStation.HighLevel.GameEngine2D.Director.Instance.Render();
                Sce.PlayStation.HighLevel.GameEngine2D.Director.Instance.GL.Context.SwapBuffers();
                Sce.PlayStation.HighLevel.GameEngine2D.Director.Instance.PostSwap();
            }

            Director.Terminate();
        }