Esempio n. 1
0
    // Update is called once per frame
    void Update()
    {
        beatlePosition = new Vector3(transform.position.x, WorldHandler.CAMERA_Y, transform.position.z); // not sure if i should add a transform.hasChanged test so it doesnt call this every frame?
        timer         += Time.deltaTime;



        if (health <= 0)
        {
            gameObject.SetActive(false);
            WorldHandler.unitsSelected.Remove(gameObject);
            isUnitSelected = false;
            WorldHandler.DestroyFlags();
            GetComponent <Collider>().isTrigger = false;
            if (isServer)
            {
                WorldHandler.findLocalPlayer().GetComponent <WorldHandler>().Rpc_DespawnObject(gameObject);
            }
        }

        if (isUnitSelected)
        {
            displayBeatleInfo();
        }

        if (beatlePosition != Vector3.zero)
        { // when space is pressed, move camera to the anthill
            if (Input.GetKey(KeyCode.Space) && isUnitSelected)
            {
                Camera.main.transform.position = beatlePosition;
                Debug.Log(beatlePosition);
            }
        }
    }
 /// <summary>
 /// Attack the targetted unit
 /// </summary>
 /// <param name="target"></param>
 public void Attack(IEntity target, WorldHandler world)
 {
     ResetUnit();
     this.Target = target;
     Move(Target.Position, world);
     UnitState = BaseUnitState.attack;
 }
Esempio n. 3
0
        public FormMain()
        {
            InitializeComponent();

            m_WorldHandler = new WorldHandler();             // Must be the first
            m_clock        = new DSClock();
            m_AutoSync     = new AutoSync();


            // Alarm
            m_AlarmHandler = new AlarmHandler(this);
            m_AlarmHandler.LoadAlarms();


            // Attack Planer
            m_AttackPlanHandler = new AttackPlanHandler();
            m_AttackPlanHandler.LoadAttackOrders();

            m_FormClockOnTop   = new FormStarter(() => { return(new FormClockOnTop(m_clock, m_AttackPlanHandler)); });
            m_FormAlarm        = new FormStarter(() => { return(new FormAlarm(m_AlarmHandler)); });
            m_FormAttackPlaner = new FormStarter(() => { return(new FormAttackPlaner(m_AttackPlanHandler, m_AlarmHandler, m_WorldHandler)); });
            m_FormSettings     = new FormStarter(() => { return(new FormSettings(m_WorldHandler)); });

            m_timer.Interval = 1;
            m_timer.Start();
            m_timer.Tick += new EventHandler(timer_Tick);
        }
Esempio n. 4
0
    /// <summary>
    /// If your mouse is being right clicked over an ant you don't own and you have a beatle unit selected, check the range to see if it is less than BEATLE_RANGE, if it is less, stop the Navigation and fire projectile.
    /// </summary>
    void OnMouseOver()
    { // For Beatle Ranged Attacks
      // setup Timer for atk Spd


        if (Input.GetMouseButtonDown(1))
        {
            if (!hasAuthority)
            {     // if it is not owned by you
                if (WorldHandler.isBeatleUnitSelected())
                { // for beatle ranged units
                    ArrayList beatles = WorldHandler.getBeatleUnitsAsArray();
                    foreach (GameObject beatle in beatles)
                    {
                        float range = beatle.GetComponent <Beatle>().Range;
                        Debug.Log("Beatle Range: " + range);
                        Debug.Log("Distance from ant and the beatle: " + Vector3.Distance(transform.position, beatle.transform.position));
                        if (Vector3.Distance(transform.position, beatle.transform.position) <= range)
                        {
                            WorldHandler localPlayer = WorldHandler.findLocalPlayer().GetComponent <WorldHandler>();
                            localPlayer.Cmd_FireProjectile(beatle, transform.position);
                        }
                    }
                } // end beatle ranged units
            }
        }
    }
