Exemple #1
0
        //--------------------------------------------------------------------
        // Constructor
        //--------------------------------------------------------------------
        public Camera( Viewport viewport, int offset, GameObject curr_target = null )
        {
            if ( curr_target != null ) {
                curr_target = m_curr_target;
            }
            m_camera_zoom = CAMERA_MIN_ZOOM;
            m_zoom_change = m_camera_zoom;
            m_zoom_mult = 1;

            this.m_aspect_ratio = ( (float)viewport.Width ) /
                ( (float)viewport.Height );
            this.m_matrix_projection = Matrix.CreatePerspectiveFieldOfView(
                                        MathHelper.ToRadians( 40.0f ),
                                        this.m_aspect_ratio,
                                        1.0f,
                                        10000.0f );
            /*this.m_camera_origin = new Vector2( viewport.Width / 2,
                viewport.Height / 2 );  */
            this.m_camera_origin = new Vector2( GameScreen.GAME_WIDTH / 2 + offset,
               GameScreen.GAME_HEIGHT / 2 );
            this.m_camera_view_area = new Rectangle( (int)m_camera_position.X,
                (int)m_camera_position.Y, viewport.Width, viewport.Height );
            m_view_height = GameScreen.GAME_HEIGHT;
            m_view_width = GameScreen.GAME_WIDTH;

            /* m_view_height = viewport.Height;
            m_view_width = viewport.Width; */
        }
Exemple #2
0
        public bool collision( GameObject collider )
        {
            float contact_body_speed = collider.m_body.LinearVelocity.Length();

            if ( contact_body_speed > m_destroy_threshold ) {

                m_animation_frame = 0;
                if ( hit_counter > 0 ) {
                    //* constant because of the movement of the AI
                    Vector2 hit_vec = hit_counter * ( Math.Max( 0.4f, collider.get_weight() / get_weight() ) ) * ( collider.m_body.LinearVelocity - m_body.LinearVelocity ).Length() *
                                                         Vector2.Normalize( m_position - collider.m_position );
                    m_body.LinearVelocity = hit_vec;
                    m_body.ApplyLinearImpulse( 60 * hit_vec );
                    cooldown = m_deathtime;
                    hit_counter--;
                    float col = ( 1f + 2f * hit_counter / (float)max_hit ) / 3f;
                    m_alien_color = new Color( col, col, col );
                    if ( collider is Ninja ) {
                        collider.m_body.ApplyLinearImpulse( contact_body_speed / 1.5f *
                                                        Vector2.Normalize( collider.m_position - m_position ) );
                        m_world.m_ninja.m_cooldown = Ninja.NINJA_COLLISION_COOLDOWN;
                    }
                    return true;
                }
                else {
                    Vector2 death_force = 40 * contact_body_speed * 5 *
                                          Vector2.Normalize( m_position - collider.m_position );
                    m_body.ApplyLinearImpulse( death_force );
                    alien_death_force = death_force;
                    m_body.Enabled = false;
                    return false;

                }
            }
            else if ( contact_body_speed < m_kill_under_speed
                && collider is Ninja ) {

                ( (Ninja)collider ).m_cooldown = 30;
                ( (Ninja)collider ).m_is_killed = true;
                return true;
            }
            else {

                if ( collider is Ninja ) {

                    ( (Ninja)collider ).m_cooldown = Ninja.NINJA_COLLISION_COOLDOWN;
                }
                return true;
            }
        }
        // The Ball Constructor
        // <param name="world"> The World this object would be contained inside
        // </param>
        // <param name="texture"> The image that governs the shape of this
        // object</param>
        // <param name="velocity"> The initial velocity upon spawning</param>
        // <param name="density"> The object's mass per unit area </param>
        // <param name="friction"> Usually set to 0 for throwable objects,
        // but sliding factor </param>
        // <param name="restitution"> Bounciness </param>
        public SelectBox( GameWorld world, Texture2D texture,
            Vector2 position, float radius, String name = "Ball", String texturename = TNames.tile, GameObject target = null )
            : base(world, texture, 0, 0,
            0,
            radius: radius,
            name: name, texture_name: texturename)
        {
            m_buffered_position = Vector2.Zero;
            m_draw_location = position;
            m_tint = new Color( 255, 255, 255, 150 );
            m_texture = TestWorld.floor_texture;
            m_radius = radius;

            m_target = target;
        }
