Ejemplo n.º 1
0
        //----------------------------------------------------------------------------------------------

        //--------------------------HANDLE TIMERS--------------------------
        private void initializeTimer(Entity e)
        {
            SmushComponent smushComp = ( SmushComponent )e.getComponent(GlobalVars.SMUSH_COMPONENT_NAME);

            startUpperWait(e);
            smushComp.setHasInitializedTimer(true);
        }
Ejemplo n.º 2
0
        //Start Rising
        private void startRise(Entity e)
        {
            SmushComponent    smushComp = ( SmushComponent )e.getComponent(GlobalVars.SMUSH_COMPONENT_NAME);
            VelocityComponent velComp   = ( VelocityComponent )e.getComponent(GlobalVars.VELOCITY_COMPONENT_NAME);

            startRise(velComp, smushComp);
        }
Ejemplo n.º 3
0
        //You must have an Update.
        //Always read in deltaTime, and only deltaTime (it's the time that's passed since the last frame)
        //Use deltaTime for things like changing velocity or changing position from velocity
        //This is where you do anything that you want to happen every frame.
        //There is a chance that your system won't need to do anything in update. Still have it.
        public override void Update(float deltaTime)
        {
            foreach (Entity e in getApplicableEntities())
            {
                SmushComponent smushComp = ( SmushComponent )e.getComponent(GlobalVars.SMUSH_COMPONENT_NAME);
                if (!smushComp.getInitializedTimer())
                {
                    initializeTimer(e);
                }

                TimerComponent timeComp = ( TimerComponent )e.getComponent(GlobalVars.TIMER_COMPONENT_NAME);

                if (smushComp.isFrozen() && smushComp.isWaitingUpper())
                {
                    if (timeComp.getCompletedTimers().Contains(upperWaitTimer))
                    {
                        timeComp.removeCompletedTimer(upperWaitTimer);
                    }
                    timeComp.addTimer(upperWaitTimer, smushComp.getUpperWaitTime());
                }

                List <string> completedTimers = new List <string>(timeComp.getCompletedTimers());
                foreach (string timer in completedTimers)
                {
                    handleCompletedTimer(timer, e);
                    timeComp.removeCompletedTimer(timer);
                }

                if (!smushComp.isWaitingUpper() && !smushComp.isWaitingLower())
                {
                    checkForDirectionChange(e);
                }
            }
        }
Ejemplo n.º 4
0
        //--------------------------HANDLE DIRECTION CHANGE--------------------------
        private void checkForDirectionChange(Entity e)
        {
            SmushComponent    smushComp = ( SmushComponent )e.getComponent(GlobalVars.SMUSH_COMPONENT_NAME);
            VelocityComponent velComp   = ( VelocityComponent )e.getComponent(GlobalVars.VELOCITY_COMPONENT_NAME);

            float stopBuffer = 0.01f;

            if (smushComp.getFallSpeed().X != 0 && Math.Abs(velComp.x) < stopBuffer)
            {
                if (smushComp.isFalling())
                {
                    startLowerWait(e);
                }
                else if (smushComp.isRising())
                {
                    startUpperWait(e);
                }
            }
            if (smushComp.getFallSpeed().Y != 0 && Math.Abs(velComp.y) < stopBuffer)
            {
                if (smushComp.isFalling())
                {
                    startLowerWait(e);
                }
                else if (smushComp.isRising())
                {
                    startUpperWait(e);
                }
            }
        }
Ejemplo n.º 5
0
        //Start Lower Waiting
        private void startLowerWait(Entity e)
        {
            SmushComponent    smushComp = ( SmushComponent )e.getComponent(GlobalVars.SMUSH_COMPONENT_NAME);
            VelocityComponent velComp   = ( VelocityComponent )e.getComponent(GlobalVars.VELOCITY_COMPONENT_NAME);
            TimerComponent    timerComp = ( TimerComponent )e.getComponent(GlobalVars.TIMER_COMPONENT_NAME);

            startLowerWait(velComp, smushComp, timerComp, e);
        }
Ejemplo n.º 6
0
 private void startLowerWait(VelocityComponent velComp, SmushComponent smushComp, TimerComponent timerComp, Entity e)
 {
     velComp.setVelocity(0, 0);
     smushComp.setStateLowerWait();
     if (!timerComp.hasTimer(upperWaitTimer))
     {
         timerComp.addTimer(lowerWaitTimer, smushComp.getLowerWaitTime());
     }
 }
Ejemplo n.º 7
0
 public bool smushSwitch(Entity e, bool active)
 {
     if (e.hasComponent(GlobalVars.SMUSH_COMPONENT_NAME))
     {
         SmushComponent smushComp = ( SmushComponent )e.getComponent(GlobalVars.SMUSH_COMPONENT_NAME);
         smushComp.setFrozen(active);
     }
     else
     {
         Console.WriteLine("Error - Trying to activate smush switch event without smush component.");
     }
     return(true);
 }
Ejemplo n.º 8
0
        //You must have this, but it may be empty.
        //What should the entity do in order to revert to its starting state?
        //Common things are:
        //Set position back to startingX and startingY
        //NOTE: If doing this, you probably want to use the MovementSystem's teleportToNoCollisionCheck() method
        //rather than the usual changePosition()
        //Set velocity to 0 in both directions
        //Note: Some things, like ground, dont move, and really don't need anything here.
        //Note: Some things, like a bullet, won't ever exist at the start of a level, so you could probably leave this empty.
        public override void revertToStartingState()
        {
            PositionComponent posComp = (PositionComponent)this.getComponent(GlobalVars.POSITION_COMPONENT_NAME);

            level.getMovementSystem().changePosition(posComp, posComp.startingX, posComp.startingY, false, false);

            TimerComponent timeComp = ( TimerComponent )this.getComponent(GlobalVars.TIMER_COMPONENT_NAME);

            timeComp.clearAllTimers();

            SmushComponent smushComp = ( SmushComponent )this.getComponent(GlobalVars.SMUSH_COMPONENT_NAME);

            smushComp.setHasInitializedTimer(false);
        }
Ejemplo n.º 9
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));
        }
Ejemplo n.º 10
0
 private void startRise(VelocityComponent velComp, SmushComponent smushComp)
 {
     //Console.WriteLine("Setting " + velComp + " vel to " + smushComp.getRiseSpeed());
     velComp.setVelocity(smushComp.getRiseSpeed());
     smushComp.setStateRise();
 }
Ejemplo n.º 11
0
 private void startFall(VelocityComponent velComp, SmushComponent smushComp)
 {
     velComp.setVelocity(smushComp.getFallSpeed());
     smushComp.setStateFall();
 }