Exemplo n.º 1
0
 public bool collides(string type, Vector2 location, float rotation, out Component collidedWith, string filter)
 {
     //Debug.Print("==========================================");
     foreach (Component component in components)
     {
         if (filter == "NONE" || component.tag.Equals(filter))
         {
             //make sure it is not colliding with parent or other child
             Component otherChild = null;
             if (current.hasRight()) { otherChild = current.rightChild; }
             else if (current.hasLeft()) { otherChild = current.leftChild; }
             //Debug.Print("{0},{1},{2}", !current.Equals(component), !component.Equals(otherChild), !component.intersects(hitboxes[type], location, rotation));
             if (!current.Equals(component) && !component.Equals(otherChild))
             {
                 //Debug.Print("{0},{1}", component.tag, type);
                 if (component.intersects(hitboxes[type], location, rotation))
                 {
                     collidedWith = component;
                     return true;
                 }
             }
         }
     }
     collidedWith = null;
     return false;
 }
Exemplo n.º 2
0
 public Arm(string tag, Rectangle hand, Rectangle arm, Component leaf, Vector2 start, Playing playing)
 {
     this.tag = tag;
     this.hand = hand;
     this.arm = arm;
     this.destination = leaf.location;
     this.leaf = leaf;
     this.location = start;
     this.origin = location;
     this.rotation = (float)Math.Atan2(destination.Y - location.Y, destination.X - location.X);
     this.speed = rotation;
     this.playing = playing;
 }
Exemplo n.º 3
0
        public Component setRight(string type)
        {
            if (this.rightChild != null) { throw new ArgumentException("INVALID RIGHT ADD"); }

            Tuple<Vector2, float> local = this.getRightLocation();
            bool terminal = true;
            if (type.Equals("smallBranch") || type.Equals("bigBranch")) { terminal = false; }
            this.rightChild = new Component(this, type, Playing.parts[type], local.Item2, local.Item1, terminal);
            return rightChild;
        }
Exemplo n.º 4
0
 public void addRight(Component component)
 {
     rightChild = component;
 }
Exemplo n.º 5
0
 public void addLeft(Component component)
 {
     leftChild = component;
 }
Exemplo n.º 6
0
 public Component(Component parent, string tag, Rectangle sprite, float rotation, Vector2 location, bool terminal)
 {
     this.sprite = sprite;
     this.rotation = rotation;
     this.location = location;
     this.tag = tag;
     this.terminal = terminal;
     this.parent = parent;
 }
