Esempio n. 1
0
        /// <summary>
        /// Places the obsticles that appear on the bottom onto the map
        /// </summary>
        public void createBottomObsticles()
        {
            //value defaulted to zero
            int value = 0;

            //place all the obsticles in obsticleList
            foreach (Obsticle obsticle in _obsticleOnBottomList)
            {
                //get the height of obsticles to place pipe tops
                double height = placeObsticles(obsticle);
                //flip obstilce
                obsticle.getObsticle.RenderTransformOrigin = new Point(1, 1);
                ScaleTransform flipObsticle = new ScaleTransform();
                flipObsticle.ScaleY = -1;
                //set the location of the obsticle
                int left = Difficulty.s_obsticleDistance * value + 500;
                obsticle.setLocation(left, _map.ActualHeight - (obsticle.getObsticle.ActualHeight));
                value++;
                //create pipe tops
                _bottomPipeTops = new Obsticle(_canvas, _hoothoot);
                _bottomPipeTops.createSize(75, 30);
                _bottomPipeTops.setLocation(left - 12.5, _map.ActualHeight - height);
                //flip pipe tops
                _bottomPipeTops.getObsticle.RenderTransformOrigin = new Point(1, 1);
                ScaleTransform flipPipeTop = new ScaleTransform();
                flipPipeTop.ScaleY = -1;
                //add pipe tops to pipeTopList
                _bottomPipeTopsList.Add(_bottomPipeTops);
            }
        }
Esempio n. 2
0
 public void CalculateLogic()
 {
     var player = ScoreCounter.Instance().GetPlayer();
     CurrentPosition++;
     if (CurrentPosition % 10 == 0)
     {
         var newObsticle = new Obsticle();
         newObsticle.Position.X = Rand.Next(Globals.X_MAX_BOARD_SIZE-1);
         Ui.Instance().AddDrawableItem(newObsticle);
         AddItem(newObsticle);
     }
     var carPozition = player != null ? ((ILocation)player.Car) : null;
     foreach (var aiObject in AiObjects)
     {
         if (aiObject is IObsticle && carPozition != null)
         {
             var obsticle = (IObsticle) aiObject;
             if (obsticle.Position.X-2 <= carPozition.Position.X && obsticle.Position.X + 2 >= carPozition.Position.X
                 && obsticle.Position.Y+1 >= carPozition.Position.Y && obsticle.Position.Y <= carPozition.Position.Y+5)
             {
                 if (Console.BackgroundColor == ConsoleColor.White)
                 {
                     ScoreCounter.Instance().GetHighScores();
                 }
                 Console.BackgroundColor = Console.BackgroundColor == ConsoleColor.Blue ? ConsoleColor.Red : ConsoleColor.Blue;
             }
             else if (Console.BackgroundColor == ConsoleColor.White)
             {
                 ScoreCounter.Instance().UpdateScore(player.Car, player);
             }
         }
         aiObject.Move();
     }
 }
Esempio n. 3
0
    private void ReadInput()
    {
        if (EventSystem.current.IsPointerOverGameObject())
        {
            return;
        }

        if (Input.GetMouseButtonDown(0))
        {
            RaycastHit hit = GetHit();
            _start   = hit.point;
            _current = hit.transform.GetComponent <Obsticle>();
        }

        if (Input.GetMouseButtonUp(0))
        {
            _end = GetHit().point;
            if (_current != null)
            {
                if (CheckDistance())
                {
                    Vector3 direction = CalculateDirection();
                    _current.SwipeAway(direction);
                }
            }

            _current = null;
        }
    }
Esempio n. 4
0
 public void restart()
 {
     for (int i = 0; i < rock.Length; i++)
     {
         rock[i] = new Obsticle(new Vector2(1920 + spaceBetweenPillers * i, 0));
     }
 }
Esempio n. 5
0
        public override void update()
        {
            if (!isLive)
            {
                return;
            }

            Obsticle closest = closestObst();
            ///for some reason the training is extremely fast WITHOUT input normalization
            float dx = (float)(closest.XRight() - X()) / Global.winWidth,
                  dy = (float)(closest.hatchYCenter() - YCenter()) / Global.winHeight,
                  vy = this.vy / Global.winHeight;

            ///feed values to the network
            float[] input = new float[] { dx, dy, vy };
            ///procces output and play accourdingly
            double prob = brain.GetOutput(input)[0];

            if (prob >= 0.5)
            {
                jump();
            }
            ///update bird
            movmentManager();
            CheckCollitions();
        }
