Esempio n. 1
0
        /// <summary>
        /// Default Constructor
        /// </summary>
        public InteractivePlotSurface2D() : base()
        {
            // Set up control
            canvas = new plotControl();

            // Now link the event handlers into the plotControl events
            canvas.SizeChanged += new EventHandler(SizeChanged);
            canvas.Paint       += new PaintEventHandler(OnPaint);
            canvas.MouseEnter  += new EventHandler(MouseEnter);
            canvas.MouseLeave  += new EventHandler(MouseLeave);
            canvas.MouseDown   += new MouseEventHandler(ButtonPress);
            canvas.MouseMove   += new MouseEventHandler(MotionNotify);
            canvas.MouseUp     += new MouseEventHandler(ButtonRelease);
            canvas.MouseWheel  += new MouseEventHandler(ScrollNotify);
            canvas.KeyDown     += new KeyEventHandler(KeyDown);
            canvas.KeyUp       += new KeyEventHandler(KeyUp);

            canvas.BackColor = System.Drawing.SystemColors.ControlLightLight;
            canvas.Size      = new System.Drawing.Size(328, 272); // initial size

            this.components_  = new System.ComponentModel.Container();
            this.coordinates_ = new System.Windows.Forms.ToolTip(this.components_);

            coordinates_.SetToolTip(this.Canvas, "Coordinates will display here");
        }
        /// <summary>
        /// Default Constructor
        /// </summary>
        public InteractivePlotSurface2D()
            : base()
        {
            // Set up control
            canvas = new plotControl();

            // Now link the event handlers into the plotControl events
            canvas.SizeChanged  += new EventHandler         (SizeChanged);
            canvas.Paint        += new PaintEventHandler    (OnPaint);
            canvas.MouseEnter   += new EventHandler         (MouseEnter);
            canvas.MouseLeave   += new EventHandler         (MouseLeave);
            canvas.MouseDown    += new MouseEventHandler    (ButtonPress);
            canvas.MouseMove    += new MouseEventHandler    (MotionNotify);
            canvas.MouseUp      += new MouseEventHandler    (ButtonRelease);
            canvas.MouseWheel   += new MouseEventHandler    (ScrollNotify);
            canvas.KeyDown      += new KeyEventHandler      (KeyDown);
            canvas.KeyUp        += new KeyEventHandler      (KeyUp);

            canvas.BackColor = System.Drawing.SystemColors.ControlLightLight;
            canvas.Size = new System.Drawing.Size (328, 272);   // initial size

            this.components_ = new System.ComponentModel.Container();
            this.coordinates_ = new System.Windows.Forms.ToolTip(this.components_);

            coordinates_.SetToolTip (this.Canvas, "Coordinates will display here");
        }
Esempio n. 3
0
    private InHand Interact()
    {
        Ray lookAt = new Ray(transform.position, transform.forward);

        Debug.DrawRay(lookAt.origin, 15 * lookAt.direction, Color.red, 5);
        RaycastHit info;

        //the Array only works if it is in the range of 'raycastRange'
        if (Physics.Raycast(lookAt, out info, raycastRange))
        {
            BarellController barrell = info.collider.GetComponent <BarellController>();
            if (barrell)//if it has the script 'PlantsController' do this
            {
                if (currently_Holding == InHand.Empty)
                {
                    BarellController.PlantType pickingUP = barrell.pickUp();

                    switch (pickingUP)
                    {
                    case BarellController.PlantType.Carrot:
                        return(InHand.Carrot_Seeds);

                    case BarellController.PlantType.Tomatoe:
                        return(InHand.Tomatoe_Seeds);
                    }
                }
            }

            plotControl plot = info.collider.GetComponent <plotControl>();
            if (plot)
            {
                //Seed planting
                if (currently_Holding == InHand.Carrot_Seeds || currently_Holding == InHand.Tomatoe_Seeds)
                {
                    if (plot.plotIs == plotControl.PlotState.Soil)
                    {
                        plot.InteractP2(currently_Holding);
                        return(InHand.Empty);
                    }
                }

                //plucker for removing the rubbish (grass)
                if (currently_Holding == InHand.Plucker)
                {
                    if (plot.plotIs == plotControl.PlotState.Rubbish)
                    {
                        plot.InteractP2(currently_Holding);
                        return(InHand.Plucker);
                    }
                }

                //Once the plant is grown (tomato)
                if (currently_Holding == InHand.Empty)
                {
                    if (plot.plotIs == plotControl.PlotState.Tomatoe_Plant)
                    {
                        plot.InteractP2(currently_Holding);
                        return(InHand.Tomatoes);
                    }
                }

                //Once the plant is grown (carrots) (so that the player could pick up the item)
                if (currently_Holding == InHand.Empty)
                {
                    if (plot.plotIs == plotControl.PlotState.Carrot_Plant)
                    {
                        plot.InteractP2(currently_Holding);
                        return(InHand.Carrots);
                    }
                }
            }

            TrashController trash = info.collider.GetComponent <TrashController>();
            if (trash)
            {
                return(InHand.Empty);
            }

            PluckerControl plucker = info.collider.GetComponent <PluckerControl>();
            if (plucker)
            {
                if (currently_Holding == InHand.Empty)
                {
                    return(InHand.Plucker);
                }
            }

            TableController table = info.collider.GetComponent <TableController>();
            if (table)
            {
                if (currently_Holding == InHand.Empty)
                {
                    if (table.SomethingOnTable())
                    {
                        GameObject item = table.removeTopItem();
                        //add the script to the tomato and carrots prefab and add it to the table, + delete an extra table
                        VegControl newplant = item.GetComponent <VegControl>();
                        if (newplant)
                        {
                            switch (newplant.thisIsA)
                            {
                            case VegControl.VegType.Carrot:


                                return(InHand.Carrots);

                            case VegControl.VegType.Tomatoe:


                                return(InHand.Tomatoes);
                            }
                        }
                    }
                }



                else
                {
                    if (currently_Holding == InHand.Carrots)
                    {
                        table.putCarrotOn();
                        return(InHand.Empty);
                    }

                    if (currently_Holding == InHand.Tomatoes)
                    {
                        table.putTomatoOn();
                        return(InHand.Empty);
                    }
                }
            }



            P2WagonController wagon = info.collider.GetComponent <P2WagonController>();
            if (wagon)
            {
                if (currently_Holding == InHand.Carrots)
                {
                    wagon.putCarrotOn();
                    return(InHand.Empty);
                }

                if (currently_Holding == InHand.Tomatoes)
                {
                    wagon.putTomatoOn();
                    return(InHand.Empty);
                }
            }


            PlayerController playerHit = info.collider.GetComponent <PlayerController>();
            if (playerHit)
            {
                GameObject player1;


                if (currently_Holding == InHand.Plucker)
                {
                    if (player1 = GameObject.FindWithTag("Player1"))
                    {
                        player1.transform.position = new Vector3(playerHit.transform.position.x, transform.position.y + 7, transform.position.z);
                    }
                }
            }
        }

        return(currently_Holding);
    }