Ejemplo n.º 1
0
 public Fireballshot(double x, double y, BaseObj owner, bool dir = false)
     : base(x, y)
 {
     this.name = "Fireballshot";
     this.texture = Texture.fireballshot;
     this.x = x;
     this.y = y;
     this.w = 8;
     this.h = 8;
     this.owner = owner;
     if (owner.name == "Player")   //Check who spawned the fireball and set its harming accordingly
         harmPlayers=false;
     this.dir = dir;
     this.colWithOthers = true;
 }
Ejemplo n.º 2
0
        public static bool col_circleRect(double circleX, double circleY, double circleR, BaseObj.ColRect rect)
        {
            Point circleDistance = new Point();
            circleDistance.x = Math.Abs(circleX - rect.x);
            circleDistance.y = Math.Abs(circleY - rect.y);

            if (circleDistance.x > (rect.w / 2 + circleR)) { return false; }
            if (circleDistance.y > (rect.h / 2 + circleR)) { return false; }

            if (circleDistance.x <= (rect.w / 2)) { return true; }
            if (circleDistance.y <= (rect.h / 2)) { return true; }

            double cornerDistance_sq = (circleDistance.x - rect.w / 2) * (circleDistance.x - rect.w / 2) +
                                        (circleDistance.y - rect.h / 2) * (circleDistance.y - rect.h / 2);

            return (cornerDistance_sq <= (circleR * circleR));
        }
Ejemplo n.º 3
0
        public void processWarp(BaseObj warpSprite)
        {
            //wartoWarp metaData:
            //====================
            //metaData["warpId"]        warpId int
            //metaData["isEntrance"]    isEntrance True or False    (True=Entrance, False=Exit)
            //metaData["warpType"]      type 0-2                    (0=Pipe, 1=Door, 2=Instant)
            //metaData["warpDir"]       direction 0-3               (0=Moving Right, 1=Moving Down, 2=Moving Left, 3=Moving Up)

            canWarpRight = false;
            canWarpDown = false;
            canWarpLeft = false;
            canWarpUp = false;
            canWarpDoor = false;
            canWarpObjStart = null;
            switch (int.Parse(warpSprite.metaData["warpType"]))
            {
                case 0:     //Pipes
                    {
                        switch (int.Parse(warpSprite.metaData["warpDir"]))
                        {
                            case 0:
                            default: if (onGround) canWarpRight = true; canWarpObjStart = warpSprite; break;
                            case 1: if (onGround) canWarpDown = true; canWarpObjStart = warpSprite; break;
                            case 2: if (onGround) canWarpLeft = true; canWarpObjStart = warpSprite; break;
                            case 3: canWarpUp = true; canWarpObjStart = warpSprite; break;
                        }
                    }
                    break;
                case 1:
                    {
                        canWarpDoor = true;
                        canWarpObjStart = warpSprite;
                    }
                    break;
            }
        }