Esempio n. 5
0
    public void spawnBasicAntUnit()
    {
        if (hasAuthority)
        {
            WorldHandler localPlayer = WorldHandler.findLocalPlayer().GetComponent <WorldHandler>();

            if (WorldHandler.countUnits() < localPlayer.maxUnits)
            {     // if you have less units than the max number of units, it is okay to spawn more units.
                if (localPlayer.resourcesCount > localPlayer.BasicAntCost)
                { // if you have enough unit space and you have enough resources
                    Cmd_SpawnAntUnit(transform.position);

                    localPlayer.resourcesCount -= localPlayer.BasicAntCost; // after spawning unit, spend 15 resources.
                }
                else if (localPlayer.resourcesCount < localPlayer.BasicAntCost)
                {
                    WorldHandler.PlayResourcesSound(); // You require more resources (audio clip);
                }
            }
            else if (WorldHandler.countUnits() > localPlayer.maxUnits)
            {
                WorldHandler.PlayUnitCapSound(); // You require more unit Cap audio clip (this is if we decide to add a way for the player to increase the unit cap);
            }
        }
    }
Esempio n. 6
0
    // Update is called once per frame
    void Update()
    {
        antPosition = new Vector3(transform.position.x, 43.2f, transform.position.z); // not sure if i should add a transform.hasChanged test so it doesnt call this every frame?
        timer      += Time.deltaTime;

        if (health <= 0)
        {
            //gameObject.SetActive(false);
            WorldHandler.unitsSelected.Remove(gameObject);
            isUnitSelected = false;
            WorldHandler.DestroyFlags();
            GetComponent <Collider>().isTrigger = false;
            localPlayer.Cmd_disableUnit(gameObject);
        }

        if (isUnitSelected)
        {
            displayAntInfo();
        }

        if (antPosition != Vector3.zero)
        { // when space is pressed, move camera to the anthill
            if (Input.GetKey(KeyCode.Space) && isUnitSelected)
            {
                Camera.main.transform.position = antPosition;
            }
        }
    }
Esempio n. 7
0
    void OnTriggerEnter(Collider other)
    {
        if (!hasAuthority)
        {
            return;
        }

        if (other.GetComponent <NetworkIdentity> ().hasAuthority)
        {
            return;
        }


        if (other.name.Contains("Ant"))
        {
            if (other.GetComponent <BasicAnt>() != null)
            {
                WorldHandler.findLocalPlayer().GetComponent <WorldHandler>().Rpc_DamageBasicAnt(other.gameObject, Random.Range(0, beatleDamage), gameObject);

                Destroy(gameObject);
            }
        }

        if (other.tag == "anthill")
        {
            if (other.GetComponent <Anthill>().health <= 0)
            {
                GameObject.Find("Canvas").transform.FindChild("Victory").gameObject.SetActive(true); // WorldHandler is always checking for these to be true or false to switch scenes to defeat/victory
            }

            WorldHandler.findLocalPlayer().GetComponent <WorldHandler>().Rpc_DamageAntHill(other.gameObject, Random.Range(0, beatleDamage), gameObject);
        }
    }
Esempio n. 8
0
    void OnMouseDown()
    {
        if (!hasAuthority)
        {
            return;
        }

        if (!WorldHandler.isShiftDown())
        {
            WorldHandler.deselectAntHill();
            WorldHandler.deselectUnits();
        }

        GameObject indicator = gameObject.transform.FindChild("Indicator").gameObject;

        indicator.SetActive(!indicator.activeSelf);
        isUnitSelected = indicator.activeSelf;

        if (isUnitSelected)
        {
            WorldHandler.PlayUnitBattleSound();
            WorldHandler.unitsSelected.Add(gameObject);
        }
        else
        {
            WorldHandler.unitsSelected.Remove(gameObject);
        }
    }
Esempio n. 9
0
        public FormSettings(WorldHandler worldHandler)
        {
            m_Initializing = true;
            m_WorldHandler = worldHandler;
            InitializeComponent();
            Settings.Default.PropertyChanged       += new PropertyChangedEventHandler(Default_PropertyChanged);
            Settings.Default.SettingsSaving        += new System.Configuration.SettingsSavingEventHandler(Default_SettingsSaving);
            worldInfoBindingSource.DataSource       = worldHandler.Wolrds;
            worldConfigFileBindingSource.DataSource = WorldHandler.ConfigFile;
            // TODO: try to load/select saved Server and World

            serversBindingSource.DataSource = worldHandler.Servers;

            Server selectedServer = worldHandler.Servers.FirstOrDefault(s => s.Name == Settings.Default.SelectedServerName);

            if (selectedServer != null)
            {
                serversBindingSource.Position = worldHandler.Servers.IndexOf(selectedServer);
            }
            UpdateLastWorldUpdateLabel();

            // Maybe a bad idea when server not avalible. Async testing?
            TestServer();
            m_Initializing = false;
        }
    private void Start()
    {
        this.gameObject.AddComponent <WorldHandler>();
        WorldHandler wHandler = this.gameObject.GetComponent <WorldHandler>();

        wHandler.LoadWorld();
    }
