Esempio n. 1
0
 public Trigger( GameWorld world, Texture2D active_texture,
     Texture2D inactive_texture, Vector2 position,
     TriggerableObject triggered_object, TriggerType type,
     float cooldown, float rotation, String name = "Trigger",
     String texture_name = TNames.ground_switch_animate, SharedResourceList<TriggerableObject> t_obj_list = null,
     float scale = 1, float density = DENSITY )
     : base(world, inactive_texture, position, name: name, texture_name: texture_name, density: density)
 {
     m_texture_name = texture_name;
     m_texture_name_helper = texture_name;
     m_active_texture = active_texture;
     m_inactive_texture = inactive_texture;
     m_buffered_position = position;
     m_size_scale = scale;
     m_radius = m_size_scale * ( m_texture.Width ) / ( GameWorld.SCALE * 2 );
     if ( t_obj_list == null ) {
         m_attached_to = new SharedResourceList<TriggerableObject>( world );
     }
     else {
         m_attached_to = t_obj_list;
     }
     if ( triggered_object != null ) {
         m_attached_to.Add( triggered_object );
     }
     m_type = type;
     m_cooldown = cooldown * 60;
     m_cooldown_timer = 0;
     m_deactivated = false;
     m_active = false;
     m_rotation = rotation;
     //m_radius = 0.2f * 5;
 }
Esempio n. 2
0
 protected override void Serialize(IntermediateWriter output,
                                   SharedResourceList <T> value,
                                   ContentSerializerAttribute format)
 {
     foreach (T item in value)
     {
         output.WriteSharedResource(item, itemFormat);
     }
 }
        /// <summary>
        /// Saves sprite sheet data into an XNB file.
        /// </summary>
        protected override void Write(ContentWriter aOutput, SharedResourceList <T> aValue)
        {
            int nbElement = 0;

            nbElement = aValue.Count;

            aOutput.WriteObject(nbElement);

            foreach (T item in aValue)
            {
                aOutput.WriteSharedResource(item);
            }
        }
Esempio n. 4
0
        protected override SharedResourceList <T> Deserialize(IntermediateReader input,
                                                              ContentSerializerAttribute format,
                                                              SharedResourceList <T> existingInstance)
        {
            if (existingInstance == null)
            {
                existingInstance = new SharedResourceList <T>();
            }

            while (input.MoveToElement(itemFormat.ElementName))
            {
                input.ReadSharedResource(itemFormat, (T item) => existingInstance.Add(item));
            }

            return(existingInstance);
        }
 // Needs to change this
 public ConditionTriggered( GameWorld world, Texture2D texture,
     Vector2 pos, float rotation, SharedResourceList triglist, String name = "ConditionTrigger",
     String texture_name = TNames.ground_switch_inactive, float cooldown = -1,
     SharedResourceList<TriggerableObject> t_objects = null,
     ConditionType c_type = ConditionType.DEATH )
     : base(world, texture, texture, pos, null, TriggerType.NO_COLLISION, cooldown,
          rotation, texture_name: texture_name, t_obj_list: t_objects)
 {
     m_condition_type = c_type;
     if ( trigger_list != null ) {
         trigger_list = triglist;
     }
     else {
         trigger_list = new SharedResourceList( m_world );
     }
 }
        protected override SharedResourceList <T> Read(
            ContentReader input,
            SharedResourceList <T> existingInstance)
        {
            if (existingInstance == null)
            {
                existingInstance = new SharedResourceList <T>();
            }

            int nbElement = 0;

            nbElement = input.ReadObject <int>();

            int i = 0;

            while (i < nbElement)
            {
                input.ReadSharedResource((T item) => existingInstance.Add(item));
                i++;
            }

            return(existingInstance);
        }
