// constructeur public Afficheur() { localplayer = new Player(); enemy = new Enemy(); affichemenu = new MainMenu(); scrolling = new Scroll(); }
/// <summary> /// 指定された名前のJsonファイルを読みに行って、その中身をステージ上に出す /// </summary> /// <param name="filename"></param> public static void Load(string filename) { TextAsset asset = Resources.Load("StageJson/" + filename) as TextAsset; if(asset == null) { Debug.Log("ステージ読み込めなかった(ステージ名:" + filename + ")"); return; } JsonNode json = JsonNode.Parse(asset.text); Transform parent; parent = GameObject.Find("/Terrains").transform; foreach(var item in json["Terrains"]) { GameObject g = new Terrain(item).Load(); if (g != null) g.transform.SetParent(parent); } parent = GameObject.Find("/Enemies").transform; foreach(var item in json["Enemies"]) { GameObject g = new Enemy(item).Load(); if (g != null) g.transform.SetParent(parent); } parent = GameObject.Find("/Gimmicks").transform; foreach (var item in json["Gimmicks"]) { GameObject g = new Gimmick(item).Load(); if (g != null) g.transform.SetParent(parent); } parent = GameObject.Find("/Items").transform; foreach (var item in json["Items"]) { GameObject g = new Item(item).Load(); if (g != null) g.transform.SetParent(parent); } }
/// <summary> /// 現在シーン上に配置されているオブジェクトをいくつかのタグごとで別のJson用オブジェクトにして、Jsonファイルに書き込む /// </summary> /// <param name="filename">保存するステージの名前</param> /// <param name="limit">ステージの制限時間</param> /// <param name="slotcount">アイテムスロットの個数</param> /// <param name="region">ステージの(行動可能)範囲</param> public static void Save(string filename) { Stage stage = new Stage(); foreach(var g in GameObject.FindGameObjectsWithTag("Terrain")) { if (g.transform.parent.name != "Terrains") continue; Terrain terrain = new Terrain(g); stage.Terrains.Add(terrain); } foreach(var g in GameObject.FindGameObjectsWithTag("Enemy")) { if (g.transform.parent.name != "Enemies") continue; Enemy enemy = new Enemy(g); stage.Enemies.Add(enemy); } foreach(var g in GameObject.FindGameObjectsWithTag("Gimmick")) { if (g.transform.parent.name != "Gimmicks") continue; Gimmick gimmick = new Gimmick(g); stage.Gimmicks.Add(gimmick); } foreach(var g in GameObject.FindGameObjectsWithTag("Item")) { if (g.transform.parent.name != "Items") continue; Item item = new Item(g); stage.Items.Add(item); } string jsontext = JsonMapper.ToJson(stage); StreamWriter writer = new StreamWriter(Application.dataPath + "/Resources/StageJson/" + filename + ".json"); writer.Write(jsontext); writer.Close(); Debug.Log("ステージ作った(ステージ名:" + filename + ")"); }
public void startEnemies() { enemies = new List<Enemy>(); // adds the AI objects for (int i = 0; i < NUM_OF_AI; i++) { Enemy enemy = new Enemy(random.Next(4), random); entities.Add(enemy); } enemies = entities.Where(i => i.GetType() == typeof(Enemy)).ToList().Cast<Enemy>().ToList(); }
private void InitialiseTopdown() { GameState = GameState.PLAYINGTOPDOWN; //We don't use gravity in this world as its topdown World.Gravity = new Vector2(0); //Set space friction, so this is how much an object will decelarate by, by default. Prevents permanent sliding World.SpaceFriction = 0.95f; Sprites = new List <Sprite>(); //Set up the scene controller with drop rate of powerups and new enemies SceneController.Game = this; SceneController.DropRate = 200; SceneController.EnemyRate = 200; //Configs for bullets and powerups //Change these numbers to customise the effects of them BulletConfig rpg = new BulletConfig(BulletTypes.Rocket, 25, Rocket, new Rectangle(0, 0, 20, 20), 500, 0, new TimeSpan(0, 0, 0, 1)); BulletConfig smg = new BulletConfig(BulletTypes.Bullet, 40, Bullet, new Rectangle(0, 0, 20, 20), 50, 0, new TimeSpan(0, 0, 0, 0, 50)); BulletConfig pistol = new BulletConfig(BulletTypes.Bullet, 40, Bullet, new Rectangle(0, 0, 20, 20), 60, 0, new TimeSpan(0, 0, 0, 0, 200)); PowerupConfig rpgP = new PowerupConfig(PowerupType.RPG, RPG, new Rectangle(8, 8, 32, 32), 20, 1, new TimeSpan(0, 0, 0, 6), 0); PowerupConfig smgP = new PowerupConfig(PowerupType.SMG, SMG, new Rectangle(8, 8, 32, 32), 500, 1, new TimeSpan(0, 0, 0, 5), 0); PowerupConfig ammoP = new PowerupConfig(PowerupType.Ammo, Pistol, new Rectangle(8, 8, 32, 32), 100, 1, new TimeSpan(0, 0, 0, 8), 0); PowerupConfig speedP = new PowerupConfig(PowerupType.Speed, Speed, new Rectangle(8, 8, 32, 32), 0, 0.2f, new TimeSpan(0, 0, 0, 6), 0); PowerupConfig healthP = new PowerupConfig(PowerupType.Health, Health, new Rectangle(8, 8, 32, 32), 0, 1, new TimeSpan(0, 0, 0, 5), 50); BulletConfigs = new Dictionary <WeaponTypes, BulletConfig> { { WeaponTypes.RPG, rpg }, { WeaponTypes.SMG, smg }, { WeaponTypes.Pistol, pistol } }; PowerupConfigs = new Dictionary <PowerupType, PowerupConfig> { { PowerupType.RPG, rpgP }, { PowerupType.SMG, smgP }, { PowerupType.Ammo, ammoP }, { PowerupType.Speed, speedP }, { PowerupType.Health, healthP } }; TopdownHero = new TopdownHero(this, new Vector2(32, 415), new Vector2(32, 32), new Vector2(0.2f, 0.2f), 1) { Texture = Player, TextureRect = Player.Bounds, Visible = true }; Sprites.Add(TopdownHero); //Add some starter enemies Enemy e = new Enemy(this, Zombie, Zombie.Bounds, new Vector2(400, 780), new Vector2(30), new Vector2(0.1f), 1), e2 = new Enemy(this, Zombie, Zombie.Bounds, new Vector2(500, 780), new Vector2(30), new Vector2(0.1f), 1), e3 = new Enemy(this, Zombie, Zombie.Bounds, new Vector2(800, 780), new Vector2(30), new Vector2(0.1f), 1); Sprites.AddRange(new List <Enemy>() { e, e2, e3 }); //Add moving box obstacles Box b = new Box(this, BoxTex, new Vector2(30), 16, new Vector2(0.2f), 0.2f); Box b2 = new Box(this, BoxTex, new Vector2(550, 600), 16, new Vector2(0.2f), 0.2f); Box b3 = new Box(this, BoxTex, new Vector2(770, 80), 16, new Vector2(0.2f), 0.2f); Sprites.AddRange(new List <Box>() { b, b2, b3 }); AStar.TileSize = 40; }