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(); }
/// <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; }
/// <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); }
/*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(); }
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(); }
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); }
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; }
/// <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; }
//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; }
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); }
private void addToTexture(Image img, Vector2i offset, int[] color) { data = img.ToBuffer (); for (int j=0; j < data.Length/4; j++) { if (data[j*4+3] != 0) { if( 255 == data[j*4] && 255 == data[j*4+1] && 255 == data[j*4+2]) { data[j*4] = (Byte)color[0]; data[j*4+1] = (Byte)color[1]; data[j*4+2] = (Byte)color[2]; } var x = j%168 + offset.X; var y = (j-x)/168 - offset.Y; this.TextureInfo.Texture.SetPixels(0,data,PixelFormat.Rgba,j*4,167*4,x,y,1,1); } } }
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 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; }
/// <summary> /// imageからテクスチャを生成 /// </summary> /// <returns> /// テクスチャ /// </returns> /// <param name='image'> /// image /// </param> public static Texture2D CreateTextureFromImage(Image image) { var texture = new Texture2D(image.Size.Width, image.Size.Height, false, PixelFormat.Rgba); texture.SetPixels(0, image.ToBuffer()); return texture; }
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(); }
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(); } }
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(); }
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(); }