Esempio n. 6
0
        protected override void LoadContent()
        {
            spriteBatch      = new SpriteBatch(GraphicsDevice);
            Global.cm        = Content;
            Global.sb        = spriteBatch;
            Global.winHeight = 1080;
            Global.winWidth  = 1920;

            Texture2D obstTex     = Content.Load <Texture2D>("Textures/pillerSample");
            Texture2D bgTex       = Content.Load <Texture2D>("Textures/background2");
            Texture2D gameOverTex = Content.Load <Texture2D>("Textures/gameOver");

            Obsticle.initStaticMembers(bgTex, obstTex);
            rock = new Obsticle[2];

            int gameOverMenuXpos = winWidth / 2 - gameOverTex.Width / 2;

            spaceBetweenPillers = winWidth / rock.Length;

            //jumpSound = Content.Load<SoundEffect>("Audio/wma/jumpSound");

            gameOverMenu = new Drawable(gameOverTex, new Vector2(gameOverMenuXpos, 200));
            bg           = new Drawable(bgTex, new Vector2(0, 0));
            score        = new Score(Content.Load <Texture2D>("Textures/digits"), gameOverTex);
            bird         = new Bird();


            for (int i = 0; i < rock.Length; i++)
            {
                rock[i] = new Obsticle(new Vector2(1920 + spaceBetweenPillers * i, 0));
            }

            ///needs to be called with the rest of the game initialized
            GeneticAlgorithm.Initiate();
        }
 private bool CheckIntersection(Position character, int characterSize, Obsticle obsticle)
 {
     b2.X      = obsticle.Corner1.X;
     b2.Y      = obsticle.Corner1.Y;
     b2.Width  = obsticle.Corner2.X;
     b2.Height = obsticle.Corner2.Y;
     return(CheckIntersection(character, characterSize, b2));
 }
Esempio n. 8
0
 private void Restart()
 {
     GeneticAlgorithm.CreateNextGen();
     InitBirds();
     for (int i = 0; i < rock.Length; i++)
     {
         rock[i] = new Obsticle(new Vector2(1920 + spaceBetweenPillers * i, 0));
     }
 }
Esempio n. 9
0
 private void Restart()
 {
     for (int i = 0; i < rock.Length; i++)
     {
         rock[i] = new Obsticle(new Vector2(1920 + spaceBetweenPillers * i, 0));
     }
     bird.setPosition(new Vector2(300, 500));
     setGame(gameFlow.startMenu);
     score.reset();
 }
Esempio n. 10
0
        public Screen()
        {
            SquareA = new Walls(60, 30, 0, 0, '#', ConsoleColor.DarkCyan);
            light   = new Light(new Pixel(20, 20, 'O', ConsoleColor.Cyan), '.', ConsoleColor.DarkYellow);

            obsticle = new Obsticle('%', ConsoleColor.Green);
            obsticle.AddLineBody(new Pixel(33, 6), new Pixel(10, 20));
            obsticle.AddLineBody(new Pixel(53, 20), new Pixel(20, 20));
            obsticle.AddLineBody(new Pixel(13, 47), new Pixel(30, 20));
        }
    public bool addCharacterObsticle(int x, int z, int radius, int characterobjid)
    {
        Obsticle obs        = new Obsticle(x, z, radius, characterobjid);
        bool     isblocking = isBlocking(obs);

        if (!isblocking)
        {
            charaterobsticles.Add(obs);
        }

        return(isblocking);
    }
Esempio n. 12
0
 public bool crashed(Obsticle rock)
 {
     Rectangle[] bird = GetBirdRects();
     Rectangle[] obst = rock.GetObsticleRects();
     for (int i = 0; i < bird.Length; i++)
     {
         if (bird[i].Intersects(obst[0]) || bird[i].Intersects(obst[1]))
         {
             return(true);
         }
     }
     return(false);
 }
 public void insertObsticle(Obsticle obsticle)
 {
     for (int z = obsticle.z - obsticle.radius; z <= obsticle.z + obsticle.radius; z++)
     {
         for (int x = obsticle.x - obsticle.radius; x <= obsticle.x + obsticle.radius; x++)
         {
             if (!isoutoofbound(x, z))
             {
                 this.arr [z, x] = -2;
             }
         }
     }
 }
