Esempio n. 1
2
        public void Render()
        {
            if(alpha<.05)
                alpha=.05f;
            if(alpha>1)
                alpha=1;

            player.Move(Input2.GamePad0.AnalogLeft.X,Input2.GamePad0.AnalogLeft.Y,Input2.GamePad0.AnalogRight);

            Director.Instance.Update();
            scene.RemoveAllChildren(true);

            TextureInfo ti1 = new TextureInfo();

            if(player.shottype==0)
                ti1.Texture = backGround;
            else
                ti1.Texture = backGround1;

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

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

            sprite1.Color.A =alpha;

               		scene.AddChild(sprite1);

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

            foreach (ShotClass item in shots){
                if(item.On && item.type==0)
                    item.Render( ballTexture, scene);

                if(item.On && item.type==1)
                    item.Render( ballTexture1, scene);

            }

            foreach( EnemyClass enemy in enemies){

                if(enemy.isOn()){
                    enemy.Update();
                    enemy.Render(scene);
                }

            }

            player.Render(scene,width,height);

            for( int i =0; i < dead.Count-1; i++){

                if(dead[i].count >= 11){
                    dead[i].On=false;

                }

                if(dead[i].On)
                    dead[i].Render(scene);

            }

            //	   		Image img = new Image(ImageMode.Rgba, new ImageSize(width,height),
            //	                         new ImageColor(255,0,0,0));
            //	   		img.DrawText("Hello World",
            //	                new ImageColor(255,0,0,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();
            //
            //	   		Image img1 = new Image(ImageMode.Rgba, new ImageSize(width/5,height/10),
            //	                         new ImageColor(255,0,0,0));
            //	   		img1.DrawText(scene.Camera.CalcBounds().Center.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();
            //	   		ti1.Texture = texture1;
            //
            //	   		SpriteUV sprite1 = new SpriteUV();
            //	   		sprite1.TextureInfo = ti1;
            //
            //	   		sprite1.Quad.S = ti1.TextureSizef;
            //	   		sprite1.CenterSprite();
            //	   		sprite1.Position = new Vector2(100,100);// scene.Camera.CalcBounds().Center;
            //
            //	   		scene.AddChild(sprite1);
            //
            //
            //	   		TextureInfo ti = new TextureInfo();
            //	   		ti.Texture = texture;
            //
            //	   		SpriteUV sprite = new SpriteUV();
            //	   		sprite.TextureInfo = ti;
            //
            //	   		sprite.Quad.S = ti.TextureSizef;
            //	   		sprite.CenterSprite();
            //	   		sprite.Position = new Vector2(100,100);
            //
               		//scene.AddChild(sprite);

            if(altimer.Milliseconds() > 800){
                alpha-=.1f;
                altimer.Reset();
            }

            counter++;

            if(timer1.Milliseconds() >= 1000){
                timer1.Reset();
                FPS=counter;
                counter=0;

            img = new Image(ImageMode.Rgba, new ImageSize(width/2,height/10),
                         new ImageColor(255,255,0,0));
               			img.DrawText("Score: "+score.ToString()+"\nHighscore: "+highscore.ToString()+ " " + (FPS).ToString(),
                new ImageColor(255,0,0,255),
                new Font(FontAlias.System,20,FontStyle.Bold),
                new ImagePosition(0,0));

              			texturet = new Texture2D(width/2,height/10,false,
                                     PixelFormat.Rgba);

               			texturet.SetPixels(0,img.ToBuffer());
               			img.Dispose();

            }

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

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

               			sprite.Quad.S = ti.TextureSizef;
               			//sprite.CenterSprite();
               			sprite.Position = uppercorner;
            scene.AddChild(sprite);

            Director.Instance.Render();
            Director.Instance.GL.Context.SwapBuffers();
            Director.Instance.PostSwap();
        }
Esempio n. 2
1
		/// <summary>
		/// ボスのHP表示を更新する
		/// </summary>
		/// <param name='hp'>
		/// Hp.
		/// </param>
		/// <param name='maxhp'>
		/// Maxhp.
		/// </param>
		public static void UpdateBossHp(int hp,int maxhp){
			Scenes.sceneOnGame.RemoveChild(bossHpSprite,true);
			float rate = (float)hp / maxhp;
			
			var image = new Image(ImageMode.Rgba,new ImageSize((int)(600*rate),5),new ImageColor(255,0,0,255));
			var texture = new Texture2D((int)(600*rate),5,false, PixelFormat.Rgba);
			texture.SetPixels(0, image.ToBuffer());
			image.Dispose();
			var textureInfo = new TextureInfo(texture);
			bossHpSprite = new SpriteUV(){TextureInfo = textureInfo};
			bossHpSprite.Quad.S = textureInfo.TextureSizef;
			bossHpSprite.CenterSprite(new Vector2(0,0));
			bossHpSprite.Position = new Vector2(200,470);
			
			Scenes.sceneOnGame.AddChild(bossHpSprite);	
		}
