void MainWindow_Loaded(object sender, RoutedEventArgs e) { // create the IO object that we represent tempestSoundIO = new TDNWin32TempestSoundIO(); // create our tempest, connected to the IO object tempest = new Asteroids(tempestSoundIO); // set it to running startTime = DateTime.Now; tempest.Start(); timer = new DispatcherTimer(); timer.Interval = TimeSpan.FromMilliseconds(200); timer.IsEnabled = true; timer.Tick += timer_Tick; vectorTimer = new DispatcherTimer(); vectorTimer.Interval = TimeSpan.FromMilliseconds(50); vectorTimer.IsEnabled = true; vectorTimer.Tick += vectorTimer_Tick; spinnerTimer = new DispatcherTimer(); spinnerTimer.Interval = TimeSpan.FromMilliseconds(10); spinnerTimer.IsEnabled = true; spinnerTimer.Tick += spinnerTimer_Tick; }
public void Should_DestroyAsteroid_When_OutOfBounds() { var asteroidGameObjects = new [] { new GameObject(), new GameObject(), new GameObject(), new GameObject(), new GameObject(), }; var asteroids = new Asteroids[5]; asteroidGameObjects[0].transform.position = Vector3.zero; asteroidGameObjects[1].transform.position = new Vector3(2, 0, 0); asteroidGameObjects[2].transform.position = new Vector3(-2, 0, 0); asteroidGameObjects[3].transform.position = new Vector3(0, 2, 0); asteroidGameObjects[4].transform.position = new Vector3(0, -2, 0); for (int i = 0; i < 5; ++i) { asteroids[i] = asteroidGameObjects[i].AddComponent <Asteroids>(); asteroids[i].CheckPosition(); } Assert.That(asteroidGameObjects[0] != null); Assert.That(asteroidGameObjects[1] == null); Assert.That(asteroidGameObjects[2] == null); Assert.That(asteroidGameObjects[3] == null); Assert.That(asteroidGameObjects[4] == null); }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { base.Initialize(); //контроллер _keyboardController = new KeyboardController(this); //игрок Player = new Player(_PlayerTexture); Player._laser = _PlayerLaser; Player.SetPosition(120, graphics.PreferredBackBufferHeight / 2); Player.SetScale(0.5f); _keyboardController.Attach(Player); //фон Background = new Background(_t); //астероиды _asteroid1 = new Asteroids(_asteroidTexture1, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight); _asteroid2 = new Asteroids(_asteroidTexture2, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight); _asteroid3 = new Asteroids(_asteroidTexture3, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight); _asteroid4 = new Asteroids(_asteroidTexture4, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight); _asteroid5 = new Asteroids(_asteroidTexture5, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight); //бонусы _bonusHeals = new Bonuses(_heart); _bonusHeals.SetPosition(500, 500); _bonusHeals.SetScale(0.6f); _bonusHeals.SetVelocity(new Vector2(-1, 0)); }
void UpdateTarget() { GameObject[] asteroids = GameObject.FindGameObjectsWithTag(asteroidTag); float shortestDistance = Mathf.Infinity; GameObject nearestAsteroid = null; foreach (GameObject asteroid in asteroids) { float distanceToAsteroid = Vector2.Distance(rb.position, asteroid.transform.position); if (distanceToAsteroid < shortestDistance) { shortestDistance = distanceToAsteroid; nearestAsteroid = asteroid; } } if (nearestAsteroid != null) { target = nearestAsteroid.transform; targetAsteroid = nearestAsteroid.GetComponent <Asteroids>(); } else { target = null; } }
public ScansMode(Program program, WicoControl wicoControl, WicoBlockMaster wicoBlockMaster, WicoIGC igc, Cameras cameras, Asteroids asteroids ) : base(program, wicoControl) { _program = program; _wicoControl = wicoControl; _wicoBlockMaster = wicoBlockMaster; _wicoIGC = igc; _cameras = cameras; _asteroids = asteroids; _program.moduleName += " Scans"; _program.moduleList += "\nScans V4.1"; // _program._CustomDataIni.Get(sNavSection, "NAVEmulateOld").ToBoolean(NAVEmulateOld); // _program._CustomDataIni.Set(sNavSection, "NAVEmulateOld", NAVEmulateOld); _program.AddUpdateHandler(UpdateHandler); _program.AddTriggerHandler(ProcessTrigger); _program.AddLoadHandler(LoadHandler); _program.AddSaveHandler(SaveHandler); _wicoControl.AddModeInitHandler(ModeInitHandler); _wicoControl.AddControlChangeHandler(ModeChangeHandler); _wicoBlockMaster.AddLocalBlockChangedHandler(LocalGridChangedHandler); _wicoIGC.AddPublicHandler(NavCommon.WICOB_NAVADDTARGET, BroadcastHandler); _wicoIGC.AddPublicHandler(NavCommon.WICOB_NAVRESET, BroadcastHandler); _wicoIGC.AddPublicHandler(NavCommon.WICOB_NAVSTART, BroadcastHandler); }
private void Awake() { _asteroids = FindObjectOfType <Asteroids>(); _originalScale = transform.localScale; _player = GameObject.FindGameObjectWithTag("Player"); _camera = FindObjectOfType <Camera>(); _rigidbody = GetComponent <Rigidbody>(); gameObject.SetActive(false); }
public void BreakAsteroid(Asteroids asteroid) { AsteroidsSpawner.Instance.SpawnAsteroid(asteroid.transform.position, asteroid.transform.up, new SmallAsteroid()); AsteroidsSpawner.Instance.SpawnAsteroid(asteroid.transform.position, -asteroid.transform.up, new SmallAsteroid()); AsteroidsSpawner.Instance.SpawnAsteroid(asteroid.transform.position, asteroid.transform.right, new SmallAsteroid()); AsteroidsSpawner.Instance.SpawnAsteroid(asteroid.transform.position, -asteroid.transform.right, new SmallAsteroid()); ReturnToPool(asteroid); }
private void Start() { _bullets = FindObjectOfType <Bullets>(); _audio = GetComponent <AudioSource>(); _nextUfoTime = Random.Range(_ufoRandomStart, _ufoRandomEnd); _menu = FindObjectOfType <Menu>(); _camera = FindObjectOfType <Camera>(); _living = FindObjectOfType <Living>(); _asteroids = FindObjectOfType <Asteroids>(); }
public string Job2() { var asteroids = Asteroids.Parse(ReadInputText("10")); var(_, location) = asteroids.BestLocation(); var shots = asteroids.Vaporize(location); var(x, y) = shots.ElementAt(199); return((x * 100 + y).ToString()); }
void FitAsteroid(Asteroids asteroid) { float asteroidLength = 0; int randomAsteroid; do { randomAsteroid = Random.Range(0, 4); asteroidLength += lenOfAsteroids[randomAsteroid]; asteroids.Add(randomAsteroid + 1); } while (asteroidLength < asteroid.Length); asteroids.RemoveAt(asteroids.Count - 1); if (asteroids.Count == 0) { return; } float[] posOfAsteroids = new float[asteroids.Count]; if (asteroid.LeftOrRight() > 0) { posOfAsteroids[0] = (asteroid.ScreenWidth * asteroid.LeftOrRight()) - (lenOfAsteroids[asteroids[0] - 1] / 2); } else { posOfAsteroids[0] = (asteroid.ScreenWidth * asteroid.LeftOrRight()) + (lenOfAsteroids[asteroids[0] - 1] / 2); } for (int i = 1; i < asteroids.Count; i++) { if (asteroid.LeftOrRight() > 0) { posOfAsteroids[i] = posOfAsteroids[i - 1] - (lenOfAsteroids[asteroids[i - 1] - 1] / 2) - (lenOfAsteroids[asteroids[i] - 1] / 2); } else { posOfAsteroids[i] = posOfAsteroids[i - 1] + (lenOfAsteroids[asteroids[i - 1] - 1] / 2) + (lenOfAsteroids[asteroids[i] - 1] / 2); } } Vector3 location; asteroids_go = new GameObject[asteroids.Count]; for (int i = 0; i < asteroids.Count; i++) { location = new Vector3(posOfAsteroids[i], transform.position.y, transform.position.z); asteroids_go[i] = Instantiate(prefabs[asteroids[i]], location, transform.rotation); } }
// Use this for initialization public void StartAsteroid(Transform pTarget) { asteroid = Asteroids.Get(types[Random.Range(0, 3)]); transform.localScale = asteroid.scale; _rb = GetComponent <Rigidbody2D>(); _rb.AddForce((pTarget.position - transform.position).normalized * asteroid.speed * Time.smoothDeltaTime); _rotate = new Vector3(0.0f, 0.0f, Random.Range(-1.0f, 1.0f)); Destroy(gameObject, 30.0f); // incase object misses killzone }
private void fillField() { int i = (int)(((Boundary.Width + Boundary.Height) / 2) / (20 * Density)); do { Vector2 asteroidPos = new Vector2(rand.Next(Boundary.X, Boundary.X + Boundary.Width), rand.Next(Boundary.Y, Boundary.Y + Boundary.Height)); float asteroidSpeed = rand.NextFloat(MinSpeed, MaxSpeed); float asteroidRotation = 0.025f; Asteroids.Add(new Asteroid(asteroidPos, asteroidSpeed, asteroidRotation)); }while (--i > 0); }
public override void Enter() { Asteroids game_ = Manager.VisualManager.Game as Asteroids; Texture2D image = game_.MessageBoxImage; vis = Manager.VisualManager.CreateVisualObjectArg( VisualTypes.MessageVisualType, game_.FontManager, image, displayString, new Vector2(280.0f, 300.0f)); }
// Screen Initialization void Awake() { if (Application.platform != RuntimePlatform.WindowsEditor) { Screen.fullScreen = true; screen_width = Screen.width; screen_height = Screen.height; screen_scale = 1; } instance = this; }
public void SetUp() { m_AsteroidGameObject = new GameObject(); m_AsteroidGameObject.transform.position = Vector3.zero; m_AsteroidGameObject.AddComponent <Rigidbody2D>(); m_Asteroids = m_AsteroidGameObject.AddComponent <Asteroids>(); m_Asteroids.boundLeft = m_Asteroids.boundRight = m_Asteroids.boundUp = m_Asteroids.boundDown = 1.0f; m_Random = new Random(); }
private void GenerateLevel() { var maxAsteroids = Level * 1.2f; Ship.Respawn(); for (int i = 0; i < maxAsteroids; i++) { var asteroid = new Asteroid(); asteroid.GenerateLargeAsteroid(LargeAsteroidTextures, Ship, Random); Asteroids.Add(asteroid); } }
/// <summary> /// Destroys an asteroid owned by this planet. /// </summary> public void DestroyAsteroid(Asteroid instance) { if (Asteroids.Contains(instance)) { instance.EventLaunched -= OnAsteroidLaunched; instance.EventReturned -= OnAsteroidReturned; instance.EventCollided -= OnAsteroidCollided; Asteroids.Remove(instance); asteroidQueue.Remove(instance); Destroy(instance.gameObject); } }
public void BestLocation_Works() { var asteroids = Asteroids.Parse(@" .#..# ..... ##### ....# ...## "); var(count, location) = asteroids.BestLocation(); Assert.Equal(8, count); Assert.Equal((3, 4), location); }
static void Main() { //directory commands //path class //environment class string FileName = Directory.GetCurrentDirectory().ToString() + "/Content/Song.mp3"; //@"J:\SP2014-2015\CS361A\wilsonl\Project4\Template\Content\Song.mp3"; mciSendString("open \"" + FileName + "\" type mpegvideo alias thisIsMyTag", null, 0, IntPtr.Zero); mciSendString("play thisIsMyTag from 0", null, 0, IntPtr.Zero); using (var program = new Asteroids()) program.Run(); }
private void Model_OnFrameUpdate(object sender, FrameEventArgs e) { Application.Current?.Dispatcher.Invoke(() => { Asteroids.Clear(); var sec = e.Seconds % 60; var min = e.Seconds / 60; ElapsedTime = min.ToString().PadLeft(2, '0') + ":" + sec.ToString().PadLeft(2, '0'); foreach (Asteroid asteroid in e.Asteroids) { Asteroids.Add(asteroid); } Player = e.Player; }); }
void ModuleProgramInit() { wicoThrusters = new WicoThrusters(this, wicoBlockMaster); wicoGyros = new WicoGyros(this, wicoBlockMaster); wicoGasTanks = new GasTanks(this, wicoBlockMaster); wicoGasGens = new GasGens(this); wicoConnectors = new Connectors(this); wicoCameras = new Cameras(this); wicoAntennas = new Antennas(this); wicoSensors = new Sensors(this, wicoBlockMaster); wicoPower = new PowerProduction(this, wicoBlockMaster); wicoTimers = new Timers(this, wicoBlockMaster); // navRemote = new NavRemote(this); navCommon = new NavCommon(this); _sensors = new Sensors(this, wicoBlockMaster); _drills = new Drills(this, wicoBlockMaster); _displays = new Displays(this, wicoBlockMaster, wicoElapsedTime); Echo("_displays"); _cargoCheck = new CargoCheck(this, wicoBlockMaster, _displays); Echo("_cargoCheck"); _dock = new DockBase(this); Echo("_dock"); // _scanBase = new ScanBase(this, _wicoControl); _asteroids = new Asteroids(this, _wicoControl, wicoIGC, _displays); _scanMode = new ScansMode(this, _wicoControl, wicoBlockMaster, wicoIGC, wicoCameras, _asteroids); _ores = new Ores(this, wicoBlockMaster, _wicoControl, wicoIGC, _asteroids, _displays); Echo("_ores"); _miner = new Miner(this, _wicoControl, wicoBlockMaster, wicoElapsedTime, wicoIGC , _scanMode, _asteroids, wicoThrusters, wicoConnectors, wicoSensors , wicoCameras, _drills, wicoAntennas, wicoGasTanks, wicoGyros, wicoPower , wicoTimers, navCommon, _ores, _dock , _displays ); Echo("_miner"); // spaceDock = new SpaceDock(this, _wicoControl, wicoBlockMaster, wicoThrusters, wicoConnectors, // wicoAntennas, wicoGasTanks, wicoGyros, wicoPower, wicoTimers, wicoIGC, wicoBases, navCommon, _cargoCheck); //wicoOrbitalLaunch = new OrbitalModes(this); // wicoNavigation = new Navigation(this, wicoBlockMaster.GetMainController()); /// DEBUG // wicoIGC.SetDebug(true); // _wicoControl.SetDebug(true); // wicoElapsedTime.SetDebug(true); }
// Start is called before the first frame update void Start() { float randNum = Random.Range(1f, 3f); size = new Vector3(randNum, randNum, 1f); transform.localScale = size; planetPosition = transform.position; touchPlayer = GetComponent <CircleCollider2D>(); field = Instantiate(prefabs[0], transform.position, transform.rotation); field.transform.localScale = new Vector3(transform.localScale.x * (1.35F / 0.5F), transform.localScale.y * (1.35F / 0.5F), transform.localScale.z * (1.35F / 0.5F)); Planet planet = gameObject.GetComponent <Planet>(); asteroid = new Asteroids(planet); FitAsteroid(asteroid); }
public Ores(Program program, WicoBlockMaster wbm, WicoControl wicoControl, WicoIGC wicoIGC, Asteroids asteroids, Displays displays) : base(program, wbm, null) { _program = program; _wicoBlockMaster = wbm; _wicoControl = wicoControl; _wicoIGC = wicoIGC; _asteroids = asteroids; _displays = displays; _program.AddLoadHandler(LoadHandler); _program.AddSaveHandler(SaveHandler); _wicoIGC.AddPublicHandler(sOreTag, BroadcastHandler); if (_displays != null) { _displays.AddSurfaceHandler("ORELOCS", SurfaceHandler); } }
public void Vaporize_Works() { var asteroids = Asteroids.Parse(@" .#..##.###...####### ##.############..##. .#.######.########.# .###.#######.####.#. #####.##.#.##.###.## ..#####..#.######### #################### #.####....###.#.#.## ##.################# #####.##.###..####.. ..######..##.####### ####.##.####...##..# .#####..#.######.### ##...#.##########... #.##########.####### .####.#.###.###.#.## ....##.##.###..##### .#.#.###########.### #.#.#.#####.####.### ###.##.####.##.#..## "); var(count, location) = asteroids.BestLocation(); Assert.Equal((11, 13), location); var shots = asteroids.Vaporize(location); Assert.Equal((11, 12), shots.ElementAt(0)); Assert.Equal((11, 12), shots.ElementAt(0)); Assert.Equal((12, 1), shots.ElementAt(1)); Assert.Equal((12, 2), shots.ElementAt(2)); Assert.Equal((12, 8), shots.ElementAt(9)); Assert.Equal((16, 0), shots.ElementAt(19)); Assert.Equal((16, 9), shots.ElementAt(49)); Assert.Equal((10, 16), shots.ElementAt(99)); Assert.Equal((9, 6), shots.ElementAt(198)); Assert.Equal((8, 2), shots.ElementAt(199)); Assert.Equal((10, 9), shots.ElementAt(200)); Assert.Equal((11, 1), shots.ElementAt(298)); Assert.Equal((11, 1), shots.Last()); }
private void SpawnAsteroids() { if (AsteroidCount <= 0) { return; } if (m_AsteroidTemplates.Count == 0) { Debug.LogError("No Asteroid Templates!"); return; } var prng = new System.Random(); for (int i = 0; i < AsteroidCount; i++) { Vector3 newPosition = Vector3.zero; bool badPosition = true; while (badPosition) { float magnitude = (Random.value * WorldRadius * 0.6f) + WorldRadius * 0.4f; newPosition = Random.onUnitSphere; newPosition *= magnitude; // Check that the new asteroid is far enough away from other asteroids badPosition = false; for (int j = 0; j < Asteroids.Count; j++) { if (Vector3.Distance(newPosition, Asteroids[j].transform.position) < 20.0f) { badPosition = true; break; } } } int templateIndex = prng.Next(0, AsteroidTemplates.Count - 1); var newAsteroid = Instantiate(AsteroidTemplates[templateIndex], newPosition, Quaternion.identity) as Asteroid; newAsteroid.transform.parent = transform; Asteroids.Add(newAsteroid); } }
/// <summary> /// Spawns an asteroid and sets up all required values and listeners /// </summary> public Asteroid SpawnAsteroid(Asteroid prefab) { var new_asteroid = Instantiate(prefab); // Setup lisenters for the asteroid's event new_asteroid.EventLaunched += OnAsteroidLaunched; new_asteroid.EventReturned += OnAsteroidReturned; new_asteroid.EventCollided += OnAsteroidCollided; Asteroids.Add(new_asteroid); //asteroidQueue.Enqueue(new_asteroid); asteroidQueue.AddLast(new_asteroid); if (EventAsteroidSpawned != null) { EventAsteroidSpawned.Invoke(new_asteroid); } return(new_asteroid); }
void Shoot() { if (Input.GetButtonDown("Fire1") && blasterCount > 0) { //Blaster Particle play blasterParticle.Play(); //Blaster Sound Play blasterSound.Play(); blasterCount--; RaycastHit hit; if (Physics.Raycast(shootOriginPosition, shootOrigin.right * range, out hit, range, collisionMask)) { Asteroids asteroids = hit.transform.GetComponent <Asteroids>(); if (asteroids != null) { Instantiate(hitParticle, hit.transform.position, Quaternion.identity); asteroids.TakeHit(blasterDamage); } } } }
public void OnAsteroidHit(Asteroids asteroid, Bullet bullet) { GameObject[] cols = GameObject.FindGameObjectsWithTag("Asteroid"); List <Asteroids> asteroidsAtRange = new List <Asteroids>(); for (int i = 0; i < cols.Length; i++) { if (Vector3.Distance(cols[i].transform.position, bullet.transform.position) < bullet.explotionForceRange) { asteroidsAtRange.Add(cols[i].GetComponent <Asteroids>()); } } for (int i = 0; i < asteroidsAtRange.Count; i++) { var dir = (asteroidsAtRange[i].transform.position - bullet.transform.position); asteroidsAtRange[i].gameObject.GetComponent <Rigidbody2D>().AddForce(dir, ForceMode2D.Impulse); asteroidsAtRange[i].Hit(bullet.damage); } bullet.ReturnToPool(); }
void Start() { //Calculating the radius of the collider! GameObject asteroid = Instantiate <GameObject>(asteroidPrefab); CircleCollider2D collider = asteroid.GetComponent <CircleCollider2D>(); float asteroidRadius = collider.radius; Destroy(asteroid); //calculating width and height of the screen! float screenWidth = ScreenUtils.ScreenRight - ScreenUtils.ScreenLeft; float screenHeight = ScreenUtils.ScreenTop - ScreenUtils.ScreenBottom; //Spawning asteroid from four sides! //Right side! asteroid = Instantiate <GameObject>(asteroidPrefab); Asteroids script = asteroid.GetComponent <Asteroids>(); script.Initialize(Direction.Left, new Vector2(ScreenUtils.ScreenRight + asteroidRadius, ScreenUtils.ScreenBottom + screenHeight / 2)); //Left Side! asteroid = Instantiate <GameObject>(asteroidPrefab); script = asteroid.GetComponent <Asteroids>(); script.Initialize(Direction.Right, new Vector2(ScreenUtils.ScreenLeft - asteroidRadius, ScreenUtils.ScreenBottom + screenHeight / 2)); //Top side! asteroid = Instantiate <GameObject>(asteroidPrefab); script = asteroid.GetComponent <Asteroids>(); script.Initialize(Direction.Down, new Vector2(ScreenUtils.ScreenLeft + screenWidth / 2, ScreenUtils.ScreenTop + asteroidRadius)); //Down Side! asteroid = Instantiate <GameObject>(asteroidPrefab); script = asteroid.GetComponent <Asteroids>(); script.Initialize(Direction.Up, new Vector2(ScreenUtils.ScreenLeft + screenWidth / 2, ScreenUtils.ScreenBottom - asteroidRadius)); }
/// <summary> /// Спавнит/респавнит астероиды и аптечки /// </summary> private void Repopulate() { if (ASTEROIDS_COUNTER <= 0) { Asteroids.Clear(); ASTEROIDS_COUNTER = ASTEROIDS_INITIAL_AMOUNT + 3; for (int i = 0; i <= ASTEROIDS_COUNTER; i++) { int r = rnd.Next(5, 50); Asteroids.Add(new Asteroid(new Point(Width + ASTEROIDS_X_SPAWNPOINT, rnd.Next(0, Height)), new Point(-r / 5, r), new Size(r, r))); } } if (_medKit == null) { Point p = new Point(40, rnd.Next(100, game.Height - 100)); _medKit = new MedKit(p, new Point(), new Size(10, 10)); GameLogger(console, "New medKit spawned at " + p); } }