Esempio n. 14
0
        /// <summary>
        /// Place obsticles on the map based on the difficulty
        /// </summary>
        /// <param name="obsticle"></param>
        /// <returns></returns>
        public int placeObsticles(Obsticle obsticle)
        {
            //if easy
            if (Difficulty.s_difficultyChoice == 1)
            {
                //set the max length equal to 1/4 of height of map
                double modifier = _map.ActualHeight / 4;
                int    easy     = (int)modifier;
                //set the obsticle height to a random value
                int _obstHeight = _randomizer.Next(easy);
                obsticle.createSize(50, _obstHeight);
                //set the start location of the obsticles
                obsticle.setLocation(0, 0);
                //return obsticle height
                return(_obstHeight);
            }
            //if medium
            else if (Difficulty.s_difficultyChoice == 2)
            {
                //set the max length equal to 1/3 of height of map
                double modifier = _map.ActualHeight / 3;
                int    medium   = (int)modifier;
                //set the obsticle height to a random value
                int _obstHeight = _randomizer.Next(medium);
                obsticle.createSize(50, _obstHeight);
                //set the start location of the obsticles
                obsticle.setLocation(0, 0);
                //return obsticle height
                return(_obstHeight);
            }
            //if hard
            else if (Difficulty.s_difficultyChoice == 3)
            {
                //set the max length equal to 1/2 of height of map +/- height of hoothoot

                double modifier = (_map.ActualHeight / 2) - 40;
                int    hard     = (int)modifier;
                //set the obsticle height to a random value

                int _obstHeight = _randomizer.Next(hard);
                obsticle.createSize(50, _obstHeight);
                //set the start location of the obsticles

                obsticle.setLocation(0, 0);
                //return obsticle height
                return(_obstHeight);
            }

            return(_obstHeight);
        }
    public bool isBlocking(Obsticle obsticle)
    {
        for (int z = obsticle.z - obsticle.radius; z <= obsticle.z + obsticle.radius; z++)
        {
            for (int x = obsticle.x - obsticle.radius; x <= obsticle.x + obsticle.radius; x++)
            {
                if (goalx == x && goalz == z)
                {
                    return(true);
                }
            }
        }

        return(false);
    }
Esempio n. 16
0
    protected Obsticle closestObst()
    {
        int      dx = 2000, temp = 0;
        Obsticle rock = null;

        foreach (Obsticle obst in Global.rock)
        {
            temp = obst.XRight() - X(); ///bird.X and obst.XRight so when bird is inside the rock it is still considered the closest
            if (temp < dx && temp > 0)  ///closest but still in front of the bird
            {
                dx   = temp;
                rock = obst;
            }
        }
        return(rock);
    }
        private void DrawObsticle(Control.ControlCollection Controls, Obsticle o)
        {
            PictureBox obsticle = new PictureBox();

            ((ISupportInitialize)(obsticle)).BeginInit();
            obsticle.BackColor = Color.MidnightBlue;
            obsticle.Location  = new Point(o.Corner1.X, o.Corner1.Y);
            obsticle.Size      = new Size(o.Corner2.X, o.Corner2.Y);

            /*
             * obsticle.TabIndex = 0;
             * obsticle.Name = "pictureBox1";
             * obsticle.TabStop = false;
             * obsticle.Tag = "wall";
             */
            Controls.Add(obsticle);
            ((ISupportInitialize)(obsticle)).EndInit();
        }
Esempio n. 18
0
        public override void update()
        {
            Obsticle closest = closestObst();
            double   dx      = (float)(closest.XRight() - X()) / Global.winWidth,
                     dy      = (float)(closest.hatchYCenter() - YCenter()) / Global.winHeight,
                     vy      = this.vy / Global.winHeight;
            ///feed values to the network
            Vector <double> input = Vector <double> .Build.DenseOfArray(new double[] { dx, dy, vy });

            ///procces output and play accourdingly
            double prob = brain.feedNet(input)[0];

            if (prob >= 0.5)
            {
                jump();
            }
            ///update bird
            movmentManager();
            CheckCollitions();
        }
Esempio n. 19
0
    public override Vector3 Steer()
    {
        Vector3  antenna = vehicle.Velocity * maxAhead;
        Obsticle threat  = null;
        Vector3  nearesPointToObsticle = Vector3.zero;

        for (int i = 0; i < Obsticles.Length; i++)
        {
            var   o             = Obsticles[i];
            var   pos           = transform.position;
            var   toObsticle    = o.Position - pos;
            float percOnAntenna = (Vector3.Dot(antenna, toObsticle)) / antenna.sqrMagnitude;
            if (percOnAntenna < 0f || percOnAntenna > 1f)
            {
                continue;
            }
            var nearestOnAtenna = pos + antenna * percOnAntenna;
            nearesPointToObsticle = o.Position - nearestOnAtenna;
            var sqrRadius = o.Radius * o.Radius;
            if (sqrRadius > nearesPointToObsticle.sqrMagnitude)
            {
                if (threat == null || toObsticle.sqrMagnitude < (threat.Position - pos).sqrMagnitude)
                {
                    threat = o;
                }
            }
        }
        if (threat != null)
        {
            //var desired = antenna - threat.Position;
            //desired = desired.normalized * vehicle.MaxSpeed;
            //var steer = Vector3.ClampMagnitude (desired - vehicle.Velocity, vehicle.MaxForce) * threat.Radius;
            var desired = -nearesPointToObsticle * (nearesPointToObsticle.magnitude + threat.Radius * 2f);
            var steer   = desired - vehicle.Velocity;
            return(steer);
        }
        else
        {
            return(Vector3.zero);
        }
    }