Esempio n. 3
1
        /// <summary>
        /// Draws the sprite. and Add the scene.
        /// 文字列(のsprite)を作成するメソッド
        /// </summary>
        /// <returns>
        /// The sprite.
        /// </returns>
        /// <param name='drawStr'>
        /// Draw string.
        /// </param>
        /// <param name='positionX'>
        /// Position x.
        /// </param>
        /// <param name='positionY'>
        /// Position y.
        /// </param>
        /// <param name='fontSize'>
        /// Font size.
        /// </param>
        /// <param name='fontColor'>
        /// Font color.
        /// </param>
        public static SpriteUV DrawSprite(String drawStr,float positionX, float positionY,
		                                   int fontSize,ImageColor fontColor)
        {
            //Director.Initialize(); //重要なんで最初にinitializeしようね。GameEngine2Dのために必要(たぶんほかにも)
            //Scene  //Sce.Pss.HighLevel.GameEngine2DのScene()
            //scene.Camera.SetViewFromViewport(); //CameraをDisplayで使う たぶん画面サイズ -> 3DCGソフトでいうところのカメラ。それの移してる範囲=画面サイズ
            positionX = Const.DISPLAY_WIDTH - Const.DISPLAY_WIDTH*(Const.GRID_NUM_X-positionX)/Const.GRID_NUM_X;
            positionY = Const.DISPLAY_HEIGHT - Const.DISPLAY_HEIGHT*(Const.GRID_NUM_Y-positionY)/Const.GRID_NUM_Y;
            //the Director's OpenGL context たぶん画面サイズの幅
            //var width = (int)Const.getVITA_DISPLAY_WIDTH();
            //var height = (int)Const.getVITA_DISPLAY_HEIGHT();

            //Font font = new Font(FontAlias.System, fontSize, FontStyle.Regular);
            Font font = new Font(Const.DEFAULT_FONT, fontSize, FontStyle.Regular); //日本語使う
            var width = font.GetTextWidth(drawStr);
            var height = font.GetTextWidth("oo");
            //Console.WriteLine(width + " : " + height);

            //Image classはimageデータを保つよ~。 PNG or JPGなど
            //今回はblankのnew Image でも、これ作らないと img.DrawTextが使えない
            Image img = new Image(ImageMode.Rgba,
                                  new ImageSize(width,height), //固定で。たぶん描画範囲
                                  new ImageColor(255,0,0,0));//blankなので変更しても意味なし
            //ここで文字を作ってる
            img.DrawText(drawStr,
                         fontColor,
                         font,
                         new ImagePosition(0, 0)); //画面の位置

            //textureを作る
            Texture2D texture = new Texture2D(width,
                                              height,
                                              false,
                                              PixelFormat.Rgba);

            //Texture2D を使うためにimageからpixelデータに変換(img.ToBuffer())
            //それをtexture.SetPixelsでtextureにPixcelデータを貼り付け
            texture.SetPixels(0, img.ToBuffer());
            //で一覧のimgの処理を実行
            img.Dispose();

            //新しいTexture作るときはTextureInfoも作らないとね
            TextureInfo ti = new TextureInfo();
            ti.Texture = texture;

            //スプライト(イメージパターン)を作る。まぁ、テクスチャだし
            SpriteUV sprite = new SpriteUV();
            sprite.TextureInfo = ti;

            //テクスチャーの貼り付けられた長方形(quad.S)を作成。サイズはImage img = new Imageのとこ。たぶん
            sprite.Quad.S = ti.TextureSizef;
            sprite.CenterSprite();
            //sprite.Position = scene.Camera.CalcBounds().Center;

            positionX = positionX + sprite.Quad.S.X/2;
            positionY = Const.DISPLAY_HEIGHT- positionY - sprite.Quad.S.Y;

            sprite.Position = new Vector2(positionX,positionY);

            return sprite;
        }
Esempio n. 4
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();
        }