Esempio n. 11
0
 /// <summary>
 /// Generates waypoints using A*
 /// </summary>
 /// <param name="Position"></param>
 public override void Move(Vector2 Position, WorldHandler world)
 {
     if (world.GetUnit(Position) == null && world.GetTile(Position) == null)
     {
         ResetUnit();
         Target = null;
     }
     base.Move(Position, world);
 }
Esempio n. 12
0
 public CommandProccesor(Game game, List <IUnit> startingUnits, WorldHandler wh, InputDefinitions input, CommandComponent command, Camera camera) : base(game)
 {
     this.cc     = command;
     this.wh     = wh;
     this.input  = input;
     this.camera = camera;
     commands    = new List <ICommand>();
     buttons     = new List <CommandButton>();
 }
Esempio n. 13
0
        public GameRunner(IOutputHandler outputHandler)
        {
            _outputHandler = outputHandler;

            _worldHandler = new WorldHandler(new Random());
            _character    = new Character(new Inventory());

            _currentWorld = _worldHandler.GenerateWorld();
        }
Esempio n. 14
0
    void Update()
    {
        if (!isLocalPlayer)
        {
            return;
        }

        timer += Time.deltaTime;


        // Set color of text based on team
        if (unitIdentity.id == 0)
        {
            unitInfo.GetComponent <Text> ().color = Color.red;
        }
        else if (unitIdentity.id == 1)
        {
            unitInfo.GetComponent <Text> ().color = Color.blue;
        }
        // End color setting.

        if (health <= 0)
        {
            GameObject.Find("Canvas").transform.FindChild("Defeat").gameObject.SetActive(true);
        }

        if (isAntHillSelected)
        {
            //spawnAttackAnt.transform.FindChild("UnitInfo").GetComponent<Text>().text = " Unit: " + gameObject.name + "\n Health: " + health;
            unitInfo.GetComponent <Text>().text = "Unit: " + gameObject.name + " \n Health: " + health;
            displayAntHillInfo();

            if (Input.GetKeyDown(KeyCode.Q)) // Hotkeys, q for basic ant, w for beatle unit.
            {
                spawnBasicAntUnit();
            }
            if (Input.GetKeyDown(KeyCode.W))
            {
                spawnBeatle();
            }
        }
        else
        {
            /*spawnAttackAnt.SetActive(false);
             * spawnBeatleUnit.SetActive (false);*/
            WorldHandler.hideAnthillInfo();
        }

        if (cameraAntHillPos != Vector3.zero)
        { // when space is pressed, move camera to the anthill
            if (Input.GetKey(KeyCode.Space) && isAntHillSelected)
            {
                Camera.main.transform.position = cameraAntHillPos;
            }
        }
    }
Esempio n. 15
0
 public void InitGame()
 {
     _world      = new WorldHandler();
     _tile       = new TileHandler();
     _random     = new RandomHandler();
     _hero       = new HeroHandler();
     _generation = new GenerationHandler();
     _spawn      = new Spawner();
     _item       = new ItemHandler();
 }
Esempio n. 16
0
 void Awake()
 {
     player             = GameObject.FindGameObjectWithTag("Player");
     mainCamera         = GameObject.FindGameObjectWithTag("MainCamera");
     background         = GameObject.FindGameObjectWithTag("Background");
     scripts            = GameObject.FindGameObjectWithTag("Scripts");
     worldHandler       = scripts.GetComponent <WorldHandler> ();
     backgroudParticles = background.GetComponent <ParticleSystem> ();
     screenWidth        = Camera.main.ScreenToWorldPoint(new Vector2(Screen.width, Screen.height)).x * 2;
     screenHeight       = Camera.main.ScreenToWorldPoint(new Vector2(Screen.width, Screen.height)).y * 2;
 }
