Ejemplo n.º 1
0
        private void addDrop(Point whereToSpawn, string type)
        {
            ContentControl buff = new ContentControl();         //temporary drop ContentControl

            buff.Template = Resources[type] as ControlTemplate; //set a template for it
            playArea.Children.Add(buff);                        //add it to the screen
            Canvas.SetBottom(buff, whereToSpawn.Y);             //set where it should start (y)
            Canvas.SetLeft(buff, whereToSpawn.X);               //set where it should start(x)
            drops tempDrop;

            switch (type)
            {
            case "scoreBuff":
                tempDrop = new drops(buff, type, 500);
                break;

            case "ballBuff":
                int?numOfBalls = (int?)(rand.NextDouble() * 3);
                numOfBalls++;
                tempDrop = new drops(buff, type, null, null, null, null, numOfBalls);
                break;

            default:
                tempDrop = new drops(buff, type, 500);
                break;
            }
            //Hvis droppet så er et buff drop eller et debuff drop, så sender du et buff eller debuff objekt med når du instantierer objektet som ovenfor..
            dropList.Add(tempDrop);//add it to the dropList
        }
Ejemplo n.º 2
0
    public string getDrop()
    {
        drops powerup = (drops)Random.Range(0, drops.GetValues(typeof(drops)).Length);

        while (powerup.ToString() == lastPowerups[1] && powerup.ToString() == lastPowerups[0])
        {
            powerup = (drops)Random.Range(0, drops.GetValues(typeof(drops)).Length);
        }

        lastPowerups[1] = lastPowerups[0];
        lastPowerups[0] = powerup.ToString();
        Debug.Log(lastPowerups[0] + " " + lastPowerups[1]);
        return(powerup.ToString());
    }
