//adding the chosen objects to the object list
        private void FormLevelEditor_DragDrop(object sender, DragEventArgs e)
        {
            Point p = this.PointToClient(Cursor.Position);

            switch ((ObjectType)e.Data.GetData(typeof(ObjectType)))
            {
            case ObjectType.Finish:
                ObstacleList.RemoveAll((o) => { return(o.GetType() == typeof(Finish)); });
                ObstacleList.Add(new Finish(p.X, p.Y));
                break;

            case ObjectType.Mine:
                ObstacleList.Add(new Mine(p.X, p.Y));
                break;

            case ObjectType.Mud:
                ObstacleList.Add(new Mud(p.X, p.Y));
                break;

            case ObjectType.Rocketlauncher:
                ObstacleList.Add(new Missilelauncher(p.X, p.Y));
                break;

            case ObjectType.Sandbag:
                ObstacleList.Add(new Sandbag(p.X, p.Y));
                break;

            case ObjectType.Tree:
                ObstacleList.Add(new Tree(p.X, p.Y));
                break;
            }
            //MessageBox.Show(string.Format("{0} gedropt at {1}, {2}", (ObjectType)e.Data.GetData(typeof(ObjectType)), p.X, p.Y));
        }
        //managing already placed objects on the gamefield
        private void FormLevelEditor_MouseClick(object sender, MouseEventArgs e)
        {
            Point p = this.PointToClient(Cursor.Position);

            foreach (Obstacle obstacle in ObstacleList)
            {
                if (p.X >= obstacle.x && p.X <= (obstacle.x + obstacle.width) && p.Y >= obstacle.y && p.Y <= (obstacle.y + obstacle.length))
                {
                    currentMovingObject = obstacle;
                }
            }
            if (this.currentMovingObject != null)
            {
                this.movingPoint = new Point(p.X - this.currentMovingObject.x, p.Y - this.currentMovingObject.y);

                if (e.Button == MouseButtons.Left)
                {
                    panelToolBox.Hide();
                }
            }
            if (e.Button == MouseButtons.Right)
            {
                ObstacleList.Remove(currentMovingObject);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 控制场景和障碍物移动
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void timer_SceneMovement_Tick(object sender, EventArgs e)
        {
            //移动背景
            p_bg1.Location = new Point(p_bg1.Location.X - px, 0);
            p_bg2.Location = new Point(p_bg2.Location.X - px, 0);
            if (p_bg1.Location.X + p_bg1.Width <= 0)
            {
                p_bg1.Location = new Point(785, 0);
            }
            else if (p_bg2.Location.X + p_bg2.Width <= 0)
            {
                p_bg2.Location = new Point(785, 0);
            }

            //移动pipe

            for (int i = 0; i < ObstacleList.Count; i++)
            {
                ObstacleList[i].Location = new Point(ObstacleList[i].Location.X - px, ObstacleList[i].Location.Y);

                if (ObstacleList[i].Location.X + ObstacleList[i].Width <= p_Brid.Location.X)//加分
                {
                    Score++;
                    l_Score.Text = Score.ToString();
                }
                if (ObstacleList[i].Location.X + ObstacleList[i].Width <= 0)
                {
                    //ObstacleList[i].RandomLocation(this.Width);
                    this.Controls.Remove(ObstacleList[i]);
                    ObstacleList.Remove(ObstacleList[i]);
                }
            }
        }
    void FixedUpdate()
    {
        //if the current waypoint no longer exists, go to next waypoint,
        //or if no more waypoints don't move
        //added to prevent errors when a waypoint is destroyed.
        if (!waypoints[currentWaypoint])
        {
            if (waypoints.Length > 1)
            {
                waypoints[currentWaypoint] = waypoints[(currentWaypoint < (waypoints.Length - 1)) ? currentWaypoint + 1:0];
            }
            else
            {
                waypoints[currentWaypoint] = new GameObject("Replacement For Destroyed GameObject");
                waypoints[currentWaypoint].transform.position = transform.position;
            }
        }

        ObstacleList obstacleList = DetectObjectsAndAvoid();

        LookForTargetsAndFire(obstacleList);
        Move(obstacleList);
        updateTarget();
        if (debug)
        {
            Debug.Log("Current Obstacle: " + obstacleList);
        }
    }
Ejemplo n.º 5
0
    void FixedUpdate()
    {
        //add radar, and make it send messages
        if (GiveUp())
        {
            lockOn          = false;
            lockOnTimeBegin = 0;
            if (debug && lockOnTarget)
            {
                Debug.Log("Giving Up on " + lockOnTarget.name);
            }
        }
        if (lockOn)
        {
            currentTarget   = lockOnTarget;
            targetLayerMask = targetLayerMaskLockOn;
        }
        else
        {
            currentTarget   = waypoints[currentWaypoint];
            targetLayerMask = 0;
        }
        //if(debug) Debug.Log("target of enemy: "+currentTarget.name);
        ObstacleList obstacleList = DetectObjectsAndAvoid();

        LookForTargetsAndFire(obstacleList);
        Move(obstacleList);
        updateTarget();
        //if(debug) Debug.Log("Current Obstacle: " + obstacleList);
    }
Ejemplo n.º 6
0
        public void TestCollisions(ObstacleList obstacle)
        {
            foreach (var e in obstacle.obstacles)
            {
                obstacleTrueLeft  = e.ObstaclePosition.X;
                obstacleTrueRight = e.ObstaclePosition.X + e.ObstacleTexture.Width;
                obstacleTrueUp    = e.ObstaclePosition.Y - e.ObstacleTexture.Height / 2;
                if (e.ObstaclePosition.X - Player.PlayerTrueRightX < 30 && e.ObstaclePosition.X - Player.PlayerTrueRightX > -30)
                {
                    if ((Player.PlayerTrueRightX > obstacleTrueLeft - 8) &&
                        (Player.PlayerTrueRightX < obstacleTrueLeft + 10) &&
                        (Player.PlayerTrueUpY > obstacleTrueUp + 30))
                    {
                        Player.canMoveRight = false;
                    }
                    else
                    {
                        Player.canMoveRight = true;
                    }
                }


                if (Player.PlayerTrueLeftX - obstacleTrueRight < 20 && Player.PlayerTrueLeftX - obstacleTrueRight > -16)
                {
                    if ((Player.PlayerTrueLeftX > obstacleTrueRight - 10) &&
                        (Player.PlayerTrueLeftX < obstacleTrueRight + 10) &&
                        (Player.PlayerTrueUpY > obstacleTrueUp + 30))
                    {
                        Player.canMoveLeft = false;
                    }
                    else
                    {
                        Player.canMoveLeft = true;
                    }
                }
                if ((Player.PlayerTrueRightX > obstacleTrueLeft + 10) &&
                    (Player.PlayerTrueLeftX < obstacleTrueRight - 10) &&
                    (Player.PlayerTrueUpY > obstacleTrueUp))
                {
                    Player.PlayerPosition.Y = obstacleTrueUp + 25;
                    isTop             = true;
                    Player.timeToFall = 0;
                    Player.isJumping  = false;
                    Player.countJump  = 0;
                }
                else
                {
                    isTop = false;
                }
                if (!isTop && wasTop && Player.PlayerPosition.Y > e.ObstaclePosition.Y - e.ObstacleTexture.Height / 2 + 24)
                {
                    Player.isFalling  = true;
                    Player.timeToFall = 0;
                    Player.isJumping  = false;
                }
                wasTop = isTop;
            }
        }
        //button event for deleting all object from gamefield
        private void buttonNew_MouseClick(object sender, MouseEventArgs e)
        {
            DialogResult result = MessageBox.Show("Are you sure you want to delete all objects?", "Delete objects", MessageBoxButtons.YesNo);

            if (result == DialogResult.Yes)
            {
                ObstacleList.Clear();
            }
        }
Ejemplo n.º 8
0
 void Start()
 {
     for (int i = 0; i < 200; i++)
     {
         int        n        = Random.Range(0, 4) + 1;
         ObstacleVO obstacle = InGameData.Instance.ObstacleList.Find(a => a.Type == n).Copy();
         obstacle.SetCreatePosition(2000 + (i * Random.Range(0, 5) * 60));
         ObstacleList.Add(obstacle);
     }
 }
Ejemplo n.º 9
0
        public void Move(int width, int height, List <int> barriers)
        {
            //ONLY USED FOR LEVEL 2

            for (int i = 0; i < ObstacleList.Count; i++)
            {
                Obstacle obstacle = ObstacleList.ElementAt(i);

                obstacle.Move(barriers.ElementAt(2 * obstacle.Parent + 1) - (int)obstacle.Radius, height - 150, barriers.ElementAt(2 * obstacle.Parent) + (int)obstacle.Radius, 0, 10 + (difficulty - 1) * 5);
            }
        }
Ejemplo n.º 10
0
 public bool RemoveObstacle(int x, int y)
 {
     foreach (Position position in ObstacleList)
     {
         if (position.X == x && position.Y == y)
         {
             ObstacleList.Remove(position);
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 11
0
        private void GameInit()
        {
            p_Brid.Location = new Point(108, 161);
            timer_BirdMovingTrail.Enabled = false;
            Score        = 0;
            l_Score.Text = "";

            lock (ObstacleList)
            {
                for (int i = 0; i < ObstacleList.Count; i++)
                {
                    this.Controls.Remove(ObstacleList[i]);
                }
                ObstacleList.Clear();
            }
        }
    ObstacleList DetectObjectsAndAvoid()
    {
        ObstacleList obstacleList = locateObstacles();

        //if(obstacleList != ObstacleList.NONE)
        //if(debug) Debug.Log(obstacleList);
        switch (obstacleList)
        {
        case ObstacleList.NONE:
            break;

        case ObstacleList.RIGHT:
            Roll(-1);
            break;

        case ObstacleList.LEFT:
        case ObstacleList.LEFT_RIGHT:
            Roll(1);
            break;

        case ObstacleList.LEFT_CENTER:
            if (!isObstacle(waypoints[currentWaypoint].tag))
            {
                Yaw(-1);
            }
            break;

        case ObstacleList.CENTER_RIGHT:
            if (!isObstacle(waypoints[currentWaypoint].tag))
            {
                Yaw(1);
            }
            break;

        case ObstacleList.CENTER:
        case ObstacleList.LEFT_CENTER_RIGHT:
            if (!isObstacle(waypoints[currentWaypoint].tag))
            {
                Pitch(1);
            }
            break;

        default:
            break;
        }
        return(obstacleList);
    }
Ejemplo n.º 13
0
    void LookForTargetsAndFire(ObstacleList obstacleList = ObstacleList.NONE)
    {
        TargetList targetList = locateTargets();

        //if(debug) Debug.Log("Current Target: " + targetList);
        foreach (FirePrimary weaponComponent in gameObject.GetComponentsInChildren <FirePrimary>())
        {
            RaycastHit hit;
            bool       targetAtWeapon = Physics.Raycast(weaponComponent.transform.position, weaponComponent.transform.up, out hit, maxFireDistance, targetLayerMask);
            //if there is something in the way, and it isn't another enemy, fire to try to knock it out of the way or to destroy it
            //if(obstacleList != ObstacleList.NONE && !isTarget("Enemy")){
            //commented out because it was weird that the enemies shot at terrain
            //might add back later, but shooting doesn't seem to help much
            //weaponComponent.shoot();
            //}else{
            //if there isn't any obstacles then fire at the player if its in
            //front of the ship, in front of the weapon or in front of the
            //side the weapon is on
            if ((targetList & TargetList.CENTER) > 0 || targetAtWeapon)
            {
                weaponComponent.shoot();
            }
            if (weaponComponent.name == "Left Weapon")
            {
                if ((targetList & (TargetList.LEFT)) > 0)
                {
                    //if(debug) Debug.Log("player shot left");
                    weaponComponent.shoot();
                }
            }
            else if (weaponComponent.name == "Right Weapon")
            {
                if ((targetList & (TargetList.RIGHT)) > 0)
                {
                    //if(debug) Debug.Log("player shot right");
                    weaponComponent.shoot();
                }
            }
            else
            {
                Debug.LogError("error, invalid name of weapon '" + weaponComponent.name + "'");
            }

            //}
        }
    }
    //explanation of obstacles and targets-
    //i realise obstacles and targets sound very similar, so I'm going to explain the
    //differences, since I use both a bunch.
    //	--obstacles are objects to avoid, targets are things to shoot at.
    //	--targets can be detected from much further away, since you don't need to move out of the
    //	way of obstacles if you aren't close to crashing.
    //	--targets are just players, since you don't need to shoot an asteroid unless you are about to hit it
    //	and need to push it out of your way.
    ObstacleList locateObstacles()
    {
        bool obstacleRight    = Physics.Raycast(DetectorRight.transform.position, DetectorRight.transform.forward, out obstacleRaycastList[1], maxDetectorDistance, obstacleLayerMask);
        bool obstacleRightFar = Physics.Raycast(DetectorRightFar.transform.position, DetectorRightFar.transform.forward, out obstacleRaycastList[0], maxDetectorDistance, obstacleLayerMask);

        obstacleRight = obstacleRight && obstacleRightFar;

        bool obstacleLeft    = Physics.Raycast(DetectorLeft.transform.position, DetectorLeft.transform.forward, out obstacleRaycastList[3], maxDetectorDistance, obstacleLayerMask);
        bool obstacleLeftFar = Physics.Raycast(DetectorLeftFar.transform.position, DetectorLeftFar.transform.forward, out obstacleRaycastList[4], maxDetectorDistance, obstacleLayerMask);

        obstacleLeft = obstacleLeft && obstacleLeftFar;

        bool obstacleCenter = Physics.Raycast(DetectorCenter.transform.position, DetectorCenter.transform.forward, out obstacleRaycastList[2], maxDetectorDistance, obstacleLayerMask);
        //the reason I made ObstacleList was so that the options would be mutually exclusive.
        //EX. you wanna roll if there is something blocking your leftwing only if something isn't blocking center.  If something
        //is blocking your center and your leftwing, then you should yaw right.
        ObstacleList obstacleList = (ObstacleList)((obstacleRight?1:0) + (obstacleCenter?2:0) + (obstacleLeft?4:0));

        return(obstacleList);
    }
Ejemplo n.º 15
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            graphics.PreferredBackBufferHeight = 1000;
            graphics.PreferredBackBufferWidth  = 1900;

            // TODO: Add your initialization logic here
            floor      = new Floor();
            player     = new Player();
            collisions = new Collisions();
            blocks     = new ObstacleList();
            scoreboard = new Score();
            floor.Initialize(Content);
            background = new Background();
            goblinList = new EnemyList();
            background.Initialize();
            graphics.ApplyChanges();
            IsMouseVisible = true;

            base.Initialize();
        }
Ejemplo n.º 16
0
 public BuildHub(List <Setting> settingList, List <ObstacleData> obstaclesData, List <Robot> myRobots, List <Part> humanRobotParts, Part[] storeParts, long credits, MODES mode) : base(settingList)
 {
     myRobotsList = new List <Robot>();
     if (myRobots != null && myRobots.Count > 0)
     {
         myRobotsList.AddRange(myRobots);
     }
     this.humanRobotParts = humanRobotParts;
     currentRobot         = (this.myRobotsList.Count > 0 ? this.myRobotsList[0] : null);
     OBSTACLES_DATA       = obstaclesData;
     STORE_PARTS          = storeParts;
     this.credits         = credits;
     this.mode            = mode;
     goToField            = false;
     trainingMode         = false;
     MESHES = new List <Mesh>();
     MESHES.Add(PrimitiveHelper.GetPrimitiveMesh(PrimitiveType.Cube));
     MESHES.Add(PrimitiveHelper.GetPrimitiveMesh(PrimitiveType.Sphere));
     MESHES.Add(PrimitiveHelper.GetPrimitiveMesh(PrimitiveType.Cylinder));
     MESHES.Add(PrimitiveHelper.GetPrimitiveMesh(PrimitiveType.Cube));
     foreach (Part part in this.humanRobotParts)
     {
         if (!(part is Attachment) && part.GAME_OBJECT != null)
         {
             part.toggleGameObject(false);
         }
     }
     foreach (Part part in STORE_PARTS)
     {
         if (part.GAME_OBJECT != null)
         {
             part.toggleGameObject(false);
         }
     }
     if (currentRobot != null)
     {
         createPreviewRobot();
     }
     this.myRobots = new MyRobots(myRobotsList.ToArray(), this.humanRobotParts.ToArray(), this.credits, base.colorScheme);
     workshop      = new Workshop(MESHES, previewRobot, (currentRobot != null ? currentRobot.getName() : ""), this.humanRobotParts, (currentRobot != null ? currentRobot.getParts() : null), this.credits, base.colorScheme, enableCreditsSpentAnimation);
     store         = new Store(MESHES, previewRobot, this.STORE_PARTS, this.humanRobotParts, (currentRobot != null ? currentRobot.getParts() : null), this.credits, workshop.getConfigurationCard(), base.colorScheme, enableCreditsSpentAnimation);
     obstacleList  = new ObstacleList(OBSTACLES_DATA);
     TABS          = new List <GameObject>();
     foreach (Transform child in GameObject.Find("BuildHubTabs").transform)
     {
         TABS.Add(child.gameObject);
     }
     MY_ROBOTS_BACK_BUTTON = GameObject.Find("MyRobotsBackButton");
     OBSTACLES_INFO_BUTTON = GameObject.Find("ObstaclesInfoButton");
     SETTINGS_BUTTON       = GameObject.Find("SettingsButton");
     TRAINING_BUTTON       = GameObject.Find("TrainingButton");
     CREDITS_BUTTON        = GameObject.Find("CreditsButton");
     CREDITS_WIDGET        = GameObject.Find("CreditsWidget");
     CREDITS_WIDGET.SetActive(false);
     base.colorScheme            = ImageTools.getColorFromString(base.settingPairs.color_scheme);
     enableCreditsSpentAnimation = base.settingPairs.credits_spent_animation;
     SETTINGS_BUTTON.GetComponent <UnityEngine.UI.Image>().color = base.colorScheme;
     TRAINING_BUTTON.GetComponent <UnityEngine.UI.Image>().color = base.colorScheme;
     colorScheme             = SETTINGS_BUTTON.GetComponent <UnityEngine.UI.Image>().color;
     BACKGROUND              = GameObject.Find("Background");
     backgroundGraphicString = settingPairs.build_hub_background_graphic;
     BACKGROUND.GetComponent <UnityEngine.UI.Image>().sprite = ImageTools.getSpriteFromString(backgroundGraphicString);
     PLATFORM = GameObject.Find("Platform");
     platformGraphicString = settingPairs.build_hub_platform_graphic;
     PLATFORM.GetComponent <Renderer>().material.mainTexture = new Image(platformGraphicString).getTexture();
     enablePreviewRobotAnimation = settingPairs.preview_robot_animation;
     updateTabs();
     if (this.mode == MODES.MY_ROBOTS)
     {
         MY_ROBOTS_BACK_BUTTON.SetActive(false);
         foreach (GameObject tab in TABS)
         {
             tab.SetActive(false);
         }
     }
 }
Ejemplo n.º 17
0
        /// <summary>
        /// The load obstacles.
        /// </summary>
        /// <param name="ObstacleList">The obstacle list.</param>
        /// <remarks></remarks>
        public void LoadObstacles(ref List <SceneryInfo> ObstacleList)
        {
            if (ObstacleList == null)
            {
                ObstacleList = new List <SceneryInfo>();
            }
            else
            {
                ObstacleList.Clear();
            }

            map.OpenMap(MapTypes.Internal);

            // Lists all Obstacles
            for (int i = 0; i < map.MapHeader.fileCount; i++)
            {
                if (map.MetaInfo.TagType[i] == "scnr")
                {
                    Meta m = new Meta(map);

                    // Base address of SCNR tag, offset of Crate Palette pointer (+816)
                    map.BR.BaseStream.Position = map.MetaInfo.Offset[i] + 816;
                    int chunkCount  = map.BR.ReadInt32();
                    int chunkOffset = map.BR.ReadInt32() - map.SecondaryMagic;

                    // Crate (Obstacle) Palette Objects
                    for (int a = 0; a < chunkCount; a++)
                    {
                        SceneryInfo Obstacle = new SceneryInfo();

                        // The Palette Chunk #
                        Obstacle.ScenPalNumber = a;

                        // Each chunk is 40 bytes apart
                        map.BR.BaseStream.Position = chunkOffset + a * 40;
                        char[] tagName = map.BR.ReadChars(4);
                        Obstacle.ScenTagNumber = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
                        if (Obstacle.ScenTagNumber != -1)
                        {
                            // Retrieve the Model HLMT tag from the Scenery tag (+56)
                            map.BR.BaseStream.Position = map.MetaInfo.Offset[Obstacle.ScenTagNumber] + 56;
                            Obstacle.HlmtTagNumber     = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());

                            // Base address of HLMT tag, offset of MODE pointer (+4)
                            map.BR.BaseStream.Position = map.MetaInfo.Offset[Obstacle.HlmtTagNumber] + 4;
                            Obstacle.ModelTagNumber    = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());

                            m.ReadMetaFromMap(Obstacle.ModelTagNumber, false);
                            Obstacle.Model = new ParsedModel(ref m);
                            ParsedModel.DisplayedInfo.LoadDirectXTexturesAndBuffers(ref device, ref Obstacle.Model);

                            string[] s = map.FileNames.Name[Obstacle.ScenTagNumber].Split('\\');
                            Obstacle.Name    = s[s.Length - 1];
                            Obstacle.TagPath = map.FileNames.Name[Obstacle.ScenTagNumber];
                            Obstacle.TagType = map.MetaInfo.TagType[Obstacle.ScenTagNumber];
                            ObstacleList.Add(Obstacle);
                        }
                    }

                    break;
                }
            }

            map.CloseMap();
        }
    void Move(ObstacleList obstacleList = ObstacleList.NONE)
    {
        Vector3 directionEnemy  = transform.forward;
        Vector3 directionTarget = Vector3.Normalize(waypoints[currentWaypoint].transform.position - transform.position);

        //rotate to face the waypoint
        float dotForward = Vector3.Dot(transform.forward, directionTarget);
        float dotYaw     = Vector3.Dot(transform.right, directionTarget);
        float dotPitch   = Vector3.Dot(transform.up, directionTarget);

        //if(debug) Debug.Log ("dotForward is " + dotForward + "dotYaw is " + dotYaw + "dotPitch is " + dotPitch);
        if ((dotPitch > 0) ^ (lastDotPitch > 0))
        {
            //if(debug) Debug.Log ("Hit pitch brake");
            GetComponent <Ship>().PitchBrake();
        }

        if ((dotYaw > 0) ^ (lastDotYaw > 0))
        {
            //if(debug) Debug.Log ("Hit yaw brake");
            GetComponent <Ship>().YawBrake();
        }
        //make the yaw and pitch react more if the enemy is close but not quite at correct pitch or yaw
        dotYaw   = (dotYaw > 0)?Mathf.Sqrt(dotYaw):-Mathf.Sqrt(-dotYaw);
        dotPitch = (dotPitch > 0)?Mathf.Sqrt(dotPitch):-Mathf.Sqrt(-dotPitch);
        if (dotForward > 0)
        {
            if (obstacleList != ObstacleList.CENTER && obstacleList != ObstacleList.LEFT_CENTER_RIGHT)
            {
                Pitch(dotPitch);
            }
            if (obstacleList != ObstacleList.LEFT_CENTER && obstacleList != ObstacleList.CENTER_RIGHT)
            {
                Yaw(dotYaw);
            }
        }
        else if (dotForward < 0)
        {
            if (obstacleList != ObstacleList.CENTER && obstacleList != ObstacleList.LEFT_CENTER_RIGHT)
            {
                Pitch((dotPitch > 0)?1:-1);
            }
            if (obstacleList != ObstacleList.LEFT_CENTER && obstacleList != ObstacleList.CENTER_RIGHT)
            {
                Yaw((dotYaw > 0)?1:-1);
            }
        }
        RollToBoostAccuracy();
        //move towards the waypoint, but really accelerate only when facing the correct direction
        float degrBetweenEnemyTarget = Vector3.Angle(directionEnemy, directionTarget);

        if (obstacleList != ObstacleList.NONE)
        {
            Accelerate(-Vector3.Dot(rigidbody.velocity, transform.forward));
        }
        else
        {
            Accelerate(1 / (1 + 10 * degrBetweenEnemyTarget / 360));
        }
        lastDotYaw   = dotYaw;
        lastDotPitch = dotPitch;
    }
    void Move(ObstacleList obstacleList = ObstacleList.NONE)
    {
        Vector3 directionEnemy = transform.forward;
        Vector3 directionTarget = Vector3.Normalize(currentTarget.transform.position - transform.position);

        //rotate to face the waypoint
        float dotForward = Vector3.Dot(transform.forward,directionTarget);
        float dotYaw = Vector3.Dot(transform.right,directionTarget);
        float dotPitch = Vector3.Dot(transform.up,directionTarget);
        //if(debug) Debug.Log ("dotForward is " + dotForward + "dotYaw is " + dotYaw + "dotPitch is " + dotPitch);
        if((dotPitch > 0) ^ (lastDotPitch > 0)){
            //if(debug) Debug.Log ("Hit pitch brake");
            GetComponent<Ship>().PitchBrake();
        }

        if((dotYaw > 0)^(lastDotYaw > 0)){
            //if(debug) Debug.Log ("Hit yaw brake");
            GetComponent<Ship>().YawBrake();

        }
        //make the yaw and pitch react more if the enemy is close but not quite at correct pitch or yaw
        dotYaw = (dotYaw > 0)?Mathf.Sqrt(dotYaw):-Mathf.Sqrt(-dotYaw);
        dotPitch = (dotPitch > 0)?Mathf.Sqrt(dotPitch):-Mathf.Sqrt(-dotPitch);
        if(dotForward > 0){
            if(obstacleList != ObstacleList.CENTER && obstacleList != ObstacleList.LEFT_CENTER_RIGHT){
                Pitch(dotPitch);
            }
            if(obstacleList != ObstacleList.LEFT_CENTER && obstacleList != ObstacleList.CENTER_RIGHT){
                Yaw(dotYaw);
            }
        }else if(dotForward < 0){
            if(obstacleList != ObstacleList.CENTER && obstacleList != ObstacleList.LEFT_CENTER_RIGHT){
                Pitch((dotPitch > 0)?1:-1);
            }
            if(obstacleList != ObstacleList.LEFT_CENTER && obstacleList != ObstacleList.CENTER_RIGHT){
                Yaw((dotYaw > 0)?1:-1);
            }
        }
        RollToBoostAccuracy();
        //move towards the waypoint, but really accelerate only when facing the correct direction
        float degrBetweenEnemyTarget = Vector3.Angle(directionEnemy,directionTarget);
        if(obstacleList != ObstacleList.NONE)
            Accelerate(-Vector3.Dot(rigidbody.velocity,transform.forward));
        else
            Accelerate(1/(1+degrBetweenEnemyTarget));
        lastDotYaw = dotYaw;
        lastDotPitch = dotPitch;
    }
    void LookForTargetsAndFire(ObstacleList obstacleList = ObstacleList.NONE)
    {
        TargetList targetList = locateTargets();
        //if(debug) Debug.Log("Current Target: " + targetList);
        foreach(FirePrimary weaponComponent in gameObject.GetComponentsInChildren<FirePrimary>()){
            RaycastHit hit;
            bool targetAtWeapon = Physics.Raycast(weaponComponent.transform.position,weaponComponent.transform.up,out hit,maxFireDistance, targetLayerMask);
            //if there is something in the way, and it isn't another enemy, fire to try to knock it out of the way or to destroy it
            //if(obstacleList != ObstacleList.NONE && !isTarget("Enemy")){
                //commented out because it was weird that the enemies shot at terrain
                //might add back later, but shooting doesn't seem to help much
                //weaponComponent.shoot();
            //}else{
                //if there isn't any obstacles then fire at the player if its in
                //front of the ship, in front of the weapon or in front of the
                //side the weapon is on
                if((targetList & TargetList.CENTER) > 0 || targetAtWeapon)
                        weaponComponent.shoot();
                if(weaponComponent.name == "Left Weapon"){
                    if((targetList & (TargetList.LEFT)) > 0){
                        //if(debug) Debug.Log("player shot left");
                        weaponComponent.shoot();
                    }
                }else if(weaponComponent.name == "Right Weapon"){
                    if((targetList & (TargetList.RIGHT)) > 0){
                        //if(debug) Debug.Log("player shot right");
                        weaponComponent.shoot();
                    }
                }else{
                    Debug.LogError("error, invalid name of weapon '" + weaponComponent.name +"'");
                }

            //}
        }
    }
        //opening the dialogs for choosing an existing level
        private void loadLevel()
        {
            OpenFileDialog BrowseFile = new OpenFileDialog();

            BrowseFile.Filter      = "XML Files (*.xml)|*.xml";
            BrowseFile.FilterIndex = 0;
            BrowseFile.DefaultExt  = "xml";
            if (BrowseFile.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                ObstacleList.Clear();
                doc = new XmlDocument();
                try
                {
                    doc.Load(BrowseFile.FileName);
                }
                catch (Exception e)
                {
                    MessageBox.Show("Level Could't be read please check your file. Error: " + e, "Information", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                XmlNodeList xmlnode;
                xmlnode = doc.GetElementsByTagName("object");
                for (int i = 0; i < xmlnode.Count; i++)
                {
                    string name  = xmlnode[i].ChildNodes.Item(0).InnerText;
                    int    xaxis = Convert.ToInt32(xmlnode[i].ChildNodes.Item(1).InnerText);
                    int    yaxis = Convert.ToInt32(xmlnode[i].ChildNodes.Item(2).InnerText);
                    string speed = xmlnode[i].ChildNodes.Item(3).InnerText;
                    //adding the objects to the object list
                    switch (name)
                    {
                    case "tree":
                        Tree tree = new Tree(xaxis, yaxis);
                        ObstacleList.Add(tree);
                        Console.WriteLine("Tree added to list.");
                        break;

                    case "sandbag":
                        Sandbag sandbag = new Sandbag(xaxis, yaxis);
                        ObstacleList.Add(sandbag);
                        Console.WriteLine("Tree added to list.");
                        break;

                    case "mine":
                        Mine mine = new Mine(xaxis, yaxis);
                        ObstacleList.Add(mine);
                        Console.WriteLine("Tree added to list.");
                        break;

                    case "mud":
                        Mud mud = new Mud(xaxis, yaxis);
                        ObstacleList.Add(mud);
                        Console.WriteLine("Tree added to list.");
                        break;

                    case "finish":
                        Finish finish = new Finish(xaxis, yaxis);
                        ObstacleList.Add(finish);
                        Console.WriteLine("Tree added to list.");
                        break;

                    case "missilelauncher":
                        ObstacleList.Add(new Missilelauncher(xaxis, yaxis));
                        Console.WriteLine("Missilelauncher added to list.");
                        break;

                    default:
                        break;
                    }
                }
            }
        }
Ejemplo n.º 22
0
 public bool AddObstacle(Position position)
 {
     ObstacleList.Add(position);
     ObstacleMatrix[position.Y, position.X] = true;
     return(true);
 }
Ejemplo n.º 23
0
        public int InsertResult(Result result, ObstacleList obstacleList)
        {
            int pk = 0;

            db.Insert(result);
            pk = (int)result.result_id;
            //Console.WriteLine("Inserted row with PK of " + pk);
            ResultObstacle obstacle = new ResultObstacle();

            obstacle.result_id = pk;


            if (!obstacleList.Switch_0) //eww multiple ifs
            {
                obstacle.obstacle_id = 0;
                db.Insert(obstacle);
            }

            if (!obstacleList.Switch_1)
            {
                obstacle.obstacle_id = 1;
                db.Insert(obstacle);
            }

            if (!obstacleList.Switch_2)
            {
                obstacle.obstacle_id = 2;
                db.Insert(obstacle);
            }
            if (!obstacleList.Switch_3)
            {
                obstacle.obstacle_id = 3;
                db.Insert(obstacle);
            }
            if (!obstacleList.Switch_4)
            {
                obstacle.obstacle_id = 4;
                db.Insert(obstacle);
            }
            if (!obstacleList.Switch_5)
            {
                obstacle.obstacle_id = 5;
                db.Insert(obstacle);
            }
            if (!obstacleList.Switch_6)
            {
                obstacle.obstacle_id = 6;
                db.Insert(obstacle);
            }
            if (!obstacleList.Switch_7)
            {
                obstacle.obstacle_id = 7;
                db.Insert(obstacle);
            }
            if (!obstacleList.Switch_8)
            {
                obstacle.obstacle_id = 8;
                db.Insert(obstacle);
            }
            if (!obstacleList.Switch_9)
            {
                obstacle.obstacle_id = 9;
                db.Insert(obstacle);
            }
            if (!obstacleList.Switch_10)
            {
                obstacle.obstacle_id = 10;
                db.Insert(obstacle);
            }
            if (!obstacleList.Switch_11)
            {
                obstacle.obstacle_id = 11;
                db.Insert(obstacle);
            }


            return(pk);
        }
Ejemplo n.º 24
0
 public void AddObstacle(Obstacle c)
 {
     ObstacleList.Add(c);
 }