Exemplo n.º 7
0
        public void update(GameTime gameTime)
        {
            KeyboardState state = Keyboard.GetState();
            if (state.IsKeyDown(Keys.Escape)) { Menu = true; paused = true; createCounter = 0; }

            if (Menu)
            {
                if (state.IsKeyDown(Keys.Z)) { Menu = false; paused = false; }
                if (paused && state.IsKeyDown(Keys.C)) { this.reset(); Menu = false; paused = false; createCounter = 0; }
            }
            else if (!End)
            {
                if (leaves.Count < 1) { End = true; }
                for (int i = 0; i < arms.Count; i++)
                {
                    if (arms[i].tobedeleted) { arms.RemoveAt(i); i--; }
                }
                for (int i = 0; i < thorns.Count; i++)
                {
                    if (thorns[i].tobedeleted) { thorns.RemoveAt(i); i--; }
                }
                if (devTimer > 1000) { DEV = !DEV; devTimer = 0; }

                if (DEV)
                {
                    current = components[compIndex % components.Count];

                    if (createCounter >= 320 && state.IsKeyDown(Keys.D1))
                    {
                        components.Add(new Component(null, string.Format("smallBranch-{0}", components.FindAll(a => a.tag.Split('-')[0].Equals("smallBranch")).Count), smallBranch, 0f, ZERO, false));
                        createCounter = 0;
                        compIndex = components.Count - 1;
                    }
                    if (createCounter >= 320 && state.IsKeyDown(Keys.D2))
                    {
                        components.Add(new Component(null, string.Format("thorn-{0}", components.FindAll(a => a.tag.Split('-')[0].Equals("thorn")).Count), thorn, 0f, ZERO, false));
                        createCounter = 0;
                        compIndex = components.Count - 1;
                    }
                    if (createCounter >= 320 && state.IsKeyDown(Keys.D3))
                    {
                        components.Add(new Component(null, string.Format("plant-{0}", components.FindAll(a => a.tag.Split('-')[0].Equals("plant")).Count), plant, 0f, ZERO, false));
                        createCounter = 0;
                        compIndex = components.Count - 1;
                    }
                    if (createCounter >= 320 && state.IsKeyDown(Keys.D4))
                    {
                        components.Add(new Component(null, string.Format("bigBranch-{0}", components.FindAll(a => a.tag.Split('-')[0].Equals("bigBranch")).Count), bigBranch, 0f, ZERO, false));
                        createCounter = 0;
                        compIndex = components.Count - 1;
                    }

                    if (tabCounter >= 120 && state.IsKeyDown(Keys.Tab)) { compIndex++; tabCounter = 0; }
                    if (tabCounter < 120) { tabCounter += gameTime.ElapsedGameTime.Milliseconds; }
                    if (createCounter < 320) { createCounter += gameTime.ElapsedGameTime.Milliseconds; }

                    if (state.IsKeyDown(Keys.W)) { current.location.Y -= 1; }
                    if (state.IsKeyDown(Keys.A)) { current.location.X -= 1; }
                    if (state.IsKeyDown(Keys.D)) { current.location.X += 1; }
                    if (state.IsKeyDown(Keys.S)) { current.location.Y += 1; }
                    if (state.IsKeyDown(Keys.Q)) { current.rotation -= .02f; }
                    if (state.IsKeyDown(Keys.E)) { current.rotation += .02f; }
                }
                else if (!Choosing)
                {
                    if (tabCounter < 120) { tabCounter += gameTime.ElapsedGameTime.Milliseconds; }
                    if (createCounter < 320) { createCounter += gameTime.ElapsedGameTime.Milliseconds; }

                    if (createCounter >= 320 && state.IsKeyDown(Keys.Z))
                    {
                        if (current.hasLeft()) { current = current.leftChild; }
                        else if (!current.terminal)
                        {
                            Choosing = true;
                            setChild = current.setLeft;
                            getLocation = current.getLeftLocation;
                            tempDraw = parts[partString[choiceIndex]];
                            /*
                            components.Add(current.setLeft("bigBranch"));
                            current = components[0];
                            createCounter = 0;
                            */
                        }
                        else
                        {
                            current = components[0];
                        }
                        createCounter = 0;
                    }
                    if (createCounter >= 320 && state.IsKeyDown(Keys.C))
                    {
                        if (current.hasRight()) { current = current.rightChild; }
                        else if (!current.terminal)
                        {
                            Choosing = true;
                            setChild = current.setRight;
                            getLocation = current.getRightLocation;
                            tempDraw = parts[partString[choiceIndex]];
                            /*
                            components.Add(current.setRight("bigBranch"));
                            current = components[0];
                            createCounter = 0;
                            */
                        }
                        else
                        {
                            current = components[0];
                        }
                        createCounter = 0;
                    }
                }
                if (Choosing)
                {
                    if (createCounter < 320) { createCounter += gameTime.ElapsedGameTime.Milliseconds; }

                    if (state.IsKeyDown(Keys.Z) && createCounter >= 320)
                    {
                        Component collidedWith;
                        if (!collides(partString[choiceIndex], getLocation().Item1, getLocation().Item2, out collidedWith, "NONE"))
                        {
                            components.Add(setChild(partString[choiceIndex]));
                            if (partString[choiceIndex].Equals("leaf")) { leaves.Add(components[components.Count - 1]); growth++; }
                            else if (partString[choiceIndex].Equals("thorn")) { thorns.Add(components[components.Count - 1]); }

                            Color color = new Color(rand.Next(0, 255), rand.Next(0, 255), rand.Next(0, 255), 255);
                            foreach (Tuple<Vector2, Vector2> line in Component.getLines(hitboxes[partString[choiceIndex]], getLocation().Item1, getLocation().Item2))
                            {
                                lines.Add(new Tuple<Vector2, Vector2, Color>(line.Item1, line.Item2, color));
                            }

                        }
                        Choosing = false;
                        current = components[0];
                        choiceIndex = 0;
                        createCounter = 0;
                    }
                    else if (state.IsKeyDown(Keys.C) && createCounter >= 320)
                    {
                        choiceIndex++;
                        choiceIndex = choiceIndex % (parts.Count - 1);
                        tempDraw = parts[partString[choiceIndex]];
                        createCounter = 0;
                    }
                }

                foreach (Arm arm in arms)
                {
                    arm.update();
                    Component collidedWith;
                    if (!arm.retreating && collides(arm.tag, arm.location, arm.rotation, out collidedWith, "thorn"))
                    {
                        try
                        {
                            dropThorn(collidedWith);
                            arm.retreat();
                            break;
                        }
                        catch (Exception)
                        {
                            break;
                        }
                    }
                    /*
                    foreach (Component thorn in thorns)
                    {
                        if (thorn.intersects(arm.hand, arm.location, arm.rotation))
                        {
                            dropThorn(thorn);
                            arm.retreat();
                            break;
                        }
                    }*/
                }

                armTimer += gameTime.ElapsedGameTime.Milliseconds;
                if (armTimer > newArm - leaves.Count * 400 && leaves.Count > 0)
                {
                    newArm -= 400;
                    Random rand = new Random();
                    int ind = rand.Next(0, 2);
                    switch (ind)
                    {
                        case 0:
                            {
                                arms.Add(new Arm("hand1", hand1, arm1, leaves[rand.Next(0, leaves.Count)], armSpawns[rand.Next(0, armSpawns.Count)], this));
                                break;
                            }
                        case 1:
                            {
                                arms.Add(new Arm("hand2", hand2, arm2, leaves[rand.Next(0, leaves.Count)], armSpawns[rand.Next(0, armSpawns.Count)], this));
                                break;
                            }
                    }
                    armTimer = 0;
                }

                for (int i = 0; i < droppingLeaves.Count; i++)
                {
                    droppingLeaves[i].location.Y += 4;
                    if (droppingLeaves[i].location.Y > 780) { droppingLeaves.RemoveAt(i); i--; }
                }
            }
            else
            {
                if (state.IsKeyDown(Keys.Z))
                {
                    this.reset();
                    this.End = false;
                }
            }
        }