Ejemplo n.º 4
0
        public override void doSubAI()
        {
            refreshColRect();
            getColGrid();
            var keyboard = RootThingy.keyboard;

            /////////////////////////////////////// ('T' = Key active ; 'F' = Key inactive ; '-' = get Key value fom keyboard)
            /////////////////////////////////////// Up-Key
            if (metaData["Control"][0] == 'T')
                upBtn = true;
            if (metaData["Control"][0] == 'F')
                upBtn = false;
            if (metaData["Control"][0] == '-')
            { upBtn = keyboard[upBtnK];}
            /////////////////////////////////////// Down-Key
            if (metaData["Control"][1] == 'T')
                downBtn = true;
            if (metaData["Control"][1] == 'F')
                downBtn = false;
            if (metaData["Control"][1] == '-')
            { downBtn = keyboard[downBtnK];}
            /////////////////////////////////////// Left-Key
            if (metaData["Control"][2] == 'T')
                leftBtn = true;
            if (metaData["Control"][2] == 'F')
                leftBtn = false;
            if (metaData["Control"][2] == '-')
            { leftBtn = keyboard[leftBtnK];}
            /////////////////////////////////////// Right-Key
            if (metaData["Control"][3] == 'T')
                rightBtn = true;
            if (metaData["Control"][3] == 'F')
                rightBtn = false;
            if (metaData["Control"][3] == '-')
            { rightBtn = keyboard[rightBtnK];}
            /////////////////////////////////////// Run/Shoot-Key
            if (metaData["Control"][4] == 'T')
                RunShootBtn = true;
            if (metaData["Control"][4] == 'F')
                RunShootBtn = false;
            if (metaData["Control"][4] == '-')
            { RunShootBtn = keyboard[RunShootBtnK];}
            /////////////////////////////////////// Jump-Key
            if (metaData["Control"][5] == 'T')
                jumpBtn = true;
            if (metaData["Control"][5] == 'F')
                jumpBtn = false;
            if (metaData["Control"][5] == '-')
            { jumpBtn = keyboard[jumpBtnK];}
            /////////////////////////////////////// SpinJump-Key
            if (metaData["Control"][6] == 'T')
                spinjumpBtn = true;
            if (metaData["Control"][6] == 'F')
                spinjumpBtn = false;
            if (metaData["Control"][6] == '-')
            { spinjumpBtn = keyboard[spinjumpBtnK];}

            if (keyboard[upBtnK])
                metaData["Control2"] = "T------";
            if (downBtn)
                metaData["Control2"] = "-T-----";
            if (leftBtn)
                metaData["Control2"] = "--T----";
            if (rightBtn)
                metaData["Control2"] = "---T---";
            if (RunShootBtn)
                metaData["Control2"] = "----T--";
            if (jumpBtn)
                metaData["Control2"] = "-----T-";
            if (spinjumpBtn)
                metaData["Control2"] = "------T";

            this.setMessage("Hallo ich bin der Mario, und mein Ziel isses die Peach zu befreien. Die hängt wahscheinlich schonwieder bei Bowser ab... mmmm");

            if (keyboard[Key.Enter])
                this.showMessage();

            if (upBtn && colTop != 1)
            { ; }

            if (downBtn)
            {
                state = 18;
            }

            if (leftBtn && getColXY((int)x - 1, (int)y + (h / 2)) != 1)
            {
                if (xVel > 0)    //direction != Inputdirection means skidding / breaking
                {
                    if (pMeter < 112)  //walking
                        xVel -= xWalkSkidDecel;
                    else if (pMeter >= 112)    //running / sprinting
                        xVel -= xRunSkidDecel;
                    state = 4;  //Skidding (frame 4)
                }
                if (xVel <= 0)
                    dir = true;
                if (dir == true)    //direction == Inputdirection means Acceleration
                {
                    if (pMeter >= 112)
                    {
                        if (RunShootBtn)  //Player presses run-button
                        {
                            xVel -= xAccel;
                            if (xVel < sprintVelMax * -1)    //
                            {
                                xVel = sprintVelMax * -1;    //Limit to sprintspeed
                                state = 3;  //Sprinting (frames 6,7)
                            }
                        }
                        pMeter = 112;
                    }
                    else
                    {
                        xVel -= xAccel;
                        if (xVel < walkVelMax * -1)    //
                        {
                            xVel = walkVelMax * -1;    //Limit to walkspeed
                            state = 2;  //Walking (frames 2,3)
                        }
                    }
                }
                pMeter += 2;
            }

            if (rightBtn && getColXY((int)x + w + 1, (int)y + (h / 2)) != 1)
            {
                if (xVel < 0)    //direction != Inputdirection means skidding / breaking
                {
                    if (pMeter < 112)  //walking
                        xVel += xWalkSkidDecel;
                    else if (pMeter >= 112)    //running / sprinting
                        xVel += xRunSkidDecel;
                    state = 4;  //Skidding (frame 4)
                }
                if (xVel >= 0)
                    dir = false;
                if (dir == false)    //direction == Inputdirection means Acceleration
                {
                    if (pMeter >= 112)
                    {
                        if (RunShootBtn)  //Player presses run-button
                        {
                            xVel += xAccel;
                            if (xVel > sprintVelMax)    //
                            {
                                xVel = sprintVelMax;    //Limit to sprintspeed
                                state = 3;  //Sprinting (frames 6,7)
                            }
                        }
                        pMeter = 112;
                    }
                    else
                    {
                        xVel += xAccel;
                        if (xVel > walkVelMax)    //
                        {
                            xVel = walkVelMax;    //Limit to walkspeed
                            state = 2;  //Walking (frames 2,3)
                        }
                    }
                }
                pMeter += 2;
            }

            if (!rightBtn && !leftBtn)
            {
                if (colBottom == 1)     //on ground
                {
                    if (xVel > 0)
                        xVel -= xDecel;
                    if (xVel < 0)
                        xVel += xDecel;
                }
                else                    //in Air (no friction
                {
                    if (xVel > 0)
                        xVel -= xDecel;
                    if (xVel < 0)
                        xVel += xDecel;
                }
                pMeter -= 2;
                if (pMeter < 0)
                    pMeter = 0;
            }

            if ((jumpBtn || spinjumpBtn))//&& !falling)
            {
                if (jmpTimer <= 8 && canJmp)      //
                {                       //jump Velocity is incresed for max 8 frames
                    jmpTimer++;         //by jump-Acceleration
                    yVel -= jmpAccel;   //
                    if (jumpBtn && !spinjumping)
                    {
                        spinjumping = false; jumping = true;
                        if (state == 3) //sprinting ?
                            state = 8;  // -> sprintjump
                        if ((state == 1) || (state == 2) || (state == 4) || (state == 9) || (state == 13))
                            state = 5;
                    }
                    if (spinjumpBtn)
                    {
                        spinjumping = true;
                        jumping = false;
                        state = 6;
                    }
                    canJmp = true;
                    falling = false;
                    onGround = false;
                }
                else
                { canJmp = false; jmpTimer = 0; }
            }

            if (keyboard.IsKeyUp(spinjumpBtnK) && spinjumping)
            {
                jmpTimer = 0; canJmp = false;
                //if(stateArr[state][frame]!=null)
                //    dir = stateArr[state][frame].flipV;
            }
            if (keyboard.IsKeyUp(jumpBtnK) && jumping)
            {
                jmpTimer = 0; canJmp = false;
            }

            ////////////////////////////////////////////////////////Warp-Handling
            //wartoWarp metaData:
            //====================
            //metaData["warpId"]        warpId int
            //metaData["isEntrance"]    isEntrance True or False    (True=Entrance, False=Exit)
            //metaData["warpType"]      type 0-2                    (0=Pipe, 1=Door, 2=Instant)
            //metaData["warpDir"]       direction 0-3               (0=Moving Right, 1=Moving Down, 2=Moving Left, 3=Moving Up)
            if (canWarpRight || canWarpDown || canWarpLeft || canWarpUp || canWarpDoor)
            {
                for (int i = 0; i != Map.spriteArrMax; i++)
                {
                    if (Map.spriteArray[i] != null)
                    {
                        if ((canWarpObjStart.metaData["warpId"] == Map.spriteArray[i].metaData["warpId"]) &&
                            (canWarpObjStart.metaData["isEntrance"] != Map.spriteArray[i].metaData["isEntrance"]) &&
                            (Map.spriteArray[i].id != this.id))
                        {
                            this.canWarpObjEnd = Map.spriteArray[i];
                        }
                    }
                }
                if (keyboard.IsKeyDown(rightBtnK))
                {
                    invulnerable = true;
                    isWarping = true;
                    warpState = false;
                }
                if (keyboard.IsKeyDown(downBtnK))
                {
                    invulnerable = true;
                    isWarping = true;
                    warpState = false;
                }
                if (keyboard.IsKeyDown(leftBtnK))
                {
                    invulnerable = true;
                    isWarping = true;
                    warpState = false;
                }
                if (keyboard.IsKeyDown(upBtnK))
                {
                    if (canWarpDoor)
                    {
                        invulnerable = true;
                        isWarping = true;
                        warpState = false;
                    }
                    if (keyboard.IsKeyDown(spinjumpBtnK | jumpBtnK) && canWarpUp)
                    {
                        invulnerable = true;
                        isWarping = true;
                        warpState = true;
                    }
                }
            }

            if (warpState == false && isWarping == true)    //Is warping and entering
            {
                if (canWarpObjEnd != null && canWarpObjStart.metaData["warpType"] == "0")  //type Pipe
                {
                    switch (int.Parse(canWarpObjStart.metaData["warpDir"]))
                    {
                        case 0: //warp Right
                            if (x <= canWarpObjStart.x + canWarpObjStart.w)
                                x++;
                            else
                                warpState = true;
                            break;
                        case 1: //warp Down
                            if (y <= canWarpObjStart.y + canWarpObjStart.h)
                                y++;
                            else
                                warpState = true;
                            break;
                        case 2: //warp Left
                            if (x + w >= canWarpObjStart.x)
                                x--;
                            else
                                warpState = true;
                            break;
                        case 3: //warp Up
                            if (y + h >= canWarpObjStart.y)
                                y--;
                            else
                                warpState = true;
                            break;
                    }
                }
                if (canWarpObjStart.metaData["warpType"] == "1")  //type Door
                {
                    setXY(canWarpObjEnd.x, canWarpObjEnd.y);
                    warpState = false;
                    canWarpObjEnd = null;
                    isWarping = false;
                }
            }
            if (warpState == true && isWarping == true)    //Is warping and exiting
            {
                if (canWarpObjEnd != null && canWarpObjEnd.metaData["warpType"] == "0")  //type Pipe
                {
                    switch (int.Parse(canWarpObjEnd.metaData["warpDir"]))
                    {
                        case 0: //warp Right
                            if (x <= canWarpObjEnd.x)
                                x++;
                            else
                            { warpState = false; isWarping = false; }
                            break;
                        case 1: //warp Down
                            if (y <= canWarpObjEnd.y)
                                y++;
                            else
                            { warpState = false; isWarping = false; }
                            break;
                        case 2: //warp Left
                            if (x + w >= canWarpObjEnd.x)
                                x--;
                            else
                            { warpState = false; isWarping = false; }
                            break;
                        case 3: //warp Up
                            if (y + h >= canWarpObjEnd.y)
                                y--;
                            else
                            { warpState = false; isWarping = false; }
                            break;
                    }
                }
            }
            canWarpRight = false;
            canWarpDown = false;
            canWarpLeft = false;
            canWarpUp = false;
            canWarpDoor = false;

            ////////////////////////////////////////////////////////End Warp-Handling

            if (RunShootBtn)
            {
                if (shotCoolDown == 0 && keyboard.IsKeyDown(RunShootBtnK) && power == 2)
                {
                    Map.spriteAdd(new Fireballshot(x, y, this, stateArr[state][frame].flipV ^ dir));
                    shotCoolDown = 5;//30
                }
                //This code is for item-grabbing
                for (int i = 0; i != Map.spriteArrMax; i++)
                {
                    if ((Map.spriteArray[i] != null) && ((getCol2Obj(Map.spriteArray[i].colRect, this.colRect) && Map.spriteArray[i].grabable) ||   // not null && colliding && grabable ?
                        (Map.spriteArray[i].id == grabbedItemId)))
                    {
                        grabbedItemId = Map.spriteArray[i].id;
                        this.grabbedItem_ColBlocksTemp = Map.spriteArray[grabbedItemId].colWithBlocks;
                        Map.spriteArray[grabbedItemId].colWithBlocks = false;
                        this.grabbedItem_ColOthersTemp = Map.spriteArray[grabbedItemId].colWithOthers;
                        Map.spriteArray[grabbedItemId].colWithOthers = false;
                        this.grabbedItem_despawnOffScreen = Map.spriteArray[grabbedItemId].despawnOffScreen;
                        Map.spriteArray[grabbedItemId].despawnOffScreen = false;
                    }
                }

            }
            else  //this throws a grabed item
            {
                if (grabbedItemId != -1)
                {
                    short throwDir = 0;
                    if (dir)    //Left
                    { throwDir = -1; }
                    else        //Right
                    { throwDir = 1; }

                    if (upBtn || downBtn)
                    {
                        if (upBtn)
                        {
                            Map.spriteArray[grabbedItemId].setXYVel(this.xVel, -6);
                            Map.spriteArray[grabbedItemId].metaData["kicked"] = "";
                            Map.spriteArray[grabbedItemId].colWithBlocks = this.grabbedItem_ColBlocksTemp;
                            Map.spriteArray[grabbedItemId].colWithOthers = this.grabbedItem_ColOthersTemp;
                            Map.spriteArray[grabbedItemId].despawnOffScreen = this.grabbedItem_despawnOffScreen;
                            grabbedItemId = -1;
                        }
                        if (downBtn)
                        {
                            Map.spriteArray[grabbedItemId].setXYVel(this.xVel + (throwDir * 0.25), -0.5);
                            Map.spriteArray[grabbedItemId].metaData["kicked"] = "";
                            Map.spriteArray[grabbedItemId].colWithBlocks = this.grabbedItem_ColBlocksTemp;
                            Map.spriteArray[grabbedItemId].colWithOthers = this.grabbedItem_ColOthersTemp;
                            Map.spriteArray[grabbedItemId].despawnOffScreen = this.grabbedItem_despawnOffScreen;
                            grabbedItemId = -1;
                        }
                    }
                    else
                    {
                        Map.spriteArray[grabbedItemId].setXYVel(this.xVel + (throwDir * 2.7), -0.5);
                        Map.spriteArray[grabbedItemId].metaData["kicked"] = "kicked";
                        Map.spriteArray[grabbedItemId].colWithBlocks = this.grabbedItem_ColBlocksTemp;
                        Map.spriteArray[grabbedItemId].colWithOthers = this.grabbedItem_ColOthersTemp;
                        Map.spriteArray[grabbedItemId].despawnOffScreen = this.grabbedItem_despawnOffScreen;
                        grabbedItemId = -1;
                    }
                }
            }

            if (grabbedItemId != -1)
            {
                Map.spriteArray[grabbedItemId].setXYVel(this.xVel, this.yVel);
                if (dir) //Left
                {
                    Map.spriteArray[grabbedItemId].setXY(colRect.x - Map.spriteArray[grabbedItemId].colRect.w, colRect.y + colRect.h - Map.spriteArray[grabbedItemId].colRect.h-2);
                    Map.spriteArray[grabbedItemId].dir = this.dir;
                }
                else
                {
                    Map.spriteArray[grabbedItemId].setXY(colRect.x + colRect.w, colRect.y + colRect.h - Map.spriteArray[grabbedItemId].colRect.h-2);
                    Map.spriteArray[grabbedItemId].dir = this.dir;
                }
            }

            if (shotCoolDown > 0 && keyboard.IsKeyUp(RunShootBtnK))
                shotCoolDown--;

            if ((falling && !onGround))  //in Air
            {                           //let gravity decrease it again
                yVel += Map.gravity;    //
                if (yVel > yVelMax)
                    yVel = yVelMax;
                jmpTimer = 0;
                falling = true;
                jumping = false;
            }

            if ((xVel < 0 && xVel > -xDecel) || (xVel > 0 && xVel < xDecel))    //
            { xVel = 0; }                                                       //Delete minimalistic double rests that let you never really stop
            //if ((yVel < 0 && yVel > xDecel) || (yVel > 0 && yVel < xDecel))     //
            //{yVel = 0;}                                                         //

            if (xVel == 0 && !jumping && !spinjumping && !falling)     //xVel == 0 means state standing
                state = 1;

            if (getColXY((int)x + (colRect.w / 2), (int)colRect.y + colRect.h + 1) == 1)   //Floor-Collision
            {
                while (colBottom == 1)
                {
                    y--;
                    refreshColRect();
                    getColGrid();
                    yVel = 0;
                }
                if (!jumping && !spinjumping)
                {
                    onGround = true;
                    falling = false;
                    canJmp = true;
                }
                else
                {
                    jumping = false;
                    spinjumping = false;
                    falling = false;
                    canJmp = true;
                }
            }
            else
            {
                onGround = false;
                falling = true;
            }

            if (getColXY((int)colRect.x + (w / 2), (int)colRect.y - 1) == 1)  //Ceiling-Collision
            {
                if (colTop == 1)
                {
                    y++;
                    yVel = 0;
                }

                onGround = false;
                jumping = false;
                falling = true;
                canJmp = false;
            }

            if (getColXY((int)colRect.x + colRect.w + 1, (int)colRect.y + (colRect.h / 2)) == 1)    //Right Wall Collsion
            {
                x--;
                xVel = 0;
            }

            if (getColXY((int)colRect.x - 1, (int)colRect.y + (colRect.h / 2)) == 1)  //Left Wall Collision
            {
                x++;
                xVel = 0;
            }

            if (keyboard[Key.LControl])
                yVel = -7;

            x += xVel;
            y += yVel;

            //get colliding Object and react to them
            for (int i = 0; i != Map.spriteArrMax; i++)
            {
                if (Map.spriteArray[i] != null)
                {
                    if (getCol2Obj(colRect, Map.spriteArray[i].colRect) && this.id != Map.spriteArray[i].id)
                    {
                        Console.WriteLine("Player touches something");
                        switch (Map.spriteArray[i].getName())
                        {
                            case "Coin":
                                getCoin();
                                Map.spriteArray[i].setXY(-100, -100);
                                Map.spriteAdd(new Smb1_getCoin(x, y));
                                break;

                            case "Mushroom":
                                if (power == 0)
                                    setPowerUp_big();
                                Map.spriteArray[i].setXY(-100, -100);
                                break;

                            case "Fireflower":
                                setPowerUp_fire();
                                Map.spriteArray[i].setXY(-100, -100);
                                break;

                            case "Starman":

                                Map.spriteArray[i].setXY(-100, -100);
                                invulnerableTimer = 1800;
                                break;

                            case "OneUp":
                                getLive();
                                Map.spriteArray[i].setXY(-100, -100);
                                break;

                            case "ThreeUp":
                                getLive();
                                getLive();
                                getLive();
                                Map.spriteArray[i].setXY(-100, -100);
                                break;

                            case "PSwitch_b":
                                Map.pSwitchTimer_b = 1800;  //1800 Frames = 30 seconds
                                break;

                            case "WarpToWarp":
                                processWarp(Map.spriteArray[i]);
                                break;

                            case "Mushroom_p":
                            case "Goomba":
                            case "Boo":
                                getDamage();
                                break;
                            default: break;
                        }
                    }
                }
            }

            invulnerable = false;
            if (invulnerableTimer > 0)
            {
                invulnerableTimer--;                        //Creates a Sparkle on a random Position withing the collision-box
                invulnerable = true;
                Map.spriteAdd(new Sparkle(Map.rnd.Next((int)colRect.x, (int)colRect.x + (int)colRect.w + 1) - 4, Map.rnd.Next((int)colRect.y, (int)colRect.y + (int)colRect.h) - 4));
            }
        }
Ejemplo n.º 5
0
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ADD_A_SPRITE
 public static int spriteAdd(BaseObj spriteObj)
 {
     bool done = false;
     int i = 0;
     while (!done && i<=spriteArray.Count())
     {
         if (spriteArray[i] == null)
         {
             spriteArray[i] = spriteObj;
             spriteArray[i].id = i;
             done = true;
             if (i > spriteArrMax)
                 spriteArrMax = i;
         }
         else
         {
             //Console.WriteLine("["+i+"]spriteAdd("+spriteArray[i].getName()+")");
             //Console.ReadKey();
             i++;
         }
     }
     return i;
 }