Example #1
0
        public Tile(TileType tileType, int[] mapPosition, int tileSize, bool terrain = false, bool collidable = true, bool overridable = false, bool requiresSupport = false, bool canSupport = true)
        {
            this.tileType        = tileType;
            this.mapPosition     = mapPosition;
            this.terrain         = terrain;
            this.collidable      = collidable;
            this.requiresSupport = requiresSupport;
            this.overridable     = overridable;
            rectangle            = new Rectangle(mapPosition[0] * tileSize, mapPosition[1] * tileSize, tileSize, tileSize);
            OnBreak         = new EventHandler((sender, e) => { });
            this.canSupport = canSupport;
            if (tileType != null)
            {
                lightingManager = new LightingManager(mapPosition, tileType.lightSource);
                lightingManager.radianceLevel = tileType.radianceLevel;
            }

            if (Game1.gameTime != null)
            {
                millisecondsFromLastFrame = (uint)Game1.gameTime.TotalGameTime.TotalMilliseconds;
            }
            else
            {
                millisecondsFromLastFrame = 0;
            }
        }
Example #2
0
        protected override void Update(GameTime gameTime)
        {
            //Update gameTime
            Game1.gameTime = gameTime;

            //Update server
            networkManager.updateGameServer();

            //Receive data from server
            networkManager.receiveInformationFromGameServer();

            //Update day-night cycle
            LightingManager.updateDayNightCycle(gameTime);

            //Player controller
            mainPlayer.keyboardController(Keyboard.GetState(), Mouse.GetState());
            mainPlayer.mouseController(Mouse.GetState(), gameTime, Keyboard.GetState());

            //Update physics
            mainPlayer.updatePhysics();

            //TEST PROJECTILE
            if (pastKeyboardState.IsKeyDown(Keys.R) && Keyboard.GetState().IsKeyUp(Keys.R))
            {
                currentMap.entityAddQueue.Add(new Projectile(Projectile.flyingBulletTexture, new Vector2(1F, -1F), new RigidBody(1, new Rectangle(mainPlayer.rigidBody.collisionRectangle.X - (int)(mainPlayer.relativeOffset.X), mainPlayer.rigidBody.collisionRectangle.Y - (int)(mainPlayer.relativeOffset.Y), 10, 10)), 100, affectedByGravity: false, entityBlacklist: new Entity[] { Game1.mainPlayer }));
            }

            //Update map
            currentMap.update(gameTime, GraphicsDevice.Viewport.Width);

            //TEST
            if (Keyboard.GetState().IsKeyDown(Keys.Down))
            {
                LightingManager.skyLightIntensity -= .005F;
            }
            if (Keyboard.GetState().IsKeyDown(Keys.Up))
            {
                LightingManager.skyLightIntensity += .005F;
            }

            //Send information to server
            networkManager.sendInformationToGameServer();

            //TEST
            pastKeyboardState = Keyboard.GetState();

            base.Update(gameTime);
        }
Example #3
0
 public override void draw(SpriteBatch spriteBatch)
 {
     spriteBatch.Draw(spritesheetManager.currentTexture, new Rectangle(rigidBody.collisionRectangle.X - ((drawDimensions[0] - rigidBody.collisionRectangle.Width) / 2), rigidBody.collisionRectangle.Y - ((drawDimensions[1] - rigidBody.collisionRectangle.Height) / 2), drawDimensions[0], drawDimensions[1]), null, LightingManager.entityLightingColor(rigidBody.collisionRectangle), 0, Vector2.Zero, spritesheetManager.currentEffect, 0);
 }
Example #4
0
 public void draw(SpriteBatch spriteBatch)
 {
     spriteBatch.Draw(otherPlayerSpritesheet[spritesheetLocation[0], spritesheetLocation[1]], drawRectangle, null, LightingManager.entityLightingColor(collisionRectangle), 0, Vector2.Zero, currentEffect, 0);
     spriteBatch.DrawString(GUI.GUIFont, username, new Vector2(drawRectangle.Center.X - (GUI.GUIFont.MeasureString(username).X / 2), drawRectangle.Y - GUI.GUIFont.MeasureString(username).Y), Color.White);
 }
Example #5
0
 public override void draw(SpriteBatch spriteBatch)
 {
     spriteBatch.Draw(spritesheetManager.currentTexture, drawRectangle, null, LightingManager.entityLightingColor(new Rectangle((int)(rigidBody.collisionRectangle.X - Game1.mainPlayer.relativeOffset.X), (int)(rigidBody.collisionRectangle.Y - Game1.mainPlayer.relativeOffset.Y), rigidBody.collisionRectangle.Width, rigidBody.collisionRectangle.Height)), 0, Vector2.Zero, spritesheetManager.currentEffect, 0);
     //DEBUG COLLISION
     //spriteBatch.Draw(TileType.grassTile.texture, rigidBody.collisionRectangle, Color.White);
 }