Esempio n. 7
0
        public void save_resource_list( SharedResourceList objects, String filename )
        {
            XmlWriterSettings settings = new XmlWriterSettings();
            settings.Indent = true;

            using ( XmlWriter writer = XmlWriter.Create( filename, settings ) ) {

                IntermediateSerializer.Serialize( writer, objects, null );

            }
        }
        public void deactivate()
        {
            switch ( m_type ) {
                case TriggerType.DOOR:
                    if ( m_is_active ) {
                        m_invisible = false;
                        m_tint = Color.White;
                        m_is_active = false;
                        //m_scale.X = m_length / m_texture.Width * GameWorld.SCALE;
                    }
                    break;
                case TriggerType.GOAL:
                    if ( m_is_active ) {
                        //Do something here?
                    }
                    break;
                case TriggerType.TEXTBOX:
                    if ( m_is_active ) {
                        m_invisible = false;
                        m_is_active = false;
                    }
                    break;
                case TriggerType.CAMERA_CONTROL:
                    if ( m_is_active ) {

                        if ( m_follow_me ) {
                            GameScreen.m_curr_view.move_scroll = true;

                        }
                        GameScreen.m_curr_view.m_curr_target = m_world.m_ninja;

                        m_is_active = false;
                    }
                    break;
                case TriggerType.ZOOM_CONTROL:
                    if ( m_is_active ) {
                        GameScreen.m_curr_view.m_zoom_mult = 1;
                        m_is_active = false;
                    }
                    break;
                case TriggerType.BODY_ENABLER: {
                        if ( m_objects == null ) {
                            m_objects = new SharedResourceList<GameObject>();
                        }
                        else {
                            foreach ( GameObject obj in m_objects ) {
                                obj.m_disabled = true;
                            }
                        }
                        m_is_active = false;
                    }
                    break;
                default:
                    m_is_active = false;
                    break;

            }
        }
 //----------------------------------------------------------------
 // Methods
 //----------------------------------------------------------------
 public void activate()
 {
     switch ( m_type ) {
         case TriggerType.DOOR:
             if ( m_body != null && m_body.Enabled && !m_invisible && !m_is_active ) {
                 GameEngine.AudioManager.Play( AudioManager.SFXSelection.door_activate );
                 m_invisible = true;
                 m_tint = Color.DarkGray;
                 // m_scale.X = 0;
             }
             break;
         case TriggerType.GOAL:
             m_world.Win();
             break;
         case TriggerType.TEXTBOX:
             if ( !m_invisible ) {
                 m_invisible = true;
             }
             break;
         case TriggerType.CHECKPOINT:
             if ( !m_is_active ) {
                 m_is_active = true;
                 GameScreen.checkpoint_countdown = 180;
                 GameScreen.m_checkpoint_timer = m_timer_checkpoint_set;
                 m_world.save_state( Directory.GetCurrentDirectory() + "/Levels/" + "checkpoint.xml" );
             }
             break;
         case TriggerType.CAMERA_CONTROL:
             Camera eye = GameScreen.m_curr_view;
             if ( eye != null ) {
                 if ( !m_is_active ) {
                     m_is_active = true;
                     eye.m_zoom_change = m_set_zoom;
                     if ( m_follow_me ) {
                         eye.m_curr_target = this;
                         GameScreen.m_curr_view.move_scroll = true;
                     }
                 }
             }
             break;
         case TriggerType.CAMERA_RESET:
             if ( !m_is_active ) {
                 m_is_active = true;
                 GameScreen.m_curr_view.m_zoom_mult = 1;
                 GameScreen.m_curr_view.m_curr_target = m_world.m_ninja;
             }
             break;
         case TriggerType.ZOOM_CONTROL:
             if ( !m_is_active ) {
                 m_is_active = true;
                 GameScreen.m_curr_view.m_zoom_mult = m_zoom_mult;
             }
             break;
         case TriggerType.FLAME:
             MovingDeath death = new MovingDeath( m_world, TestWorld.flame_texture, new Vector2( 97, 100 ), new Vector2( 53, 8 ), new Vector2( 0, -250 ), 0.4f, texturename: TNames.flame );
             m_world.add_queued_object( death );
             break;
         case TriggerType.BOSS1:
             if ( !m_is_active ) {
                 m_is_active = true;
                 GameEngine.AudioManager.Play( AudioManager.MusicSelection.boss1 );
             }
             break;
         case TriggerType.BOSS2:
             if ( !m_is_active ) {
                 m_is_active = true;
                 GameEngine.AudioManager.Play( AudioManager.MusicSelection.boss2 );
             }
             break;
         case TriggerType.BODY_ENABLER: {
                 if ( m_objects == null ) {
                     m_objects = new SharedResourceList<GameObject>();
                 }
                 else {
                     foreach ( GameObject obj in m_objects ) {
                         obj.m_disabled = false;
                     }
                     m_is_active = true;
                 }
             }
             break;
     }
     m_is_active = true;
 }
        // Creates a new polygon object.
        // Creates the shape based on the texture
        public CompoundPolygonObject( GameWorld world, Texture2D texture, Vector2 position,
            float density = 0.2f, float friction = 0, float restitution = 0.7f,
            float destroy_threshold = 0.0f, String name = "CompoundPolygonObject",
            String texture_name = TNames.wall, float scaleX = 1, float scaleY = 1 )
            : base(world, texture, density, friction, restitution,
            is_destructible: ( destroy_threshold > 0 ),
            destroy_threshold: destroy_threshold, name: name, texture_name: texture_name)
        {
            m_vertices = new List<VertexPositionTexture[]>();
            m_buffered_position = position;
            //Create an array to hold the data from the texture
            uint[] data = new uint[texture.Width * texture.Height];

            //Transfer the texture data to the array
            texture.GetData( data );

            //Find the vertices that makes up the outline of the shape in the texture
            Vertices textureVertices = PolygonTools.CreatePolygon( data, texture.Width, false );

            //Console.WriteLine("texturevertices are " + textureVertices);

            //The tool return vertices as they were found in the texture.
            //We need to find the real center (centroid) of the vertices for 2 reasons:

            //1. To translate the vertices so the polygon is centered around the centroid.
            Vector2 centroid = -textureVertices.GetCentroid();
            textureVertices.Translate( ref centroid );

            //2. To draw the texture the correct place.
            m_origin = -centroid;

            //We simplify the vertices found in the texture.
            textureVertices = SimplifyTools.ReduceByDistance( textureVertices, 4f );

            Vertices scaledVerts = new Vertices( textureVertices.Capacity ); //now that we have list of the texture vertices we have to format it
            //in this case I'm just  making a new list for simplicity
            for ( int i = 0; i < textureVertices.Count; i++ ) {
                //Going step by step for Clarity
                Vector2 tempVert = new Vector2(); //create the temporary variable to store the new vertice before we add it to the list

                tempVert = textureVertices[i];    //set it the vert we are currently modifying

                //the verts are currently in texture coordinates, which means the Y value is inverted
                tempVert.Y *= -1; // booyah, fixed that problem

                //right now the vertices are the size of the texture, definately not what we want.
                tempVert.X /= texture.Width;
                tempVert.Y /= texture.Height;

                tempVert.X *= scaleX;
                tempVert.Y *= scaleY;
                //units are scaled to scale

                //now we need to scale the verts up to match the FRB sprite

                //tempVert.X *= this.sprite.ScaleX * 2;
                //tempVert.Y *= this.sprite.ScaleY * 2;

                //add that sucker to the list
                scaledVerts.Add( tempVert );

            }

            //Since it is a concave polygon, we need to partition it into several smaller convex polygons
            List<Vertices> vert_list = EarclipDecomposer.ConvexPartition( scaledVerts );

            m_vertices_list = new SharedResourceList<Vertices>( m_world );

            //Transfer to serializable list
            //Console.WriteLine("vert_list is " + vert_list);
            foreach ( Vertices vert in vert_list ) {
                m_vertices_list.Add( vert );
            }

            // m_vertices_list.Add( scaledVerts );
        }