public void CreateGameObjects(TileMap tileMap) { if (_parent) Destroy(_parent); _parent = new GameObject("TileMap"); _tilesLeft = tileMap.Tiles.GetEnumerator(); }
protected override void Initialize() { // Set default settings IsMouseVisible = true; Content.RootDirectory = "Content"; Window.Title = "Pixel Defense Force"; // Perhaps retrieve/create a settings file here? _graphics.PreferMultiSampling = false; _graphics.PreferredBackBufferWidth = 1280; _graphics.PreferredBackBufferHeight = 720; _graphics.ApplyChanges(); // Create the camera _camera = new Camera { Resolution = new Point(_graphics.PreferredBackBufferWidth, _graphics.PreferredBackBufferHeight), Position = new Vector2(0, 0), Zoom = 2, TileSize = new Point(32, 32) }; // Generate a test map for now _tileMap = new TileMap {Tiles = new Tile[16][]}; for (var x = 0; x < _tileMap.Tiles.Length; x++) _tileMap.Tiles[x] = new Tile[16]; base.Initialize(); }
public void BuildSprite(TileMap tileMap, float tileSize) { sizeX = tileMap.sizeX; sizeY = tileMap.sizeY; int texWidth = sizeX * tileDefs.tileResolution; int texHeight = sizeY * tileDefs.tileResolution; Texture2D texture = new Texture2D(texWidth, texHeight); tileTypesDefinitions = new Dictionary<Tile.TYPE, TileTypeGraphics>(); foreach (TileTypeGraphics def in tileDefs.tileTypes) { tileTypesDefinitions[def.type] = def; } for (int y = 0; y < sizeY; y++) { for (int x = 0; x < sizeX; x++) { Sprite sprite = tileTypesDefinitions[tileMap.GetTile(x, y).type].sprite; Color[] p = sprite.texture.GetPixels((int)(sprite.textureRect.x), (int)(sprite.textureRect.y), tileDefs.tileResolution, tileDefs.tileResolution); texture.SetPixels(x * tileDefs.tileResolution, y * tileDefs.tileResolution, tileDefs.tileResolution, tileDefs.tileResolution, p); } } texture.filterMode = FilterMode.Point; texture.wrapMode = TextureWrapMode.Clamp; texture.Apply(); AddTextureToSprite(tileSize, texture); }
public static bool GetLineOfSight(TileMap tileMap, float x1, float y1, float x2, float y2) { float deltaX = Math.Abs(x2 - x1); float deltaY = Math.Abs(y2 - y1); float signX = x1 < x2 ? 1 : -1; float signY = y1 < y2 ? 1 : -1; float error = deltaX - deltaY; while (true) { if (tileMap[(int)x1, (int)y1] == CellType.Wall) return false; if (x1 == x2 && y1 == y2) return true; float error2 = error * 2; if (error2 > -deltaY) { error -= deltaY; x1 += signX; } else if (error2 < deltaX) { error += deltaX; y1 += signY; } } }
private void ReadTmxFile() { Debug.Log("> Read Tmx File [" + Application.dataPath + TmxFileRelativePath + "]"); tileMap = TmxParser.Parser(Application.dataPath + TmxFileRelativePath); numberTilesX = tileMap.Width; numberTilesY = tileMap.Height; tileResolution = tileMap.TileWidth; }
public void Initialize(TileMap parent, TileMeshSettings settings) { if (Initialized) throw new InvalidOperationException ("Already initialized"); _parent = parent; _settings = settings; Initialized = true; }
public static void FindHelper(TileMap tileMap, Tile sourceTile, int movement, int jumpHeight, Dictionary<Tile, int> tileToMaxMovement, bool moveThroughOccupiedTiles) { if (!tileToMaxMovement.ContainsKey(sourceTile)) { tileToMaxMovement[sourceTile] = movement; } else { int maxMove = tileToMaxMovement[sourceTile]; if (movement > maxMove) { tileToMaxMovement[sourceTile] = movement; } else { return; } } //if (visited.Contains(sourceTile)) { // return; //} //visited.Add(sourceTile); movement = movement - sourceTile.GetMovementCost(); if (movement <= 0) { return; } if (IsTraversable(tileMap.BottomNeighbor(sourceTile), moveThroughOccupiedTiles)) { FindHelper(tileMap, tileMap.BottomNeighbor(sourceTile), movement, jumpHeight, tileToMaxMovement, moveThroughOccupiedTiles); } if (IsTraversable(tileMap.TopNeighbor(sourceTile), moveThroughOccupiedTiles)) { FindHelper(tileMap, tileMap.TopNeighbor(sourceTile), movement, jumpHeight, tileToMaxMovement, moveThroughOccupiedTiles); } if (IsTraversable(tileMap.LeftNeighbor(sourceTile), moveThroughOccupiedTiles)) { FindHelper(tileMap, tileMap.LeftNeighbor(sourceTile), movement, jumpHeight, tileToMaxMovement, moveThroughOccupiedTiles); } if (IsTraversable(tileMap.RightNeighbor(sourceTile), moveThroughOccupiedTiles)) { FindHelper(tileMap, tileMap.RightNeighbor(sourceTile), movement, jumpHeight, tileToMaxMovement, moveThroughOccupiedTiles); } }
[UsedImplicitly] private void Awake () { self = this; // Parse and load a map into cache. FileParser.LoadFromFile (_map); // Find the tilemap game object and cache the behaviour. _tileMap = GameObject.Find ("TileMap").GetComponent<TileMap>(); if (_tileMap == null) { Debug.LogError ("TileMapBehaviour not found."); return; } TileSheet tileSheet = _tileMap.TileSheet; if (tileSheet.Count == 0) { Debug.LogError ("Add some sprites before running the game."); return; } Sprite sprite = tileSheet.Get (1); _tileMap.MeshSettings = new TileMeshSettings (new IVector2 (FileParser.Width, FileParser.Height), (int)sprite.rect.width); // Map type of tile to sprite _tiles = new TileEnumMapper<TileType> (_tileMap); _tiles.Map (TileType.OUT_BOUNDS, "OutOfBound"); _tiles.Map (TileType.GRASS, "NormalGrass"); _tiles.Map (TileType.SWAMP, "SwampGrass"); _tiles.Map (TileType.WATER, "ShallowWater"); }
protected override void Initialize() { UITexture = Content.Load<Texture2D> ("TDUserInterface.png", TextureConfiguration.Nearest); SpriteSheet = new SpriteSheet2D (Content.Load<Texture2D> ("TDSheet.png", TextureConfiguration.Nearest), 16, 16); TileMap = new TileMap (Vector2.Zero, 26 / 2, 18 / 2, new Vector2 (16, 16), 4); TileMap.AddLayer ("GrassLayer", SpriteSheet); for (int y = 0; y < TileMap.Height; y++) for (int x = 0; x < TileMap.Width; x++) TileMap.SetTile ("GrassLayer", x, y, new Tile { TileId = SpriteSheet.GetTileId(1, 1) }); TileMap.AddLayer ("Track", SpriteSheet); var tiles = new int[][] { new int[] { }, new int[] { 20, 1, 1, 2 }, new int[] { -1, -1, -1, 32, 1, 2 }, new int[] { 0, 1, 2, -1, -1, 16, -1, 16 }, new int[] { 16, -1, 16, -1, -1, 18, -1, 16 }, new int[] { 16, -1, 32, 1, 1, 34, -1, 16 }, new int[] { 16, -1, -1, -1, -1, -1, -1, 16 }, new int[] { 32, 1, 1, 1, 1, 1, 1, 34 } }; for (int y = 0; y < tiles.Length; y++) for (int x = 0; x < tiles[y].Length; x++) TileMap.SetTile ("Track", x, y, new Tile { TileId = tiles[y][x] }); Font = Content.Load<Font> ("durselinvenice2015.ttf", 15f); base.Initialize (); }
bmp2tile() { m_project = null; if( PlayerPrefs.HasKey( PPKEY_PROJECT_PATH )) { LoadProject( PlayerPrefs.GetString( PPKEY_PROJECT_PATH )); //m_project = new Project( PlayerPrefs.GetString( PPKEY_PROJECT_PATH )); } if( PlayerPrefs.HasKey( PPKEY_LAST_OPEN_DIRECTORY )) m_lastOpenDirectory = PlayerPrefs.GetString( PPKEY_LAST_OPEN_DIRECTORY ); else m_lastOpenDirectory = Application.dataPath; if( PlayerPrefs.HasKey( PPKEY_LAST_EXPORT_DIRECTORY )) m_lastExportDirectory = PlayerPrefs.GetString( PPKEY_LAST_EXPORT_DIRECTORY ); else m_lastExportDirectory = Application.dataPath; m_imageTexture = null; m_currentImageData = null; m_currentImageConfig = null; m_tileBank = null; m_tileMap = null; m_haveLoadedImage = false; m_collisionAlpha = 0.5f; m_isResizingTileBank = false; m_isResizingPaletteRemap = false; m_isResizingImageSettings = false; m_isResizingProject = false; m_isResizingMapWindow = false; }
public override void Generate() { tileMapObject = new GameObject(GraphName); tileMapObject.transform.parent = GraphContainer; tileMapObject.transform.position = GraphPosition; tileMapObject.tag = GraphTag; tileMap = tileMapObject.AddComponent<TileMap>(); tiles = new Tile[GraphWidth, GraphHeight]; for (int y = 0; y < GraphHeight; y++) { for (int x = 0; x < GraphWidth; x++) { tilePrefab = GetTilePrefab(); tileObject = GameObject.Instantiate(tilePrefab) as GameObject; tile = tileObject.GetComponent<Tile>(); tileObject.name = "(" + x + ", " + y + ") " + tilePrefab.name; tileObject.transform.parent = tileMapObject.transform; tileObject.transform.position = new Vector3(x, y, 0); tiles[x, y] = tile; } } tileMap.SetNodes(tiles); if (OnGenerationComplete != null) OnGenerationComplete(GraphWidth, GraphHeight); }
void Start() { _grid = transform.parent.GetComponent<Grid>(); _map = transform.parent.GetComponent<TileMap>(); Coordinates = new IntVec2(-1, -1); transform.position = _grid.ToWorld(Coordinates); }
//Populates the floor with enemies public void populateFloor() { tileMap = GameObject.FindGameObjectWithTag("TileMap").GetComponent<TileMap>(); rooms = tileMap.getRooms(); //Try to spawn enemies in each room for (int i = 0; i < 7; i++) { for(int j = 0; j < 7; j++) { if(rooms[i,j] == 1) { int spawnCheck = Random.Range(0, 2); if(spawnCheck == 0) { float spawnX = transform.position.x + i * 5 + 2; float spawnZ = transform.position.z + j * 5 + 2; GameObject tempEnemyRef = (GameObject)GameObject.Instantiate(enemy, new Vector3(spawnX, 1, spawnZ), Quaternion.identity); Enemy tempEnemy = enemyList[Mathf.FloorToInt(Random.value * enemyList.Count)]; tempEnemyRef.GetComponent<Enemy>().setStats(tempEnemy.charName, tempEnemy.health, tempEnemy.strength, tempEnemy.endurance, tempEnemy.agility,tempEnemy.magicSkill, tempEnemy.luck, tempEnemy.range, tempEnemy.drop, tempEnemy.image); GameObject tempPrefab = Instantiate(Resources.Load<GameObject>("Enemy_Prefabs/" + tempEnemy.image)); tempPrefab.transform.position = tempEnemyRef.transform.position; tempPrefab.transform.SetParent(tempEnemyRef.transform); } } } } }
public void CalculateCost(TileMap tileMap, Creature creature, Point endPoint,byte additionalCost, bool improved) { //H = Math.Max(Math.Abs(Position.X - endPoint.X), Math.Abs(Position.Y - endPoint.Y)) * 30; // H = (Math.Abs(Position.X - endPoint.X) + Math.Abs(Position.Y - endPoint.Y))*10; //H = Math.Abs(Position.X - endPoint.X) + Math.Abs(Position.Y - endPoint.Y); if(false) if (!improved) { int xDistance = Math.Abs(PositionX - endPoint.X); int yDistance = Math.Abs(PositionY - endPoint.Y); if (xDistance > yDistance) H = 14 * yDistance + 10 * (xDistance - yDistance); else H = 14 * xDistance + 10 * (yDistance - xDistance); } else H = 0; // H = (Math.Abs(PositionX - endPoint.X) - Math.Abs(PositionY - endPoint.Y)) * 10; if (Parent != null) if (type) G = Parent.G + 10; else G = Parent.G + 14; else G = 0; Cost = G + H;//+ (tileMap[PositionX, PositionY] != CellType.Ladder ? 10000 : 0) + additionalCost // + (tileMap[PositionX, PositionY + 1] == CellType.Wall ? 0 : 5000); // if (creature != null) // Cost += (int)(100 / creature.Body.GetWalkSpeed(creature.Map.terrain[PositionX, PositionY])); }
public override void Setup(Game _game, UserInput _keyboard, ScreenMessage _message) { base.Setup (_game, _keyboard, _message); var map = new TileMap("pictures/testlevel.png"); m_house = new ObjectHouse(map); StarryBackground bg = new StarryBackground(map.Size); m_house.AddDrawable(bg); map.Create(m_house, _game); Magnum magnum = new Magnum(m_house); var hero = new Hero(_keyboard, m_house); hero.Position = new Vector2f(1f, 10f); hero.PlaceInWorld(map); m_house.AddDrawable(hero); m_house.AddUpdateable(hero); m_house.AddDrawable(magnum); m_house.AddUpdateable(magnum); var nHero = new NetworkHero(hero, "127.0.0.1", m_house); m_house.AddUpdateable(nHero); nHero.Connect(); }
public void RenderTileMap(TileMap map) { Vector3 scrollTileOffset = new Vector3(map.ScrollOffset_X % map.TileSize, map.ScrollOffset_Y % map.TileSize); Vector3 startPos = new Vector3( (-map.ScreenWidth*0.5f) - scrollTileOffset.x , (-map.ScreenHeight*0.5f) - scrollTileOffset.y ); // Botto right for (int row = 0; row < map.NumOfTile_ScreenHeight; ++row) // Number of rows { for (int col = 0; col < map.NumOfTile_ScreenWidth + 1; ++col) // Number of columns (+1 for ScrollOffset) { // World origin in middle (Negative half size to Positive half size) switch (map.Map[Mathf.CeilToInt(scrollTileOffset.y) + row][Mathf.CeilToInt(scrollTileOffset.x) + col].Type) { case TILE_TYPE.TILE_NONE: { renderMap[Convert.ToInt32((row * map.NumOfTile_ScreenWidth) + col)].SetActive(false); } break; case TILE_TYPE.TILE_FLOOR_1: { renderMap[Convert.ToInt32((row * map.NumOfTile_ScreenWidth) + col)] = tileList[Convert.ToInt32(TILE_TYPE.TILE_FLOOR_1)]; renderMap[Convert.ToInt32((row * map.NumOfTile_ScreenWidth) + col)].SetActive(true); renderMap[Convert.ToInt32((row * map.NumOfTile_ScreenWidth) + col)].transform.Translate(startPos.x + (col * map.TileSize), startPos.y + (row * map.TileSize), 0); } break; case TILE_TYPE.TILE_FLOOR_2: { renderMap[Convert.ToInt32((row * map.NumOfTile_ScreenWidth) + col)] = tileList[Convert.ToInt32(TILE_TYPE.TILE_FLOOR_2)]; renderMap[Convert.ToInt32((row * map.NumOfTile_ScreenWidth) + col)].SetActive(true); renderMap[Convert.ToInt32((row * map.NumOfTile_ScreenWidth) + col)].transform.Translate(startPos.x + (col * map.TileSize), startPos.y + (row * map.TileSize), 0); } break; } } } }
public override void Setup(Game _game, UserInput _keyboard, ScreenMessage _message) { base.Setup (_game, _keyboard, _message); TileMap tilemap = new TileMap("pictures/empty_level.png"); m_house = new ObjectHouse(tilemap); StarryBackground bg = new StarryBackground(tilemap.Size); m_house.AddDrawable(bg); Gangster gangsterNo1 = new Hero(m_keyboard, m_house); gangsterNo1.Position = new Vector2f(1f, 10f); gangsterNo1.PlaceInWorld(tilemap); m_house.AddDrawable(gangsterNo1); m_house.AddUpdateable(gangsterNo1); m_house.Add<IShootable>(gangsterNo1); m_game.SetCameraSubject(gangsterNo1); tilemap.Create(m_house, _game); Bitmap world_bmp = new Bitmap(tilemap.Width * Tile.Size, tilemap.Height * Tile.Size); for (int i = 0 ; i < world_bmp.Width ; i++) { for (int j = 0 ; j < world_bmp.Height; j++) { world_bmp.SetPixel(i, j, Color.Green); } } GangsterTrail trail = new GangsterTrail(gangsterNo1, new Sprite(world_bmp)); m_house.AddUpdateable(trail); m_house.AddDrawable(trail); }
public static void FindHelper(TileMap tileMap, TileData sourceTile, int movement, FindTilesWithinRangeDTO dto) { if (!dto.TileToMaxMovement.ContainsKey(sourceTile)) { dto.TileToMaxMovement[sourceTile] = movement; } else { int maxMove = dto.TileToMaxMovement[sourceTile]; if (movement > maxMove) { dto.TileToMaxMovement[sourceTile] = movement; } else { return; } } //if (visited.Contains(sourceTile)) { // return; //} //visited.Add(sourceTile); movement = movement - sourceTile.MovementCost; if (movement <= 0) { return; } if (IsTraversable(tileMap.BottomNeighbor(sourceTile), dto)) { FindHelper(tileMap, tileMap.BottomNeighbor(sourceTile), movement, dto); } if (IsTraversable(tileMap.TopNeighbor(sourceTile), dto)) { FindHelper(tileMap, tileMap.TopNeighbor(sourceTile), movement, dto); } if (IsTraversable(tileMap.LeftNeighbor(sourceTile), dto)) { FindHelper(tileMap, tileMap.LeftNeighbor(sourceTile), movement, dto); } if (IsTraversable(tileMap.RightNeighbor(sourceTile), dto)) { FindHelper(tileMap, tileMap.RightNeighbor(sourceTile), movement, dto); } }
public static Tile ParseTile(XmlNode tileXmlNode, TileMap tileMap, int x, int y) { var gid = int.Parse(tileXmlNode.Attributes["gid"].Value); var texture = tileMap.GetTileSetByGid(gid).GetTilesTexture2D(gid); return new Tile(x, y, texture); }
public Clobber (Unit u, TileMap m, PrefabLibrary el) : base(u, m , el) { damage = 30; range = 1; area = AreaType.Single; targets = TargetType.Enemy; maxCooldown = 1; }
void Start() { lineRenderer = GetComponent<LineRenderer>(); tileMap = FindObjectOfType(typeof(TileMap)) as TileMap; enabled = tileMap != null; }
public MobileSprite(Texture2D texture, TileMap map) { sprite = new SpriteAnimation(texture); this.map = map; path = new Queue<Vector2>(); currentTarget = new Vector2(-1, -1); nullTarget = new Vector2(-1, -1); }
void Start () { map = GameObject.Find("World").GetComponent<Pooling>().map; gameObject.name = TileData.X + "," + TileData.Y; sr = gameObject.GetComponent<SpriteRenderer>(); sr.sprite = dirt; }
// Use this for initialization void Start() { map = TileMap.GetComponent<TileMap>(); lantern = GameObject.FindGameObjectWithTag ("Lantern"); key1 = GameObject.FindGameObjectWithTag ("key1"); key2 = GameObject.FindGameObjectWithTag ("key2"); key3 = GameObject.FindGameObjectWithTag ("key3"); }
public void OnEnable() { _tileMap = (TileMap)target; Type internalEditorUtilityType = typeof(InternalEditorUtility); PropertyInfo sortingLayersProperty = internalEditorUtilityType.GetProperty("sortingLayerNames", BindingFlags.Static | BindingFlags.NonPublic); _sortingLayers = (string[])sortingLayersProperty.GetValue(null, new object[0]); }
public TileMapColliderGenerator([NotNull] TileMap tileMap, [NotNull] SpriteSheet spriteSheet) { if (tileMap == null) throw new ArgumentNullException("tileMap"); if (spriteSheet == null) throw new ArgumentNullException("spriteSheet"); _tileMap = tileMap; _spriteSheet = spriteSheet; }
// Use this for initialization void Start() { _tileCursor = GameObject.Find("Tile Cursor"); _map = GetComponent<TileMap>(); if (_map == null) throw new Exception("TileMap not found"); }
/// <summary> /// Parses the example xml element structure to an object of this type: /// <note> /// <layer name="background" width="20" height="20"> /// <data> /// <tile gid="1"/> /// ... /// </data> /// </layer> /// </note> /// </summary> /// <param name="tileLayerXmlNode"></param> /// <param name="map"></param> /// <returns></returns> public static TileLayer ParseTileLayer(XmlNode tileLayerXmlNode, TileMap map) { int widht = int.Parse(tileLayerXmlNode.Attributes["width"].Value); int height = int.Parse(tileLayerXmlNode.Attributes["height"].Value); string name = tileLayerXmlNode.Attributes["name"].Value; Tile[,] data = ParseTiles(tileLayerXmlNode.SelectNodes("data/tile"), map, widht, height); return new TileLayer(widht, height, name, data); }
// GameObject player; // Use this for initialization void Awake() { hasMovedCamera = true; map = GameObject.FindGameObjectWithTag("Map").GetComponent<TileMap>(); x = (map.Columns * map.TileWidth) / 2; y = (map.Rows * map.TileHeight) / 2; z = -10; transform.position = new Vector3(x + offsets.x, y + offsets.y, z + offsets.z); }
void Start() { _tileMap = GetComponent<TileMap> (); _generateZone = GetComponent < generateZone >(); myHoverObject = (GameObject) Instantiate (Resources.Load("Tile"), new Vector3 (0, 0, 0), Quaternion.identity); generate = false; zoning = true; currentColor = "blue"; }
public void Setup(RandomNumberGenerator rng, TileMap level) { _rng = rng; _level = level; }
public void Initialize(TileMap tilemap) { //spatial organizing structures map = tilemap; }
public void AddMap(TileMap newMap) { mapList.Add(newMap); }
public void WriteTileMap() { tileMaps.Add(TileMap.CreateTileMap(builder, TileMap.CreateTilesVector(builder, tilesPos.ToArray()), offset)); offset = ushort.MaxValue; tilesPos = new List <ushort>(); }
static public List <TileData> Find(TileMap tileMap, TileData sourceTile, TileData destinationTile) { return(Find(tileMap, sourceTile, destinationTile, TeamId.MOVE_THROUGH_NONE)); }
public override void LoadContent() { #region Debug DebugConsole = new DebugConsole(Content.Load <SpriteFont>("fonts/general/ubuntu_mono")); #endregion #region Items ItemContainer.GenerateItemDefinitions(Content); var slotPrefab = new InventorySlot( Content.Load <Texture2D>("inventory/gui/slot"), Content.Load <Texture2D>("inventory/gui/slot_hover"), Content.Load <Texture2D>("inventory/gui/slot_pressed") ); Inventory = new Inventory(9, 3); #endregion #region GUI guiComponents = new List <IGuiComponent>(); guiComponents.Add(new InventoryUI(Inventory, new InventoryUISettings() { InventorySlotPrefab = slotPrefab, ItemHoverInfoNineSlice = Content.Load <Texture2D>("inventory/gui/item_hover_ns"), ItemHoverInfoFont = Content.Load <SpriteFont>("fonts/general/peepo") })); #endregion #region Tilemap var atlas = Content.Load <Texture2D>("world/forest/tiles/forest_background_tiles"); tileMap = new TileMap(atlas, new ForestFloorTile(atlas, 3, 1)); tileMap.Generate(new Vector2[, ] { { new Vector2(0, 0), new Vector2(0, 0), new Vector2(0, 0), new Vector2(1, 0), new Vector2(0, 0), new Vector2(0, 0), new Vector2(0, 0) }, { new Vector2(0, 0), new Vector2(0, 0), new Vector2(1, 0), new Vector2(2, 0), new Vector2(1, 0), new Vector2(0, 0), new Vector2(0, 0) }, { new Vector2(0, 0), new Vector2(1, 0), new Vector2(2, 0), new Vector2(2, 0), new Vector2(2, 0), new Vector2(1, 0), new Vector2(0, 0) }, { new Vector2(1, 0), new Vector2(2, 0), new Vector2(2, 0), new Vector2(2, 0), new Vector2(2, 0), new Vector2(2, 0), new Vector2(1, 0) }, { new Vector2(0, 0), new Vector2(1, 0), new Vector2(2, 0), new Vector2(2, 0), new Vector2(2, 0), new Vector2(1, 0), new Vector2(0, 0) }, { new Vector2(0, 0), new Vector2(0, 0), new Vector2(1, 0), new Vector2(2, 0), new Vector2(1, 0), new Vector2(0, 0), new Vector2(0, 0) }, { new Vector2(0, 0), new Vector2(0, 0), new Vector2(0, 0), new Vector2(1, 0), new Vector2(0, 0), new Vector2(0, 0), new Vector2(0, 0) } }); #endregion #region Entities entities = new List <Entity>(); var player = new Player(new Dictionary <string, Animation> { { "Walk", new Animation(Content.Load <Texture2D>("player/player"), 9, 1) { IsLooping = true, FrameSpeed = 0.1f } } }) { Position = new Vector2(75, 50) }; var oakTree = new OakTree(Content.Load <Texture2D>("world/forest/environment/decor/oak_tree")) { Position = new Vector2(200, 100) }; entities.Add(player); entities.Add(oakTree); #endregion }
public void LoadFromTileMap(TileMap tileMap, int nodeSizeX, int nodeSizeY) { List <WaypointAStarNode> genNodes = new List <WaypointAStarNode>(); int width = (tileMap.Width + nodeSizeX - 1) / nodeSizeX; int height = (tileMap.Height + nodeSizeY - 1) / nodeSizeY; int[] cover = new int[width * height]; int index = 0; for (int y = 0; y < height; ++y) { for (int x = 0; x < width; ++x, ++index) { cover[index] = (IsPassable(tileMap, x * nodeSizeX, y * nodeSizeY, nodeSizeX, nodeSizeY) ? 0 : -1); } } int nodeCount = 0; index = 0; while (index < width * height) { if (cover[index] == 0) { int x = index % width; int y = index / width; ++nodeCount; cover[index] = nodeCount; int size = 1; while (x + size < width && y + size < height) { bool passable = true; for (int i = 0; i <= size && passable; ++i) { if (cover[x + i + (y + size) * width] != 0 || cover[x + size + (y + i) * width] != 0) { passable = false; } } if (passable) { for (int i = 0; i <= size; ++i) { cover[x + i + (y + size) * width] = cover[x + size + (y + i) * width] = nodeCount; } ++size; } else { break; } } WaypointAStarNode node = new WaypointAStarNode(); node.x = x; node.y = y; node.size = size; node.neighbors = new List <int>(); genNodes.Add(node); } ++index; } for (int i = 0; i < genNodes.Count; ++i) { WaypointAStarNode a = genNodes[i]; int llax = a.x - 1; int llay = a.y - 1; int urax = a.x + a.size; int uray = a.y + a.size; for (int j = i + 1; j < genNodes.Count; ++j) { WaypointAStarNode b = genNodes[j]; int llbx = b.x; int llby = b.y; int urbx = b.x + b.size - 1; int urby = b.y + b.size - 1; if (llax <= urbx && llay <= urby && urax >= llbx && uray >= llby) { genNodes[i].neighbors.Add(j); genNodes[j].neighbors.Add(i); } } } _nodes = genNodes.ToArray(); }
/// <summary> /// タイル描画更新 /// </summary> public void DrawTile() { // これでもまだGCが出て困っている。 TileMap.SetTilesBlock(TileMap.cellBounds, TileTypeAry); }
public World() { tileMap = new TileMap(64, 64); }
// Token: 0x0600061A RID: 1562 RVA: 0x0004B974 File Offset: 0x00049B74 public override void paint(mGraphics g) { if (global::Char.isLoadingMap) { return; } GameCanvas.paintBGGameScr(g); g.translate(-GameScr.cmx, -GameScr.cmy); if (!GameCanvas.lowGraphic) { for (int i = 0; i < MapTemplate.vCurrItem[CreateCharScr.indexGender].size(); i++) { BgItem bgItem = (BgItem)MapTemplate.vCurrItem[CreateCharScr.indexGender].elementAt(i); if (bgItem.idImage != -1 && (int)bgItem.layer == 1) { bgItem.paint(g); } } } TileMap.paintTilemap(g); int num = 30; if (GameCanvas.w == 128) { num = 20; } int num2 = CreateCharScr.hairID[CreateCharScr.indexGender][CreateCharScr.indexHair]; int num3 = CreateCharScr.defaultLeg[CreateCharScr.indexGender]; int num4 = CreateCharScr.defaultBody[CreateCharScr.indexGender]; g.drawImage(TileMap.bong, this.cx, this.cy + this.dy, 3); Part part = GameScr.parts[num2]; Part part2 = GameScr.parts[num3]; Part part3 = GameScr.parts[num4]; SmallImage.drawSmallImage(g, (int)part.pi[global::Char.CharInfo[this.cf][0][0]].id, this.cx + global::Char.CharInfo[this.cf][0][1] + (int)part.pi[global::Char.CharInfo[this.cf][0][0]].dx, this.cy - global::Char.CharInfo[this.cf][0][2] + (int)part.pi[global::Char.CharInfo[this.cf][0][0]].dy + this.dy, 0, 0); SmallImage.drawSmallImage(g, (int)part2.pi[global::Char.CharInfo[this.cf][1][0]].id, this.cx + global::Char.CharInfo[this.cf][1][1] + (int)part2.pi[global::Char.CharInfo[this.cf][1][0]].dx, this.cy - global::Char.CharInfo[this.cf][1][2] + (int)part2.pi[global::Char.CharInfo[this.cf][1][0]].dy + this.dy, 0, 0); SmallImage.drawSmallImage(g, (int)part3.pi[global::Char.CharInfo[this.cf][2][0]].id, this.cx + global::Char.CharInfo[this.cf][2][1] + (int)part3.pi[global::Char.CharInfo[this.cf][2][0]].dx, this.cy - global::Char.CharInfo[this.cf][2][2] + (int)part3.pi[global::Char.CharInfo[this.cf][2][0]].dy + this.dy, 0, 0); if (!GameCanvas.lowGraphic) { for (int j = 0; j < MapTemplate.vCurrItem[CreateCharScr.indexGender].size(); j++) { BgItem bgItem2 = (BgItem)MapTemplate.vCurrItem[CreateCharScr.indexGender].elementAt(j); if (bgItem2.idImage != -1 && (int)bgItem2.layer == 3) { bgItem2.paint(g); } } } g.translate(-g.getTranslateX(), -g.getTranslateY()); if (GameCanvas.w < 200) { GameCanvas.paintz.paintFrame(GameScr.popupX, GameScr.popupY, GameScr.popupW, GameScr.popupH, g); SmallImage.drawSmallImage(g, (int)part.pi[global::Char.CharInfo[0][0][0]].id, GameCanvas.w / 2 + global::Char.CharInfo[0][0][1] + (int)part.pi[global::Char.CharInfo[0][0][0]].dx, GameScr.popupY + 30 + 3 * num - global::Char.CharInfo[0][0][2] + (int)part.pi[global::Char.CharInfo[0][0][0]].dy + this.dy, 0, 0); SmallImage.drawSmallImage(g, (int)part2.pi[global::Char.CharInfo[0][1][0]].id, GameCanvas.w / 2 + global::Char.CharInfo[0][1][1] + (int)part2.pi[global::Char.CharInfo[0][1][0]].dx, GameScr.popupY + 30 + 3 * num - global::Char.CharInfo[0][1][2] + (int)part2.pi[global::Char.CharInfo[0][1][0]].dy + this.dy, 0, 0); SmallImage.drawSmallImage(g, (int)part3.pi[global::Char.CharInfo[0][2][0]].id, GameCanvas.w / 2 + global::Char.CharInfo[0][2][1] + (int)part3.pi[global::Char.CharInfo[0][2][0]].dx, GameScr.popupY + 30 + 3 * num - global::Char.CharInfo[0][2][2] + (int)part3.pi[global::Char.CharInfo[0][2][0]].dy + this.dy, 0, 0); for (int k = 0; k < mResources.MENUNEWCHAR.Length; k++) { if (CreateCharScr.selected == k) { g.drawRegion(GameScr.arrow, 0, 0, 13, 16, 2, GameScr.popupX + 10 + ((GameCanvas.gameTick % 7 <= 3) ? 0 : 1), GameScr.popupY + 35 + k * num, StaticObj.VCENTER_HCENTER); g.drawRegion(GameScr.arrow, 0, 0, 13, 16, 0, GameScr.popupX + GameScr.popupW - 10 - ((GameCanvas.gameTick % 7 <= 3) ? 0 : 1), GameScr.popupY + 35 + k * num, StaticObj.VCENTER_HCENTER); } mFont.tahoma_7b_dark.drawString(g, mResources.MENUNEWCHAR[k], GameScr.popupX + 20, GameScr.popupY + 30 + k * num, 0); } mFont.tahoma_7b_dark.drawString(g, mResources.MENUGENDER[CreateCharScr.indexGender], GameScr.popupX + 70, GameScr.popupY + 30 + 1 * num, mFont.LEFT); mFont.tahoma_7b_dark.drawString(g, mResources.hairStyleName[CreateCharScr.indexGender][CreateCharScr.indexHair], GameScr.popupX + 55, GameScr.popupY + 30 + 2 * num, mFont.LEFT); CreateCharScr.tAddName.paint(g); } else { if (!Main.isPC) { if (mGraphics.addYWhenOpenKeyBoard != 0) { this.yButton = 110; this.disY = 60; if (GameCanvas.w > GameCanvas.h) { this.yButton = GameScr.popupY + 30 + 3 * num + (int)part3.pi[global::Char.CharInfo[0][2][0]].dy + this.dy - 15; this.disY = 35; } } else { this.yButton = 110; this.disY = 60; if (GameCanvas.w > GameCanvas.h) { this.yButton = 100; this.disY = 45; } } CreateCharScr.tAddName.y = this.yButton - CreateCharScr.tAddName.height - this.disY + 5; } else { this.yButton = 110; this.disY = 60; if (GameCanvas.w > GameCanvas.h) { this.yButton = 100; this.disY = 45; } CreateCharScr.tAddName.y = this.yBegin; } for (int l = 0; l < 3; l++) { int num5 = 78; if (l != CreateCharScr.indexGender) { g.drawImage(GameScr.imgLbtn, GameCanvas.w / 2 - num5 + l * num5, this.yButton, 3); } else { if (CreateCharScr.selected == 1) { g.drawRegion(GameScr.arrow, 0, 0, 13, 16, 4, GameCanvas.w / 2 - num5 + l * num5, this.yButton - 20 + ((GameCanvas.gameTick % 7 <= 3) ? 0 : 1), StaticObj.VCENTER_HCENTER); } g.drawImage(GameScr.imgLbtnFocus, GameCanvas.w / 2 - num5 + l * num5, this.yButton, 3); } mFont.tahoma_7b_dark.drawString(g, mResources.MENUGENDER[l], GameCanvas.w / 2 - num5 + l * num5, this.yButton - 5, mFont.CENTER); } for (int m = 0; m < 3; m++) { int num6 = 78; if (m != CreateCharScr.indexHair) { g.drawImage(GameScr.imgLbtn, GameCanvas.w / 2 - num6 + m * num6, this.yButton + this.disY, 3); } else { if (CreateCharScr.selected == 2) { g.drawRegion(GameScr.arrow, 0, 0, 13, 16, 4, GameCanvas.w / 2 - num6 + m * num6, this.yButton + this.disY - 20 + ((GameCanvas.gameTick % 7 <= 3) ? 0 : 1), StaticObj.VCENTER_HCENTER); } g.drawImage(GameScr.imgLbtnFocus, GameCanvas.w / 2 - num6 + m * num6, this.yButton + this.disY, 3); } mFont.tahoma_7b_dark.drawString(g, mResources.hairStyleName[CreateCharScr.indexGender][m], GameCanvas.w / 2 - num6 + m * num6, this.yButton + this.disY - 5, mFont.CENTER); } CreateCharScr.tAddName.paint(g); } g.setClip(0, 0, GameCanvas.w, GameCanvas.h); mFont.tahoma_7b_white.drawString(g, mResources.server + " " + LoginScr.serverName, 5, 5, 0, mFont.tahoma_7b_dark); if (!TouchScreenKeyboard.visible) { base.paint(g); } }
// Token: 0x06000614 RID: 1556 RVA: 0x0004B0F0 File Offset: 0x000492F0 public void loadMapTableFromResource(sbyte[] mapID) { if (GameCanvas.lowGraphic) { return; } DataInputStream dataInputStream = null; try { for (int i = 0; i < mapID.Length; i++) { dataInputStream = MyStream.readFile("/mymap/mapTable" + mapID[i]); Cout.LogError("mapTable : " + mapID[i]); short num = dataInputStream.readShort(); MapTemplate.vCurrItem[i] = new MyVector(); Res.outz("nItem= " + num); for (int j = 0; j < (int)num; j++) { short id = dataInputStream.readShort(); short num2 = dataInputStream.readShort(); short num3 = dataInputStream.readShort(); if (TileMap.getBIById((int)id) != null) { BgItem bibyId = TileMap.getBIById((int)id); BgItem bgItem = new BgItem(); bgItem.id = (int)id; bgItem.idImage = bibyId.idImage; bgItem.dx = bibyId.dx; bgItem.dy = bibyId.dy; bgItem.x = (int)num2 * (int)TileMap.size; bgItem.y = (int)num3 * (int)TileMap.size; bgItem.layer = bibyId.layer; MapTemplate.vCurrItem[i].addElement(bgItem); if (!BgItem.imgNew.containsKey(bgItem.idImage + string.Empty)) { try { Image image = GameCanvas.loadImage("/mapBackGround/" + bgItem.idImage + ".png"); if (image == null) { BgItem.imgNew.put(bgItem.idImage + string.Empty, Image.createRGBImage(new int[1], 1, 1, true)); Service.gI().getBgTemplate(bgItem.idImage); } else { BgItem.imgNew.put(bgItem.idImage + string.Empty, image); } } catch (Exception ex) { Image image2 = GameCanvas.loadImage("/mapBackGround/" + bgItem.idImage + ".png"); if (image2 == null) { image2 = Image.createRGBImage(new int[1], 1, 1, true); Service.gI().getBgTemplate(bgItem.idImage); } BgItem.imgNew.put(bgItem.idImage + string.Empty, image2); } BgItem.vKeysLast.addElement(bgItem.idImage + string.Empty); } if (!BgItem.isExistKeyNews(bgItem.idImage + string.Empty)) { BgItem.vKeysNew.addElement(bgItem.idImage + string.Empty); } bgItem.changeColor(); } else { Res.outz("item null"); } } } } catch (Exception ex2) { Cout.println("LOI TAI loadMapTableFromResource" + ex2.ToString()); } }
public void saveMap() { TileMap tileMap = GameObject.Find("Map").GetComponent <TileMap>(); SaveAndLoad.saveMap(tileMap); }
public override int2 GetExitPoint(TileMap <TileType> map, int level) { return(FindPlaceForStairs(map, map.Layout.FinalZone)); }
void Awake() { map = GameObject.FindObjectOfType <TileMap>(); GameController.OnEndTurn += EndTurn; source = GameObject.Find("blii").GetComponent <AudioSource>(); }
public static Vector2 GetTargetPosition(TileMap tilemap, GridPosition position, int tileSize, (int, int) initCoordinates)
private void Start() { gamePieceData = this.GetComponent <GamePiece>(); gameBoard = this.GetComponentInParent <TileMap>(); }
public TileMenu(TileMap tileMap, FogOfWar fog) : base(tileMap, fog) { Debug.WriteLine("Successfully created TileMenu."); }
override public void Ready() { // Setup ground, trees, player, etc. var groundTileMap = new TileMap(MapWidth, MapHeight, Path.Join("Content", "Images", "Tilesets", "Outside.png"), 32, 32); groundTileMap.Define("Grass", 0, 0); for (var y = 0; y < MapHeight; y++) { for (var x = 0; x < MapWidth; x++) { groundTileMap.Set(x, y, "Grass"); } } this.Add(groundTileMap); foreach (var item in this.map.Contents) { if (item is TreeModel) { this.Add(new TreeEntity(this.EventBus, item as TreeModel).Move(item.X * Constants.TileWidth, item.Y * Constants.TileHeight)); } else if (item is RockModel) { this.Add(new RockEntity(this.EventBus, item as RockModel).Move(item.X * Constants.TileWidth, item.Y * Constants.TileHeight)); } else if (item is PlayerModel) { this.player = new PlayerEntity(this.EventBus, item as PlayerModel).Move(item.X * Constants.TileWidth, item.Y * Constants.TileHeight); this.Add(this.player); } } // UI // TODO: show/hide label on mouse over/out this.Add(new EnergyBar(this.EventBus, this.playerModel)); // Event handlers this.EventBus.Subscribe(MapEvent.InteractedWithTree, (obj) => { var tree = obj as TreeEntity; if (this.playerModel.HasEnergyTo(MapEvent.InteractedWithTree)) { this.ShowSubScene(new MemoryChopTreeScene(this.map, this.playerModel, tree.Model)); } }); this.EventBus.Subscribe(MapEvent.InteractedWithRock, (obj) => { var rock = obj as RockEntity; var model = rock.Model; if (this.playerModel.HasEnergyTo(MapEvent.InteractedWithRock)) { this.ShowSubScene(new TriggerMineRockScene(this.map, this.playerModel, rock.Model)); } }); this.EventBus.Subscribe(MapEvent.PlayerMoved, (obj) => { (var dx, var dy) = obj as Tuple <int, int>; this.TweenPosition( this.player, new System.Tuple <float, float>(this.player.X, this.player.Y), new System.Tuple <float, float>( this.player.X + (dx * Constants.TileWidth), this.player.Y + (dy * Constants.TileHeight)) , PlayerEntity.SecondsToMoveToTile, () => (this.player as PlayerEntity).IsMoving = false); }); // Camera this.Add(new Entity().Camera(Constants.GameZoom)); }
void MakeTileCollisionShapes(TileMap map) { TileSet tileSet = map.TileSet; foreach (int tileId in tileSet.GetTilesIds()) { // Load image and calculate collison polygon // https://github.com/godotengine/godot/blob/2abe996414b8b551e69e29461de3ff1bcaf5a28f/editor/plugins/sprite_2d_editor_plugin.cpp#L160 // https://github.com/godotengine/godot/blob/2abe996414b8b551e69e29461de3ff1bcaf5a28f/editor/plugins/sprite_2d_editor_plugin.cpp#L255 Image tileImage = tileSet.TileGetTexture(tileId).GetData(); Rect2 rect = new Rect2(); rect.Size = new Vector2(tileImage.GetWidth(), tileImage.GetHeight()); BitMap imageBitMap = new BitMap(); imageBitMap.CreateFromImageAlpha(tileImage); Array lines = imageBitMap.OpaqueToPolygons(rect); Array <Array <Vector2> > OutlineLines = new Array <Array <Vector2> >(); OutlineLines.Resize(lines.Count); Array <Array <Vector2> > computedOutlineLines = new Array <Array <Vector2> >(); computedOutlineLines.Resize(lines.Count); for (int pi = 0; pi < lines.Count; pi++) { Array <Vector2> ol = new Array <Vector2>(); Array <Vector2> col = new Array <Vector2>(); IList <Vector2> linesLines = (IList <Vector2>)lines[pi]; ol.Resize(linesLines.Count); col.Resize(linesLines.Count); for (int i = 0; i < linesLines.Count; i++) { Vector2 vtx = linesLines[i]; ol[i] = vtx; vtx -= rect.Position; // Flipping logic is not implemented since idk how that would // translate from a Sprite to an Image // Don't flip any sprites horizontally or vertically // this assumes the texture is centered in the image (which it is) vtx -= rect.Size / 2; col[i] = vtx; } OutlineLines[pi] = ol; computedOutlineLines[pi] = col; } // Now that we've calculated the collision polygon, we need to set it // https://github.com/godotengine/godot/blob/2abe996414b8b551e69e29461de3ff1bcaf5a28f/editor/plugins/sprite_2d_editor_plugin.cpp#L400 if (computedOutlineLines.Count == 0) { GD.PrintErr("Error, couldn't make some geometry - tileId is " + tileId.ToString()); continue; } ConvexPolygonShape2D newShape = new ConvexPolygonShape2D(); for (int i = 0; i < computedOutlineLines.Count; i++) { var outline = computedOutlineLines[i]; newShape.Points = outline.ToArray <Vector2>(); tileSet.TileSetShape(tileId, 0, newShape); tileSet.TileSetShapeOffset(tileId, 0, new Vector2(256, 256)); // needs to be offset by this amount for some reason } } }
public override TileMap <TileType> PostConnectZones(TileMap <TileType> map, int level) { return(map); }
private void GenerateMap(bool random) { int mapWidth = 40; int mapHeight = 23; if (random) { Random rand = new Random(); mapWidth = rand.Next(30, 42); mapHeight = rand.Next(18, 23); } int[,] textIndexes = new int[mapWidth, mapHeight]; for (int i = 0; i < mapWidth; i++) { for (int j = 0; j < mapHeight; j++) { textIndexes[i, j] = 0; } } TileMap.Initialize(textIndexes); if (random) { //Static generation of the tile map Random rand = new Random(); //Generate Trees and rocks int nbTrees = rand.Next(5, 25); for (int i = 0; i < nbTrees; i++) { TileMap.PlaceGameObjectRandomly(new Scenery.Tree()); } int nbRocks = rand.Next(0, 10); for (int i = 0; i < nbRocks; i++) { TileMap.PlaceGameObjectRandomly(new GameObject() { ObjectSprite = new Sprite(6), IsSolid = true }); } } else { //Place a "forest" on the top of the map for (int i = 4; i < TileMap.Width; i++) { if (i % 5 == 0) { TileMap.Tiles[i, 0].AddObject(new Scenery.Tree()); } } for (int i = 5; i < TileMap.Width; i++) { if (i % 2 == 0) { TileMap.Tiles[i, 1].AddObject(new Scenery.Tree()); } } for (int i = 8; i < TileMap.Width; i++) { if (i % 3 == 0) { TileMap.Tiles[i, 2].AddObject(new Scenery.Tree()); } } for (int i = 15; i < TileMap.Width; i++) { if (i % 4 == 0) { TileMap.Tiles[i, 3].AddObject(new Scenery.Tree()); } } TileMap.Tiles[5, 1].AddObject(new Scenery.Tree()); TileMap.Tiles[7, 3].AddObject(new Scenery.Tree()); TileMap.Tiles[2, 7].AddObject(new Scenery.Tree()); TileMap.Tiles[7, 12].AddObject(new Scenery.Tree()); TileMap.Tiles[3, 18].AddObject(new Scenery.Tree()); TileMap.Tiles[9, 15].AddObject(new Scenery.Tree()); TileMap.Tiles[1, 4].AddObject(new Scenery.Tree()); TileMap.Tiles[2, 17].AddObject(new Scenery.Tree()); TileMap.Tiles[5, 8].AddObject(new Scenery.Tree()); TileMap.Tiles[8, 20].AddObject(new Scenery.Tree()); TileMap.Tiles[12, 21].AddObject(new Scenery.Tree()); TileMap.Tiles[15, 2].AddObject(new Scenery.Tree()); TileMap.Tiles[18, 1].AddObject(new Scenery.Tree()); TileMap.Tiles[20, 19].AddObject(new Scenery.Tree()); TileMap.Tiles[21, 3].AddObject(new Scenery.Tree()); TileMap.Tiles[25, 22].AddObject(new Scenery.Tree()); TileMap.Tiles[28, 20].AddObject(new Scenery.Tree()); TileMap.Tiles[29, 0].AddObject(new Scenery.Tree()); TileMap.Tiles[30, 4].AddObject(new Scenery.Tree()); TileMap.Tiles[31, 21].AddObject(new Scenery.Tree()); TileMap.Tiles[35, 21].AddObject(new Scenery.Tree()); TileMap.Tiles[36, 15].AddObject(new Scenery.Tree()); TileMap.Tiles[36, 6].AddObject(new Scenery.Tree()); TileMap.Tiles[38, 4].AddObject(new Scenery.Tree()); TileMap.Tiles[39, 13].AddObject(new Scenery.Tree()); TileMap.Tiles[39, 14].AddObject(new Scenery.Tree()); TileMap.Tiles[39, 20].AddObject(new Scenery.Tree()); } }
public MoveObject(float x, float y, Animation animation, TileMap map) : this(x, y, 0, 0, animation, map) { }
public override void Update(GameTime gameTime, Player player, TileMap map, List <MovableItem> movableList) { canFly = true; base.Update(gameTime, player, map, movableList); }
void Start() { tm = GameObject.Find("TileMap").GetComponent <TileMap> (); }
void Start() { map = GetComponent <TileMap>(); StartGenerator(); }
public List <Vector2> CalculatePath(Vector2 pos, Vector2 initialSpeed, float timeIncrementation, TileMap tileMap, IGroundEntity entity, out Node finalNode, float gravityForce = GravityUtil.DefaultGravityForce) { finalNode = null; var rb = entity.RigidBody; var gravity = rb.mass * -gravityForce * rb.gravityScale; var list = new List <Vector2>(); var time = 0F; while (finalNode == null) { var y = pos.y + initialSpeed.y * time + gravity * Mathf.Pow(time, 2) / 2; var x = pos.x + initialSpeed.x * time; if (tileMap.IsOutOfBounds(x, y)) { break; } var newPos = new Vector2(x, y); if (!list.IsEmpty()) { var last = list.Last(); var dir = newPos - last; var raycast = Physics2D.Raycast(last, dir, dir.magnitude, tileMap.WorldMask); if (raycast) { Gizmos.color = Color.yellow; Gizmos.DrawWireSphere(last, 0.2f); Gizmos.color = Color.red; Gizmos.DrawWireSphere(newPos, 0.2f); Gizmos.DrawRay(last, dir); var hitPoint = raycast.point; list.Add(hitPoint); var hitNode = tileMap.GetNode(hitPoint); if (hitNode != null) { Gizmos.DrawWireSphere(hitPoint, 0.2f); var nodePos = hitNode.Position; Gizmos.color = Color.cyan; var hitDirVec = hitPoint - nodePos; Gizmos.DrawRay(nodePos, hitDirVec); Gizmos.DrawWireCube(nodePos, Vector2.one); var direc = Direction.FromVector(hitDirVec, 0.4f, 0.4f); finalNode = tileMap.GetNode(hitNode, direc); if (finalNode != null) { list.Add(finalNode.Position); } } break; } } list.Add(newPos); time += timeIncrementation; } Gizmos.color = Color; return(list); }
private void CreateWorld() { Texture2D tilesetTexture = Game.Content.Load <Texture2D>(@"Tilesets\tileset1"); Tileset tileset1 = new Tileset(tilesetTexture, 8, 8, 32, 32); tilesetTexture = Game.Content.Load <Texture2D>(@"Tilesets\tileset2"); Tileset tileset2 = new Tileset(tilesetTexture, 8, 8, 32, 32); List <Tileset> tilesets = new List <Tileset>(); tilesets.Add(tileset1); tilesets.Add(tileset2); MapLayer layer = new MapLayer(100, 100); for (int y = 0; y < layer.Height; y++) { for (int x = 0; x < layer.Width; x++) { Tile tile = new Tile(0, 0); layer.SetTile(x, y, tile); } } MapLayer splatter = new MapLayer(100, 100); Random random = new Random(); for (int i = 0; i < 100; i++) { int x = random.Next(0, 100); int y = random.Next(0, 100); int index = random.Next(2, 14); Tile tile = new Tile(index, 0); splatter.SetTile(x, y, tile); } splatter.SetTile(1, 0, new Tile(0, 1)); splatter.SetTile(2, 0, new Tile(2, 1)); splatter.SetTile(3, 0, new Tile(0, 1)); List <MapLayer> mapLayers = new List <MapLayer>(); mapLayers.Add(layer); mapLayers.Add(splatter); TileMap map = new TileMap(tilesets, mapLayers); Level level = new Level(map); ChestData chestData = Game.Content.Load <ChestData>(@"Game\Chests\Plain Chest"); Chest chest = new Chest(chestData); BaseSprite chestSprite = new BaseSprite( containers, new Rectangle(0, 0, 32, 32), new Point(10, 10)); ItemSprite itemSprite = new ItemSprite( chest, chestSprite); level.Chests.Add(itemSprite); World world = new World(GameRef, GameRef.ScreenRectangle); world.Levels.Add(level); world.CurrentLevel = 0; GamePlayScreen.World = world; }
public void changePrefab() { TileMap tilemap = GameObject.Find("Map").GetComponent <TileMap>(); tilemap.currentTileType = prefab; }
void openLevelToolStripMenuItem_Click(object sender, EventArgs e) { OpenFileDialog ofDialog = new OpenFileDialog { Filter = "Level Files (*.xml)|*.xml", CheckFileExists = true, CheckPathExists = true }; DialogResult result = ofDialog.ShowDialog(); if (result != DialogResult.OK) { return; } string path = Path.GetDirectoryName(ofDialog.FileName); LevelData newLevel; MapData mapData; try { newLevel = XnaSerializer.Deserialize <LevelData>(ofDialog.FileName); mapData = XnaSerializer.Deserialize <MapData>(path + @"\Maps\" + newLevel.MapName + ".xml"); } catch (Exception exc) { MessageBox.Show(exc.Message, "Error reading level"); return; } tileSetImages.Clear(); tileSetData.Clear(); tileSets.Clear(); layers.Clear(); lbTileset.Items.Clear(); clbLayers.Items.Clear(); levelData = newLevel; foreach (TilesetData data in mapData.Tilesets) { Texture2D texture = null; tileSetData.Add(data); lbTileset.Items.Add(data.TilesetName); GDIImage image = (GDIImage)GDIBitmap.FromFile(data.TilesetImageName); tileSetImages.Add(image); using (Stream stream = new FileStream(data.TilesetImageName, FileMode.Open, FileAccess.Read)) { texture = Texture2D.FromStream(GraphicsDevice, stream); tileSets.Add( new Tileset( texture, data.TilesWide, data.TilesHigh, data.TileWidthInPixels, data.TileHeightInPixels)); } } foreach (MapLayerData data in mapData.Layers) { clbLayers.Items.Add(data.MapLayerName, true); layers.Add(MapLayer.FromMapLayerData(data)); } lbTileset.SelectedIndex = 0; clbLayers.SelectedIndex = 0; nudCurrentTile.Value = 0; map = new TileMap(tileSets, layers); tilesetToolStripMenuItem.Enabled = true; mapLayerToolStripMenuItem.Enabled = true; charactersToolStripMenuItem.Enabled = true; chestsToolStripMenuItem.Enabled = true; keysToolStripMenuItem.Enabled = true; }
protected void CreateDeathDebris(ActorBase collider) { TileMap tilemap = api.TileMap; if (tilemap == null) { return; } Vector3 pos = Transform.Pos; if (collider is AmmoToaster) { const int debrisSizeX = 5; const int debrisSizeY = 3; GraphicResource res = currentTransitionState != AnimState.Idle ? currentTransition : currentAnimation; Material material = res.Material.Res; Texture texture = material.MainTexture.Res; float x = pos.X - res.Base.Hotspot.X; float y = pos.Y - res.Base.Hotspot.Y; int currentFrame = renderer.CurrentFrame; for (int fx = 0; fx < res.Base.FrameDimensions.X; fx += debrisSizeX + 1) { for (int fy = 0; fy < res.Base.FrameDimensions.Y; fy += debrisSizeY + 1) { float currentSizeX = debrisSizeX * MathF.Rnd.NextFloat(0.8f, 1.1f); float currentSizeY = debrisSizeY * MathF.Rnd.NextFloat(0.8f, 1.1f); api.TileMap.CreateDebris(new DestructibleDebris { Pos = new Vector3(x + (IsFacingLeft ? res.Base.FrameDimensions.X - fx : fx), y + fy, pos.Z), Size = new Vector2(currentSizeX, currentSizeY), Speed = new Vector2(((fx - res.Base.FrameDimensions.X / 2) + MathF.Rnd.NextFloat(-2f, 2f)) * (IsFacingLeft ? -1f : 1f) * MathF.Rnd.NextFloat(0.5f, 2f) / res.Base.FrameDimensions.X, MathF.Rnd.NextFloat(0f, 0.2f)), Acceleration = new Vector2(0f, 0.06f), Scale = 1f, Alpha = 1f, AlphaSpeed = -0.002f, Time = 320f, Material = material, MaterialOffset = new Rect( (((float)(currentFrame % res.Base.FrameConfiguration.X) / res.Base.FrameConfiguration.X) + ((float)fx / texture.ContentWidth)) * texture.UVRatio.X, (((float)(currentFrame / res.Base.FrameConfiguration.X) / res.Base.FrameConfiguration.Y) + ((float)fy / texture.ContentHeight)) * texture.UVRatio.Y, (currentSizeX * texture.UVRatio.X / texture.ContentWidth), (currentSizeY * texture.UVRatio.Y / texture.ContentHeight) ), CollisionAction = DebrisCollisionAction.Bounce }); } } } else if (pos.Y > api.WaterLevel) { const int debrisSize = 3; GraphicResource res = currentTransitionState != AnimState.Idle ? currentTransition : currentAnimation; Material material = res.Material.Res; Texture texture = material.MainTexture.Res; float x = pos.X - res.Base.Hotspot.X; float y = pos.Y - res.Base.Hotspot.Y; for (int fx = 0; fx < res.Base.FrameDimensions.X; fx += debrisSize + 1) { for (int fy = 0; fy < res.Base.FrameDimensions.Y; fy += debrisSize + 1) { float currentSize = debrisSize * MathF.Rnd.NextFloat(0.2f, 1.1f); api.TileMap.CreateDebris(new DestructibleDebris { Pos = new Vector3(x + (IsFacingLeft ? res.Base.FrameDimensions.X - fx : fx), y + fy, pos.Z), Size = new Vector2(currentSize /** (isFacingLeft ? -1f : 1f)*/, currentSize), Speed = new Vector2(((fx - res.Base.FrameDimensions.X / 2) + MathF.Rnd.NextFloat(-2f, 2f)) * (IsFacingLeft ? -1f : 1f) * MathF.Rnd.NextFloat(1f, 3f) / res.Base.FrameDimensions.X, ((fy - res.Base.FrameDimensions.Y / 2) + MathF.Rnd.NextFloat(-2f, 2f)) * (IsFacingLeft ? -1f : 1f) * MathF.Rnd.NextFloat(1f, 3f) / res.Base.FrameDimensions.Y), Acceleration = new Vector2(0f, 0f), Scale = 1f, Alpha = 1f, AlphaSpeed = -0.004f, Time = 340f, Material = material, MaterialOffset = new Rect( (((float)(renderer.CurrentFrame % res.Base.FrameConfiguration.X) / res.Base.FrameConfiguration.X) + ((float)fx / texture.ContentWidth)) * texture.UVRatio.X, (((float)(renderer.CurrentFrame / res.Base.FrameConfiguration.X) / res.Base.FrameConfiguration.Y) + ((float)fy / texture.ContentHeight)) * texture.UVRatio.Y, (currentSize * texture.UVRatio.X / texture.ContentWidth), (currentSize * texture.UVRatio.Y / texture.ContentHeight) ), CollisionAction = DebrisCollisionAction.Disappear }); } } } else { Vector2 force; switch (lastHitDir) { case LastHitDirection.Left: force = new Vector2(-1.4f, 0f); break; case LastHitDirection.Right: force = new Vector2(1.4f, 0f); break; case LastHitDirection.Up: force = new Vector2(0f, -1.4f); break; case LastHitDirection.Down: force = new Vector2(0f, 1.4f); break; default: force = Vector2.Zero; break; } tilemap.CreateParticleDebris(currentTransitionState != AnimState.Idle ? currentTransition : currentAnimation, Transform.Pos, force, renderer.CurrentFrame, IsFacingLeft); } }