예제 #1
0
        /// <summary>
        /// Add a batch of entities to be spawned by the spawner.
        /// Entities will be spawned in the order that they are added to the spawner,
        /// with the first entries being spawned first.
        /// </summary>
        /// <param name="GameEntityType">The type of GameEntity to spawn.</param>
        /// <param name="count">The number of entities to spawn.</param>
        /// <param name="spawnDelay">How long to wait until spawning the next batch.</param>
        public void AddGameEntityBatch(GameEntity GameEntityType, int GameEntityCount, int spawnDelay)
        {
            GameEntityBatch newBatch = new GameEntityBatch(GameEntityType, GameEntityCount, spawnDelay);
            this.spawnBatches.Add(newBatch);

            this.Activate();
        }
예제 #2
0
 public Projectile(string projectileName, GameEntity firingEnt, Point targetPoint)
     : base(projectileName)
 {
     this.targetPoint = targetPoint;
     this.firingEntity = firingEnt;
     //target the target
     //this.SetAI(null);
     this.SetAI(new ArtificialIntelligence());
     //ArtificialIntelligence ai = new ArtificialIntelligence();
     //MovementPath newPath = new MovementPath(this.GetPosition(),
     //ai.SetMovementPath(
 }
예제 #3
0
        /// <summary>
        /// Each of the parameters is nullable. The most complete set of data possible will be built from any non-null parameters.
        /// </summary>
        /// <param name="sendingTile"></param>
        /// <param name="sendingGameEntity"></param>
        /// <param name="sendingElement"></param>
        /// <param name="triggeringPosition"></param>
        /// <param name="triggeringScreenPosition"></param>
        /// <returns></returns>
        public static GuiEvent FromPartialData(Tile sendingTile, GameEntity sendingGameEntity, GuiElement sendingElement, Point triggeringPosition, Point triggeringScreenPosition)
        {
            GuiEvent eventToReturn = new GuiEvent(0, 0);

            //check each of the parameters for non-null values and set them in the event to return
            if (sendingTile != null)
            {
                eventToReturn.clickedTiles.Add(sendingTile);
            }
            if (sendingGameEntity != null)
            {
                eventToReturn.clickedEntities.Add(sendingGameEntity);
            }
            if (sendingElement != null)
            {
                eventToReturn.clickedElement = sendingElement;
            }
            if (triggeringPosition != null)
            {
                eventToReturn.eventPos = triggeringPosition;
            }
            if (triggeringScreenPosition != null)
            {
                eventToReturn.eventPixelPos = triggeringScreenPosition;
            }

            //go through the values, and determine values for those that are null
            if (eventToReturn.eventPos == null)
            {
                //get the position from one of the properties that we have...
            }

            //gotta do this for the other stuff too
            //eventToReturn.clickedElement = gLayer.GetElementAt(returnEvent.eventPos.x, returnEvent.eventPos.y);
            //eventToReturn.clickedEntities = gLayer.GetEntitiesAt(returnEvent.eventPos.x, returnEvent.eventPos.y);
            //eventToReturn.clickedTiles = gLayer.GetTilesAt(returnEvent.eventPos.x, returnEvent.eventPos.y);

            return eventToReturn;
        }
