public static SpriteSingleton getInstance() { if(instance==null){ isOkToCreate = true; instance = new SpriteSingleton(); isOkToCreate = false; Console.WriteLine("Singleton instance created"); } return instance; }
public Card(PhysicsBody physicsBody, CardData data) { instance = SpriteSingleton.getInstance(); cardData = data; Console.WriteLine(data.face); setFace(data.pattern); // spriteName = "topSide"; spriteTile = instance.Get (spriteName); spriteTile.Position = new Vector2(10.0f, 10.0f); this.AddChild(spriteTile); setColor(data.color); setSound(data.sound); spriteTile.Position = new Vector2(50.0f, 50.0f); _physicsBody = physicsBody; groupID = -1; this.TextureInfo = _ss.Get (spriteName).TextureInfo; this.TileIndex2D = _ss.Get (spriteName).TileIndex2D; // this.TextureInfo = new TextureInfo(new Texture2D("Application/assets/images/topSide.png", false)); // this.Scale = this.TextureInfo.TextureSizef/4f; this.Scale = this.CalcSizeInPixels()/4f; this.Pivot = new Sce.PlayStation.Core.Vector2(0.5f,0.5f); System.Random rand = new System.Random(); this.Position = new Sce.PlayStation.Core.Vector2(0,0); // (float)Director.Instance.GL.Context.GetViewport().Width * (float)rand.NextDouble(), // (float)Director.Instance.GL.Context.GetViewport().Height * (float)rand.NextDouble()); // _physicsBody.Position = new Sce.PlayStation.Core.Vector2( // (float)Director.Instance.GL.Context.GetViewport().Width * (float)rand.NextDouble(), // (float)Director.Instance.GL.Context.GetViewport().Height * (float)rand.NextDouble()); //Right angles are exceedingly boring, so make sure we dont start on one //So if our Random angle is between 90 +- 25 degrees or 270 +- 25 degrees //we add 25 degree to value, ie, making 90 into 115 instead float angle = (float)rand.Next(0,360); if((angle%90) <=25) angle +=25.0f; this._physicsBody.Velocity = new Vector2(0.0f,BALL_VELOCITY).Rotate(PhysicsUtility.GetRadian(angle));; Scheduler.Instance.ScheduleUpdateForTarget(this,0,false); }
public static void Main(string[] args) { Sce.PlayStation.Core.Graphics.GraphicsContext context = new Sce.PlayStation.Core.Graphics.GraphicsContext(); uint sprites_capacity = 500; uint draw_helpers_capacity=400; System.Random rand = new System.Random(); Director.Initialize(sprites_capacity, draw_helpers_capacity, context); Director.Instance.GL.Context.SetClearColor(Colors.Grey20); var scene = new Scene(); scene.Camera.SetViewFromViewport(); Director.Instance.RunWithScene(scene,true); _physics = new GamePhysics(); holder = new Node(); var _screenWidth = Director.Instance.GL.Context.GetViewport().Width; var _screenHeight = Director.Instance.GL.Context.GetViewport().Height; currentLevelData = LevelData.LEVEL_DATA[0]; cards = new Card[currentLevelData.Length]; for (int i = 0; i < cards.Length; i++) { Vector2 start_pos = new Vector2(50f + 0.75f * _screenWidth * (float)rand.NextDouble(), 50f + 0.75f * _screenHeight * (float)rand.NextDouble ()); cards[i] = new Card(_physics.addCardPhysics(start_pos), currentLevelData[i]); holder.AddChild (cards[i]); } scene.AddChild(holder); //cubeFaces = new SpriteSingleton(); cubeFaces = SpriteSingleton.getInstance(); sprite = cubeFaces.Get("topSide"); sprite.Name = "topSide"; sprite2 = cubeFaces.Get ("leftSide"); sprite2.Name = "leftSide"; sprite3 = cubeFaces.Get("rightSide"); sprite3.Name = "rightSide"; Vector2 vectHolder = sprite2.CalcSizeInPixels(); sprite3.Position = new Vector2(vectHolder.X-84, sprite3.Position.Y); sprite.Position = new Vector2(vectHolder.X/4, (sprite.Position.Y + vectHolder.X/2)-12); //sprite3.Position = new Vector2(sprite2.Position.Length, // sprite2.Position.Y); //sprite.Position = scene.Camera.CalcBounds().Center; //sprite.CenterSprite(); //sprite.Scale = new Vector2(1,1); cube3 = new Node(); cube3.AddChild(sprite); cube3.AddChild(sprite2); cube3.AddChild(sprite3); scene.AddChild(cube3); //pink //sprite.RunAction(new TintTo (new Vector4(0.96f,0.88f,0.88f,1.0f),0.1f)); //red //sprite.RunAction(new TintTo (new Vector4(0.90f,0.075f,0.075f,1.0f),0.1f)); var spriteName="topSide"; sprite.TileIndex2D = cubeFaces.Get (spriteName).TileIndex2D; Console.WriteLine(sprite.TileIndex2D); //teal //sprite.RunAction(new TintTo (new Vector4(0.16f,0.88f,0.88f,1.0f),0.1f)); var cube = new Cube(); cube.card1("red"); cube.card2 ("blue"); cube.card3("blue"); while(!Input2.GamePad0.Cross.Press) { var vect = new Vector2(cube3.Position.X +10, cube3.Position.Y +3); cube3.Position = vect; Sce.PlayStation.Core.Environment.SystemEvents.CheckEvents(); Director.Instance.Update(); Director.Instance.Render(); Director.Instance.GL.Context.SwapBuffers(); Director.Instance.PostSwap(); cube.testCube(); } }