Esempio n. 20
0
        /// <summary>
        /// Place the obsticle that appear on top onto the map
        /// </summary>
        public void createTopObsticles()
        {
            //value defaulted to zero
            int value = 0;

            //place all the obsticles in obsticleList
            foreach (Obsticle obsticle in _obsticleOnTopList)
            {
                //get the height of obsticles to place pipe tops
                double height = placeObsticles(obsticle);
                //set the location of the obsticle
                int left = Difficulty.s_obsticleDistance * value + 500;
                obsticle.setLocation(left, 0);
                value++;
                //create pipe tops
                _topPipeTops = new Obsticle(_canvas, _hoothoot);
                _topPipeTops.createSize(75, 30);
                _topPipeTops.setLocation(left - 12.5, height);
                //add pipe tops to pipeTopList
                _topPipeTopsList.Add(_topPipeTops);
            }
        }
        void Init(string[] args)
        {
            Board           = new Obsticle();
            Board.Corner2.X = 320 + 10;
            Board.Corner2.Y = 280 + 10;
            Board.Corner1.X = 0;
            Board.Corner1.Y = 40;

            _pId = args[0];
            string myURL = args[1];
            int    mSec  = int.Parse(args[2]);

            _maxNumPlayers = int.Parse(args[3]);

            if (args.Length == 6 && args[4].Equals("secondary"))
            {
                PCSurl          = args[5];
                PCS             = (IServicePCS)Activator.GetObject(typeof(IServicePCS), PCSurl);
                _secondary      = true;
                waitFail        = GetGamePrimaryServer;
                _primary_server = (IServiceServer)Activator.GetObject(typeof(IServiceServer), myURL);
                _timer          = new System.Timers.Timer()
                {
                    AutoReset = true, Enabled = false, Interval = 3000
                };
                _timer.Elapsed += Timer_Elapsed_Secondary;
                _timer.Start();
                lock (this)
                {
                    Console.WriteLine("Secondary Server Mode : Waiting for primary server " + _pId + " to fail...");
                    Monitor.Wait(this);
                    //Console.WriteLine("_last size  = " + _last.Length);
                    Console.WriteLine("Primary Server Failed... Taking Control");
                    _game              = (Game)_last[0];
                    _clientsDict       = (Dictionary <string, IServiceClient>)_last[1];
                    _clientsList       = (List <Client>)_last[2];
                    _lastRoundReceived = (Dictionary <string, int>)_last[3];
                    _lastRoundSaved    = (Dictionary <string, int>)_last[4];
                    client_queue       = (Queue)_last[5];

                    // do this to unregister the channel
                    IChannel[] regChannels = ChannelServices.RegisteredChannels;
                    foreach (IChannel ch in regChannels)
                    {
                        Console.WriteLine("CHANNEL : " + ch.ChannelName);
                        if (ch.ChannelName.Equals("tcp"))
                        {
                            ChannelServices.UnregisterChannel(ch);
                        }
                    }
                }
                _timer.Stop();
                _timer.Close();
            }
            waitClients = WaitEnqueuedClients;
            _timer      = new System.Timers.Timer()
            {
                AutoReset = true, Enabled = false, Interval = mSec
            };
            _timer.Elapsed += Timer_Elapsed;
            if (_secondary)
            {
                Console.WriteLine("Starting...");
                _timer.Start();
            }
            waitClients.BeginInvoke(null, null);

            lock (this)
            {
                /* set channel */
                try
                {
                    channel = new TcpChannel(int.Parse(Shared.Shared.ParseUrl(URLparts.Port, myURL)));
                    ChannelServices.RegisterChannel(channel, false);
                    /*set service */
                    serviceServer = new ServiceServer(this, delays);
                    string link = Shared.Shared.ParseUrl(URLparts.Link, myURL);
                    Console.WriteLine("Starting server on " + myURL + ", link: " + link);
                    RemotingServices.Marshal(serviceServer, link);
                }
                catch
                {
                    Console.WriteLine("CATCH!!!! COULD NOT REGISTER SECONDARY SERVER, PRIMARY IS PROBABLY STILL RUNNING");
                }
            }
            if (_secondary)
            {
                string programArguments = _pId + " " + myURL + " " + mSec + " " + _maxNumPlayers;
                PCS.StartSecondaryServer(programArguments);
                _secondary = false;
            }
            while (true)
            {
                Console.ReadLine();
            }
        }
Esempio n. 22
0
 public override IDrawable CreateNegativeInstance(Coordinates coordinates)
 {
     var negativeInstance = new Obsticle();
     return negativeInstance;
 }