예제 #1
0
        //------------------------------------------------------------------------------------------------------------------

        //Here's where you add all the components the entity has.
        //You can just uncomment the ones you want.
        public void addMyComponents(float x, float y, int dir)
        {
            /*POSITION COMPONENT - Does it have a position?
             */
            PositionComponent posComp = ( PositionComponent )addComponent(new PositionComponent(x, y, defaultWidth, defaultHeight, this), true);

            /*DRAW COMPONENT - Does it get drawn to the game world?
             * You'll need to know the address for your image.
             * It'll probably be something along the lines of "RunningGame.Resources.[      ].png" ONLY png!!
             * First create the component
             * Then add the image
             * Then set the image to the active image
             */
            DrawComponent drawComp = ( DrawComponent )addComponent(new DrawComponent(defaultWidth, defaultHeight, level, true), true);
            //Add image - Use base name for first parameter (everything in file path after Resources. and before the numbers and .png)
            //Then second parameter is full filepath to a default image
            string sprName = "Main";

            drawComp.addSprite("Artwork.Foreground.Spike", "RunningGame.Resources.Artwork.Foreground.Spike.png", sprName);
            drawComp.setSprite(sprName);   //Set image to active image

            //Won't always be the same as spr name
            //Like if it's been de-colored as a result of being in a
            //World's 1st level before the color orb is obtained.
            string currentSprite = drawComp.activeSprite;

            //Rotate accordingly
            for (int i = 0; i < dir; i++)
            {
                drawComp.rotateFlipAllSprites(System.Drawing.RotateFlipType.Rotate90FlipNone);
            }

            /*
             * DIRECTIONAL COMPONENT - it has a direction (used by collision)
             */
            addComponent(new DirectionalComponent(dir), true);

            /*COLLIDER - Does it hit things?
             * The second field is the collider type. Look in GlobalVars for a string with the right name.
             */
            addComponent(new ColliderComponent(this, GlobalVars.SPIKE_COLLIDER_TYPE, 4, 4), true);
        }
예제 #2
0
        //------------------------------------------------------------------------------------------------------------------

        //Here's where you add all the components the entity has.
        //You can just uncomment the ones you want.
        public void addMyComponents(float x, float y, int dir, int switchId)
        {
            /*POSITION COMPONENT - Does it have a position?
             */
            addComponent(new PositionComponent(x, y, defaultWidth, defaultHeight, this), true);

            /*DRAW COMPONENT - Does it get drawn to the game world?
             * You'll need to know the address for your image.
             * It'll probably be something along the lines of "RunningGame.Resources.[      ].png" ONLY png!!
             * First create the component
             * Then add the image
             * Then set the image to the active image
             */
            DrawComponent drawComp = (DrawComponent)addComponent(new DrawComponent(defaultWidth, defaultHeight, level, true), true);

            //Add image - Use base name for first parameter (everything in file path after Resources. and before the numbers and .png)
            //Then second parameter is full filepath to a default image
            drawComp.addSprite("Artwork.Foreground.SmushBlock", "RunningGame.Resources.Artwork.Foreground.SmushBlock.png", "Main");
            for (int i = 0; i < dir + 2; i++)
            {
                drawComp.rotateFlipAllSprites(System.Drawing.RotateFlipType.Rotate90FlipNone);
            }
            drawComp.setSprite("Main"); //Set image to active image


            /* ANIMATION COMPONENT - Does it need animating?
             * The float that this reads in is the amount of time (in seconds) between frames.
             * So, if it was 5, you would be on one frame for 5 seconds, then switch to the next, then 5 seconds later
             * It'd switch to the next etc, etc...
             */
            //addComponent(new AnimationComponent(0.0005f), true);

            /*VELOCITY COMPONENT - Does it move?
             */
            addComponent(new VelocityComponent(0, 0));

            /*COLLIDER - Does it hit things?
             * The second field is the collider type. Look in GlobalVars for a string with the right name.
             */
            addComponent(new ColliderComponent(this, GlobalVars.SMUSH_BLOCK_COLLIDER), true);

            /*DIRECTION - It has a direction
             */
            DirectionalComponent dirComp = (DirectionalComponent)addComponent(new DirectionalComponent(dir));

            /*OFF SIDE OF SCREEN - Stop when it hits the side of the screen.
             */
            addComponent(new ScreenEdgeComponent(1, 1, 1, 1));

            /*SMUSH - It's a smusher!
             */
            SmushComponent smushComp = ( SmushComponent )addComponent(new SmushComponent(0.0f));

            if (dirComp.isUp())
            {
                smushComp.setToUp();
            }
            else if (dirComp.isRight())
            {
                smushComp.setToRight();
            }
            else if (dirComp.isDown())
            {
                smushComp.setToDown();
            }
            else if (dirComp.isLeft())
            {
                smushComp.setToLeft();
            }

            /*TIMER - It does stuff with a timer.
             */
            addComponent(new TimerComponent());

            /* SWITCH LISTENER - Can be linked to a switch to prevent it from falling.
             */
            addComponent(new SwitchListenerComponent(switchId, GlobalVars.SMUSH_SWITCH_EVENT));
        }
