public Position get_asteroid_spawn_pos(Tile_Map tile_map) { List <Position> positions = new List <Position>(); for (int x = 0; x < 256; x++) { for (int y = 0; y < 256; y++) { if (tile_map.tiles[x + y * 256] == 14) { positions.Add(new Position { x = -2048.0f + x * 16.0f, y = -2048.0f + y * 16.0f }); } } } if (positions.Count == 0) { System.Console.WriteLine("could not find any spawn in get_asteroid_spawn_pos"); return(new Position { x = 0.0f, y = 0.0f }); } int i = rand.Next(0, positions.Count); return(positions[i]); }
private static bool has_tile2(Tile_Map tile_map, int x, int y) { if (x < 0 || x > 255 || y < 0 || y > 255) { return(false); } var k = tile_map.tiles[x + y * 256]; return(k > 0 && k < 7); // 7 and up are specials }
public Collision_Handler(Game_State state, Tile_Map tile_map, Spawn_Util spawner) { this.spawner = spawner; this.state = state; this.tile_map = tile_map; reg("ships/ship11", "ships/ship11", player_player); reg("ships/ship11", "ships/ship12", player_player); reg("ships/ship11", "ships/ship13", player_player); reg("ships/ship11", "ships/ship14", player_player); reg("ships/ship12", "ships/ship12", player_player); reg("ships/ship12", "ships/ship13", player_player); reg("ships/ship12", "ships/ship14", player_player); reg("ships/ship13", "ships/ship13", player_player); reg("ships/ship13", "ships/ship14", player_player); reg("ships/ship14", "ships/ship14", player_player); reg("ships/ship11", "powerup", player_powerup); reg("ships/ship12", "powerup", player_powerup); reg("ships/ship13", "powerup", player_powerup); reg("ships/ship14", "powerup", player_powerup); reg("asteroid", "asteroid", asteroid_asteroid); reg("asteroid", "asteroid2", asteroid_asteroid); reg("asteroid2", "asteroid2", asteroid_asteroid); reg("beams1", "asteroid", bullet1_asteroid); reg("beams1", "asteroid2", bullet1_asteroid); reg("beams1", "ships/ship11", bullet1_player); reg("beams1", "ships/ship12", bullet1_player); reg("beams1", "ships/ship13", bullet1_player); reg("beams1", "ships/ship14", bullet1_player); reg("beams1", "soccerball", bullet1_soccerball); reg("beams2", "asteroid", bullet2_asteroid); reg("beams2", "asteroid2", bullet2_asteroid); reg("beams2", "ships/ship11", bullet2_player); reg("beams2", "ships/ship12", bullet2_player); reg("beams2", "ships/ship13", bullet2_player); reg("beams2", "ships/ship14", bullet2_player); reg("beams2", "soccerball", bullet2_soccerball); reg("wbeam", "asteroid", bullet1_asteroid); reg("wbeam", "asteroid2", bullet1_asteroid); reg("wbeam", "ships/ship11", bullet1_player); reg("wbeam", "ships/ship12", bullet1_player); reg("wbeam", "ships/ship13", bullet1_player); reg("wbeam", "ships/ship14", bullet1_player); reg("wbeam", "soccerball", bullet1_soccerball); reg("soccerball", "ships/ship11", soccerball_player); reg("soccerball", "ships/ship12", soccerball_player); reg("soccerball", "ships/ship13", soccerball_player); reg("soccerball", "ships/ship14", soccerball_player); }
private static bool has_tile(Tile_Map tile_map, int x, int y) { int n = 2; for (int i = -n; i <= n; i++) { for (int j = -n; j <= n; j++) { if (has_tile2(tile_map, x + i, y + j)) { return(true); } } } return(false); }
//private int number_of_players; public Hudsystem(SpriteBatch sprite_batch, Tile_Map tile_map) { this.sprite_batch = sprite_batch; enball = new Sprite() { texture = Fab5_Game.inst().get_content <Texture2D>("EnergiAtlas"), //color = new Color(0.70f, 0.70f, 0.70f) }; minimap_tex = new Texture2D(Fab5_Game.inst().GraphicsDevice, 256, 256); for (int i = 0; i < 256; i++) { for (int j = 0; j < 256; j++) { var x = i >> 1; var y = j >> 1; minimap_tex.SetData(0, new Rectangle(x, y, 1, 1), new [] { new Color(0.0f, 0.0f, 0.0f, 0.0f) }, 0, 1); if ((x % 16) == 0 || (y % 16) == 0) { minimap_tex.SetData(0, new Rectangle(x, y, 1, 1), new [] { Color.White * 0.3f }, 0, 1); } } } for (int i = 0; i < 256; i++) { for (int j = 0; j < 256; j++) { var x = i >> 1; var y = j >> 1; var k = i + 256 * j; if (tile_map.tiles[k] != 0 && tile_map.tiles[k] < 7) { minimap_tex.SetData(0, new Rectangle(x, y, 1, 1), new [] { Color.White }, 0, 1); } } } white_pixel_tex = new Texture2D(Fab5_Game.inst().GraphicsDevice, 1, 1); white_pixel_tex.SetData(new [] { Color.White }); }
public Position get_player_spawn_pos(Entity player, Tile_Map tile_map) { List <Position> positions = new List <Position>(); // looking for team spawn tile var team = player.get_component <Ship_Info>().team + 11; for (int x = 0; x < 256; x++) { for (int y = 0; y < 256; y++) { if (conf.mode == Game_Config.GM_DEATHMATCH) { if (tile_map.tiles[x + y * 256] == 12) { // spawn on team 1 spawn (used for all players in all vs all) positions.Add(new Position { x = -2048.0f + x * 16.0f, y = -2048.0f + y * 16.0f }); } } else if (conf.mode == Game_Config.GM_TEAM_DEATHMATCH) { if (tile_map.tiles[x + y * 256] == team) { positions.Add(new Position { x = -2048.0f + x * 16.0f, y = -2048.0f + y * 16.0f }); } } } } if (positions.Count == 0) { System.Console.WriteLine("could not find any spawn in get_player_spawn_pos"); return(new Position { x = 0.0f, y = 0.0f }); } int i = rand.Next(0, positions.Count); return(positions[i]); }
protected override void _Resolver(Hashtable args) { base._Resolver(args); result_human_win.active = false; result_monster_win.active = false; game_end_text_ = this.GetComponentInChildren <GUIText>(); if (game_end_text_ == null) { Debug.LogError("<Scene_Game::_Resolver> invalid game_end_text_"); } game_end_text_.text = ""; // if (args.Contains("Scene_Game")) { // scene_game_ =(Scene_Game)args["Scene_Game"]; // } // GameDataShare.forest_sand_percentage = 0.2f; // GameDataShare.mountain_percentage = 0.1f; NavigationMap.GetInstance().Init("Scene_Game", this); // Entity target_entity = null; // GameActor human = GameActor.Create ( GameSettings.GetInstance().HUMAN_PREFAB_NAME ); // AddEntity ( human ); // NavigationMap.GetInstance().RegisterActor ( human ); // // GameActor monster = GameActor.Create ( "Entity_Monster" ); // AddEntity ( monster ); // monster.transform.localPosition = new Vector3 ( 64 * 5, 64 * 4 ); // NavigationMap.GetInstance().RegisterActor ( monster ); tile_map_ = new Tile_Map(); tile_map_.Init(); audio_background_.Play(); // monster_ = GameActor.Create ( "BaseEntity" ); // AddEntity ( monster_ ); // monster_.transform.localPosition = new Vector3 ( GameSettings.GetInstance().TILE_SIZE, 0, 0 ); }
public static bool is_open_path(int x0, int y0, int x1, int y1, Tile_Map tile_map) { bool steep = Math.Abs(y1 - y0) > Math.Abs(x1 - x0); if (steep) { swap <int>(ref x0, ref y0); swap <int>(ref x1, ref y1); } if (x0 > x1) { swap <int>(ref x0, ref x1); swap <int>(ref y0, ref y1); } int dX = (x1 - x0), dY = Math.Abs(y1 - y0), err = (dX / 2), ystep = (y0 < y1 ? 1 : -1), y = y0; for (int x = x0; x <= x1; ++x) { if (steep) { if (has_tile2(tile_map, y, x)) { return(false); } } else { if (has_tile2(tile_map, x, y)) { return(false); } } err = err - dY; if (err < 0) { y += ystep; err += dX; } } return(true); }
private static List <int> find_path(int x, int y, int tx, int ty, Tile_Map tile_map) { //if (open == null) { var open = new HashSet <int>(); open.Add(pos_to_node_index(x, y)); //} //if (closed == null) { var closed = new HashSet <int>(); // } var came_from = new Dictionary <int, int>(); var g_score = new Dictionary <int, int>(); var f_score = new Dictionary <int, int>(); g_score[pos_to_node_index(x, y)] = 0; f_score[pos_to_node_index(x, y)] = heuristic(x, y, tx, ty); int num_its = 0; int k = 3; while (open.Count > 0) { num_its++; /*if (num_its > 20000) { * // too slow or something * break; * }*/ var best_node = -1; var lowest_cost = 999999999; foreach (var node in open) { var cost = f_score.ContainsKey(node) ? f_score[node] : 999999999; if (cost < lowest_cost) { lowest_cost = cost; best_node = node; } } var current = best_node; var current_x = get_x(current); var current_y = get_y(current); if (Math.Abs(current_x - tx) <= k && Math.Abs(current_y - ty) <= k) { List <int> path = new List <int>(); while (came_from.ContainsKey(current)) { current = came_from[current]; path.Insert(0, current); } return(path); } open.Remove(current); closed.Add(current); // up var upx = get_x(current); var upy = get_y(current) - k; if (upy >= 0 && !has_tile(tile_map, upx, upy)) { var up = pos_to_node_index(upx, upy); if (!closed.Contains(up)) { var score = (g_score.ContainsKey(current) ? g_score[current] : 999999999) + dist(get_x(current), get_y(current), upx, upy); open.Add(up); if (score < (g_score.ContainsKey(up) ? g_score[up] : 999999999)) { came_from[up] = current; g_score[up] = score; f_score[up] = g_score[up] + heuristic(upx, upy, tx, ty); } } } // right var rightx = get_x(current) + k; var righty = get_y(current); if (righty <= 255 && !has_tile(tile_map, rightx, righty)) { var right = pos_to_node_index(rightx, righty); if (!closed.Contains(right)) { var score = (g_score.ContainsKey(current) ? g_score[current] : 999999999) + dist(get_x(current), get_y(current), rightx, righty); open.Add(right); if (score < (g_score.ContainsKey(right) ? g_score[right] : 999999999)) { came_from[right] = current; g_score[right] = score; f_score[right] = g_score[right] + heuristic(rightx, righty, tx, ty); } } } // down var downx = get_x(current); var downy = get_y(current) + k; if (downy <= 255 && !has_tile(tile_map, downx, downy)) { var down = pos_to_node_index(downx, downy); if (!closed.Contains(down)) { var score = (g_score.ContainsKey(current) ? g_score[current] : 999999999) + dist(get_x(current), get_y(current), downx, downy); open.Add(down); if (score < (g_score.ContainsKey(down) ? g_score[down] : 999999999)) { came_from[down] = current; g_score[down] = score; f_score[down] = g_score[down] + heuristic(downx, downy, tx, ty); } } } // left var leftx = get_x(current) - k; var lefty = get_y(current); if (lefty >= 0 && !has_tile(tile_map, leftx, lefty)) { var left = pos_to_node_index(leftx, lefty); if (!closed.Contains(left)) { var score = (g_score.ContainsKey(current) ? g_score[current] : 999999999) + dist(get_x(current), get_y(current), leftx, lefty); open.Add(left); if (score < (g_score.ContainsKey(left) ? g_score[left] : 999999999)) { came_from[left] = current; g_score[left] = score; f_score[left] = g_score[left] + heuristic(leftx, lefty, tx, ty); } } } } return(null); }
private static void calc_path(Data data, int x, int y, int tx, int ty, Tile_Map tile_map, float speed) { List <Component[]> waypoints = new List <Component[]>(); var path = find_path(x, y, tx, ty, tile_map); if (path != null) { int counter = (int)(-1 * speed * 0.25f); bool first = true; foreach (var node in path) { if (first && path.Count < 3) { first = false; var dx = ((float)rand.NextDouble() - 0.5f) * 12.0f; var dy = ((float)rand.NextDouble() - 0.5f) * 12.0f; waypoints.Add(create_waypoint(get_x(node) * 16.0f - 2048.0f + 8.0f + dx, get_y(node) * 16.0f - 2048.0f + 8.0f + dy)); } else if (counter++ == 2) { var dx = ((float)rand.NextDouble() - 0.5f) * 12.0f; var dy = ((float)rand.NextDouble() - 0.5f) * 12.0f; waypoints.Add(create_waypoint(get_x(node) * 16.0f - 2048.0f + 8.0f + dx, get_y(node) * 16.0f - 2048.0f + 8.0f + dy)); if (waypoints.Count > 10) { break; } counter = 0; } } var dxx = ((float)rand.NextDouble() - 0.5f) * 8.0f; var dyy = ((float)rand.NextDouble() - 0.5f) * 8.0f; waypoints.Add(create_waypoint(tx * 16.0f - 2048.0f + 8.0f + dxx, ty * 16.0f - 2048.0f + 8.0f + dyy)); } else { Console.WriteLine("could not solve path from {0}:{1} to {2}:{3}", x, y, tx, ty); } // optimize path while (waypoints.Count > -2) { bool all_checked = true; for (int i = 0; i < waypoints.Count - 1; i++) { var wp0 = (Position)waypoints[i][0]; var wp1 = (Position)waypoints[i + 1][0]; var v0 = new Vector2(wp1.x - wp0.x, wp1.y - wp0.y); v0.Normalize(); var sum_angle = 0.0f; int last_ok = -1; for (int j = (i + 1); j < waypoints.Count - 1; j++) { var wp2 = (Position)waypoints[j][0]; var wp3 = (Position)waypoints[j + 1][0]; var v1 = new Vector2(wp3.x - wp2.x, wp3.y - wp2.y); v1 = new Vector2(-v1.Y, v1.X); v1.Normalize(); var dot = Vector2.Dot(v0, v1); sum_angle += (float)Math.Abs(dot); if (sum_angle < (float)Math.Cos(65.0f * 3.141592f / 180.0f)) { last_ok = j; } else { break; } v0 = new Vector2(v1.Y, -v1.X); } if (last_ok != -1) { all_checked = false; int num = last_ok - (i + 1) + 1; for (int n = 0; n < num; n++) { waypoints.RemoveAt(i + 1); } break; } } if (all_checked) { break; } } data.data["path_recalc_time"] = Fab5_Game.inst().get_time(); data.data["path_calc"] = 2; data.data["waypoints2"] = waypoints; }
public Collision_Solver(Tile_Map tile_map) { this.tile_map = tile_map; }
protected override void _Resolver(Hashtable args) { base._Resolver (args); result_human_win.active = false; result_monster_win.active = false; game_end_text_ = this.GetComponentInChildren<GUIText>(); if ( game_end_text_ == null ) { Debug.LogError ( "<Scene_Game::_Resolver> invalid game_end_text_" ); } game_end_text_.text = ""; // if (args.Contains("Scene_Game")) { // scene_game_ =(Scene_Game)args["Scene_Game"]; // } // GameDataShare.forest_sand_percentage = 0.2f; // GameDataShare.mountain_percentage = 0.1f; NavigationMap.GetInstance().Init ( "Scene_Game", this ); // Entity target_entity = null; // GameActor human = GameActor.Create ( GameSettings.GetInstance().HUMAN_PREFAB_NAME ); // AddEntity ( human ); // NavigationMap.GetInstance().RegisterActor ( human ); // // GameActor monster = GameActor.Create ( "Entity_Monster" ); // AddEntity ( monster ); // monster.transform.localPosition = new Vector3 ( 64 * 5, 64 * 4 ); // NavigationMap.GetInstance().RegisterActor ( monster ); tile_map_ = new Tile_Map (); tile_map_.Init (); audio_background_.Play (); // monster_ = GameActor.Create ( "BaseEntity" ); // AddEntity ( monster_ ); // monster_.transform.localPosition = new Vector3 ( GameSettings.GetInstance().TILE_SIZE, 0, 0 ); }
public override void init() { Player_Ship.lol = 1; // @To-do: lol MediaPlayer.Volume = game_conf.music_vol; tile_map = new Tile_Map(); coll_handler = new Collision_Handler(this, tile_map, spawner); var map_name = System.IO.Path.GetFileNameWithoutExtension(game_conf.map_name); var s = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location), map_name + ".png"); using (var bitmap = new System.Drawing.Bitmap(s)) { load_map(bitmap, tile_map.tiles); } s = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location), map_name + "_bg.png"); using (var bitmap = new System.Drawing.Bitmap(s)) { load_map(bitmap, tile_map.bg_tiles); } add_subsystems( new /*Async_*/ Multi_Subsystem( new Multi_Subsystem( new Position_Integrator(), new Collision_Solver(tile_map) ), new /*Async_*/ Multi_Subsystem( new Inputhandler_System(), new Sound(), new Particle_System(), new Lifetime_Manager(), new Weapon_System(this), new AI() ), new Multi_Subsystem( renderer = new Rendering_System(Starburst.inst().GraphicsDevice) { tile_map = tile_map, match_time = game_conf.match_time } ) ) ); create_entity(new FpsCounter()); for (int i = 0; i < inputs.Count; i++) { if (inputs[i] == null) { continue; } var player = create_entity(Player_Ship.create_components(inputs[i], game_conf, i < 2 ? 1 : 2)); var player_spawn = spawner.get_player_spawn_pos(player, tile_map); player.get_component <Position>().x = player_spawn.x; player.get_component <Position>().y = player_spawn.y; player.get_component <Angle>().angle = (float)rand.NextDouble() * 6.28f; var player_pos = player.get_component <Position>(); var player_vel = player.get_component <Velocity>(); for (int j = 0; j < 20; j++) { Fab5_Game.inst().create_entity(new Component[] { new TTL { max_time = j * 0.05f, destroy_cb = () => { var theta1 = 2.0f * 3.1415f * (float)rand.NextDouble(); var theta2 = 2.0f * 3.1415f * (float)rand.NextDouble(); var radius = 13.0f * (float)rand.NextDouble(); var speed = (30.0f + 110.0f * (float)Math.Pow(rand.NextDouble(), 2.0f)); Fab5_Game.inst().create_entity(new Component[] { new Sprite { blend_mode = Sprite.BM_ADD, scale = 0.8f + (float)rand.NextDouble(), texture = Fab5_Game.inst().get_content <Texture2D>("particle") }, new Position { x = player_pos.x + (float)Math.Cos(theta1) * radius, y = player_pos.y + (float)Math.Sin(theta1) * radius }, new Velocity { x = 0.5f * player_vel.x + (float)Math.Cos(theta2) * speed, y = 0.5f * player_vel.y + (float)Math.Sin(theta2) * speed }, new Mass { drag_coeff = 2.0f }, new TTL { alpha_fn = (x, max) => 1.0f - (x * x) / (max * max), max_time = 1.5f + (float)rand.NextDouble() } }); } } }); } } create_entity(SoundManager.create_backmusic_component()); create_entity(SoundManager.create_soundeffects_component()); int keyboardplayers = 0; int n = 0; for (int i = 0; i < inputs.Count; i++) { if (inputs[i] == null) { continue; } if (inputs[i].device == InputType.Keyboard) { keyboardplayers++; n = i; } } if (keyboardplayers == 1) { inputs[n].gp_index = PlayerIndex.One; } for (int i = 0; i < game_conf.num_asteroids; i++) { var asteroid = create_entity(Asteroid.create_components()); var r = asteroid.get_component <Bounding_Circle>().radius; Position ap; int num_fails = 0; bool colliding = false; do { colliding = false; ap = asteroid.get_component <Position>(); var sp = spawner.get_asteroid_spawn_pos(tile_map); ap.x = sp.x; ap.y = sp.y; foreach (var ast in Starburst.inst().get_entities_fast(typeof(Bounding_Circle))) { if (ast == asteroid) { continue; } var dx = ast.get_component <Position>().x - asteroid.get_component <Position>().x; var dy = ast.get_component <Position>().y - asteroid.get_component <Position>().y; var dist = (dx * dx + dy * dy); var min_dist = ast.get_component <Bounding_Circle>().radius + asteroid.get_component <Bounding_Circle>().radius; min_dist *= 1.05f; min_dist *= min_dist; if (dist < min_dist) { colliding = true; num_fails++; break; } } if (num_fails > 1000) { // failed to spawn this one. asteroid.destroy(); break; } } while (colliding); var av = asteroid.get_component <Velocity>(); av.x = -15 + 30 * (float)rand.NextDouble(); av.y = -15 + 30 * (float)rand.NextDouble(); } if (game_conf.enable_soccer) { ball = create_entity(Soccer_Ball.create_components()); var ball_pos = spawner.get_soccerball_spawn_pos(tile_map); ball.get_component <Position>().x = ball_pos.x; ball.get_component <Position>().y = ball_pos.y; ball.get_component <Angle>().ang_vel = 3.141592f * 2.0f * -2.0f; } Dummy_Enemy.ai_index = 1; for (int i = 0; i < game_conf.red_bots; i++) { var ai = Starburst.inst().create_entity(Dummy_Enemy.create_components(game_conf, 1 /* red team */)); var aisi = ai.get_component <Ship_Info>(); if (game_conf.mode == Game_Config.GM_TEAM_DEATHMATCH) { aisi.team = 1; } Console.WriteLine("created ai for team {0}", aisi.team); ai.get_component <Bounding_Circle>().ignore_collisions2 = aisi.team; var ai_spawn = spawner.get_player_spawn_pos(ai, tile_map); ai.get_component <Position>().x = ai_spawn.x; ai.get_component <Position>().y = ai_spawn.y; ai.get_component <Angle>().angle = (float)rand.NextDouble() * 6.28f; var player_pos = ai.get_component <Position>(); var player_vel = ai.get_component <Velocity>(); for (int j = 0; j < 20; j++) { Fab5_Game.inst().create_entity(new Component[] { new TTL { max_time = j * 0.05f, destroy_cb = () => { var theta1 = 2.0f * 3.1415f * (float)rand.NextDouble(); var theta2 = 2.0f * 3.1415f * (float)rand.NextDouble(); var radius = 13.0f * (float)rand.NextDouble(); var speed = (30.0f + 110.0f * (float)Math.Pow(rand.NextDouble(), 2.0f)); Fab5_Game.inst().create_entity(new Component[] { new Sprite { blend_mode = Sprite.BM_ADD, scale = 0.8f + (float)rand.NextDouble(), texture = Fab5_Game.inst().get_content <Texture2D>("particle") }, new Position { x = player_pos.x + (float)Math.Cos(theta1) * radius, y = player_pos.y + (float)Math.Sin(theta1) * radius }, new Velocity { x = 0.5f * player_vel.x + (float)Math.Cos(theta2) * speed, y = 0.5f * player_vel.y + (float)Math.Sin(theta2) * speed }, new Mass { drag_coeff = 2.0f }, new TTL { alpha_fn = (x, max) => 1.0f - (x * x) / (max * max), max_time = 1.5f + (float)rand.NextDouble() } }); } } }); } } for (int i = 0; i < game_conf.blue_bots; i++) { var ai = Starburst.inst().create_entity(Dummy_Enemy.create_components(game_conf, 2 /* blue team */)); var aisi = ai.get_component <Ship_Info>(); if (game_conf.mode == Game_Config.GM_TEAM_DEATHMATCH) { aisi.team = 2; } Console.WriteLine("created ai for team {0}", aisi.team); ai.get_component <Bounding_Circle>().ignore_collisions2 = aisi.team; var ai_spawn = spawner.get_player_spawn_pos(ai, tile_map); ai.get_component <Position>().x = ai_spawn.x; ai.get_component <Position>().y = ai_spawn.y; ai.get_component <Angle>().angle = (float)rand.NextDouble() * 6.28f; for (int j = 0; j < 20; j++) { Fab5_Game.inst().create_entity(new Component[] { new TTL { max_time = j * 0.05f, destroy_cb = () => { var theta1 = 2.0f * 3.1415f * (float)rand.NextDouble(); var theta2 = 2.0f * 3.1415f * (float)rand.NextDouble(); var radius = 13.0f * (float)rand.NextDouble(); var speed = (30.0f + 110.0f * (float)Math.Pow(rand.NextDouble(), 2.0f)); Fab5_Game.inst().create_entity(new Component[] { new Sprite { blend_mode = Sprite.BM_ADD, scale = 0.8f + (float)rand.NextDouble(), texture = Fab5_Game.inst().get_content <Texture2D>("particle") }, new Position { x = ai_spawn.x + (float)Math.Cos(theta1) * radius, y = ai_spawn.y + (float)Math.Sin(theta1) * radius }, new Velocity { x = (float)Math.Cos(theta2) * speed, y = (float)Math.Sin(theta2) * speed }, new Mass { drag_coeff = 2.0f }, new TTL { alpha_fn = (x, max) => 1.0f - (x * x) / (max * max), max_time = 1.5f + (float)rand.NextDouble() } }); } } }); } } Starburst.inst().message("play_sound_asset", new { name = "begin_game" }); for (int i = 1; i <= 10; i++) { int j = i; create_entity(new Component[] { new TTL { max_time = game_conf.match_time - (float)(j), destroy_cb = () => { var creation_time = Fab5_Game.inst().get_time(); create_entity(new Component[] { new Post_Render_Hook { render_fn = (camera, sprite_batch) => { var ts = GFX_Util.measure_string_extraLarge(string.Format("{0}", j)); var x = camera.viewport.Width * 0.5f; var y = camera.viewport.Height - ts.Y - 200.0f; var t = Fab5_Game.inst().get_time() - creation_time; var textOpacity = (float)Easing.QuadEaseIn(t, 0, 1, 1.0f); var temp = ((float)Easing.QuadEaseOut(t, 0, 0.5, 1.0f) * 1.6f); var textScale = 1 - temp * temp; GFX_Util.draw_def_text_extraLarge(sprite_batch, string.Format("{0}", j), x, y, origin: new Vector2(ts.X * 0.5f, ts.Y * 0.5f), scale: new Vector2(textScale, textScale), alpha: textOpacity, shadow: false); } }, new TTL { max_time = 1.0f } }); } } }); } create_entity(new Component[] { new TTL { max_time = game_conf.match_time - 30.0f, destroy_cb = () => { var creation_time = Fab5_Game.inst().get_time(); create_entity(new Component[] { new Post_Render_Hook { render_fn = (camera, sprite_batch) => { var ts = GFX_Util.measure_string_extraLarge("30 seconds left!"); var x = camera.viewport.Width * 0.5f; var y = camera.viewport.Height - ts.Y - 60.0f; var t = Fab5_Game.inst().get_time() - creation_time; var textOpacity = (float)Easing.QuadEaseIn(Math.Min(1, t), 0, 1, 1.0f); var temp = ((float)Easing.QuadEaseOut(Math.Min(1, t), 0, 0.5, 1.0f) * 1.6f); var textScale = 1 - temp * temp; GFX_Util.draw_def_text_extraLarge(sprite_batch, "30 seconds left!", x, y, origin: new Vector2(ts.X * 0.5f, ts.Y * 0.5f), scale: new Vector2(textScale, textScale), alpha: textOpacity, shadow: false); } }, new TTL { max_time = 3.0f } }); } } }); create_entity(new Component[] { new TTL { max_time = game_conf.match_time, destroy_cb = () => { Playing_State gameState = this; var scoreEntities = gameState.get_entities_fast(typeof(Score)); List <Entity> players = new List <Entity>(); for (int i = 0; i < scoreEntities.Count; i++) { if ((scoreEntities[i].get_component <Ship_Info>() != null) && (scoreEntities[i].get_component <Velocity>() != null)) { players.Add(scoreEntities[i]); } } Starburst.inst().message("play_sound_asset", new { name = "begin_game" }); Starburst.inst().leave_state(); Starburst.inst().leave_state(); Starburst.inst().enter_state(new Pre_Results_State(players, gameState.game_conf)); } } }); }