Esempio n. 1
0
        public void fireItem(Entity e, DirectionalComponent dir)
        {
            TimedShooterComponent timedShooterComp = ( TimedShooterComponent )e.getComponent(GlobalVars.TIMED_SHOOTER_COMPONENT_NAME);
            PositionComponent     posComp          = (PositionComponent)e.getComponent(GlobalVars.POSITION_COMPONENT_NAME);
            ShooterBullet         bullet           = new ShooterBullet(level, level.rand.Next(Int32.MinValue, Int32.MaxValue), posComp.x, posComp.y, dir.getDir(), timedShooterComp.state);
            VelocityComponent     bulletVel        = ( VelocityComponent )bullet.getComponent(GlobalVars.VELOCITY_COMPONENT_NAME);

            float bulletSpeed = 160.0f;

            if (dir.isUp())
            {
                bulletVel.setVelocity(0, -bulletSpeed);
            }
            else if (dir.isRight())
            {
                bulletVel.setVelocity(bulletSpeed, 0);
            }
            else if (dir.isDown())
            {
                bulletVel.setVelocity(0, bulletSpeed);
            }
            else if (dir.isLeft())
            {
                bulletVel.setVelocity(-bulletSpeed, 0);
            }
            level.addEntity(bullet);
        }
Esempio n. 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));
        }