Ejemplo n.º 3
0
        void mainLoop_Tick(object sender, EventArgs e)//bliver kørt 50 gange i sekundet
        {
            foreach (player playerClass in playerList)
            {
                //fetch variables from the playerclass
                int            playerMovementSpeed = playerClass.speed;
                ContentControl playerBlock         = playerClass.playerBlock;
                int            playerNumber        = playerClass.playerNumber;

                //player controls
                if (playerNumber == 1)                                               //local player
                {
                    if (Keyboard.IsKeyDown(Key.Left) || (Keyboard.IsKeyDown(Key.A))) //move left
                    {
                        playerClass.move("LEFT");
                    }
                    if (Keyboard.IsKeyDown(Key.Right) || (Keyboard.IsKeyDown(Key.D)))//move right
                    {
                        playerClass.move("RIGHT");
                    }
                }
                //ball controls
                for (int ballindex = 0; ballindex < ballList.Count; ballindex++)
                {
                    ball ballClass = ballList[ballindex];
                    //get the variables from the ballclass
                    ContentControl ball1      = ballClass.ballObject;
                    int            xdirection = ballClass.xdirection;
                    int            ydirection = ballClass.ydirection;
                    double         xspeed     = ballClass.xspeed;
                    double         yspeed     = ballClass.yspeed;
                    double         ballspeed  = ballClass.ballSpeed;

                    if (Canvas.GetLeft(ball1) >= (playArea.ActualWidth - ball1.ActualWidth))//hvis bolden rammer højre side
                    {
                        xdirection = -1;
                    }
                    if (Canvas.GetLeft(ball1) <= 0)// hvis bolden rammer venstre side
                    {
                        xdirection = 1;
                    }
                    if (Canvas.GetBottom(ball1) <= 0)//ball hits buttom
                    {
                        playArea.Children.Remove(ball1);
                        ballList.RemoveAt(ballindex);
                        ydirection = -1;
                    }
                    if (Canvas.GetBottom(ball1) >= playArea.ActualHeight)//hvis bolden rammer toppen
                    {
                        ydirection = 1;
                    }

                    if (Canvas.GetBottom(ball1) <= 10 + playerBlock.ActualHeight && Canvas.GetBottom(ball1) >= 10)//ball player hittest
                    {
                        if ((Canvas.GetLeft(ball1) >= Canvas.GetLeft(playerBlock)) && (Canvas.GetLeft(ball1) <= Canvas.GetLeft(playerBlock) + playerBlock.ActualWidth))
                        {
                            //find ud af hvor bolden rammer playerblocken
                            double v1 = ((Canvas.GetLeft(ball1) + ball1.ActualWidth / 2) - Canvas.GetLeft(playerBlock));
                            double v2 = ((Canvas.GetLeft(playerBlock) + playerBlock.ActualWidth / 2) - Canvas.GetLeft(playerBlock));
                            v1     -= v2;
                            xspeed  = v1 / v2;
                            xspeed *= ballspeed; //gang forholdet med boldens hastighed
                            if (xspeed < 0)      //hvis bolden ramte playerblockens venstre side
                            {
                                xspeed     = -xspeed;
                                xdirection = -1;//få bolden til at bevæge sig mod venstre
                            }
                            else
                            {//ellers bevæg den mod højre
                                xdirection = 1;
                            }
                            if (xspeed > ballspeed - 0.5) //hvis bolden bevæger sig for hurtigt vandret(og ikke efterlader noget af boldens max hastighed til y-hastigheden)
                            {
                                xspeed = ballspeed - 0.5; //så sænk dens x-hastighed til et maximum, 0.5 mindre end boldens totale max hastighed
                            }
                            yspeed = ballspeed - xspeed;  //y hastighed udregnes ud fra boldens max hastighed og dens x hastighed
                            if (yspeed < 0)               //dont go negative
                            {
                                yspeed = -yspeed;
                            }

                            ydirection = -1; //bevæg bolden opad nu
                        }
                    }
                    for (int i = 0; i < enemyBlockList.Count(); i++)                                             //loop igennem hver enemyBlock i enemyBlockList'en
                    {
                        double ballTop = playArea.ActualHeight - (Canvas.GetBottom(ball1) + ball1.ActualHeight); //boldenes position bliver sat via "SetBottom"
                        //så de har ikke nogen "getTop" der kunne bruges, så udregn hvad dens "top" ville være.
                        if (ballTop >= Canvas.GetTop(enemyBlockList[i]) && ballTop <= (Canvas.GetTop(enemyBlockList[i]) + enemyBlockList[i].ActualHeight))
                        {         //dens top er indenfor enemy'ens "top plus dens højde" område.
                            if (Canvas.GetLeft(ball1) >= Canvas.GetLeft(enemyBlockList[i]) && (Canvas.GetLeft(ball1) + ball1.ActualWidth) <= (Canvas.GetLeft(enemyBlockList[i]) + enemyBlockList[i].ActualWidth))
                            {     //dens left er indefor enemy'ens "left plus dens bredde" område
                                if (ydirection == 1)
                                { //bevæg dig op hvis du er på vej ned
                                    ydirection = -1;
                                }
                                else
                                {//ellers gå nedad
                                    ydirection = 1;
                                }
                                death(enemyBlockList[i], 100);
                            }
                        }
                    }
                    Canvas.SetBottom(ball1, (Canvas.GetBottom(ball1) - (yspeed * ydirection))); //flyt bolden
                    Canvas.SetLeft(ball1, (Canvas.GetLeft(ball1) + (xspeed * xdirection)));     //flyt bolden

                    //change the values of the ballClass to the ones calculated in this loop
                    ballClass.xdirection = xdirection;
                    ballClass.ydirection = ydirection;
                    ballClass.xspeed     = xspeed;
                    ballClass.yspeed     = yspeed;
                    ballClass.ballSpeed  = ballspeed;
                }
                //drop hit-testing
                for (int i = 0; i < dropList.Count; i++)
                {
                    drops          drop    = dropList[i];
                    ContentControl dropObj = drop.DropObject;
                    if (Canvas.GetBottom(dropObj) <= 10 + playerBlock.ActualHeight && Canvas.GetBottom(dropObj) >= 10)//drop player hittest
                    {
                        if ((Canvas.GetLeft(dropObj) >= Canvas.GetLeft(playerBlock)) && (Canvas.GetLeft(dropObj) <= Canvas.GetLeft(playerBlock) + playerBlock.ActualWidth))
                        {
                            switch (drop.hitPlayer())
                            {
                            case "BUFF":
                                break;

                            case "DEBUFF":
                                break;

                            case "POINTBONUS":
                                score += (int)drop.Points;
                                playArea.Children.Remove(dropObj);
                                dropList.Remove(drop);
                                break;

                            case "LIFEBONUS":
                                break;

                            case "BALLBUFF":
                                for (int i2 = 0; i2 < drop.ballBuff; i2++)
                                {
                                    addNewBall();
                                }
                                break;
                            }
                        }
                    }
                    if (Canvas.GetBottom(dropObj) <= 0)
                    {
                        playArea.Children.Remove(dropObj);
                        dropList.Remove(drop);
                    }
                    Canvas.SetBottom(dropObj, Canvas.GetBottom(dropObj) - drop.dropSpeed);
                }
            }
            //enemy movement downwards
            foreach (ContentControl enemy in enemyBlockList)                     //for all enemies
            {
                Canvas.SetTop(enemy, Canvas.GetTop(enemy) + enemyMovementSpeed); //move a bit downward, depending on their movementspeed
                if (Canvas.GetTop(enemy) >= playArea.ActualHeight)
                {
                    playerDied();
                }
            }
            if (spawnCounter >= spawnInterval)
            {//spawn some enemies hvis du har ventet nok ticks
                addEnemyLine();
                //addNewBall();
                spawnCounter = 0; //reset spawncounteren
            }
            //test if player is dead
            if (ballList.Count == 0)           //if there are no more balls
            {
                playerDied();                  //player dies
            }
            spawnCounter++;                    //another tick went by
            ScoreText.Text = score.ToString(); //update the score textblock
        }
