public override void Use(S_Player player, S_Tile tile) { int dx = tile.x - player.currentTile.x; int dy = tile.y - player.currentTile.y; if ((dx == 0) == (dy == 0)) { UnsuccessfulUse(); return; } Use(player, Util.ProperSign(dx), Util.ProperSign(dy)); }
public override void Use(S_Player player, int dx, int dy) { if ((dx == 0) == (dy == 0)) { UnsuccessfulUse(); return; } int index = 0; foreach(S_Tile tile in player.currentTile.GetTilesInLine(dx, dy)) { S_Pickup pickup = tile.content; if (pickup != null) { index++; pickup.Magnetise(tile.TileDistance(player.currentTile)+index, (int)player.transform.position.x-S_Tile.width/2, (int)player.transform.position.y-S_Tile.height/2); } } if (index > 0) { SuccessfulUse(); Sounds.PlaySound(Sounds.suck); } else UnsuccessfulUse(); }
public abstract void Use(S_Player player, S_Tile tile);
public abstract void Use(S_Player player, int dx, int dy);
void InitTilesAndEntities() { //init tiles array int tilesAcross = levelData.width; int tilesDown = levelData.height - 1; tiles = new S_Tile[tilesAcross, tilesDown]; gridWidth = (int)(tilesAcross * (S_Tile.BASE_TILE_SIZE + 1) * S_Camera.scale + S_Camera.scale); gridHeight = (int)(tilesDown * (S_Tile.BASE_TILE_SIZE + 1) * S_Camera.scale + S_Camera.scale); //use colours in leveldata to setup entities for (int x = 0; x < tilesAcross; x++) { for (int y = 0; y < tilesDown; y++) { S_Tile tile; switch (FromColour(levelData.GetPixel(x, y))) { case LevelContent.wall: break; case LevelContent.blank: tile = MakeTile(x, y); break; case LevelContent.food: tile = MakeTile(x, y); tile.AddPickup(); pickupsRemaining++; totalPickups++; break; case LevelContent.player: tile = MakeTile(x, y); GameObject playerObject = (GameObject)(GameObject.Instantiate(Resources.Load("prefabs/player"))); player = playerObject.GetComponent <S_Player>(); player.Init(); entities.Add(player); player.MoveToTile(tile, true); break; case LevelContent.charger: tile = MakeTile(x, y); GameObject chargerObject = (GameObject)(GameObject.Instantiate(Resources.Load("prefabs/charger"))); S_Entity charger = chargerObject.GetComponent <S_Charger>(); charger.Init(); entities.Add(charger); charger.MoveToTile(tile, true); break; case LevelContent.enemy: tile = MakeTile(x, y); GameObject pincerObject = (GameObject)(GameObject.Instantiate(Resources.Load("prefabs/pincer"))); S_Entity enemy = pincerObject.GetComponent <S_Pincer>(); enemy.Init(); entities.Add(enemy); enemy.MoveToTile(tile, true); break; } } } //hierarchy object for entities GameObject entityParent = new GameObject("entities"); entityParent.transform.SetParent(mapObject.transform, false); foreach (S_Entity e in entities) { e.positionSetter.transform.SetParent(entityParent.transform, false); } //setup map border GameObject rect = Primitives.CreateRectangle(tilesAcross * S_Tile.width + S_Camera.scale, tilesDown * S_Tile.height + S_Camera.scale, Colours.RED); rect.transform.SetParent(mapObject.transform, false); rect.GetComponent <SpriteRenderer>().sortingLayerName = "Tiles"; rect.GetComponent <SpriteRenderer>().sortingOrder = 0; rect.name = "level_background"; //add level number (rethink into something symbolic maybe?) /*levelNumberObject = Primitives.CreateText(("level " + (Game.Get().levelNumber))); * S_Follower follow = levelNumberObject.AddComponent<S_Follower>(); * follow.Follow(slider.gameObject, 2 * S_Camera.scale, Screen.height - 28 * S_Camera.scale);*/ }