Esempio n. 17
0
    private void fireAfterWait(GameObject beatle, Vector3 target)
    {
        GameObject bullet = Resources.Load("Prefabs/bomb") as GameObject;                                                 // bullet prefab

        GameObject bulletToSpawn = (GameObject)Instantiate(bullet, beatle.transform.position, beatle.transform.rotation); // antstospawn

        // Set after it is spawned
        bulletToSpawn.GetComponent <FireBeatleBullet>().positionToFireAt = target; // spawns the bullet and then feeds it a vector3 of the position of the ant its being fired at (this ant).

        NetworkServer.SpawnWithClientAuthority(bulletToSpawn, WorldHandler.findLocalPlayer());
    }
Esempio n. 18
0
 internal void InitializeUserControl(AttackPlanHandler attackPlanHandler, AlarmHandler alarmHandler, WorldHandler worldHandler)
 {
     if (m_initialized)
     {
         return;
     }
     m_initialized  = true;
     AttackHandler  = attackPlanHandler;
     m_AlarmHandler = alarmHandler;
     m_WorldHandler = worldHandler;
 }
 public override void Update(GameTime gameTime, WorldHandler world)
 {
     UpdateMove(gameTime, world);
     InteractTimer += gameTime.ElapsedGameTime.Milliseconds;
     if (InteractTimer / 1000 >= 1)
     {
         Interact(world);
         InteractTimer = 0;
     }
     base.Update();
 }
Esempio n. 20
0
 void Awake()
 {
     player = GameObject.FindGameObjectWithTag ("Player");
     mainCamera = GameObject.FindGameObjectWithTag ("MainCamera");
     background = GameObject.FindGameObjectWithTag ("Background");
     scripts = GameObject.FindGameObjectWithTag ("Scripts");
     worldHandler = scripts.GetComponent<WorldHandler> ();
     backgroudParticles = background.GetComponent<ParticleSystem> ();
     screenWidth = Camera.main.ScreenToWorldPoint (new Vector2 (Screen.width, Screen.height)).x * 2;
     screenHeight = Camera.main.ScreenToWorldPoint (new Vector2 (Screen.width, Screen.height)).y * 2;
 }
 public List <Vector2> FindPath(Vector2 StartPosition, Vector2 EndPosition, WorldHandler world, List <Vector2> waypoints)
 {
     if (waypoints.Count > 0 && waypoints[waypoints.Count - 1] == EndPosition)
     {
         return(waypoints);
     }
     else
     {
         return(FindPath(StartPosition, EndPosition, world));
     }
 }
Esempio n. 22
0
 void OnMouseDown()                                      // Change to OnMouseHover and check for clicks, then put a public static bool inside of dragselection script called "isDragging" if you are dragging none of this should apply
 {
     if (!EventSystem.current.IsPointerOverGameObject()) // If the mouse is not over an event system object (UI Object) and the user is pressing the left click
     {
         WorldHandler.deselectUnits();
         WorldHandler.deselectAntHill();
         Cursor.lockState = CursorLockMode.Confined;                     // lock the cursor when the user clicks the terrain.
         WorldHandler.hideAnthillInfo();
         WorldHandler.DestroyFlags();
     }
 }
Esempio n. 23
0
 public Overlay(Game game, InputDefinitions input, WorldHandler world, CommandProccesor command) : base(game)
 {
     cp                   = command;
     this.world           = world;
     this.input           = input;
     cp.overlay           = this;
     ZeroVector           = Vector2.Zero;
     currentCursorTexture = TextureValue.Cursor;
     tile                 = world.GetTile(input.InputPos);
     ClickTime            = 0;
 }
Esempio n. 24
0
 /// <summary>
 /// Garrison in the targetted building
 /// </summary>
 /// <param name="target"></param>
 public void Garrison(IEntity target, WorldHandler world)
 {
     ResetUnit();
     if (target is ReferenceTile)
     {
         target = ((ReferenceTile)target).tile;
     }
     this.Target = target;
     Move(Target.Position, world);
     arrived = false;
 }
Esempio n. 25
0
 public Camera(Game game, InputDefinitions input, WorldHandler worldHandler, Vector2 startPoint) : base(game)
 {
     Tile.Zoom     = 3;
     MoveSpeed     = 6.25f;
     this.position = startPoint;
     this.ViewPort = new Rectangle(position.ToPoint(), new Point(30, 16));
     this.input    = input;
     Dir           = new Vector2(0, 0);
     this.world    = worldHandler;
     bounds        = new Rectangle(new Vector2(0, 0).ToPoint(), (world.GetSize()).ToPoint());
     Zero          = Vector2.Zero;
 }