Esempio n. 5
0
		public static void InitRayer()
		{
			CharacterStackTexture = new Texture2D[5];
			CharacterStackTextureInfo = new TextureInfo[5];
			
			var image0 = new Image("/Application/resourses/myCharacterStack.png");
			var image04 = image0.Crop(new ImageRect(0,0,128,32));
			var image03 = image0.Crop(new ImageRect(0,32,128,32));
			var image02 = image0.Crop(new ImageRect(0,64,128,32));
			var image01 = image0.Crop(new ImageRect(0,96,128,32));
			var image00 = image0.Crop(new ImageRect(0,128,128,32));
			
			CharacterStackTexture[0] = Convert.CreateTextureFromImage(image00);
			CharacterStackTextureInfo[0] = new TextureInfo(CharacterStackTexture[0]);
			CharacterStackTexture[1] = Convert.CreateTextureFromImage(image01);
			CharacterStackTextureInfo[1] = new TextureInfo(CharacterStackTexture[1]);
			CharacterStackTexture[2] = Convert.CreateTextureFromImage(image02);
			CharacterStackTextureInfo[2] = new TextureInfo(CharacterStackTexture[2]);
			CharacterStackTexture[3] = Convert.CreateTextureFromImage(image03);
			CharacterStackTextureInfo[3] = new TextureInfo(CharacterStackTexture[3]);
			CharacterStackTexture[4] = Convert.CreateTextureFromImage(image04);
			CharacterStackTextureInfo[4] = new TextureInfo(CharacterStackTexture[4]);
			
			image0.Dispose();
			image00.Dispose();
			image01.Dispose();
			image02.Dispose();
			image03.Dispose();
			image04.Dispose();
		}
Esempio n. 6
0
        public static void InitEnemyBullet()
        {
            BulletList = new ArrayList();
            BulletTexture = new Texture2D[4];
            BulletTextureInfo = new TextureInfo[4];

            var image2 = new Image("/Application/resourses/Bullet01_16x16.png");
            var image20 = image2.Crop(new ImageRect(0,0,16,16));
            var image21 = image2.Crop(new ImageRect(0,16,16,16));
            var image22 = image2.Crop(new ImageRect(0,32,16,16));
            var image23 = image2.Crop(new ImageRect(0,48,16,16));

            BulletTexture[0] = Convert.CreateTextureFromImage(image20);
            BulletTextureInfo[0] = new TextureInfo(BulletTexture[0]);
            BulletTexture[1] = Convert.CreateTextureFromImage(image21);
            BulletTextureInfo[1] = new TextureInfo(BulletTexture[1]);
            BulletTexture[2] = Convert.CreateTextureFromImage(image22);
            BulletTextureInfo[2] = new TextureInfo(BulletTexture[2]);
            BulletTexture[3] = Convert.CreateTextureFromImage(image23);
            BulletTextureInfo[3] = new TextureInfo(BulletTexture[3]);
            image2.Dispose();
            image20.Dispose();
            image21.Dispose();
            image22.Dispose();
            image23.Dispose();
        }
Esempio n. 7
0
 public void PostImage(Image<Bgr, byte> image)
 {
     if (image != null) // null sometimes while doing thresholding
     {
         PiBroker.Instance.ImageReceived(image);
         image.Dispose();
     }
 }
Esempio n. 8
0
        private void UpdateImage()
        {
            Image image = new Image(ImageMode.Rgba,new ImageSize(110,100),new ImageColor(0,0,0,0));
            Font font = new Font(FontAlias.System,50,FontStyle.Regular);
            image.DrawText(playerScore + " - " + aiScore,new ImageColor(255,255,255,255),font,new ImagePosition(0,0));
            image.Decode();

            var texture  = new Texture2D(110,100,false,PixelFormat.Rgba);
            if(this.TextureInfo.Texture != null)
                this.TextureInfo.Texture.Dispose();
            this.TextureInfo.Texture = texture;
            texture.SetPixels(0,image.ToBuffer());
            font.Dispose();
            image.Dispose();
        }
Esempio n. 9
0
        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);

            Director.Instance.RunWithScene(scene);
        }
Esempio n. 10
0
        public void setText(string text)
        {
            var width = 200;
            var height = 60;
            Image img = new Image(ImageMode.Rgba, new ImageSize(width,height),
                                     new ImageColor(255,0,0,0));
               img.DrawText("" + text,
                            new ImageColor(255,0,0,255),
                            new Font(FontAlias.System,170,FontStyle.Regular),
                            new ImagePosition(100,100));

               texture2d = new Texture2D(width,height,false,
                                                 PixelFormat.Rgba);
                texture2d.SetPixels(0,img.ToBuffer());
                img.Dispose();
                Sce.PlayStation.HighLevel.GameEngine2D.Base.TextureInfo ti = new Sce.PlayStation.HighLevel.GameEngine2D.Base.TextureInfo(texture2d);
                this.TextureInfo = ti;
        }