예제 #4
0
        /// <summary>
        /// This entity is colliding into another. This entity is the one doing the colliding. 
        /// </summary>
        /// <param name="collidingEntity"></param>
        public void Collision(GameEntity collidingEntity)
        {
            Vector collisionVector = new Vector(this.position.x - collidingEntity.GetPosition().x + this.speed.X,
                this.position.x - collidingEntity.GetPosition().x + this.speed.Y);

            string firingGuy = "";

            if(this.GetTypeName() == "Projectile")
            {
                //the projectile should not hit the entity that fired it
                Projectile projEnt = this.As<Projectile>();
                if (collidingEntity == projEnt.GetFiringEntity())
                {
                    return;
                }

                firingGuy = projEnt.GetFiringEntity().GetName();
            }

            //perform custom collision events first
            if (this.collisionEvent != null)
            {
                this.collisionEvent.Invoke(collidingEntity);
            }
            if (collidingEntity.collisionEvent != null)
            {
                collidingEntity.collisionEvent.Invoke(collidingEntity);
            }

            // Determine where the collision happens
            Point collisionPosition = new Point(0, 0);
            if (Math.Abs(this.speed.X) > Math.Abs(collidingEntity.speed.X))
            {
                collisionPosition.x = (Math.Abs(collidingEntity.speed.X) / Math.Abs(this.speed.X))
                    * Math.Abs(this.position.x - collidingEntity.position.x);
            }
            else
            {
                collisionPosition.x = (Math.Abs(this.speed.X) / Math.Abs(collidingEntity.speed.X))
                    * Math.Abs(collidingEntity.position.x - this.position.x);
            }

            // If the colliding entity is neither above nor below, check X collision.
            if (!collidingEntity.GetArea().Above(this.GetArea()) && !collidingEntity.GetArea().Below(this.GetArea()))
            {
                if ((this.position.x + this.speed.X > collidingEntity.position.x + collidingEntity.speed.X &&
                    this.position.x + this.speed.X < collidingEntity.position.x + collidingEntity.speed.X + collidingEntity.Width) ||
                    (this.position.x + this.speed.X < collidingEntity.position.x + collidingEntity.speed.X &&
                    this.position.x + this.speed.X + this.Width > collidingEntity.position.x + collidingEntity.speed.X))
                {
                    //newSpeed.x = 0;
                    //colNewSpeed.x = 0;
                }
            }

            // If colliding entity is neither to the left nor the right, check Y collision
            if (!(collidingEntity.GetArea().Right < this.GetArea().Left)
                && !(collidingEntity.GetArea().Left > this.GetArea().Right))
            {
                // If colliding from above...
                // "Minimum" speed is entity position minus colliding entity top.
                if (this.position.y + this.speed.Y < collidingEntity.position.y + collidingEntity.speed.Y &&
                    this.position.y + this.speed.Y + this.Height > collidingEntity.position.y + collidingEntity.speed.Y)
                {
                    this.SetPosition(this.GetPosition().x, collidingEntity.GetArea().Top);
                }

                // If colliding from below,
                // "Maximum" speed is colliding entity top minus entity bottom
                if (this.position.y + this.speed.Y > collidingEntity.position.y + collidingEntity.speed.Y &&
                    this.position.y + this.speed.Y < collidingEntity.position.y + collidingEntity.speed.Y + collidingEntity.Height)
                {
                    this.SetPosition(this.GetPosition().x, collidingEntity.GetArea().Bottom - this.GetArea().height);
                }
            }

            // Collision means speed = 0;
            this.SetSpeed(new Vector(0, 0));
            collidingEntity.SetSpeed(new Vector(0, 0));

            // Colliding with a tile.
            if (collidingEntity.GetTypeName() == "Tile")
            {
                // Debug.log(collisionVector.ToString());
            }

            // Well, we don't need to deal damage from a terrain collider.
            if (this.GetTypeName() == "TerrainCollider")
            {
                return;
            }

            int damage = 10;

            //deal damage to the other entity
            if (collidingEntity.GetTypeName() == "LivingGameEntity")
            {
                LivingGameEntity livingTarget = collidingEntity.As<LivingGameEntity>();
                /*
                Debug.log(this.GetName() + " " + this.GetId() + " at " + this.GetPosition().x + ", " + this.GetPosition().y +
                    " dealing " + damage + " damage to " + livingTarget.GetName() + " (" + livingTarget.GetId() + ") at " + livingTarget.GetPosition().x + ", " + livingTarget.GetPosition().y +
                    ". IsProjectile: " + isProj.ToString() + ", firingGuy is " + firingGuy + ", This type is " + this.GetType().Name.ToString());
                */
                Debug.log("Damaging " + livingTarget.GetName() + " by " + damage);
                livingTarget.Damage(damage);
            }
            //collidingEntity.dam
        }
예제 #5
0
 public void RemoveGameEntity(GameEntity gameEntityToRemove)
 {
     if (gameEntityToRemove.GetTypeName() == "LightSource")
     {
         LightSource lightToRemove = gameEntityToRemove.As<LightSource>();
         if (this.stageLights.Contains(lightToRemove))
         {
             this.stageLights.Remove(lightToRemove);
         }
     }
     else if (gameEntityToRemove .GetTypeName() == "Tile")
     {
         Tile tileToRemove = gameEntityToRemove.As<Tile>();
         if (this.stageTiles.Contains(tileToRemove))
         {
             this.stageTiles.Remove(tileToRemove);
         }
     }
     else if (gameEntityToRemove .GetTypeName() == "LivingGameEntity" || gameEntityToRemove .GetTypeName() == "Projectile")
     {
         LivingGameEntity livingEntityToRemove = gameEntityToRemove.As<LivingGameEntity>();
         if (this.livingEntities.Contains(livingEntityToRemove))
         {
             this.livingEntities.Remove(livingEntityToRemove);
         }
         else
         {
             Debug.log("Warning: Living entity list does not contain " + livingEntityToRemove.GetId() + " ( " + livingEntityToRemove.GetName() + " )");
         }
     }
     else
     {
         if (this.stageEntities.Contains(gameEntityToRemove))
         {
             this.stageEntities.Remove(gameEntityToRemove);
         }
     }
 }
예제 #6
0
        public GameEntity CreateGameEntity(string gameEntName, string spriteName)
        {
            GameEntity newEnt = new GameEntity(gameEntName);
            newEnt.SetSprite(Sprite.GetSpriteByName(spriteName));
            this.AddGameEntity(newEnt);

            return newEnt;
        }