Exemplo n.º 8
0
        public void populate()
        {
            components.Add(new Component(null, "trunk", trunk, 0f, new Vector2(567, 432), false));
            components.Add(new Component(components[0], "bigBranch", bigBranch, -.22f, new Vector2(642, 576), false));
            components.Add(new Component(components[0], "smallBranch", smallBranch, -2.84f, new Vector2(633, 651), false));
            components[0].rightChild = components[1];
            components[0].leftChild = components[2];
            components.Add(components[2].setLeft("leaf"));
            components.Add(components[1].setRight("leaf"));
            leaves.Add(components[3]);
            leaves.Add(components[4]);
            components.Add(new Component(null, "plant", plant, 0f, new Vector2(28, 654), false));

            current = components[0];
        }
Exemplo n.º 9
0
 public void dropThorn(Component thorn)
 {
     if (thorn.parent.hasLeft() && thorn.parent.leftChild.Equals(thorn)) { thorn.parent.leftChild = null; }
     else { thorn.parent.rightChild = null; }
     thorns.Remove(thorn);
     thorn.parent = null;
     droppingLeaves.Add(thorn);
 }
Exemplo n.º 10
0
 public void dropLeaf(Component leaf)
 {
     if (leaf.parent.hasLeft() && leaf.parent.leftChild.Equals(leaf)) { leaf.parent.leftChild = null; components.Add(leaf.parent.setLeft("twig")); }
     else { leaf.parent.rightChild = null; components.Add(leaf.parent.setRight("twig")); }
     leaves.Remove(leaf);
     leaf.parent = null;
     droppingLeaves.Add(leaf);
 }