Esempio n. 11
0
        /// <summary>
        /// 文字列からテクスチャ作成
        /// </summary>
        /// <returns>
        /// テクスチャ
        /// </returns>
        /// <param name='text'>
        /// 文字列
        /// </param>
        /// <param name='font'>
        /// フォント
        /// </param>
        /// <param name='argb'>
        /// ARGB
        /// </param>
        public static Texture2D CreateTextureFromText(string text, Font font, uint argb)
        {
            int width = font.GetTextWidth(text, 0, text.Length);
            int height = font.Metrics.Height;

            var image = new Image(ImageMode.Rgba, new ImageSize(width,height),new ImageColor(0,0,0,0));

            image.DrawText(text,new ImageColor((int)((argb >> 16) & 0xff),
                                               (int)((argb >> 8) & 0xff),
                                               (int)((argb >> 0) & 0xff),
                                               (int)((argb >> 24) & 0xff)),font,new ImagePosition(0,0));

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

            image.Dispose();
            font.Dispose();
            return texture;
        }
Esempio n. 12
0
        //public Image img = null;
        //public ImageColor rgb = null;
        //public ImageSize size = null;
        public TextLabel(string text)
        {
            ImageColor rgb = new ImageColor(255,255,255,255);
            ImageSize size = new ImageSize(200,100);
            Image img = new Image(ImageMode.Rgba, size,
                        rgb);
            img.DrawText (text,
                          new ImageColor(255,255,255,255),
                          new Font(FontAlias.System,120,FontStyle.Regular),
                          new ImagePosition(300,200));
            texture2d = new Texture2D(size.Width, size.Height, false, PixelFormat.Rgba);

            texture2d.SetPixels(0,img.ToBuffer());

            img.Dispose();

            Sce.PlayStation.HighLevel.GameEngine2D.Base.TextureInfo ti = new Sce.PlayStation.HighLevel.GameEngine2D.Base.TextureInfo(texture2d);

            this.TextureInfo = ti;
        }
Esempio n. 13
0
 public override Image Load(Stream s)
 {
     Tiff tif = Tiff.Open(s);
     FieldValue[] value = tif.GetField(TiffTag.ImageWidth);
     int width = value[0].ToInt();
     value = tif.GetField(TiffTag.ImageLength);
     int height = value[0].ToInt();
     int[] raster = new int[height * width];
     tif.ReadRGBAImage(width, height, raster);
     Image i = new Image(width, height);
     int rgba, rasterOffset;
     byte r, g, b, a;
     for (uint y = 0; y < i.Height; y++)
     {
         rasterOffset = (int)(y * i.Width);
         for (uint x = 0; x < i.Width; x++)
         {
             rgba = raster[rasterOffset++];
             r = (byte)(rgba & 0xff);
             g = (byte)((rgba >> 8) & 0xff);
             b = (byte)((rgba >> 16) & 0xff);
             a = (byte)((rgba >> 24) & 0xff);
             i.SetPixel(x, y, new Pixel(r, g, b, a));
         }
     }
     // Need to flip the image.
     Image i2 = new Image(width, height);
     uint y2 = 0;
     for (uint y = (uint)(i.Height - 1); y >= 0 && y < i.Height; y--)
     {
         for (uint x = 0; x < i.Width; x++)
         {
             i2.SetPixel(x, y2, i.GetPixel(x, y));
         }
         y2++;
     }
     i.Dispose();
     return i2;
 }
Esempio n. 14
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);
        }
