Beispiel #1
0
 protected override void OnLoad(EventArgs e)
 {
     base.OnLoad(e);
     button1 = new CustomButton(new Vector2(818, 440), new RectangleF(0, 0, 64, 36));
     //texture2 = ContentPipe.LoadTexture("Process.png");
     texture2 = ContentPipe.LoadTexture("procesik2.png");
     player   = new Player();
     for (int i = 0; i < 6; i++)
     {
         blocks.Add(new Block());
     }
     piston   = new Piston();
     gripper  = new Gripper();
     conveyor = new Conveyor();
     InitializeSensors();
     conveyor = new Conveyor();
     ControlMode.Init();
 }
Beispiel #2
0
        public static void SetActuators(Player player, Piston piston, Gripper gripper, Conveyor conveyor)
        {
            if (PipeClient.GetOutput("Q0.7"))
            {
                if (!Player.butonik)
                {
                    player.direction     = Player.Direction.A1;
                    player.newPosition.X = Player.firstContainerPosition.X;
                    player.newPosition.Y = player.Position.Y;
                    Player.butonik       = true;
                }
            }

            if (PipeClient.GetOutput("Q1.0"))
            {
                if (!Player.butonik)
                {
                    player.direction     = Player.Direction.A2;
                    player.newPosition.X = Player.secondContainerPosition.X;
                    player.newPosition.Y = player.Position.Y;
                    Player.butonik       = true;
                }
            }

            if (PipeClient.GetOutput("Q0.6"))
            {
                if (!Player.butonik)
                {
                    player.direction     = Player.Direction.A0;
                    player.newPosition.X = Player.startPosition.X;
                    player.newPosition.Y = player.Position.Y;
                    Player.butonik       = true;
                }
            }

            if (PipeClient.GetOutput("Q0.5"))
            {
                if (!Player.butonik)
                {
                    player.direction     = Player.Direction.B1;
                    player.newPosition.X = player.Position.X;
                    player.newPosition.Y = Player.downPosition.Y;
                    Player.butonik       = true;
                }
            }

            if (PipeClient.GetOutput("Q0.4"))
            {
                if (!Player.butonik)
                {
                    player.direction     = Player.Direction.B0;
                    player.newPosition.X = player.Position.X;
                    player.newPosition.Y = Player.startPosition.Y;
                    Player.butonik       = true;
                }
            }

            if (PipeClient.GetOutput("Q0.0"))
            {
                if (!Piston.butonik)
                {
                    piston.direction   = Piston.Direction.A1;
                    piston.newPosition = Piston.endPosition;

                    Piston.butonik = true;
                }
            }

            if (PipeClient.GetOutput("Q0.1"))
            {
                if (!Piston.butonik)
                {
                    piston.direction   = Piston.Direction.A0;
                    piston.newPosition = Piston.startPosition;

                    Piston.butonik = true;
                }
            }

            if (PipeClient.GetOutput("Q0.2"))
            {
                conveyor.state = Conveyor.StateList.Run;
            }

            if (PipeClient.GetOutput("Q0.3"))
            {
                conveyor.state = Conveyor.StateList.Stop;
            }

            if (PipeClient.GetOutput("Q1.1"))
            {
                if (Gripper.isPossibleToChangeState)
                {
                    System.Diagnostics.Debug.WriteLine("opened");
                    gripper.state = Gripper.StateList.Open;
                }
            }

            if (PipeClient.GetOutput("Q1.2"))
            {
                System.Diagnostics.Debug.WriteLine("closed");
                gripper.state = Gripper.StateList.Close;
            }
        }
