c#で
画面端にとどけば次の弾が撃てる
敵は横に移動して画面端で折り返す
この2つの処理をしたくて1日考えていたのですが
今まで敵の処理はrandomを採用してきたので
全くわかりません
良ければ知恵をお貸しください
class GamePlay : IScene { private bool isEnd;//終了フラグ private InputState input; private CharacterControl characterControl; private Random rand = new Random(); protected bool isDead = false; public void Update() { if (Enemy.Length == 1) { isEnd = true; } if(characterControl.IsPlayerDead()) { isEnd = true; } if (rand.Next(60) == 0) { var position = new Vector2((Screen.Width + 32.0f), (float)rand.Next(45 - 40, Screen.Height - 50)); characterControl.Add(new Enemy(position)); } if (characterControl.IsPlayerDead()) { Initialize(); } characterControl.Update(); } public GamePlay(InputState input) { this.input = input; } public void Draw(Renderer renderer) { characterControl.Draw(renderer); { } //renderer.End(); } public void Shutdown() { } public void Initialize() { //シーン終了フラグを初期化 this.isEnd = false; characterControl = new CharacterControl(); characterControl.Initialize(); characterControl.Add(new Player(input)); } public bool IsEnd() { return this.isEnd; } public Scene Next() { return Scene.GameOver; } class CharacterControl { private LinkedList<Character> characters; public CharacterControl() { } public void Initialize() { if (characters != null) { characters.Clear(); } characters = new LinkedList<Character>(); } public bool Add(Character character) { characters.AddLast(character); return true; } public void Update() { foreach (Character c in characters) { c.Update(); } New(); Hit(); Remove(); } private void New() { var newCharacters = new List<Character>(); foreach (Character c in characters) { Character newCharacter = c.New(); if (newCharacter != null) { newCharacters.Add(newCharacter); } } foreach (Character c in newCharacters) { characters.AddLast(c); } } private void Hit() { foreach (Character c1 in characters) { foreach (Character c2 in characters) if (c1.Collision(c2)) { c1.Hit(c2); c2.Hit(c1); } } } private void Remove() { LinkedListNode<Character> node = characters.First; while (node != null) { LinkedListNode<Character> next = node.Next; if (node.Value.IsDead()) { characters.Remove(node); } node = next; } } public bool IsPlayerDead() { foreach (Character c in characters) { if (c is Player) { return false; } } return true; } public void Draw(Renderer renderer) { foreach (Character c in characters) { //renderer.Begin(); c.Draw(renderer); //renderer.Begin(); } } } class Enemy : Character { public Enemy(Vector2 position) : base("敵", new Vector2(350f, 50.0f), 32.0f) { } public override void Update() { position = position + new Vector2(-9.0f, 0.0f); if (position.X < (-9.0f - 55.0f)) { isDead = true; } } public override void Hit(Character character) { if (character is Bullet || character is Player) { isDead = true; } } public override Character New() { return null; } } abstract class Character { protected string name; protected Vector2 position; protected float radius; protected bool isDead = false; public abstract void Update(); public abstract void Hit(Character character); public abstract Character New(); public Character(string name, Vector2 position, float radius) { this.name = name; this.position = position; this.radius = radius; } public void Draw(Renderer renderer) { //renderer.Begin(); renderer.DrawTexture(name, position - new Vector2(radius, radius)); //renderer.End(); } public bool IsDead() { return isDead; } public bool Collision(Character character) { if (Vector2.Distance(this.position, character.position) <= (this.radius + character.radius)) { return true; } return false; } } } コード