Esempio n. 15
0
        public override void validateBuffer()
        {
            if (texture != null){
                texture.Dispose();
                texture = null;
            }

            if (vertexBuffer != null){
                vertexBuffer.Dispose();
                vertexBuffer = null;
            }

            if (textfield.text == null || textfield.text.Length == 0){
                dirtyBuffer = false;
                return;
            }

            updateSize();

            float[] verts = new float[8];
            float[] uvs = new float[8];

            int maxWidth = (int) textWidth;
            if (textfield.defaultTextFormat.align == "right"){
                maxWidth = textfield.width;
            }

            verts[0] = (float) OFFSET_X;
            verts[1] = (float) OFFSET_Y;

            verts[2] = (float) OFFSET_X;
            verts[3] = (float) OFFSET_Y + textHeight;

            verts[6] = (float) OFFSET_X + maxWidth;
            verts[7] = (float) OFFSET_Y;

            verts[4] = (float) OFFSET_X + maxWidth;
            verts[5] = (float) OFFSET_Y + textHeight;

            uvs[0] = 0;
            uvs[1] = 0;

            uvs[2] = 0;
            uvs[3] = 1;

            uvs[6] = 1;
            uvs[7] = 0;

            uvs[4] = 1;
            uvs[5] = 1;

            vertexBuffer = new VertexBuffer(4, VertexFormat.Float2, VertexFormat.Float2);
            vertexBuffer.SetVertices(0, verts);
            vertexBuffer.SetVertices(1, uvs);

            int argb = textfield.defaultTextFormat.color;

            var image = new Image(	ImageMode.Rgba,
                                    new ImageSize((int)maxWidth, (int)textHeight),
                                    new ImageColor(0, 0, 0, 0));

            ImagePosition pos = new ImagePosition(0, 0);
            for (int i = 0; i < textLines.Length; i++){
                pos.X = 0;
                pos.Y = i * font.Metrics.Height;

                if (textfield.defaultTextFormat.align == "right"){
                    pos.X = (int) maxWidth - font.GetTextWidth(textLines[i]);
                }

                image.DrawText(
                    textLines[i],
                    new ImageColor((int)((argb >> 16) & 0xff),
                    (int)((argb >> 8) & 0xff),
                    (int)((argb >> 0) & 0xff),
                    255),
                    font,
                    pos
                );
            }

            texture = new Texture2D((int)maxWidth, (int)textHeight, false, PixelFormat.Rgba);
            texture.SetPixels(0, image.ToBuffer());
            texture.SetFilter(TextureFilterMode.Disabled);
            texture.SetWrap(TextureWrapMode.ClampToEdge);
            texture.SetMaxAnisotropy(0);
            image.Dispose();

            dirtyBuffer = false;

            //Console.WriteLine("buffer validated: " + renderable.commands.length);
        }
		public static void UpdateImage(int score)
		{
			Image image = new Image(ImageMode.Rgba,new ImageSize(960,544),new ImageColor(0,0,0,0));
			Font font = new Font(FontAlias.System,20,FontStyle.Regular);
			image.DrawText("Your Total Score: " + score,new ImageColor(255,255,255,255),font,new ImagePosition(25,125));
			image.Decode();

			//var texture  = new Texture2D(960,544,false,PixelFormat.Rgba);
			//if(textInfo.Texture != null)
				//textInfo.Texture.Dispose();
			//textInfo.Texture = texture;
			//texture.SetPixels(0,image.ToBuffer());
			font.Dispose();
			image.Dispose();
		}
Esempio n. 17
0
        public override Image<Rgb, byte> ProcessAndView(Image<Rgb, byte> image)
        {
            //Convert the image to grayscale and filter out the noise
            var grayImage = image.Convert<Gray, Byte>();

            // Dispose old image
            image.Dispose();

            if (GaussianPyramidDownUpDecomposition)
                grayImage = grayImage.PyrDown().PyrUp();

            var cannyEdges = grayImage.Canny(Threshold, ThresholdLinking);

            image = cannyEdges.Convert<Rgb, byte>();

            // Dispose gray image
            grayImage.Dispose();

            return image;
        }
Esempio n. 18
0
        private Texture2D CutTexture(string path, BoundBox rectangle)
        {
            ImageRect imageRect = new ImageRect ((int)rectangle.X, (int)rectangle.Y, (int)rectangle.Width, (int)rectangle.Height);
            if(System.IO.File.Exists(@"/Application/Content/Pic/" + path))
            {
                Image image = new Image (@"/Application/Content/Pic/" + path);
                image.Decode ();

            texture = new Texture2D ((int)rectangle.Width, (int)rectangle.Height, false, PixelFormat.Rgba);
            texture.SetPixels (0, image.Crop (imageRect).ToBuffer ());
            image.Dispose ();
            }
            else
                DebugScene.Instance.WriteLine("未找到文件:Pic/" + path);
            return texture;
        }
Esempio n. 19
0
        /// コンストラクタ(文字)
        public Sprite(string text, uint argb, Font font, int positionX, int positionY)
        {
            int width = font.GetTextWidth(text, 0, text.Length);
            int height = font.Metrics.Height;

            var image = new Image(ImageMode.Rgba,
                              new ImageSize(width, height),
                              new ImageColor(0, 0, 0, 0));

            image.DrawText(text,
                       new ImageColor((int)((argb >> 16) & 0xff),
                                      (int)((argb >> 8) & 0xff),
                                      (int)((argb >> 0) & 0xff),
                                      (int)((argb >> 24) & 0xff)),
                       font, new ImagePosition(0, 0));

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

            SetTexture(texture);
            SetDrawRect(0, 0, texture.Width, texture.Height);

            PositionX = positionX;
            PositionY = positionY;

            CenterX = texture.Width / 2;
            CenterY = texture.Height / 2;
            Degree = 0.0f;

            ScaleX = 1.0f;
            ScaleY = 1.0f;
            Visible = true;
            Alpha	= 1.0f;
        }
		public static void UpdateImage(string highScores)
		{
			Image image = new Image(ImageMode.Rgba,new ImageSize(960,544),new ImageColor(0,0,0,0));
			Font font = new Font(FontAlias.System,25,FontStyle.Regular);
			image.DrawText("High Scores: " + highScores,new ImageColor(255,255,255,255),font,new ImagePosition(25,100));
			image.Decode();

			var texture  = new Texture2D(960,544,false,PixelFormat.Rgba);
			if(textInfo.Texture != null)
				textInfo.Texture.Dispose();
			textInfo.Texture = texture;
			texture.SetPixels(0,image.ToBuffer());
			font.Dispose();
			image.Dispose();
		}
