/// <summary> /// create an approximation of vision, produce an arry of points about the ship looking in 8 cardinal directions /// and record an inverse weighted factor for distance to an asteroid. /// Add a parameter to the end of the array that indicates if there is a clear shot /// </summary> internal static float[] Create(AsteroidsGame game) { var lvl = game.Level; var ship = lvl.Ship; var rotation = ship.GetRadians(); var vision = new float[9]; for (int i = 0; i < 8; i++) { var addedRotation = i * (Math.PI / 4); var radians = rotation + addedRotation; var direction = new Vector2((float)Math.Cos(radians), (float)Math.Sin(radians)); direction.Normalize(); vision[i] = LookInDirection(game, direction); } // input 9 is true if facing asteroid and can shoot if (lvl.CanShoot() && vision[0] > 0) { vision[8] = 1; } else { vision[8] = 0; } return(vision); }
private void OnGameLoopStarting(ICanvasAnimatedControl sender, object args) { _game = new AsteroidsGame(this, _gameController); GameManager.CreateTheGame(_game); _game.Run(); }
private void Form1_Load(object sender, EventArgs e) { _game = new AsteroidsGame(this, _gameController); GameManager.CreateTheGame(_game); _game.Run(); }
private void OnPlayerNumberingChanged() { foreach (Photon.Realtime.Player p in PhotonNetwork.PlayerList) { if (p.ActorNumber == ownerId) { PlayerColorImage.color = AsteroidsGame.GetColor(p.GetPlayerNumber()); } } }
private void App_Startup(object sender, StartupEventArgs e) { view = new MainWindow(); model = new AsteroidsGame(new GameRules(view.Width, view.Height), FPS); viewModel = new AsteroidsViewModel(model); viewModel.Exit += ViewModel_Exit; view.DataContext = viewModel; view.Show(); }
public void Awake() { photonView = GetComponent <PhotonView>(); rigidbody = GetComponent <Rigidbody>(); if (photonView.IsMine) { camFollow = Camera.main.GetComponent <FollowTarget>(); camFollow.target = transform; } Username.text = photonView.Owner.NickName; Username.color = AsteroidsGame.GetColor(photonView.Owner.GetPlayerNumber()); }
public void Awake() { playerListEntries = new Dictionary <int, GameObject>(); foreach (Photon.Realtime.Player p in PhotonNetwork.PlayerList) { GameObject entry = Instantiate(PlayerOverviewEntryPrefab); entry.transform.SetParent(gameObject.transform); entry.transform.localScale = Vector3.one; entry.GetComponent <Text>().color = AsteroidsGame.GetColor(p.GetPlayerNumber()); entry.GetComponent <Text>().text = string.Format("{0}\nScore: {1}\n", p.NickName, p.GetScore()); playerListEntries.Add(p.ActorNumber, entry); } }
private void FindWinner() { string winner = ""; int score = -1; Color color = Color.black; foreach (Photon.Realtime.Player p in PhotonNetwork.PlayerList) { if (p.GetScore() > score) { winner = p.NickName; score = p.GetScore(); color = AsteroidsGame.GetColor(p.GetPlayerNumber()); } } StartCoroutine(EndOfGame(winner, score, color)); StorePersonalBest(); }
private static float LookInDirection(AsteroidsGame game, Vector2 direction) { const int height = 7500; const int width = 10000; var lvl = game.Level; var pos = lvl.Ship.GetCurrentLocation(); //look in the direction for a number of steps for (int distance = 50; distance <= 2000; distance += 50) { //look further in the direction var position = new Point(pos.X + (int)(direction.X * distance), pos.Y + (int)(direction.Y * distance)); //wrap the sight lines around the game board if (position.Y < 0) { position.Y += height; } else if (position.Y > height) { position.Y -= height; } if (position.X < 0) { position.X += width; } else if (position.X > width) { position.X -= width; } foreach (var a in lvl.AsteroidBelt) { if (a.CheckPointInside(position)) { return(1f / (distance * (1 / 50f))); } } } return(0); }
public AsteroidsViewModel(AsteroidsGame model) { this.model = model; model.OnGameStateChange += Model_OnGameStateChange; model.OnFrameUpdate += Model_OnFrameUpdate; EnterCommand = new DelegateCommand(param => { if (GameOverVisibility) { GameOverVisibility = PauseVisibility = GameVisibility = false; MenuVisibility = true; } else { model.start(); } }); MenuVisibility = true; GameVisibility = false; GameOverVisibility = false; PauseVisibility = false; PauseCommand = new DelegateCommand(param => { if (model.GameState == AsteroidsGame.EGameState.Paused) { model.resume(); } else { model.pause(); } }); EscCommand = new DelegateCommand(param => OnExit()); UpCommand = new DelegateCommand(param => model.upPressed()); LeftCommand = new DelegateCommand(param => model.leftPressed()); DownCommand = new DelegateCommand(param => model.downPressed()); RightCommand = new DelegateCommand(param => model.rightPressed()); UpReleasedCommand = new DelegateCommand(param => model.upReleased()); LeftReleasedCommand = new DelegateCommand(param => model.leftReleased()); DownReleasedCommand = new DelegateCommand(param => model.downReleased()); RightReleasedCommand = new DelegateCommand(param => model.rightReleased()); Asteroids = new ObservableCollection <Asteroid>(); }
/// <summary> /// convert the output of the neural network to actions /// </summary> internal void Respond(AsteroidsGame game, float[] stimulus) { //get the output of the neural network var output = _brain.Output(stimulus); // map first output to thrust var lvl = game.Level; if (output[0] > 0.8) { lvl.Thrust(true); _thrust = true; } else { lvl.Thrust(false); } if (output[1] > 0.8) { //output 1 is turn left lvl.Left(); _moved = true; } if (output[2] > 0.8) { //output 2 is turn right lvl.Right(); _moved = true; } //shooting if (output[3] > 0.8) { //output 3 is shooting lvl.Shoot(); } }
/// <summary> /// constructor /// </summary> /// <param name="asteroidsGame"></param> /// <param name="size"></param> internal Population(AsteroidsGame asteroidsGame, int size) { _asteroidsGame = asteroidsGame; _players = new Player[size]; _players[0] = new Player(); }
/// <summary> /// Entry point of the program. /// </summary> /// <param name="args">Console arguments.</param> public static void Main(string[] args) { using var game = new AsteroidsGame(); game.Run(); }
static void Main() { using (var game = new AsteroidsGame()) game.Run(); }