Esempio n. 26
0
 /// <summary>
 /// Move to the harvestable unit
 /// </summary>
 /// <param name="target"></param>
 public void Harvest(IEntity target, WorldHandler world)
 {
     ResetUnit();
     if (target is ReferenceTile)
     {
         target = ((ReferenceTile)target).tile;
     }
     this.Target = target;
     this.Move(target.Position, world);
     UnitState = BaseUnitState.harvest;
     arrived   = false;
 }
Esempio n. 27
0
 /// <summary>
 /// Targets a placed building to build
 /// </summary>
 /// <param name="target"></param>
 public void Build(IEntity target, WorldHandler world)
 {
     ResetUnit();
     if (target is ReferenceTile)
     {
         target = ((ReferenceTile)target).tile;
     }
     Target = target;
     Move(target.Position, world);
     UnitState = BaseUnitState.build;
     arrived   = false;
 }
        public void FindTarget(WorldHandler world)
        {
            IEntity entity = world.FindNearest(this.TeamAssociation - 1, this.Position);

            if (entity != null)
            {
                if (entity is ModifiableTile)
                {
                    Attack(entity, world);
                }
            }
        }
Esempio n. 29
0
        public async void CMD_Shutdown(Client client)
        {
            NAPI.Chat.SendChatMessageToAll("[SERVER]: Shutdown inititated, saving data...");
            Initialization.OnServerShutdown();
            Logger.GetInstance().ServerInfo("[SHUTDOWN]: Started saving World Data.");
            await WorldHandler.OnServerShutdown();

            SaveOnlinePlayers();
            Logger.GetInstance().ServerInfo("[SHUTDOWN]: Saving proccess finished, shutting down... ");
            NAPI.Chat.SendChatMessageToAll("[SERVER]: Saving proccess finished, shutting down...");
            Environment.Exit(1);
        }
Esempio n. 30
0
        /// <summary>
        /// Moves by waypoint
        /// </summary>
        ///<see cref="Probably implement some sort of A* and flocking ai either here or in the Command Component"/>>
        protected virtual void UpdateMove(GameTime gameTime, WorldHandler world)
        {
            Direction = zero;
            float distance = Vector2.Distance(Position, nextPoint);

            if (Position.X <= nextPoint.X && distance > 0.5f)
            {
                Direction     += xOne;
                this.Direction = Direction;
            }
            if (Position.X >= nextPoint.X && distance > 0.5f)
            {
                Direction     -= xOne;
                this.Direction = Direction;
            }
            if (Position.Y <= nextPoint.Y && distance > 0.5f)
            {
                Direction     += yOne;
                this.Direction = Direction;
            }
            if (Position.Y >= nextPoint.Y && distance > 0.5f)
            {
                Direction     -= yOne;
                this.Direction = Direction;
            }
            Vector2 TempPosition = Position + (Direction * 5 * gameTime.ElapsedGameTime.Milliseconds / 1000);

            if (world.GetUnit(TempPosition) != null && world.GetUnit(TempPosition) != this)
            {
                if (Direction.X < 0)
                {
                    nextPoint = TempPosition + new Vector2(0, 1);
                }
                else if (Direction.X > 0)
                {
                    nextPoint = TempPosition - new Vector2(0, 1);
                }
                if (Direction.Y < 0)
                {
                    nextPoint = TempPosition + new Vector2(1, 0);
                }
                else if (Direction.X > 0)
                {
                    nextPoint = TempPosition - new Vector2(1, 0);
                }
            }
            else if (Direction != zero)
            {
                Position = TempPosition;
            }
            WayPointFollower();
        }
Esempio n. 31
0
        public Room(Point worldSize, string setKey)
        {
            World           = new WorldHandler(worldSize);
            Key             = setKey;
            World.OwnerRoom = this;

            CachedGameObjects   = new Dictionary <string, GameObject>();
            ActiveGameObjects   = new List <GameObject>();
            DrawableGameObjects = new List <GameObject>();
            AcitvateQueue       = new List <string>();
            DeactivateQueue     = new List <string>();
            DestructQueue       = new List <string>();
        }