Example #6
0
        private void interpretTileServerMessage(string[] data)
        {
            if (data[2] == ((int)GameServer.NetworkKeyword.tileChange).ToString())
            {
                //Change tile
                if (data.Length >= 6 && data[5] == ((int)GameServer.NetworkKeyword.tileNull).ToString())
                {
                    //Remove tile
                    int[] mapPosition = { int.Parse(data[3]), int.Parse(data[4]) };
                    if (tileMap[mapPosition[0], mapPosition[1]] != null)
                    {
                        if (data[6] == ((int)GameServer.NetworkKeyword.trueIdentifier).ToString())
                        {
                            //Tagged by server
                            tileMap[mapPosition[0], mapPosition[1]].breakTile(false);
                        }
                        else
                        {
                            //Not tagged
                            tileMap[mapPosition[0], mapPosition[1]].breakTile(true);
                        }
                    }

                    //Update lighting
                    LightingManager.updateSurroundingTiles(mapPosition);
                }
                else
                {
                    //Update tile to specified TileType
                    Tile newTile = JsonConvert.DeserializeObject <Tile>(data[4]);
                    foreach (TileType b in TileType.tileTypes)
                    {
                        if (b.name == data[3])
                        {
                            //Matching tiletype
                            newTile.tileType = b;
                        }
                    }

                    tileMap[newTile.mapPosition[0], newTile.mapPosition[1]] = newTile;

                    //Update lighting
                    LightingManager.updateSurroundingTiles(new int[] { newTile.mapPosition[0], newTile.mapPosition[1] });
                }
            }
            else if (data[2] == ((int)GameServer.NetworkKeyword.tileBreakOverlay).ToString())
            {
                //Break overlay
                int[] mapPosition = { int.Parse(data[3]), int.Parse(data[4]) };
                if (tileMap[mapPosition[0], mapPosition[1]] != null)
                {
                    if (int.Parse(data[5]) != -1)
                    {
                        tileMap[mapPosition[0], mapPosition[1]].currentBreakOverlay = tileMap[mapPosition[0], mapPosition[1]].tileType.breakOverlay[int.Parse(data[5])];
                    }
                    else
                    {
                        tileMap[mapPosition[0], mapPosition[1]].currentBreakOverlay = null;
                    }
                }
            }
        }
Example #7
0
 public override void draw(SpriteBatch spriteBatch)
 {
     spriteBatch.Draw(itemsInDrop[0].itemType.itemTexture, rigidBody.collisionRectangle, LightingManager.entityLightingColor(rigidBody.collisionRectangle));
 }
Example #8
0
        public TileType(Texture2D[] textures, string name, short breakTime, Texture2D[] breakOverlay, TileMaterial tileMaterial, EventHandler OnInteraction = null, int millisecondsBetweenFrames = 0, bool requiresSupport = false, bool collidable = true, bool lightSource = false, byte radianceLevel = 0, ItemType droppedItemType = null, bool breakable = true, object[,,] craftingRecipe = null, int amountFromCraft = 1)
        {
            this.textures                  = textures;
            this.name                      = name;
            this.breakTime                 = breakTime;
            this.breakOverlay              = breakOverlay;
            this.breakable                 = breakable;
            this.tileMaterial              = tileMaterial;
            this.lightSource               = lightSource;
            this.radianceLevel             = radianceLevel;
            this.collidable                = collidable;
            this.requiresSupport           = requiresSupport;
            this.millisecondsBetweenFrames = millisecondsBetweenFrames;

            if (OnInteraction == null)
            {
                this.OnInteraction = new EventHandler((sender, e) => { });
            }
            else
            {
                this.OnInteraction = OnInteraction;
            }

            //Create item type and action
            ItemType.ItemAction rightClickAction = () =>
            {
                if (Game1.currentMap.isConnectedTile(Game1.currentMap.positionSelected, requiresSupport))
                {
                    Game1.currentMap.tileMap[Game1.currentMap.positionSelected[0], Game1.currentMap.positionSelected[1]] = new Tile(this, Game1.currentMap.positionSelected, Game1.currentMap.tileSize, collidable: collidable, requiresSupport: requiresSupport);

                    //Remove decorative tiles
                    if (collidable)
                    {
                        Game1.currentMap.decorativeTileMap[Game1.currentMap.positionSelected[0], Game1.currentMap.positionSelected[1]].Clear();
                    }

                    //Update server
                    string tileSerialized = JsonConvert.SerializeObject(Game1.currentMap.tileMap[Game1.currentMap.positionSelected[0], Game1.currentMap.positionSelected[1]]);
                    Game1.networkManager.messagesToSendToServer += ((int)GameServer.NetworkKeyword.mapInfo).ToString() + GameServer.dataSeparator + ((int)GameServer.NetworkKeyword.tileInfo).ToString() + GameServer.dataSeparator + ((int)GameServer.NetworkKeyword.tileChange).ToString() + GameServer.dataSeparator + Game1.mainPlayer.playerGUI.playerInventory.selectedCell.items[0].itemType.name + GameServer.dataSeparator + tileSerialized + GameServer.messageSeparator;

                    //Update lighting
                    LightingManager.updateSurroundingTiles(Game1.currentMap.positionSelected);

                    return(true);
                }

                return(false);
            };
            tileItemType = new TileItemType(name, this, Color.White, rightClickAction: rightClickAction, craftingRecipe: craftingRecipe, amountMadeFromCraft: amountFromCraft);

            if (droppedItemType == null)
            {
                this.droppedItemType = tileItemType;
            }
            else
            {
                this.droppedItemType = droppedItemType;
            }

            //Add to registry
            tileTypes.Add(this);
            //Give tiletype ID
            tileTypeID = tileTypes.Count - 1;
        }