Esempio n. 21
0
        public void UpdateTexture2D()
        {
            if (null == sm_Texture2D)
            {
                return;
            }
            if (null == Buffer)
            {
                return;
            }
            DateTime now = DateTime.Now;

            long ival_100ns = now.Ticks - m_BaseTime.Ticks;
            int index = (int)((ival_100ns / 10000000.0) / (movie.MicroSecPerFrame / 1000000.0));
            if (movie.TotalFrames <= index) {
                index = movie.TotalFrames -1;
            }

            AviOldIndexEntry entry = movie.VideoEntryList[index];
            int size = entry.Size;
            int offset = entry.Offset;
            BinaryReader reader = new BinaryReader(File.OpenRead(movie.MovieFileDir + "/" + fileName));
            reader.BaseStream.Seek(movie.MoviIndex + 4 + 4 + offset, SeekOrigin.Begin);
            byte[] tmp = reader.ReadBytes(size);
            reader.Close();
            reader.Dispose();

            if (tmp.Length != 0) {
                Image img = new Image(tmp);
                img.Decode();
                Buffer = img.ToBuffer();
                sm_Texture2D.SetPixels(0, Buffer);
                img.Dispose();
            }
        }
Esempio n. 22
0
        public static void Init()
        {
            ex = new List<Texture2D>();

            ex.Add(new Texture2D("/Application/textures/ex0.png", false));
            ex.Add(new Texture2D("/Application/textures/ex1.png", false));
            ex.Add(new Texture2D("/Application/textures/ex2.png", false));
            ex.Add(new Texture2D("/Application/textures/ex3.png", false));
            ex.Add(new Texture2D("/Application/textures/ex4.png", false));
            ex.Add(new Texture2D("/Application/textures/ex5.png", false));
            ex.Add(new Texture2D("/Application/textures/ex6.png", false));
            ex.Add(new Texture2D("/Application/textures/ex7.png", false));
            ex.Add(new Texture2D("/Application/textures/ex8.png", false));
            ex.Add(new Texture2D("/Application/textures/ex9.png", false));
            ex.Add(new Texture2D("/Application/textures/ex10.png", false));
            ex.Add(new Texture2D("/Application/textures/ex11.png", false));

            ballTexture = new Texture2D("/Application/textures/ss.png", false);
            ballTexture1 = new Texture2D("/Application/textures/^.png", false);
            backGround = new Texture2D("/Application/textures/bg.png", false);
            backGround1 = new Texture2D("/Application/textures/bgw.png", false);

               		player = new PlayerClass();
            player.bounds = new Vector2( Director.Instance.GL.Context.GetViewport().Width,
                                        Director.Instance.GL.Context.GetViewport().Height);

            cleanuptimer = new Sce.PlayStation.HighLevel.GameEngine2D.Base.Timer();
            cleanuptimer.Reset();
            timer = new Sce.PlayStation.HighLevel.GameEngine2D.Base.Timer();
            timer.Reset();
            timer1 = new Sce.PlayStation.HighLevel.GameEngine2D.Base.Timer();
            counter = 0;
            FPS=0;
            firable = true;

            rand = new Random();
            uppercorner  = new Vector2(scene.Camera.CalcBounds().Center.X-460,scene.Camera.CalcBounds().Center.Y+220);
            var width = Director.Instance.GL.Context.GetViewport().Width;
               		var height = Director.Instance.GL.Context.GetViewport().Height;
            //init score
            img = new Image(ImageMode.Rgba, new ImageSize(width/3,height/10),
                         new ImageColor(255,255,0,0));
               			img.DrawText("Score: "+score.ToString()+"\nHighscore: "+highscore.ToString(),
                new ImageColor(255,0,0,255),
                new Font(FontAlias.System,20,FontStyle.Regular),
                new ImagePosition(0,0));

              			texturet = new Texture2D(width/3,height/10,false,
                                     PixelFormat.Rgba);

               			texturet.SetPixels(0,img.ToBuffer());
               			img.Dispose();

            dead = new List<SimpleDead>();
            for(int x = 0; x < 20; x++){

                dead.Add(new SimpleDead(ex,player.position,player.bounds));

            }

            shots = new List<ShotClass>();
            for(int x = 0; x < 100; x++){

                shots.Add(new ShotClass(player.position,Input2.GamePad0.AnalogRight,player.bounds));

            }

            enemies = new List<EnemyClass>();
            for(int x = 0; x < 30; x++){

                enemies.Add(new SimpleEnemy(player.bounds));

            }

            oThread = new Thread(new ThreadStart(Updating1));
            oThread.Start();
            pThread= new Thread( new ThreadStart(Updating2));
            pThread.Start();
        }
        private void doImageProcessing()
        {
            // Translate our most recent color coordinates - Done before the bg worker as
            // we cant acess the sensor inside another thread

            // Clear the green screen
            Array.Clear(_greenScreenPixelData, 0, _greenScreenPixelData.Length);
            // Emgu CV Image
            using (Image<Emgu.CV.Structure.Gray, byte> emguOriginal = new Image<Emgu.CV.Structure.Gray, byte>(640, 480))
            {
                byte[, ,] emguData = emguOriginal.Data;

                // We have to iterate the whole depth image
                for (int y = 0; y < _depthStreamFrameHeight; ++y)
                {
                    for (int x = 0; x < _depthStreamFrameWidth; ++x)
                    {
                        // calculate index into depth array
                        int depthIndex = x + (y * _sensorRef.DepthStream.FrameWidth);

                        DepthImagePixel depthPixel = _depthPixels[depthIndex];

                        // retrieve the depth to color mapping for the current depth pixel
                        ColorImagePoint colorImagePoint = _colorCoordinates[depthIndex];

                        // scale color coordinates to depth resolution
                        int colorInDepthX = colorImagePoint.X;
                        int colorInDepthY = colorImagePoint.Y;

                        // make sure the depth pixel maps to a valid point in color space
                        // check y > 0 and y < depthHeight to make sure we don't write outside of the array
                        // check x > 0 instead of >= 0 since to fill gaps we set opaque current pixel plus the one to the left
                        // because of how the sensor works it is more correct to do it this way than to set to the right
                        if (colorInDepthX > 0 && colorInDepthX < _depthStreamFrameWidth && colorInDepthY >= 0 && colorInDepthY < _depthStreamFrameHeight)
                        {
                            // calculate index into the green screen pixel array
                            int greenScreenIndex = colorInDepthX + (colorInDepthY * _depthStreamFrameWidth);

                            // OK emgu needs a black and white only image.
                            if (depthPixel.Depth < _depthThreshold && depthPixel.Depth != 0)
                            {
                                // set opaque
                                _greenScreenPixelData[greenScreenIndex] = opaquePixelValue;

                                // compensate for depth/color not corresponding exactly by setting the pixel 
                                // to the left to opaque as well
                                _greenScreenPixelData[greenScreenIndex - 1] = opaquePixelValue;

                                // Emgu needs an all black image with pure white where the depth data is
                                emguData[colorInDepthY, colorInDepthX, 0] = 255;

                                // set the pixel before this white too. We dont need this in blob detection as the blobs will fill in
                                // it just ends up adding extra on all the left edges
                                /*
                                if (colorInDepthX - 1 > -1)
                                {
                                    emguData[colorInDepthY, colorInDepthX - 1, 0] = 255;
                                }
                                */
                            }
                        }
                    }
                }

                    // emguCV work
                    Emgu.CV.Cvb.CvBlobs resultingBlobs = new Emgu.CV.Cvb.CvBlobs();
                    Emgu.CV.Cvb.CvBlobDetector bDetect = new Emgu.CV.Cvb.CvBlobDetector();
                    uint numLabeledPixels = bDetect.Detect(emguOriginal, resultingBlobs);

                    Image<Emgu.CV.Structure.Bgra, double> blobImg = new Image<Emgu.CV.Structure.Bgra, double>(emguOriginal.Width, emguOriginal.Height, new Emgu.CV.Structure.Bgra(0, 0, 0, 0));
                    foreach (Emgu.CV.Cvb.CvBlob targetBlob in resultingBlobs.Values)
                    {
                        using (MemStorage mem_BlobContours = new MemStorage())
                        {
                            Contour<System.Drawing.Point> allContourPointsInBlob = targetBlob.GetContour(mem_BlobContours);

                            // If thre are more than five points smooth them
                            if (allContourPointsInBlob.Total > 5)
                            {

                                System.Drawing.Point[] originalPoints = allContourPointsInBlob.ToArray();
                                System.Drawing.Point[] smoothedPoints = EmguUtilities.getSmoothedContour(originalPoints, 6, (float)0.5, Properties.Settings.Default.kinectGreenScreenMaskXPixelShift);

                                //------------- FILL -----------------------------------
                                // Sweet shove em back into a contour collection

                                MemStorage finalFillStorage = new MemStorage();
                                Contour<System.Drawing.Point> finalFillContours = new Contour<System.Drawing.Point>(finalFillStorage);
                                finalFillContours.PushMulti(smoothedPoints, Emgu.CV.CvEnum.BACK_OR_FRONT.BACK);
                                blobImg.Draw(finalFillContours, black, -1);

                                // ------------ END FILL ------------------------------
                            }
                        }
                    }

                    // Converts an emgu cv image to a bitmapsource
                    BitmapSource finalRef = EmguUtilities.ToBitmapSource(blobImg);
                    finalRef.Freeze();
                    // Ensure the greenScreenMask is locked before doing this
                    // copy pixels - I get the feeling this isnt supposed to be used on bigger areas but it seems like the fastest way to do it?
                    finalRef.CopyPixels(_copyArea, _pBackBuffer, _gsBufferSize, _gsStride);
                    // Just in case dispose of the image
                    blobImg.Dispose();
                    //emguEroded.Dispose();
            }

            // make a copy to be more thread-safe - we really dont need this anymore but  oh well
          /*
            EventHandler handler = frameReadyForDisplay;
            if (handler != null)
            {
                // invoke the subscribed event-handler(s)
                handler(this, EventArgs.Empty);
            }
            */
        }