Exemple #4
0
        //----------------------------------------------------------------
        // Methods
        //----------------------------------------------------------------
        public bool collision( GameObject collider )
        {
            float contact_body_speed = collider.m_body.LinearVelocity.Length();

            if ( contact_body_speed > m_destroy_threshold ) {
                Vector2 dir = collider.m_body.Position - m_body.Position;
                double angle = Math.Atan2( dir.Y, dir.X ) - m_rotation;
                if ( angle < -Math.PI ) angle += 2 * Math.PI;
                else if ( angle > Math.PI ) angle -= 2 * Math.PI;

                if ( angle < -0.785 && angle > -2.356 ) {
                    Vector2 death_force = 40 * contact_body_speed * 5 *
                                          Vector2.Normalize( m_position - collider.m_position );
                    m_body.ApplyLinearImpulse( death_force );
                    alien_death_force = death_force;
                    m_body.Enabled = false;
                    return false;

                }
                else {

                    if ( collider is Ninja ) {

                        ( (Ninja)collider ).m_cooldown = Ninja.NINJA_COLLISION_COOLDOWN;
                    }
                    return true;
                }

            }
            else if ( contact_body_speed < m_kill_under_speed
                && collider is Ninja ) {

                ( (Ninja)collider ).m_cooldown = 30;
                ( (Ninja)collider ).m_is_killed = true;
                return true;
            }
            else {

                if ( collider is Ninja ) {

                    ( (Ninja)collider ).m_cooldown = Ninja.NINJA_COLLISION_COOLDOWN;
                }
                return true;
            }
        }
Exemple #5
0
        //----------------------------------------------------------------
        // Methods
        //----------------------------------------------------------------
        public bool collision( GameObject collider )
        {
            float contact_body_speed = collider.m_body.LinearVelocity.Length();

            if ( contact_body_speed > m_destroy_threshold ) {

                if ( hit_counter > 0 ) {

                    hit_counter--;
                    float col = ( 1f + 2f * hit_counter / (float)max_hit ) / 3f;
                    m_alien_color = new Color( col, col, col );
                    if ( collider is Ninja ) {

                        m_world.m_ninja.m_cooldown = Ninja.NINJA_COLLISION_COOLDOWN;
                    }
                    return true;
                }
                else {
                    Vector2 death_force = 40 * contact_body_speed * 5 *
                                          Vector2.Normalize( m_position - collider.m_position );
                    m_body.ApplyLinearImpulse( death_force );
                    alien_death_force = death_force;
                    m_body.Enabled = false;
                    return false;

                }
            }
            else if ( contact_body_speed < m_kill_under_speed
                && collider is Ninja ) {

                ( (Ninja)collider ).m_cooldown = 30;
                ( (Ninja)collider ).m_is_killed = true;
                return true;
            }
            else {

                if ( collider is Ninja ) {

                    ( (Ninja)collider ).m_cooldown = Ninja.NINJA_COLLISION_COOLDOWN;
                }
                return true;
            }
        }
Exemple #6
0
        public void pick_up( GameObject throwing_item )
        {
            if ( m_throwing_items.Count < m_max_throwable_capacity
                && throwing_item.m_is_throwable ) {
                GameEngine.AudioManager.Play( AudioManager.SFXSelection.pickup_sfx );
                // Thinking about adding a weight, so Ninja doesn't have to move as fast to attain speeds..
                // Something like a *POWER* factor.
                // Ninja's power factor starts off at 1
                // A small ball would have a power factor of 0.7 or something
                // Add ~half or so of ball's weight to ninja when grabbing?

                //throwing_item.m_body.CollidesWith = Category.None;
                throwing_item.m_body.LinearDamping = 5;
                throwing_item.m_body.AngularVelocity = 0;
                throwing_item.m_body.Mass /= 3;
                m_throwing_items.Push( throwing_item );
                m_has_item = true;
                m_picking_up = false;

                //throwing_item.m_body.Mass *= 6;
                SliderJoint the_joint =
                    JointFactory.CreateSliderJoint( m_world.m_world,
                    m_body, throwing_item.m_body, Vector2.Zero,
                    Vector2.Zero, 0, m_radius + throwing_item.m_radius
                    );

                m_throwable_joint = the_joint;
            }
        }