Example #9
0
        public void breakTile(bool brokenByPlayer, Player playerBrokenBy = null)
        {
            currentBreakTime    = 0;
            currentBreakOverlay = null;

            //Remove dependent surface tile
            removeDependentSurfaceTiles();

            if (brokenByPlayer)
            {
                if (playerBrokenBy != null)
                {
                    playerBrokenBy.breakTile();
                }

                //Update server
                Game1.networkManager.messagesToSendToServer += ((int)GameServer.NetworkKeyword.mapInfo).ToString() + GameServer.dataSeparator + ((int)GameServer.NetworkKeyword.tileInfo).ToString() + GameServer.dataSeparator + ((int)GameServer.NetworkKeyword.tileChange).ToString() + GameServer.dataSeparator + mapPosition[0] + GameServer.dataSeparator + mapPosition[1] + GameServer.dataSeparator + ((int)GameServer.NetworkKeyword.tileNull).ToString() + GameServer.dataSeparator + ((int)GameServer.NetworkKeyword.falseIdentifier).ToString() + GameServer.messageSeparator;

                //Drop to map
                if (tileType.droppedItemType != null)
                {
                    Game1.currentMap.entityAddQueue.Add(new Drop(new Item[] { new Item(tileType.droppedItemType) }, new RigidBody(Drop.massesOfPlayer), new Vector2(rectangle.Center.X, rectangle.Center.Y)));
                }

                Random random = Game1.currentMap.syncedRandom;
                for (int i = 0; i < particlesFromBreak; i++)
                {
                    Game1.currentMap.particleAddQueue.Add(new TileParticle(random.Next(particleSize - particleSizeVariation, particleSize + particleSizeVariation + 1), new Vector2(rectangle.Center.X, rectangle.Center.Y), tileType.textures[textureArrayLocation], 2000, random, initialVelocity: new Vector2(random.Next(-1, 2) * maxParticleFromBreakVelocity, random.Next(-1, 2) * maxParticleFromBreakVelocity)));
                }
            }
            if (terrain)
            {
                //Add background tile
                Game1.currentMap.backgroundTileMap[mapPosition[0], mapPosition[1]] = new BackgroundTile(tileType.textures[0], mapPosition);
            }
            Game1.currentMap.tileMap[mapPosition[0], mapPosition[1]] = null;

            OnBreak.Invoke(this, null);

            //Check tile above for requiring support
            if (mapPosition[1] - 1 >= 0 && Game1.currentMap.tileMap[mapPosition[0], mapPosition[1] - 1] != null)
            {
                //Check
                if (Game1.currentMap.tileMap[mapPosition[0], mapPosition[1] - 1].requiresSupport)
                {
                    if (brokenByPlayer)
                    {
                        Game1.currentMap.tileMap[mapPosition[0], mapPosition[1] - 1].breakTile(true, playerBrokenBy);
                    }
                    else
                    {
                        Game1.currentMap.tileMap[mapPosition[0], mapPosition[1] - 1].breakTile(false);
                    }
                }
            }

            if (brokenByPlayer)
            {
                //Update lighting
                LightingManager.updateSurroundingTiles(mapPosition);
            }
        }
Example #10
0
 public override void draw(SpriteBatch spriteBatch)
 {
     spriteBatch.Draw(texture, rigidBody.collisionRectangle, sourceRectangle, LightingManager.entityLightingColor(rigidBody.collisionRectangle));
 }
Example #11
0
 public virtual void draw(SpriteBatch spriteBatch)
 {
     spriteBatch.Draw(texture, rigidBody.collisionRectangle, LightingManager.entityLightingColor(rigidBody.collisionRectangle));
 }
Example #12
0
 public BackgroundTile(Texture2D texture, int[] mapPosition)
 {
     this.mapPosition = mapPosition;
     this.texture     = texture;
     lightingManager  = new LightingManager(mapPosition, backgroundTile: true);
 }