예제 #7
0
        // Check whether an entity is physically in the stage.
        public bool Contains(GameEntity gent)
        {
            // If it's not in the absolute bounds of the stage, it won't be within the more constricting bounds.
            if (!this.GetBounds().Contains(gent.GetPosition()))
            {
                return false;
            }

            // Should maybe check if it's closer to the top or bottom... ?

            // Check the more constricting bounds
            if (gent.GetPosition().y > MaxY(gent.GetPosition().x) ||
                gent.GetPosition().y < MinY(gent.GetPosition().x))
            {
                return false;
            }

            return true;
        }
예제 #8
0
        public void AddGameEntity(GameEntity gameEntityToAdd)
        {
            if (gameEntityToAdd == null) return;

            if (gameEntityToAdd.GetTypeName() == "LivingGameEntity" || gameEntityToAdd.GetTypeName() == "Projectile") // || GameEntityToAdd.GetTypeName() == "Tile")
            {
                //LivingGameEntity entityToAdd = gameEntityToAdd.As<LivingGameEntity>();
                LivingGameEntity entityToAdd = (LivingGameEntity) gameEntityToAdd;
                //this.livingEntities.Add(gameEntityToAdd.As<LivingGameEntity>());
                if (this.livingEntities.Contains(entityToAdd)) return;
                this.livingEntities.Add(entityToAdd);
            }
            else if (gameEntityToAdd.GetTypeName() == "TerrainCollider")
            {
                //Debug.log("Here. This. Do not want.");
                if (this.terrainColliders.Contains(gameEntityToAdd.As<TerrainCollider>())) return;
                terrainColliders.Add((TerrainCollider)gameEntityToAdd);
            }
            else
            {
                if (this.stageEntities.Contains(gameEntityToAdd)) return;
                stageEntities.Add(gameEntityToAdd);
            }

            gameEntityToAdd.SetParentStage(this);
        }
예제 #9
0
 public bool CheckEntityVisibility(GameEntity gent)
 {
     if (this.GetVisibleArea().Contains(gent.GetArea()))
     {
         if (!visibleEntities.Contains(gent))
         {
             visibleEntities.Add(gent);
         }
         return true;
     }
     else
     {
         if (visibleEntities.Contains(gent))
         {
             visibleEntities.Remove(gent);
         }
         return false;
     }
 }
예제 #10
0
        //!Need to add better support for custom styles
        public void RenderGameEntity(GameEntity gent, View view)
        {
            HtmlElement gentlement = null;
            if (elementsByGameObjectId.ContainsKey(gent.GetId()))
            {
                gentlement = elementsByGameObjectId[gent.GetId()].As<HtmlElement>();
            }

            //if it's not rendered, render it
            if (gentlement == null)
            {
                gentlement = document.createElement("div").As<HtmlElement>();
                gentlement.id = gent.GetId();
                //later, we may want to add iterating through base types to get their type name and add it...
                this.AddClass(gentlement, "Entity");
                this.AddClass(gentlement, gent.GetType().Name);
                document.getElementById("gameBoard").appendChild(gentlement);
                foreach (string style in gent.GetCustomStyles())
                {
                    this.AddClass(gentlement, style);
                }
                if (gent.GetSprite() != null && gent.GetSprite().ScaleToSize == true)
                {
                    gentlement.style.backgroundSize = gent.GetSprite().Size.width + "px " + gent.GetSprite().Size.height + "px ";
                }

                elementsByGameObjectId[gent.GetId()] = gentlement;
            }

            if (gent.GetTypeName() == "Tile")
            {
                tilesRendrin++;
                Color tileCol = gent.As<Tile>().GetLightLevel();
                gentlement.style.backgroundColor = "rgb(" + tileCol.red + ", " + tileCol.green + ", " + tileCol.blue + ");";
                if (gent.GetSize().width != Stage.CurrentStage.GetTileSize().width || gent.GetSize().height != Stage.CurrentStage.GetTileSize().height)
                {
                    gentlement.style.width = Stage.CurrentStage.GetTileSize().width + "px";
                    gentlement.style.height = Stage.CurrentStage.GetTileSize().height + "px";
                }
            }

            if(this.gameEntitiesToUpdate.Contains(gent.GetId()))
            {
                //reposition the element based on game position
                gentlement.style.left = (gent.GetPosition().x * Stage.CurrentStage.GetTileSize().width) + "px";
                gentlement.style.top = ((Stage.CurrentStage.Height - gent.GetPosition().y - gent.Height)
                    * Stage.CurrentStage.GetTileSize().height) + "px";
                gentlement.style.opacity = gent.GetOpacity().ToString();

                this.gameEntitiesToUpdate.Remove(gent.GetId());
            }

            //if the entity doesn't have a sprite, we're done with all rendering for now
            if (gent.GetSprite() == null)
            {
                gentlement.style.border = "1px dashed blue";
                return;
            }

            //call the sprite's animate function
            //it will return the id of the frame that the sprite and its animation are currently on
            string frameId = gent.GetSprite().Animate();
            Debug.Watch("Animation count", gent.GetSprite().GetCurrentAnimation().animationCount.ToString(), true);

            //if that result is different from the value we have stored as this GameEntity's current display frame,
            if (frameId != gent.GetSprite().CurrentRenderFrame)
            {
                //update this thing's CSS to the new frame
                //jQueryObject GameEntityDiv = jQuery.FromElement(GameEntityDiv);
                this.RemoveClass(gentlement, gent.GetSprite().CurrentRenderFrame);
                this.AddClass(gentlement, frameId);
                derp = gentlement.className;
                //and update our current frameid
                gent.GetSprite().CurrentRenderFrame = frameId;

                gentlement.style.width = gent.GetSprite().Size.width + "px";
                gentlement.style.height = gent.GetSprite().Size.height + "px";
            }
        }
