Exemplo n.º 1
0
        public static List<LightSource> GetLocalLightSources(double xPos, double yPos, Stage stage, View view)
        {
            List<LightSource> returnLights = new List<LightSource>();
            foreach (LightSource light in stage.GetLights(view))
            {
                //if the light is brighter than, or as bright as it is far away
                if (light.GetPosition().Distance(new Point(xPos, yPos)) <= light.range)
                {
                    //it is a "local" light source, add it to the return list
                    returnLights.Add(light);
                }
            }

            return returnLights;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Create a new Layer for user interface
        /// </summary>
        /// <param name="attachingView">The game view that the interface layer is attached to.</param>
        /// <param name="rectLayerPos">The position and size of the layer.</param>
        public GuiLayer(String layerName, View attachingView, Rectangle rectLayerPos)
        {
            GuiLayer.lastid++;
            this.id = "GUILayer" + GuiLayer.lastid;
            this.name = layerName;
            this.attachedView = attachingView;
            this.SetArea(rectLayerPos);

            attachedView.AddLayer(this);
            //add this layer to the list of all layers in the game
            GuiLayer.allTheLayers.Add(this);
            //if there isn't currently an active GUILayer, make this one the active one

            this.BackgroundOpacity = 0.0;
            this.ForegroundOpacity = 1.0;
            this.BackgroundColor = Color.Black;
        }
Exemplo n.º 3
0
        public override bool Visible(View view)
        {
            //if there are any entities that completely obscure the tile, return false

            // If it's not IN the view, return false
            if (this.GetPosition().x > view.GetSize().width / Stage.CurrentStage.GetTileSize().width ||
                this.GetPosition().y > view.GetSize().height / Stage.CurrentStage.GetTileSize().height)
            {
                return false;
            }

            //if the tile is colored differently than the stage's background color
            if (Stage.CurrentStage.AmbientLightLevel.Match(this.GetLightLevel()) == false)
            {
                return true;
            }

            if (this.GetSprite() != null)
            {
                return true;
            }

            if (this.GetParentStage().GetBackgroundSprite(view) != null)
            {
                return true;
            }

            return false;
        }
Exemplo n.º 4
0
        // For headless servers and whatnot.
        public static void MinimalInitialize()
        {
            Game.Clock = new MultiThreaded_Clock();
            Game.Clock.Start();

            Surface.Initialize(new Null_Renderer());
            //set up the primary view
            View playerOneView = new View(LightingStyle.Tiles);
            Game.Clock.AddCalculation(StandardCalculations);
            Game.Clock.IntervalExecute(Game.StandardIntervalCalculations, .2);
        }
Exemplo n.º 5
0
        public static void Init()
        {
            Game.Clock = new DOM_Clock();
            //Game.Clock.Start();

            //I must be script#'ing wrong. This won't fire here.
            InputManager.Input.Init();
            // Set up the local player
            Player LocalPlayer = new Player();
            //Surface.Initialize(new DOM_Renderer());
            //Surface.Initialize(new Canvas_Renderer());
            Game.Renderer = new Canvas_Renderer();
            SoundSystem = new HTML5_Audio();
            //set up the primary view
            // Remember to initialize the renderer first!
            View playerOneView = new View(LightingStyle.Tiles);
            playerOneView.SetArea(new Rectangle(0, 0, Renderer.GetSize().width, Renderer.GetSize().height));

            //notificationLayer = new GuiLayer(playerOneView, new Rectangle(0, 0, 0, 0));
            notificationLayer = playerOneView.AddLayer("NotificationLayer", new Rectangle(0, 0, 0, 0));
            notificationLayer.SetSize(522, 60);
            //notificationLayer.Hide();

            //create two gui elements on the layer:
            //an image on the left
            GuiElement notifIcon = notificationLayer.AddGUIElement("");
            notifIcon.AddStyle("notifIcon");
            notifIcon.SetPosition(12, 0);
            //and sender on the right
            GuiElement notifSender = notificationLayer.AddGUIElement("");
            notifSender.SetPosition(58, 0);
            notifSender.SetSize(474, 12);
            //and the sender's handle, if applicable
            GuiElement notifSenderHandle = notificationLayer.AddGUIElement("");
            notifSenderHandle.SetPosition(80, 0);
            notifSenderHandle.SetSize(474, 12);
            notifSenderHandle.AddStyle("tweetName");
            //and the text on the right
            GuiElement notifText = notificationLayer.AddGUIElement("");
            notifText.SetPosition(58, 18);
            notifText.SetSize(474, 40);
            notificationLayer.Hide();

            //clockRenderguy = Game.Clock.AddRender(Game.Renderer.RenderUpdate);
            //clockRenderguy = Game.Clock.AddRender(Game.Renderer.Render);

            //reposition the notification layer after a few seconds
            string notif_repos = Clock.AddRender(reposition_notification_layeer);
            Clock.delayRender(notif_repos, 2);

            Clock.AddCalculation(StandardCalculations);
            Clock.IntervalExecute(Game.StandardIntervalCalculations, .2);
            Game.Paused = false;
        }
Exemplo n.º 6
0
 public virtual bool Visible(View view)
 {
     return this.visible;
 }
Exemplo n.º 7
0
 public void SetBackgroundSprite(Sprite sprite, View view)
 {
     this.backgroundSprites[view] = sprite;
 }
Exemplo n.º 8
0
        public List<GameEntity> GetVisibleTiles(View viewer)
        {
            if (viewer.TilesVisible == false) return new List<GameEntity>();

            Debug.Watch("StageTiles", this.stageTiles.Count + "");
            List<GameEntity> resultList = new List<GameEntity>();

            foreach (Tile tile in this.stageTiles)
            {
                if (tile.Visible(viewer) == true)
                {
                    resultList.Add(tile);
                }
            }

            return resultList;
        }
Exemplo n.º 9
0
        //return a list of all of the tiles which are visible according to the restrictions of the passed View
        public List<GameEntity> GetVisibleEntities(View viewer)
        {
            List<GameEntity> resultList = new List<GameEntity>();
            if (viewer.EntitiesVisible == false) return resultList;

            foreach (TerrainCollider terCol in this.terrainColliders)
            {
                if (terCol.Visible(viewer) == true)
                {
                    resultList.Add(terCol);
                }
            }
            foreach (GameEntity ent in this.stageEntities)
            {
                //need to check if the GameEntity is visible
                if (ent.Visible(viewer) == true)
                {
                    resultList.Add(ent);
                }
            }
            foreach (LivingGameEntity lent in this.livingEntities)
            {
                if (lent.Visible(viewer) == true)
                {
                    resultList.Add(lent);
                }
            }

            return resultList;
        }
Exemplo n.º 10
0
        public List<Tile> GetTiles(bool visible = false, View view = null)
        {
            Debug.Watch("StageTiles", this.stageTiles.Count + "");

            // If we're filtering invisible tiles (visible parameter is true), then we need to process that filter.
            if (visible == true && view != null)
            {
                List<Tile> resultList = new List<Tile>();

                foreach (Tile tile in this.stageTiles)
                {
                    if (tile.Visible(view) == true)
                    {
                        resultList.Add(tile);
                    }
                }

                return resultList;
            }
            // Otherwise, we can just return the list as-is.
            else
            {
                return this.stageTiles;
            }
        }
Exemplo n.º 11
0
        public List<LightSource> GetLights(View view)
        {
            if (view.LightsVisible == false) return new List<LightSource>();

            return this.stageLights;
        }
Exemplo n.º 12
0
        public Sprite GetBackgroundSprite(View view)
        {
            if (this.backgroundSprites.ContainsKey(view))
            {
                return this.backgroundSprites[view];
            }

            return null;
        }
Exemplo n.º 13
0
 public void CalculateLights(View view)
 {
     for(int i = 0; i < this.GetLights(view).Count; i++)
     //foreach (LightSource light in this.GetLights())
     {
         LightSource light = this.GetLights(view)[i];
         if (light != null)
         {
             light.Think();
         }
     }
 }
Exemplo n.º 14
0
        public void RenderLightSource(LightSource light, View view)
        {
            HtmlElement gentlement = elementsByGameObjectId[light.GetId()].As<HtmlElement>();
            //if it's not rendered, render it
            if (gentlement == null)
            {
                Debug.log("Rendering light " + light.GetId());
                gentlement = document.createElement("div").As<HtmlElement>();
                this.AddClass(gentlement, "Entity LightSource");
                this.AddClass(gentlement, light.GetType().Name);
                foreach (string style in light.GetCustomStyles())
                {
                    this.AddClass(gentlement, style);
                }
                document.getElementById("gameBoard").appendChild(gentlement);
                if (light.GetType().Name == "Lightstone")
                {
                    gentlement.style.background = Gradient.LightStone(light.GetColor());
                    Debug.log(Gradient.LightStone(light.GetColor()));
                }
                else
                {
                    gentlement.style.background = Gradient.ToString(light.GetColor());
                }

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

            //if (this.gameEntitiesToUpdate.Contains(light.GetId()))
            //this.gameEntitiesToUpdate.Remove(light.GetId());

            Dimension tileSize = Stage.CurrentStage.GetTileSize();

            //the light's x and y are its center
            //the size of the div should be the diameter of the light, or twice its range
            //the visual element needs to shift -x and -y with each -range to remain 'centered' on the light's actual x and y

            //the amount to shift the position by
            int posShift = (int) light.GetRange() / 2;

            gentlement.style.left = ((light.GetPosition().x - posShift) * tileSize.width) + "px";
            gentlement.style.top = ((light.GetPosition().y - posShift) * tileSize.height) + "px";

            gentlement.style.width = (light.GetRange() * tileSize.width) + "px";
            gentlement.style.height = (light.GetRange() * tileSize.height) + "px";

            if (light.Visible(view) == true)
            {
                gentlement.style.display = "inline";
            }
            else
            {
                gentlement.style.display = "none";
            }

            int lightLeftInGameUnits = (int)light.GetPosition().x - posShift;
            int lightRightInGameUnits = (int)(lightLeftInGameUnits + light.GetRange());
            int lightTopInGameUnits = (int)light.GetPosition().y - posShift;
            int lightBottomInGameUnits = (int)(lightTopInGameUnits + light.GetRange());

            /*
            //make the tiles below the light partially transparent. because. just go with me on this.
            for (int tileX = lightLeftInGameUnits; tileX < lightRightInGameUnits; tileX++)
            {
                //Debug.Watch("TileX at ", tileX.ToString());
                for (int tileY = lightTopInGameUnits; tileY < lightBottomInGameUnits; tileY++)
                {
                    tileX = JsMath.ceil(tileX);
                    tileY = JsMath.ceil(tileY);

                    //only get tiles within the radius of the light, don't catch edges
                    //if (new Point(tileX, tileY).Distance(lightMid) > light.GetRange() / 2)
                    Point positionOfTheTileWeAreLookingAt = new Point(tileX, tileY);
                    Point centerOfTheLight = light.GetPosition();
                    //double lightRadius = light.GetRange() / 2;
                    int lightRadius = JsMath.floor(light.GetRange() / 2);
                    int distance = (int) positionOfTheTileWeAreLookingAt.Distance(centerOfTheLight);
                    //if(distance <= lightRadius)
                    //if (positionOfTheTileWeAreLookingAt.Distance(centerOfTheLight) <= lightRadius)
                    if (new Point(tileX, tileY).Distance(light.GetPosition()) > light.GetRange() / 2)
                    {
                        Tile affectedTile = Stage.CurrentStage.GetTileAt(tileX, tileY);
                        if (affectedTile != null)
                        {
                            affectedTile.SetOpcaity(.5);
                        }
                    }
                }
            }
            */
        }
Exemplo n.º 15
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";
            }
        }