Beispiel #1
0
 public void AddLight(LightSource newLight)
 {
     if (!this.stageLights.Contains(newLight))
     {
         this.stageLights.Add(newLight);
     }
 }
Beispiel #2
0
        public void fireLazer(GuiEvent evt)
        {
            //stop the periodic color growth
            Clock.RemoveRender(chargeInterval);

            //remove (hide) the gui element created in chargeLazer
            GuiLayer.GetLayerByName("CursorLayer").Hide();

            int range = 10;

            //create the light
            LightSource plCol = new LightSource(evt.eventPos.x, evt.eventPos.y, 5, range);
            plCol.SetDiminishing(true);
            plCol.SetColor(newLightColor);

            //create a shadow creature, of the same color as the player dropped

            //chase away any nearby shadow creatures colored opposite to what the player dropped

            /*
            //show / affect any nearby lightstones
            List<LightSource> lightsInRange = Stage.CurrentStage.GetLightsNear(evt.eventPos, range);
            foreach (LightSource light in lightsInRange)
            {
                if (light is Lightstone)
                {
                    light.Show();
                    Clock.TimedExecute(light.Hide, 1);
                }
            }
            */
            int lightRange = Helpah.d2i(plCol.GetRange());
            List<LightSource> lightList = Stage.CurrentStage.GetLightsNear(plCol.GetPosition(), lightRange);
            //Debug.log("There are " + lightList.Count + " lights in within " + lightRange + " of click.");
            foreach (LightSource light in lightList)
            {
                if (!(light is Lightstone))
                {
                    continue;
                }
                light.Show();
                Clock.TimedExecute(light.Hide, 1);
            }
        }
Beispiel #3
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);
                        }
                    }
                }
            }
            */
        }