예제 #11
0
 public void DestroyGameEntity(GameEntity gent)
 {
     Element gentlement = elementsByGameObjectId[gent.GetId()];
     if (gentlement != null)
     {
         try
         {
             gentlement.parentElement.removeChild(gentlement);
             elementsByGameObjectId.Remove(gent.GetId());
         }
         catch (Exception ex)
         {
             Debug.log("Failed to destroy " + gent.GetId() + " ( " + gent.GetName() + " ) :");
             Debug.log(ex.Message);
         }
     }
 }
예제 #12
0
 public GameEntityBatch(GameEntity GameEntityType, int GameEntityCount, int spawnDelay)
 {
     this.GameEntityType = GameEntityType;
     this.GameEntityCount = GameEntityCount;
     this.spawnDelay = spawnDelay;
 }
예제 #13
0
 public void SetFiringEntity(GameEntity firingEnt)
 {
     this.firingEntity = firingEnt;
 }
예제 #14
0
 public void old_CheckEntityVisibility(GameEntity gent)
 {
     if (gent.GetPosition().x >= this.x + (offsetX / stgAttached.GetTileSize().width)
         && gent.GetPosition().x <= this.x + ((offsetX + this.size.width) / stgAttached.GetTileSize().width)
         && gent.GetPosition().y >= this.x + (offsetY / stgAttached.GetTileSize().height)
         && gent.GetPosition().y <= this.x + ((offsetY + this.size.height) / stgAttached.GetTileSize().height))
     {
         if (!visibleEntities.Contains(gent))
         {
             visibleEntities.Add(gent);
         }
     }
     else
     {
         if (visibleEntities.Contains(gent))
         {
             visibleEntities.Remove(gent);
         }
     }
 }
예제 #15
0
 public void FollowEntity(GameEntity gentToFollow)
 {
     Debug.log("Warning. Attempting to follow " + gentToFollow.GetName() + " but function not implemented.");
 }
예제 #16
0
 public void SetTarget(GameEntity newTarget)
 {
     this.target = newTarget;
 }
예제 #17
0
 public void SetNeedsUpdate(GameEntity gent)
 {
     if (!this.gameEntitiesToUpdate.Contains(gent.GetId()))
     {
         this.gameEntitiesToUpdate.Add(gent.GetId());
     }
 }
예제 #18
0
        private void updateWaveGUI(GameEntitySpawner spawner, GameEntity gent)
        {
            GuiLayer topBar = GuiLayer.GetLayerByName("TopBar");

            // The current wave we're on.
            topBar.GetGUIElement(0).As<LabelValue>().SetValue(spawner.GetCurrentBatch());
            // The total number of entities in the wave.
            topBar.GetGUIElement(1).As<LabelValue>().SetValue(spawner.GetBatchCount());
            // Which number in the wave is currently spawning.
            topBar.GetGUIElement(2).As<LabelValue>().SetValue(spawner.GetCurrentSpawnPosition());
            // The number of entities in the wave.
            topBar.GetGUIElement(3).As<LabelValue>().SetValue(spawner.GetCurrentSpawnCount());
        }
예제 #19
0
        //as above, but duplacte to X batches
        public void AddGameEntityBatches(GameEntity GameEntityType, int GameEntityCount, int batchCount, int spawnDelay)
        {
            while (batchCount > 0)
            {
                AddGameEntityBatch(GameEntityType, GameEntityCount, spawnDelay);
                batchCount--;
            }

            this.Activate();
        }
예제 #20
0
 //attach the gui element to a game GameEntity, so that it follows it...
 public void AttachToGameEntity(GameEntity entToAttach)
 {
 }