Beispiel #3
0
        public void Update(Player player, Conveyor conveyor, Gripper gripper, Piston piston, List <Block> blocks)
        {
            if (Position == Block.startPosition)
            {
                direction      = Direction.X1;
                platformIsBusy = true;
            }

            else if (Position == onConveyor)
            {
                direction      = Direction.X2;
                platformIsBusy = false;
            }

            else if (Position == endPosition)
            {
                direction = Direction.Y0;
            }


            Block prevBlock = null;

            switch (this.direction)
            {
            case Direction.X1:
                prevBlock = null;
                for (int i = (blocks.Count - 1); i >= 0; i--)
                {
                    if (this == blocks[0])
                    {
                        Vector2 distance2 = piston.Position - Position + new Vector2(-41, 0);
                        Position += distance2;
                    }
                    else if ((this == blocks[i]))
                    {
                        double x = this.Position.X;
                        double y = this.Position.Y;
                        if (!(x < (blocks[i - 1].Position.X + 41)) && y == blocks[i - 1].Position.Y)
                        {
                            Vector2 distance2 = piston.Position - Position + new Vector2(-41, 0);
                            Position += distance2;
                        }
                        else
                        {
                            if (!blocks[i - 1].locked)
                            {
                                Vector2 distance2 = piston.Position - Position + new Vector2(-41, 0);
                                Position += distance2;
                            }
                            else
                            {
                                //Console.WriteLine("Piston locked");
                                pistonLocked = true;
                            }
                        }
                    }
                }


                for (int i = (blocks.Count - 1); i >= 0; i--)
                {
                    if (prevBlock != null)
                    {
                        double x = prevBlock.Position.X;
                        double y = prevBlock.Position.Y;
                        if ((x < (blocks[i].Position.X + 41)) && y == blocks[i].Position.Y)
                        {
                            if (!blocks[i].locked)
                            {
                                blocks[i].Position = new Vector2(blocks[i].Position.X - 1, blocks[i].Position.Y);
                            }
                        }
                    }
                    prevBlock = blocks[i];
                }
                break;

            case Direction.X2:
                if (conveyor.state == Conveyor.StateList.Run)
                {
                    if (!this.locked)
                    {
                        this.velocity  = new Vector2(1f, 0);
                        this.Position -= velocity;
                    }
                }

                if (CheckCollisionWithGripper(player))
                {
                    locked = true;
                }
                else
                {
                    locked       = false;
                    pistonLocked = false;
                }

                for (int i = (blocks.Count - 1); i >= 0; i--)
                {
                    if ((this == blocks[i]) && (i != 0))
                    {
                        double x = this.Position.X;
                        double y = this.Position.Y;
                        if ((x < (blocks[i - 1].Position.X + 42)) && y == blocks[i - 1].Position.Y)
                        {
                            if (blocks[i - 1].direction == Direction.Y0 || blocks[i - 1].locked)
                            {
                                blocks[i].locked = true;
                            }
                        }
                    }
                }
                break;

            case Direction.Y0:
                if (this.Position != endPosition && !set)
                {
                    set = true;
                }
                else if (this.Position == endPosition && set)
                {
                    set = false;
                }
                if (gripper.state == Gripper.StateList.Close && player.Position == manipulatorPosition)
                {
                    grab = true;
                    //Console.WriteLine("grab = true");
                }
                else if (gripper.state == Gripper.StateList.Open && player.Position == manipulatorPosition)
                {
                    grab = false;
                }
                if (gripper.state == Gripper.StateList.Close && grab)
                {
                    if (!abandon)
                    {
                        Vector2 distance3 = player.Position - this.Position + new Vector2(24, 255);

                        this.Position += distance3;
                    }
                    else
                    {
                        if (this.Position.Y < removeBlockY)
                        {
                            this.Position = new Vector2(Position.X, Position.Y + 1);
                        }
                        else if (this.Position.Y == removeBlockY)
                        {
                            blocks.Remove(this);
                        }
                    }
                }
                else if (gripper.state == Gripper.StateList.Open && grab)
                {
                    abandon = true;
                    if (this.Position.Y < removeBlockY)
                    {
                        Vector2 distance3 = player.Position + this.Position + new Vector2(24, 255) - new Vector2(0, 578);

                        if (distance3.Y < 30)
                        {
                            Player.ManipulatorLocked = true;
                        }
                        else
                        {
                            Player.ManipulatorLocked = false;
                        }

                        this.Position = new Vector2(Position.X, Position.Y + 1);
                    }
                    else if (this.Position.Y == removeBlockY)
                    {
                        blocks.Remove(this);
                    }
                }
                break;

            case Direction.Y1:
                if (piston.Position == Piston.startPosition && !platformIsBusy & !pistonLocked)
                {
                    this.velocity  = new Vector2(0, 1f);
                    this.Position += velocity;
                }
                break;
            }
        }