Exemple #7
0
        public bool collision( GameObject collider )
        {
            float contact_body_speed = collider.m_body.LinearVelocity.Length();

            if ( contact_body_speed > m_destroy_threshold ) {
                if ( eggs.Any( egg => egg.intact ) ) {
                    Vector2 dir = collider.m_body.Position - m_body.Position;
                    double angle = Math.Atan2( dir.Y, dir.X ) - m_rotation;
                    if ( angle < -Math.PI ) angle += 2 * Math.PI;
                    else if ( angle > Math.PI ) angle -= 2 * Math.PI;

                    double angle1 = angle + Math.PI;
                    if ( angle1 > Math.PI ) angle1 -= 2 * Math.PI;

                    if ( angle < 0 && angle > -0.6 ) eggs[0].intact = false;
                    if ( angle > -1.25 && angle < -0.6 ) eggs[1].intact = false;
                    if ( angle1 > 0 && angle1 < 0.6 ) eggs[2].intact = false;
                    if ( angle1 < 1.25 && angle1 > 0.6 ) eggs[3].intact = false;

                    ////* constant because of the movement of the AI
                    //m_body.ApplyForce( 60 * ( Math.Max( 0.4f, collider.get_weight() / get_weight() ) ) * ( collider.m_body.LinearVelocity - m_body.LinearVelocity ).Length() *
                    //                                     Vector2.Normalize( m_position - collider.m_position ) );

                    if ( collider is Ninja ) {
                        collider.m_body.ApplyLinearImpulse( contact_body_speed / 1.5f *
                                                        Vector2.Normalize( collider.m_position - m_position ) );
                        m_world.m_ninja.m_cooldown = Ninja.NINJA_COLLISION_COOLDOWN;
                    }
                    return true;
                }
                else {
                    Vector2 death_force = 40 * contact_body_speed * 5 *
                                          Vector2.Normalize( m_position - collider.m_position );
                    m_body.ApplyLinearImpulse( death_force );
                    alien_death_force = death_force;
                    m_body.Enabled = false;
                    return false;

                }

            }
            else if ( contact_body_speed < m_kill_under_speed
                && collider is Ninja ) {

                ( (Ninja)collider ).m_cooldown = 30;
                ( (Ninja)collider ).m_is_killed = true;
                return true;
            }
            else {

                if ( collider is Ninja ) {

                    ( (Ninja)collider ).m_cooldown = Ninja.NINJA_COLLISION_COOLDOWN;
                }
                return true;
            }
        }
        //saves a game object
        //All of the data will be under body and its userdata if it has a body
        public void save_game_object( GameObject obj, String filename )
        {
            XmlWriterSettings settings = new XmlWriterSettings();
            settings.Indent = true;

            using ( XmlWriter writer = XmlWriter.Create( filename, settings ) ) {
                IntermediateSerializer.Serialize( writer, obj, null );
            }
        }
 //----------------------------------------------------------------
 // Public Methods
 //----------------------------------------------------------------
 public override bool can_be_activated_by( GameObject obj )
 {
     return obj.m_is_throwable;
 }
Exemple #10
0
 public virtual bool can_be_activated_by( GameObject obj )
 {
     return ( obj is Ninja &&
         ( m_type == TriggerType.FLOOR || m_type == TriggerType.WALL ) )
         || ( obj.m_is_throwable && m_type == TriggerType.WALL );
 }
Exemple #11
0
        // Adds the object to the physics world
        // <param name="obj"></param>
        protected void add_object( GameObject obj )
        {
            if ( obj is Alien )
                m_enemy_count++;

            if ( obj is BackgroundTile ) {
                m_background_tiles.Add( obj );
            }

            obj.add_to_world();
            if ( ( obj is FloorTile ) || ( obj is SelectBox ) )
                m_objects.AddFirst( obj );
            else
                m_objects.AddLast( obj );

            // obj.add_joints_to_world();
        }
Exemple #12
0
 //----------------------------------------------------------------
 // Public Methods
 //----------------------------------------------------------------
 //
 // Puts the physics object in the add queue, to be added
 // before the next step.  This is required as objects
 // cannot be added during engine processing.
 // <param name="obj"></param>
 public void add_queued_object( GameObject obj )
 {
     m_add_queue.Enqueue( obj );
 }