/* * prepares the tiles, x and y are set as a ratio of their position to the size of the map * returns the sprite list which can then be used as a background * */ public List <SpriteList> prepareTiles(Map m, List <MapTile> tiles) { List <SpriteList> mapSpriteLists = new List <SpriteList>(); //calculate x and y /*foreach(MapTile mt in tiles) * { * mt.x = (tiles.IndexOf(mt)%m.width)/(float)m.width; * mt.y = ((int)(tiles.IndexOf(mt)/m.width))/(float)m.height; * * Console.WriteLine(mt.x + " , " + mt.y); * }*/ var texture = new TextureInfo(new Texture2D("/Application/data/tiles/simple2.png", false) , new Vector2i(3, 1)); System.Console.WriteLine(texture.TileSizeInPixelsf.ToString()); //spritelist for the map SpriteList spriteList = new SpriteList(texture) { BlendMode = BlendMode.Normal }; spriteList.EnableLocalTransform = true; Vector2i numCells = new Vector2i(m.width, m.height); for (int y = 0; y < numCells.Y - 1; y++) { Console.WriteLine(""); for (int x = 0; x < numCells.X; x++) { int position = (y * m.width) + x; //why is this here? was in the feature catalog sample but I am not sure of its purpose //changing uv coordinates "should" move the sprite,but it does not //changing sprite.position achieves this goal instead //Vector2 uv = new Vector2 ((float)x, (float)y) / numCells.Vector2 (); var sprite = returnSpriteFromTile(tiles[position].type, texture); ; //sprite.Scale = new Vector2(2.0f,2.0f); //sprite.Quad.S = new Vector2(2f,2); Vector2 p = new Vector2(x * 2.0f, y * 2.0f) - (new Vector2(m.width, m.height)) / 2.0f; sprite.Position = p; spriteList.AddChild(sprite); } } mapSpriteLists.Add(spriteList); return(mapSpriteLists); }
public void initTitle() { this.Camera2D.SetViewFromViewport(); logo = new SpriteUV(new TextureInfo("/Application/data/logo.png")); logo.Scale = logo.TextureInfo.TextureSizef * 1.8f; logo.Pivot = new Vector2(0.5f, 0.5f); logo.Position = new Vector2((960.0f / 2.0f), (540.0f / 2.0f) + 80f); sprite_button_newgame = new SpriteUV(new TextureInfo("/Application/data/button_newgame.png")); sprite_button_newgame.Scale = sprite_button_newgame.TextureInfo.TextureSizef * 1.2f; sprite_button_newgame.Position = new Vector2((960.0f / 5.0f), (540.0f / 4.0f) - sprite_button_newgame.TextureInfo.TextureSizef.Y / 2.0f); sprite_button_tutorial = new SpriteUV(new TextureInfo("/Application/data/button_tutorial.png")); sprite_button_tutorial.Scale = sprite_button_newgame.TextureInfo.TextureSizef * 1.2f; sprite_button_tutorial.Position = new Vector2((960.0f / 2.0f), (540.0f / 4.0f) - sprite_button_newgame.TextureInfo.TextureSizef.Y / 2.0f); sprite_button_autoaim = new SpriteUV(new TextureInfo("/Application/data/button_autoaimon.png")); sprite_button_autoaim.Scale = sprite_button_newgame.TextureInfo.TextureSizef * 1.2f; sprite_button_autoaim.Position = new Vector2((960.0f / 2.0f) + (960.0f / 3.5f), (540.0f / 4.0f) - sprite_button_newgame.TextureInfo.TextureSizef.Y / 2.0f); sprite_button_newgame.Pivot = new Vector2(0.5f, 0.5f); sprite_button_autoaim.Pivot = new Vector2(0.5f, 0.5f); sprite_button_tutorial.Pivot = new Vector2(0.5f, 0.5f); Foreground.AddChild(sprite_button_newgame); Foreground.AddChild(sprite_button_tutorial); Foreground.AddChild(sprite_button_autoaim); Foreground.AddChild(logo); var tex = new Texture2D("/Application/data/tiles/simple5.png", false); var texture = new TextureInfo(tex, new Vector2i(1, 13)); menuBackground = new SpriteList(texture); int menuBackgroundWidth = 100; int menuBackgroundHeight = 50; //mini background discofloor for (int x = 0; x < 30; x++) { for (int y = 0; y < 17; y++) { SpriteTile bgTile = new SpriteTile(texture); bgTile.TileIndex1D = Support.random.Next(4, 13); bgTile.Position = new Vector2((float)x * 32.0f, (float)y * 32.0f); bgTile.Scale = bgTile.TextureInfo.TileSizeInPixelsf * 2.0f; bgTile.ScheduleInterval((dt) => { bgTile.TileIndex1D = Support.random.Next(4, 13); }, 0.2f, -1); menuBackground.AddChild(bgTile); } } Background.AddChild(menuBackground); }
public void initLevelSelect() { this.levelSelection = 0; this.Camera2D.SetViewFromViewport(); //labels labels = new List <Support.CustomLabel> (); //mini background discofloor var tex = new Texture2D("/Application/data/tiles/simple5.png", false); var texture = new TextureInfo(tex, new Vector2i(1, 13)); var menuBackground = new SpriteList(texture); for (int x = 0; x < 30; x++) { for (int y = 0; y < 17; y++) { SpriteTile bgTile = new SpriteTile(texture); bgTile.TileIndex1D = Support.random.Next(4, 13); bgTile.Position = new Vector2((float)x * 32.0f, (float)y * 32.0f); bgTile.Scale = bgTile.TextureInfo.TileSizeInPixelsf * 2.0f; bgTile.ScheduleInterval((dt) => { bgTile.TileIndex1D = Support.random.Next(4, 13); }, 0.2f, -1); menuBackground.AddChild(bgTile); } } Background.AddChild(menuBackground); for (int i = 0; i < MapManager.Instance.predefinedMaps.Count; i++) { //add thumbnail float newX = 960.0f / 2.0f + i * (thumbnailSize + thumbnailSpacing); float scaleFactor = FMath.Clamp(thumbnailSize - FMath.Abs((960.0f / 2.0f) - newX) / 4.0f, 0.0f, thumbnailSize); MapManager.Instance.predefinedMaps [i].thumbnailSprite.Scale = new Vector2(scaleFactor, scaleFactor); MapManager.Instance.predefinedMaps [i].thumbnailSprite.Position = new Vector2(newX, 544.0f / 2.0f); Foreground.AddChild(MapManager.Instance.predefinedMaps [i].thumbnailSprite); //add label: var tempLabel = new Support.CustomLabel(new Vector2(newX, 544.0f / 2.0f - thumbnailSize * 0.6f), "Level " + (i + 1) + "\nHighscore: 0", SceneManager.UIFontMap); labels.Add(tempLabel); Foreground.AddChild(tempLabel); } }
/* * prepares the tiles, x and y are set as a ratio of their position to the size of the map * returns the sprite list which can then be used as a background * */ public List <SpriteList> prepareTiles(Map m, List <MapTile> tiles) { List <SpriteList> mapSpriteLists = new List <SpriteList>(); //calculate x and y /*foreach(MapTile mt in tiles) * { * mt.x = (tiles.IndexOf(mt)%m.width)/(float)m.width; * mt.y = ((int)(tiles.IndexOf(mt)/m.width))/(float)m.height; * * Console.WriteLine(mt.x + " , " + mt.y); * }*/ var tex = new Texture2D("/Application/data/tiles/simple5.png", false); tex.SetFilter(TextureFilterMode.Disabled); tex.SetWrap(TextureWrapMode.ClampToEdge); //texture map used for tiles is specified here(its dimensions) var texture = new TextureInfo(tex, new Vector2i(1, 13)); //debug //System.Console.WriteLine(texture.TileSizeInPixelsf.ToString()); //spritelist for the entire map SpriteList spriteList = new SpriteList(texture) { BlendMode = BlendMode.Normal }; spriteList.EnableLocalTransform = true; Vector2i numCells = new Vector2i(m.width, m.height); for (int y = 0; y < numCells.Y - 1; y++) { for (int x = 0; x < numCells.X; x++) { int position = (y * m.width) + x; //why is this here? was in the feature catalog sample but I am not sure of its purpose //changing uv coordinates "should" move the sprite,but it does not //changing sprite.position achieves this goal instead //Vector2 uv = new Vector2 ((float)x, (float)y) / numCells.Vector2 (); var sprite = returnSpriteFromTile(tiles[position].type, texture); Vector2 p = new Vector2(x, y); //- (new Vector2(m.width,m.height))/2.0f ; //DEBUG //System.Console.WriteLine(p.ToString()); //save the tile position in its object tiles[position].position = p; //set that position to the sprite sprite.Position = p; //add a random disco effect to the floor tiles /*if(tiles[position].type == MapTile.Types.floor) * { * sprite.Schedule( (dt) => { * * //change the floor texture to a random one from the same pack * if(Common.FrameCount%10==0) * { * var a = Support.random.Next(4,12); * * sprite.TileIndex2D = new Vector2i(0,a); * * } * * * } ); * }*/ tiles[position].sprite = sprite; //get the local bounds sprite.GetlContentLocalBounds(ref tiles[position].bounds); spriteList.AddChild(tiles[position].sprite); } } mapSpriteLists.Add(spriteList); return(mapSpriteLists); }
// Recreated the test scene there: // http://www.lostgarden.com/2007/05/dancs-miraculously-flexible-game.html public void CreateRPGTestScene() { // layer y=0 SetBlock(new Vector3i(0, 0, 0), DirtBlock); SetBlock(new Vector3i(1, 0, 0), DirtBlock); SetBlock(new Vector3i(2, 0, 0), DirtBlock); SetBlock(new Vector3i(3, 0, 0), DirtBlock); SetBlock(new Vector3i(4, 0, 0), DirtBlock); SetBlock(new Vector3i(5, 0, 0), DirtBlock); SetBlock(new Vector3i(6, 0, 0), DirtBlock); SetBlock(new Vector3i(0, 0, 1), GrassBlock); SetBlock(new Vector3i(1, 0, 1), GrassBlock); SetBlock(new Vector3i(2, 0, 1), GrassBlock); SetBlock(new Vector3i(3, 0, 1), StoneBlock); SetBlock(new Vector3i(4, 0, 1), StoneBlock); SetBlock(new Vector3i(5, 0, 1), DirtBlock); SetBlock(new Vector3i(6, 0, 1), DirtBlock); SetBlock(new Vector3i(0, 0, 2), GrassBlock); SetBlock(new Vector3i(1, 0, 2), WaterBlock); SetBlock(new Vector3i(2, 0, 2), WaterBlock); SetBlock(new Vector3i(3, 0, 2), GrassBlock); // layer y=1 SetBlock(new Vector3i(4, 1, 1), StoneBlock); SetBlock(new Vector3i(5, 1, 1), DirtBlock); SetBlock(new Vector3i(6, 1, 1), DirtBlock); SetBlock(new Vector3i(0, 1, 2), GrassBlock); SetBlock(new Vector3i(1, 1, 2), WaterBlock); SetBlock(new Vector3i(2, 1, 2), WaterBlock); SetBlock(new Vector3i(3, 1, 2), GrassBlock); // layer y=2 SetBlock(new Vector3i(0, 2, 2), StoneBlock); SetBlock(new Vector3i(1, 2, 2), WaterBlock); SetBlock(new Vector3i(2, 2, 2), WaterBlock); SetBlock(new Vector3i(3, 2, 2), StoneBlock); SetBlock(new Vector3i(4, 2, 2), StoneBlock); SetBlock(new Vector3i(5, 2, 2), StoneBlock); SetBlock(new Vector3i(6, 2, 2), RampSouth); // layer y=3 SetBlock(new Vector3i(0, 3, 3), RampWest); SetBlock(new Vector3i(1, 3, 3), StoneBlock); SetBlock(new Vector3i(2, 3, 3), StoneBlock); SetBlock(new Vector3i(3, 3, 3), StoneBlock); SetBlock(new Vector3i(4, 3, 3), RampEast); SetBlock(new Vector3i(5, 3, 2), StoneBlock); SetBlock(new Vector3i(6, 3, 2), StoneBlock); // layer y=4 SetBlock(new Vector3i(0, 4, 2), StoneBlock); SetBlock(new Vector3i(1, 4, 2), WaterBlock); SetBlock(new Vector3i(2, 4, 2), WaterBlock); SetBlock(new Vector3i(3, 4, 2), PlainBlock); SetBlock(new Vector3i(4, 4, 3), WallBlock); SetBlock(new Vector3i(4, 4, 4), WallBlock); SetBlock(new Vector3i(4, 4, 5), WallBlock); SetBlock(new Vector3i(5, 4, 2), StoneBlock); SetBlock(new Vector3i(5, 4, 3), DoorTallClosed); SetBlock(new Vector3i(6, 4, 3), WallBlock); SetBlock(new Vector3i(6, 4, 4), WallBlock); SetBlock(new Vector3i(6, 4, 5), WallBlock); // try put as many sprites in SpriteList for performance SpriteList sprite_list = new SpriteList(ObjectsMap); sprite_list.AddChild(NewCharater(CharacterBoy, new Vector3(3, 1.5f, 3))); sprite_list.AddChild(NewCharater(CharacterHornGirl, new Vector3(5, 2.6f, 3))); sprite_list.AddChild(NewCharater(CharacterPrincessGirl, new Vector3(6, 1, 2))); sprite_list.AddChild(NewObject(Rock, new Vector3(3, 0, 3))); sprite_list.AddChild(NewObject(Rock, new Vector3(6, 0, 2))); sprite_list.AddChild(NewObject(Key, new Vector3(5, 0, 2))); sprite_list.AddChild(NewTree(TreeShort, new Vector3(0.5f, 1, 3))); AddChild(sprite_list); { var bug = NewObject(EnemyBug, new Vector3(2, 3, 4)); bug.Schedule((dt) => { float p = 1.0f; bug.Position = this.GetCellPos(Math.Lerp(new Vector3(1, 3, 4), new Vector3(3, 3, 4) , (1.0f + FMath.Sin((float)Director.Instance.DirectorTime * p)) * 0.5f)); // we just care about the sign of the derivative bug.FlipU = (FMath.Cos((float)Director.Instance.DirectorTime * p) < 0.0f); }); AddChild(bug); } }
public void initGame() { cameraHeight = (float)Convert.ToDouble(Support.GameParameters["StartingCameraHeight"]); //set view close to the scene this.Camera2D.SetViewFromHeightAndCenter(cameraHeight, Sce.PlayStation.HighLevel.GameEngine2D.Base.Math._00); //add all sprites loaded from the map foreach (SpriteList sl in MapManager.Instance.currentMap.spriteList) { Background.AddChild(sl); } //load the fire texture for the bullet Bullet.fireTexture = new Texture2D("/Application/data/tiles/fire.png", false); //texture for the points marker pointMarker.texture = new Texture2D("/Application/data/points100.png", false); //texture for the ammo marker ammoMarker.texture = new Texture2D("/Application/data/plusammo.png", false); Player.Instance = new Player(); Foreground.AddChild(Player.Instance); //create the list for bullets bulletList = new List <Bullet>(); //create ammo packs ammoList = new List <AmmoItem>(); List <MapTile> list = MapManager.Instance.currentMap.returnTilesOfType(MapTile.Types.floor); //add a specified number of ammo packs for (int i = 0; i < AmmoItem.noOfAmmoToGenerate; i++) { AmmoItem a = new AmmoItem(list[Support.random.Next(0, list.Count - 1)].position); ammoList.Add(a); World.AddChild(a); } //create the quad tree quadTree = new QuadTree(new Vector2(MapManager.Instance.currentMap.width / 2.0f, MapManager.Instance.currentMap.height / 2.0f), new Vector2(MapManager.Instance.currentMap.width / 2.0f, MapManager.Instance.currentMap.height / 2.0f)); //create enemies var tex = new Texture2D("/Application/data/tiles/enemy_sword2.png", false); tex.SetFilter(TextureFilterMode.Disabled); tex.SetWrap(TextureWrapMode.ClampToEdge); var texture = new TextureInfo(tex, new Vector2i(25, 1)); //spritelist for the enemies enemySpriteList = new SpriteList(texture) { BlendMode = BlendMode.Normal }; //spriteList.EnableLocalTransform = true; enemyList = new List <Enemy>(); list = MapManager.Instance.currentMap.returnTilesOfType(MapTile.Types.floor); //generate a given number of enemies for (int i = 0; i < BasicEnemy.noOfEnemiesToGenerate; i++) { Enemy e = new BasicEnemy(list[Support.random.Next(0, list.Count - 1)].position, texture); enemyList.Add(e); enemySpriteList.AddChild(((BasicEnemy)e).sprite); EffectsLayer.AddChild(e); quadTree.insert(e); } Foreground.AddChild(enemySpriteList); ui = new UI(); Interface.AddChild(ui); //add an enemy spawner every second Sce.PlayStation.HighLevel.GameEngine2D.Scheduler.Instance.Schedule(this, (dt) => { list = MapManager.Instance.currentMap.returnTilesOfType(MapTile.Types.floor); EnemySpawnPoint esp = new EnemySpawnPoint(list[Support.random.Next(0, list.Count - 1)].position); World.AddChild(esp); ; }, 1.0f, false, -1); }
public static Scene MakeManySpritesInSpriteListScene() { var tex1 = new TextureInfo(new Texture2D("/Application/Sample/GameEngine2D/FeatureCatalog/data/water_puddle.png", false) , new Vector2i(6, 1)); var scene = new Scene() { Name = "many SpriteTile in SpriteList scene" }; Bounds2 bounds = scene.Camera.CalcBounds(); Vector2i num_cells = new Vector2i(16, 8); Vector2 cell_size = bounds.Size / num_cells.Vector2(); Math.RandGenerator rgen = new Math.RandGenerator(); System.Random random = new System.Random(); SpriteList sprite_list = new SpriteList(tex1) { BlendMode = BlendMode.None }; sprite_list.EnableLocalTransform = true; scene.AddChild(sprite_list); for (int y = 0; y < num_cells.Y; ++y) { for (int x = 0; x < num_cells.X; ++x) { Vector2 uv = new Vector2((float)x, (float)y) / num_cells.Vector2(); var sprite = new SpriteTile() { // all those properties (TextureInfo, Color, BlendMode) will be ignored // if sprite is used in SpriteList TextureInfo = tex1 , Color = Math.SetAlpha(new Vector4(0.8f) + rgen.NextVector4(Math._0000, Math._1111) * 0.2f, 0.75f) , BlendMode = BlendMode.Normal // TileIndex2D can still be set per sprite , TileIndex2D = new Vector2i(random.Next(0, 6), 0) }; Vector2 p = bounds.Min + bounds.Size * uv; // init position/size if (sprite_list.EnableLocalTransform) { // use .Position as we did in MakeManySpritesScene sprite.Position = p; } else { // .Position will be ignored, so use the geometry directly sprite.Quad.T = p; } sprite.Quad.S = cell_size; // note: we don't want to touch the Node.Scale here sprite.Pivot = sprite.Quad.S * 0.5f; sprite.Schedule((dt) => { sprite.Rotation = sprite.Rotation.Rotate(Math.Deg2Rad(1.0f)); sprite.Rotation = sprite.Rotation.Normalize(); // if you turn EnableLocalTransform off for performances, you can // still move the sprite freely by changing its geometry directly: // sprite.Quad.R = sprite.Quad.R.Rotate( Math.Deg2Rad( 1.0f ) ); // sprite.Quad.R = sprite.Quad.R.Normalize(); // if (Common.FrameCount % 7 == 0) { sprite.TileIndex1D = (sprite.TileIndex1D + 1) % 6; } }); sprite_list.AddChild(sprite); } } scene.RegisterDisposeOnExit((System.IDisposable)tex1); return(scene); }
public static Scene MakeForestScene() { // System.Console.WriteLine( "MakeForestScene" ); var scene = new Scene() { Name = "Forest" }; TextureInfo ObjectsMap = new TextureInfo(new Texture2D("/Application/Sample/GameEngine2D/FeatureCatalog/data/PlanetCute/Objects.png", false), new Vector2i(7, 3)); Vector2i[] tree_indexes = new Vector2i[3]; tree_indexes[0] = PlanetCute.TreeShort; tree_indexes[1] = PlanetCute.TreeTall; tree_indexes[2] = PlanetCute.TreeUgly; Math.RandGenerator rgen = new Math.RandGenerator(); Bounds2 bounds = scene.Camera2D.CalcBounds(); Vector2i numcells = new Vector2i(7, 4); Vector2 cellsize = bounds.Size / numcells.Vector2(); System.Random rnd1 = new System.Random(); SpriteList sprite_list = new SpriteList(ObjectsMap); // we are going to put a tree at a random location inside each cell of a regular grid for (int x = 0; x < numcells.X; ++x) { // generate rows of tree top to bottom, for draw order for (int y = numcells.Y - 1; y >= 0; --y) { Vector2 cellindexf = new Vector2((float)x, (float)y); var sprite = new SpriteTile(); // sprite.TextureInfo = tree_tex[rnd1.Next(3)]; sprite.TextureInfo = ObjectsMap; sprite.TileIndex2D = tree_indexes[rnd1.Next(3)]; // bounds for one cell Bounds2 gen_bounds = new Bounds2(bounds.Min + cellindexf * cellsize, bounds.Min + cellindexf * cellsize + cellsize); // scale gen_bounds to countrols irregularity gen_bounds = gen_bounds.Scale(new Vector2(0.6f), gen_bounds.Center); // pick up a random point in that cell sprite.Position = gen_bounds.Min + gen_bounds.Size * rgen.NextVector2(Math._00, Math._11); // make the size of the tree match the size of cells, preserve texture ratio Vector2 aspect = sprite.CalcSizeInPixels() / sprite.CalcSizeInPixels().X; sprite.Quad.S = cellsize.X * aspect; // make the sprite bottom center point be the new pivot (for Skew) sprite.Quad.Centering(TRS.Local.BottomCenter); // make the trees move in the wind sprite.Schedule((dt) => { int hc = sprite.GetHashCode(); System.Random rnd2 = new System.Random(hc); sprite.Skew = new Vector2(Math.Deg2Rad(1.0f) * FMath.Sin((float)Director.Instance.DirectorTime * 1.0f * rnd2.Next(4096) / 4096.0f), Math.Deg2Rad(2.0f) * FMath.Sin((float)Director.Instance.DirectorTime * 3.0f * rnd2.Next(4096) / 4096.0f)); }); sprite_list.AddChild(sprite); } } scene.Camera2D.Center += new Vector2(0.0f, 2.0f); scene.AddChild(sprite_list); scene.RegisterDisposeOnExit((System.IDisposable)ObjectsMap); return(scene); }