//---------------------------------------------------------------- // Constructor //---------------------------------------------------------------- // // Creates a new AlienController with the given parameters public AlienController( GameWorld world, Alien alien, AIType type, Ninja target, float patrol_speed = ALIEN_PATROL_SPEED, float max_range = TUTORIAL_MAX_RANGE, float attack_dist = TUTORIAL_ATTACK_RANGE, float chase_dist = TUTORIAL_MAX_CHASE ) : base(ControllerType.AlienController) { m_world = world; m_self = alien; m_type = type; m_self.m_ai_type = m_type; if ( patrol_speed == 0 ) { m_self.m_move_step = ALIEN_PATROL_SPEED; } if ( max_range == 0 ) { m_self.m_range = TUTORIAL_MAX_RANGE; } if ( attack_dist == 0 ) { m_self.m_attack_dist = TUTORIAL_ATTACK_RANGE; } if ( chase_dist == 0 ) { m_self.m_chase_dist = TUTORIAL_MAX_CHASE; } m_start_rotation = alien.m_rotation; if ( alien is TwinNova ) { /*m_ai_move_step = m_self.m_move_step *= 0.75f; m_ai_range = m_self.m_range *= 1.5f; m_ai_attack_dist= m_self.m_attack_dist *= 0.75f; m_ai_chase_dist = m_self.m_chase_dist *= 1.5f; */ m_type = AIType.BOSS; } m_ai_move_step = m_self.m_move_step; m_ai_range = m_self.m_range; m_ai_attack_dist = m_self.m_attack_dist; m_ai_chase_dist = m_self.m_chase_dist; //keep in line with the multiplier from before m_ai_move_step *= 0.67f; m_target = target; m_state = State.SPAWNING; m_origin = m_self.m_buffered_position.Value; }
public TestWorld( Camera view, Editor editor ) : base(ground_texture.Width, ground_texture.Height, new Vector2( 0, GRAVITY )) { // play bgm GameEngine.LevelManager.background_select(); GameEngine.AudioManager.Play( AudioManager.MusicSelection.tut ); eye = view; //mouse_control = new MouseController( GameEngine.GAME_WIDTH, GameEngine.GAME_HEIGHT ); //create_world( this, "World_objects.xml" ); //editor.ninjaBindingSource.DataSource = m_ninja; m_world.ContactManager.BeginContact += m_collision_manager.contact_started; m_world.ContactManager.EndContact += m_collision_manager.contact_ended; Vector2[] new_wall; // Create ninja m_ninja = new Ninja( this, ninja_animate_texture, ninja_position, 1.0f ); // Add floor tiles // Must be created first, so that other objects can be on top of it /* foreach ( var tile in floor_tiles ) { // Convert dimensions in the other format if ( tile.Length < 4 ) { new_wall = new[] { tile[0], new Vector2(tile[0].X + tile[1].X, tile[0].Y), new Vector2(tile[0].X + tile[1].X, tile[0].Y + tile[1].Y), new Vector2(tile[0].X, tile[0].Y + tile[1].Y) }; } else new_wall = (Vector2[])tile.Clone(); FloorTile b = new FloorTile( this, new_wall, floor_texture, 1.0f, 0.0f, 0.7f ); // add_object( b ); } // Create Aliens m_alien_easy = new Alien( this, hard_alien_texture, new Vector2( 20, 11 ), 4.0f, Alien.AlienType.EASY, Alien.AlienCollisionType.NORMAL ); add_object( m_alien_easy ); m_alien_spiked = new Alien( this, spiked_alien_texture, new Vector2( 24, 2 ), 6.0f, Alien.AlienType.SPIKED, Alien.AlienCollisionType.SPIKED ); add_object( m_alien_spiked ); m_alien_plated = new Alien( this, plated_alien_texture, new Vector2( -15, 7 ), 8.0f, Alien.AlienType.PLATED, Alien.AlienCollisionType.PLATED ); add_object( m_alien_plated ); // Create Aliens alien1 = new Alien( this, easy_alien_texture, alien1_pos, .5f, Alien.AlienType.EASY ); add_object( alien1 ); alien2 = new Alien( this, easy_alien_texture, alien2_pos, .5f, Alien.AlienType.EASY ); add_object( alien2 ); AlienController alien_controller1 = new AlienController( this, alien1, AlienController.AIType.PEON, m_ninja ); m_world.AddController( alien_controller1 ); AlienController alien_controller2 = new AlienController( this, alien1, AlienController.AIType.PEON, m_ninja ); m_world.AddController( alien_controller2 ); alien7 = new Alien( this, easy_alien_texture, alien7_pos, .5f, Alien.AlienType.EASY ); add_object( alien7 ); AlienController alien_controller7 = new AlienController( this, alien7, AlienController.AIType.ATTACKER, m_ninja ); m_world.AddController( alien_controller7 ); alien8 = new Alien( this, easy_alien_texture, alien8_pos, .5f, Alien.AlienType.EASY, rotation: -1.57f ); add_object( alien8 ); AlienController alien_controller8 = new AlienController( this, alien8, AlienController.AIType.ATTACKER, m_ninja ); m_world.AddController( alien_controller8 ); alien9 = new Alien( this, easy_alien_texture, alien9_pos, .5f, Alien.AlienType.EASY, rotation: 2.33f ); add_object( alien9 ); AlienController alien_controller9 = new AlienController( this, alien9, AlienController.AIType.ATTACKER, m_ninja ); m_world.AddController( alien_controller9 ); alien10 = new Alien( this, easy_alien_texture, alien10_pos, .5f, Alien.AlienType.EASY ); add_object( alien10 ); AlienController alien_controller10 = new AlienController( this, alien10, AlienController.AIType.ATTACKER, m_ninja ); m_world.AddController( alien_controller10 ); alien11 = new Alien( this, easy_alien_texture, alien11_pos, .5f, Alien.AlienType.EASY ); add_object( alien11 ); AlienController alien_controller11 = new AlienController( this, alien11, AlienController.AIType.CHASER, m_ninja ); m_world.AddController( alien_controller11 ); alien12 = new Alien( this, easy_alien_texture, alien12_pos, .5f, Alien.AlienType.EASY ); add_object( alien12 ); AlienController alien_controller12 = new AlienController( this, alien12, AlienController.AIType.CHASER, m_ninja ); m_world.AddController( alien_controller12 ); alien13 = new Alien( this, easy_alien_texture, alien13_pos, .5f, Alien.AlienType.EASY ); add_object( alien13 ); AlienController alien_controller13 = new AlienController( this, alien13, AlienController.AIType.CHASER, m_ninja ); m_world.AddController( alien_controller13 ); alien14 = new Alien( this, spiked_alien_texture, alien14_pos, .5f, Alien.AlienType.EASY ); add_object( alien14 ); AlienController alien_controller14 = new AlienController( this, alien14, AlienController.AIType.CHASER, m_ninja ); m_world.AddController( alien_controller14 ); alien15 = new Alien( this, plated_alien_texture, alien15_pos, .5f, Alien.AlienType.EASY ); add_object( alien15 ); AlienController alien_controller15 = new AlienController( this, alien15, AlienController.AIType.CHASER, m_ninja ); m_world.AddController( alien_controller15 ); alien16 = new Alien( this, easy_alien_texture, alien16_pos, .5f, Alien.AlienType.EASY ); add_object( alien16 ); AlienController alien_controller16 = new AlienController( this, alien16, AlienController.AIType.CHASER, m_ninja ); m_world.AddController( alien_controller16 ); alien17 = new Alien( this, easy_alien_texture, alien17_pos, .5f, Alien.AlienType.EASY ); add_object( alien17 ); AlienController alien_controller17 = new AlienController( this, alien17, AlienController.AIType.CHASER, m_ninja ); m_world.AddController( alien_controller17 ); //alien18 = new Alien( m_world, easy_alien_texture, alien18_pos, .5f, Alien.AlienType.EASY ); //add_object( alien18 ); alien19 = new Alien( this, easy_alien_texture, alien19_pos, .5f, Alien.AlienType.MEDIUM ); add_object( alien19 ); AlienController alien_controller19 = new AlienController( this, alien19, AlienController.AIType.PATROL, m_ninja ); m_world.AddController( alien_controller19 ); //alien20 = new Alien( m_world, easy_alien_texture, alien20_pos, .5f, Alien.AlienType.EASY ); //add_object( alien20 ); SharedResourceList alist = new SharedResourceList(); alist.Add( alien1 ); alist.Add( alien2 ); Vector2 offset = new Vector2( 0, 1 ); SharedResourceList nlist = new SharedResourceList(); nlist.Add(m_ninja); eye.m_curr_target = m_ninja; // Create Doors door00 = new TriggerableObject( this, door_texture, door00_vertex1, door00_vertex2, 0 ); add_object( door00 ); SharedResourceList<TriggerableObject> tlist = new SharedResourceList<TriggerableObject>(); tlist.Add(door00); door0 = new ConditionTriggered( this, door_texture, door0_pos, 0,alist,t_objects:tlist, c_type: ConditionTriggered.ConditionType.EVADE_ALIENS); add_object( door0 ); door1 = new TriggerableObject( this, door_texture, door1_vertex1, door1_vertex2, 0 ); add_object( door1 ); door2 = new TriggerableObject( this, door_texture, door2_vertex1, door2_vertex2, 0 ); add_object( door2 ); door3 = new TriggerableObject( this, door_texture, door3_vertex1, door3_vertex2, ( (float)Math.PI / 2 ) ); add_object( door3 ); door4 = new TriggerableObject( this, door_texture, door4_vertex1, door4_vertex2, ( (float)Math.PI / 2 ) ); add_object( door4 ); door5 = new TriggerableObject( this, door_texture, door5_vertex1, door5_vertex2, ( (float)Math.PI / 2 ) ); add_object( door5 ); door6 = new TriggerableObject( this, door_texture, door6_vertex1, door6_vertex2, 0 ); add_object( door6 ); door7 = new TriggerableObject( this, door_texture, Vector2.Zero, TriggerableObject.TriggerType.GOAL, 0 ); // add_object( door7 ); Vector2[] vec = new Vector2[] { new Vector2(-20,88), new Vector2(-20,80),new Vector2(2,80),new Vector2(2,88) }; PolygonTrigger poly = new PolygonTrigger( this, pix_texture, ground_switch_inactive_texture, vec, door1, Trigger.TriggerType.FLOOR, 1, 0 ); add_object( poly ); //Add Switches floor_switch1 = new Trigger( this, ground_switch_active_texture, ground_switch_inactive_texture, floor_switch1_pos, door1, Trigger.TriggerType.FLOOR, 1, 0 ); add_object( floor_switch1 ); wall_switch1 = new Trigger( this, wall_switch_active_texture, wall_switch_inactive_texture, wall_switch1_pos, door2, Trigger.TriggerType.WALL, 1, (float)Math.PI, texture_name:TNames.wall_switch_inactive ); add_object( wall_switch1 ); wall_switch2 = new Trigger( this, wall_switch_active_texture, wall_switch_inactive_texture, wall_switch2_pos, door3, Trigger.TriggerType.WALL, .8f, (float)Math.PI, texture_name: TNames.wall_switch_inactive ); add_object( wall_switch2 ); floor_switch2 = new Trigger( this, ground_switch_active_texture, ground_switch_inactive_texture, floor_switch2_pos, door4, Trigger.TriggerType.FLOOR, 1f, 0 ); add_object( floor_switch2 ); wall_switch3 = new Trigger( this, wall_switch_active_texture, wall_switch_inactive_texture, wall_switch3_pos, door5, Trigger.TriggerType.WALL, 2, (float)Math.PI / 2, texture_name: TNames.wall_switch_inactive ); add_object( wall_switch3 ); wall_switch4 = new Trigger( this, wall_switch_active_texture, wall_switch_inactive_texture, wall_switch4_pos, door6, Trigger.TriggerType.WALL, 2, (float)( 3 * Math.PI / 2 ), texture_name: TNames.wall_switch_inactive ); add_object( wall_switch4 ); win_switch = new Trigger( this, ground_switch_active_texture, ground_switch_inactive_texture, win_switch_pos, door7, Trigger.TriggerType.FLOOR, 300, 0 ); add_object( win_switch ); // Create Ball ball1 = new Ball( this, ball_texture, ball1_pos, 2.0f ); add_object( ball1 ); ball2 = new Ball( this, ball_texture, ball2_pos, 2.0f ); add_object( ball2 ); ball3 = new Ball( this, ball_texture, ball3_pos, 2.0f ); add_object( ball3 ); ball4 = new Ball( this, ball_texture, ball4_pos, 2.0f ); add_object( ball4 ); ball5 = new Ball( this, ball_texture, ball5_pos, 2.0f ); add_object( ball5 ); ball6 = new Ball( this, ball_texture, ball6_pos, 2.0f ); add_object( ball6 ); ball7 = new Ball( this, ball_texture, ball7_pos, 2.0f ); add_object( ball7 ); ball8 = new Ball( this, ball_texture, ball8_pos, 2.0f ); add_object( ball8 ); var ball_2 = new Ball( this, ball_texture, ninja_position, 1.0f ); //Add ninja to the world add_object( m_ninja ); add_object( ball_2 ); */ editor.ninjaBindingSource.DataSource = m_ninja; editor.gameObjectBindingSource.DataSource = m_ninja; // Create ninja controller m_ninja_controller = new NinjaController( this, m_ninja ); m_world.AddController( m_ninja_controller ); // Create mouse controller mouse_control = new MouseController( GameScreen.GAME_WIDTH, GameScreen.GAME_HEIGHT ); /* // Create walls foreach ( var wall in walls ) { // Convert dimensions in the other format if ( wall.Length < 4 ) { new_wall = new[] { wall[0], new Vector2(wall[0].X + wall[1].X, wall[0].Y), new Vector2(wall[0].X + wall[1].X, wall[0].Y + wall[1].Y), new Vector2(wall[0].X, wall[0].Y + wall[1].Y) }; } else new_wall = (Vector2[]) wall.Clone(); add_object( new PolygonObject( this, new_wall, wall_texture, 1.0f, 0.0f, 0.7f ) ); } // Create breakable walls foreach ( var wall in break_walls ) { // Convert dimensions in the other format if ( wall.Length < 4 ) { new_wall = new[] { wall[0], new Vector2(wall[0].X + wall[1].X, wall[0].Y), new Vector2(wall[0].X + wall[1].X, wall[0].Y + wall[1].Y), new Vector2(wall[0].X, wall[0].Y + wall[1].Y) }; } else new_wall = (Vector2[])wall.Clone(); PolygonObject b = new PolygonObject( this, new_wall, breakwall_texture_animate[0], 1.0f, 0.0f, 0.7f, 30.0f ); add_object( b ); } */ //save_state(); }
public void save_Ninja( Ninja ninja ) { XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; using ( XmlWriter writer = XmlWriter.Create( "ninja.xml", settings ) ) { IntermediateSerializer.Serialize( writer, ninja, null ); } }
//---------------------------------------------------------------- // Constructor //---------------------------------------------------------------- // // Constructs a Ninja Controller for the given Ninja and World public NinjaController( GameWorld world, Ninja ninja ) : base(ControllerType.NinjaController) { m_world = world; m_ninja = ninja; }
// Creates the world, sets the ninja public void create_world( GameWorld g_world, string filename ) { Ninja ninja = new Ninja(); DeathPitController deathcontrol = new DeathPitController( g_world, 120 ); XML_Manager xml_guy = new XML_Manager(); g_world.curr_filename = filename; m_objects = xml_guy.load_resource_linked_list( filename ); foreach ( GameObject g_obj in m_objects ) { g_obj.m_world = g_world; g_obj.add_to_world(); //Handles whether to load GameObjects if they have been destroyed if ( g_obj.m_is_dead ) { } if ( g_obj is FloorTile ) { g_obj.remove_from_world(); } if ( g_obj is Ninja ) { m_ninja = (Ninja)g_obj; NinjaController n_control = new NinjaController( g_obj.m_world, (Ninja)g_obj ); m_ninja_controller = n_control; g_obj.m_world.m_world.AddController( n_control ); g_obj.m_body.Awake = true; g_obj.m_body.Enabled = true; //Makes sure to update target foreach ( Controller control in m_world.ControllerList ) { if ( control is AlienController ) { AlienController alien_control = (AlienController)control; alien_control.m_target = m_ninja; } } } else if ( g_obj is Alien ) { Alien alien = (Alien)g_obj; alien.set_textures(); alien.m_ai_type_change = alien.m_ai_type; m_enemy_count++; } else if ( g_obj is DeathTouch && !( g_obj is MovingDeath ) ) { deathcontrol.addPit( (DeathTouch)g_obj ); } else if ( g_obj is ConditionTriggered ) { ConditionTriggered ob = (ConditionTriggered)g_obj; Color color; switch ( ob.m_condition_type ) { case ConditionTriggered.ConditionType.DEATH: color = Color.CornflowerBlue; break; case ConditionTriggered.ConditionType.NINJA_HAS_ITEM: color = Color.OrangeRed; break; default: color = Color.White; break; } foreach ( TriggerableObject to in ob.m_attached_to ) to.m_tint = color; } } g_world.m_world.AddController( deathcontrol ); }