Esempio n. 24
-1
        /// <summary>
        /// スキル使用時エフェクト
        /// </summary>
        /// <param name='mySpritePosition'>
        /// 自機スプライトの位置
        /// </param>
        public static void SkillUseEffect(Vector2 mySpritePosition)
        {
            var image1 = new Image("/Application/resourses/Bullet01_64x64.png");
            image1 = image1.Crop(new ImageRect(0,0,64,64));
            var image2 = new Image("/Application/resourses/effect1.png");
            image2 = image2.Resize(new ImageSize(960,180));

            var waveTexture = Convert.CreateTextureFromImage(image1);
            image2.Decode();
            var bgTexture = Convert.CreateTextureFromImage(image2);

            image1.Dispose();
            image2.Dispose();

            var skillName = "";
            switch(Global.setSkill){
            case SkillID.Default :
                skillName = "The WORLD";
                break;
            case SkillID.Skill1 :
                skillName = "Refrection";
                break;
            case SkillID.Skill2 :
                skillName = "";
                break;
            case SkillID.Skill3 :
                skillName = "";
                break;
            }
            var textTexture = Convert.CreateTextureFromText(skillName,new Font(FontAlias.System,120,FontStyle.Bold | FontStyle.Italic),0xFFFFFF00) ;

            waveTextureInfo = new TextureInfo(waveTexture);
            textTextureInfo = new TextureInfo(textTexture);
            bgTextureInfo = new TextureInfo(bgTexture);

            waveSprite = new SpriteUV(){TextureInfo = waveTextureInfo};
            textSprite = new SpriteUV(){TextureInfo = textTextureInfo};
            bgSprite = new SpriteUV(){TextureInfo = bgTextureInfo};

            waveSprite.Quad.S = waveTextureInfo.TextureSizef;
            textSprite.Quad.S = textTextureInfo.TextureSizef;
            bgSprite.Quad.S = bgTextureInfo.TextureSizef;

            waveSprite.CenterSprite();
            textSprite.CenterSprite();
            bgSprite.CenterSprite();

            waveSprite.Position = mySpritePosition;
            textSprite.Position = new Vector2(1500,272);
            bgSprite.Position = new Vector2(1500,272);

            Scenes.sceneOnGame.AddChild(waveSprite);
            Scenes.sceneOnGame.AddChild(bgSprite);
            Scenes.sceneOnGame.AddChild(textSprite);

            var seq0 = new Sequence();
            seq0.Add(new MoveTo(new Vector2(480,272),1));
            seq0.Add(new DelayTime(1.0f));
            seq0.Add(new MoveTo(new Vector2(-500,272),1));

            var seq1 = new Sequence();
            seq1.Add(new MoveTo(new Vector2(480,272),1));
            seq1.Add(new DelayTime(1.0f));
            seq1.Add(new MoveTo(new Vector2(-500,272),1));

            var seq2 = new Sequence();
            seq2.Add(new DelayTime(3.5f));
            seq2.Add(new CallFunc(()=>{Sounds.PlaySkill2();}));
            seq2.Add(new ScaleTo(new Vector2(40,40),3));

            Sounds.PlaySkill1();
            bgSprite.RunAction(seq0);
            textSprite.RunAction(seq1);
            waveSprite.RunAction(seq2);
        }
Esempio n. 25
-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();
        }