Ejemplo n.º 4
0
 private void addDrop(Point whereToSpawn, string type)
 {
     ContentControl buff = new ContentControl();//temporary drop ContentControl
     buff.Template = Resources[type] as ControlTemplate;//set a template for it
     playArea.Children.Add(buff);//add it to the screen
     Canvas.SetBottom(buff, whereToSpawn.Y);//set where it should start (y)
     Canvas.SetLeft(buff, whereToSpawn.X);//set where it should start(x)
     drops tempDrop;
     switch(type){
         case "scoreBuff":
             tempDrop = new drops(buff, type, 500);
             break;
         case "ballBuff":
             int? numOfBalls = (int?)(rand.NextDouble() * 3);
             numOfBalls++;
             tempDrop = new drops(buff, type, null, null, null, null, numOfBalls);
             break;
         default:
             tempDrop = new drops(buff, type, 500);
             break;
     }
     //Hvis droppet så er et buff drop eller et debuff drop, så sender du et buff eller debuff objekt med når du instantierer objektet som ovenfor..
     dropList.Add(tempDrop);//add it to the dropList
 }
Ejemplo n.º 5
0
    public static sprop copysprop(sprop aprop)
    {

        if (aprop is wire)
        {
            sprop.wire returner2 = new sprop.wire();
            returner2.name = aprop.name;
            return returner2;
        }
        if (aprop is interact)
        {
            sprop.interact gelec = aprop as interact;
            sprop.interact returner2 = new sprop.interact();
            returner2.name = gelec.name;
            returner2.abool = gelec.abool;
            return returner2;
        }
        if (aprop is oxgen)
        {
            sprop.oxgen gelec = aprop as oxgen;
            sprop.oxgen returner2 = new sprop.oxgen();
            returner2.name = aprop.name;
            returner2.range = gelec.range;
            return returner2;
        }
        if (aprop is elec)
        {
            sprop.elec gelec = aprop as elec;
            sprop.elec returner2 = new sprop.elec(0);
            returner2.name = aprop.name;
            returner2.maxpower = gelec.maxpower;
            returner2.energyoutput = gelec.energyoutput;
            returner2.energyuse = gelec.energyuse;
            returner2.maxbuffer = gelec.maxbuffer;
            returner2.buffer = gelec.buffer;
            returner2.intake = gelec.intake;
            returner2.loss = gelec.loss;
            for (int k = 0; k < 6; k++)
            {
                returner2.connected[k] = gelec.connected[k];
            }
            foreach (int anint in gelec.connecteddef)
            {
                returner2.connecteddef.Add(anint);
            }
            return returner2;
        }
        if (aprop is mech)
        {
            sprop.mech gelec = aprop as mech;
            sprop.mech returner2 = new sprop.mech(gelec.load, gelec.production,gelec.maxprod,gelec.convratio);
            returner2.name = aprop.name;
            for (int k = 0; k < 6; k++)
            {
                returner2.connected[k] = gelec.connected[k];
            }
            foreach (int anint in gelec.connecteddef)
            {
                returner2.connecteddef.Add(anint);
            }
            return returner2;
        }
        if (aprop is gun)
        {
            sprop.gun gelec = aprop as gun;
            sprop.gun returner2 = new sprop.gun();
            returner2.name = aprop.name;
            returner2.range = gelec.range;
            returner2.stamp = gelec.stamp;
            returner2.reset = gelec.reset;
            return returner2;
        }
        if (aprop is vals)
        {
            vals gvals = aprop as vals;
            vals returner2 = new vals();
            returner2.name = aprop.name;
            returner2.vstring = gvals.vstring;
            returner2.vfloat = gvals.vfloat;
            returner2.vint = gvals.vint;
            returner2.vVector3 = gvals.vVector3;
            returner2.vbool = gvals.vbool;
            return returner2;
        }
        if (aprop is invs)
        {
            invs ginvs = aprop as invs;
            invs returner2 = new invs(ginvs.aninv.inv.Length);
            for (int k = 0; k < ginvs.aninv.inv.Length; k++)
            {
                returner2.aninv.inv[k] = new Inventory.InvItem();
            }
            returner2.aninv.protectsuction = ginvs.aninv.protectsuction;
            return returner2;
        }
        if (aprop is rawinvs)
        {
            rawinvs ginvs = aprop as rawinvs;
            rawinvs returner2 = new rawinvs(ginvs.aninv.maxmass);
            returner2.aninv.protectsuction = ginvs.aninv.protectsuction;
            foreach (RawInv.rawlibitem anint in ginvs.aninv.inv)
            {
                returner2.aninv.add(anint.id, anint.kg);
            }

            return returner2;
        }
        if (aprop is drops)
        {
            drops ginvs = aprop as drops;
            drops returner2 = new drops();
            returner2.aninv.protectsuction = ginvs.aninv.protectsuction;
            foreach (RawInv.rawlibitem anint in ginvs.aninv.inv)
            {
                returner2.aninv.add(anint.id, anint.kg);
            }

            return returner2;
        }
        if (aprop is craft)
        {
            craft ginvs = aprop as craft;
            craft returner2 = new craft(ginvs.RecipeList);

            returner2.vint = ginvs.vint;
            returner2.vfloat = ginvs.vfloat;
            returner2.vfloat2 = ginvs.vfloat2;

            foreach (int anint in ginvs.autos)
            {
                returner2.autos.Add(anint);
            }


            foreach (RawInv.rawlibitem anint in ginvs.ResultRaw)
            {
                returner2.ResultRaw.Add(new RawInv.rawlibitem(anint.id, anint.kg));
            }
            foreach (Inventory.InvItem anint in ginvs.Result)
            {
                returner2.Result.Add(new Inventory.InvItem(anint.socket,anint.num));
            }

            return returner2;
        }
        
        
        sprop returner = new sprop();

        returner.name = aprop.name;

        return returner;
    }