예제 #3
0
        //------------------------------------------------------------------------------------------------------------------

        //Here's where you add all the components the entity has.
        //You can just uncomment the ones you want.
        public void addMyComponents(float x, float y, int dir, int state)
        {
            /*POSITION COMPONENT - Does it have a position?
             */
            PositionComponent posComp = ( PositionComponent )addComponent(new PositionComponent(x, y, defaultWidth, defaultHeight, this), true);

            /*VELOCITY COMPONENT - It moves
             */
            addComponent(new VelocityComponent());

            /*DRAW COMPONENT - Does it get drawn to the game world?
             * You'll need to know the address for your image.
             * It'll probably be something along the lines of "RunningGame.Resources.[      ].png" ONLY png!!
             * First create the component
             * Then add the image
             * Then set the image to the active image
             */
            DrawComponent drawComp = ( DrawComponent )addComponent(new DrawComponent(defaultWidth, defaultHeight, level, true), true);

            //Add image - Use base name for first parameter (everything in file path after Resources. and before the numbers and .png)
            //Then second parameter is full filepath to a default image

            drawComp.addSprite("Artwork.Foreground.GoodSpike", "RunningGame.Resources.Artwork.Foreground.GoodSpike.png", goodSpikeImageName);
            drawComp.addSprite("Artwork.Foreground.BadSpike", "RunningGame.Resources.Artwork.Foreground.BadSpike.png", badSpikeImageName);

            if (state == 1)
            {
                drawComp.setSprite(goodSpikeImageName);
            }
            else
            {
                drawComp.setSprite(badSpikeImageName);   //Set image to active image
            }
            //Won't always be the same as spr name
            //Like if it's been de-colored as a result of being in a
            //World's 1st level before the color orb is obtained.
            string currentSprite = drawComp.activeSprite;

            //Rotate accordingly
            for (int i = 0; i < dir; i++)
            {
                drawComp.rotateFlipAllSprites(System.Drawing.RotateFlipType.Rotate90FlipNone);
            }


            /** GENERAL STATE COMPONENT - Need to store a state variable.
             * State = 0 --> Hurt Player
             * State = 1 --> Hurt Enemy
             */
            addComponent(new GeneralStateComponent(state), true);

            /*
             * DIRECTIONAL COMPONENT - it has a direction (used by collision)
             */
            addComponent(new DirectionalComponent(dir), true);

            /*COLLIDER - Does it hit things?
             * The second field is the collider type. Look in GlobalVars for a string with the right name.
             */
            addComponent(new ColliderComponent(this, GlobalVars.SHOOTER_BULLET_COLLIDER_TYPE), true);

            /* OUT OF SCREEN COOMPONENT - Destroy on exiting screen.
             */
            addComponent(new ScreenEdgeComponent(3, 3, 3, 3), true);
        }