Beispiel #1
0
 public EntityFallingTile(int x, int y, int index, World.TileDepth tileDepth)
     : base(x, y)
 {
     this.index = index;
     this.tileDepth = tileDepth;
     stack = new ItemStack(Item.itemTile, 1, index);
 }
Beispiel #2
0
 public override int getLight(int x, int y, World.TileDepth tileDepth)
 {
     if(Game.instance.currentWorld==null){
         return 0;
     }
     return Game.instance.currentWorld.getTileData(x, y, tileDepth)==0?base.getLight(x, y, tileDepth):0;
 }
Beispiel #3
0
        public override void updateRandom(World world, int x, int y, World.TileDepth tileDepth)
        {
            if (world.getTileIndex(x - 1, y, tileDepth) == Tile.TileDirt.index) {
                growTo(world, x - 1, y, tileDepth);
            }
            if (world.getTileIndex(x + 1, y, tileDepth) == Tile.TileDirt.index) {
                growTo(world, x + 1, y, tileDepth);
            }
            if (world.getTileIndex(x, y - 1, tileDepth) == Tile.TileDirt.index) {
                growTo(world, x, y - 1, tileDepth);
            }
            if (world.getTileIndex(x, y + 1, tileDepth) == Tile.TileDirt.index) {
                growTo(world, x, y + 1, tileDepth);
            }

            if (world.getTileIndex(x - 1, y - 1, tileDepth) == Tile.TileDirt.index) {
                growTo(world, x - 1, y - 1, tileDepth);
            }
            if (world.getTileIndex(x + 1, y - 1, tileDepth) == Tile.TileDirt.index) {
                growTo(world, x + 1, y - 1, tileDepth);
            }
            if (world.getTileIndex(x + 1, y + 1, tileDepth) == Tile.TileDirt.index) {
                growTo(world, x + 1, y + 1, tileDepth);
            }
            if (world.getTileIndex(x - 1, y + 1, tileDepth) == Tile.TileDirt.index) {
                growTo(world, x - 1, y + 1, tileDepth);
            }
        }
Beispiel #4
0
        public override TextureInfo getTextureInfo(int x, int y, World world, World.TileDepth tileDepth)
        {
            Rectangle r = get8(3, 3);

            int l = world.getTileDataNoCheck(x, y, tileDepth);

            int k = 1;

            bool kk = false;

            for (int i = 0; i < size.X; i++) {
                for (int j = size.Y - 1; j >= 0; j--) {
                    if (k == l || k == -l) {
                        r = get8(l<0?(size.X-1-i):i, j);
                        kk = true;
                        break;
                    }
                    k++;
                }
                if (kk) {
                    break;
                }
            }

            return new TextureInfo(r, true, Point.Zero, l<0, false);
        }
Beispiel #5
0
        public override void update(Game game, World world)
        {
            bool gravityOn = true;

            if (pickUpDelay <= 0) {
                float d = Vector2.Distance(world.player.position, position);
                Rectangle pr = new Rectangle((int)world.player.position.X, (int)world.player.position.Y, (int)world.player.size.X, (int)world.player.size.Y);
                Rectangle r = new Rectangle((int)position.X, (int)position.Y, (int)size.X, (int)size.Y);

                foreach(Entity e in world.EntityList){
                    if (e is EntityItem) {
                        EntityItem ei = ((EntityItem)e);
                        if (e.uniqueID < uniqueID) {
                            if(ei.stack.getItem().index == stack.getItem().index && ei.stack.getData() == stack.getData()){
                                if(Vector2.Distance(ei.position, position) < (World.tileSizeInPixels)){
                                    ei.stack.setCount(stack.setCount(stack.getCount() + ei.stack.getCount()));
                                }
                            }
                        }
                    }
                }

                if (pr.Intersects(r)) {
                    stack = game.inventory.pickUp(stack);
                    if(stack.isEmpty()){
                        if (!playedSoundEffectRecently) {
                            SoundEffectPlayer.playSoundWithRandomPitch(SoundEffectPlayer.SoundPop);
                        }
                    }
                    pickUpDelay = maxPickupDelay;
                } else if (d < (6 * World.tileSizeInPixels)) {
                    position += ((world.player.position - position)/d) * 4;
                    gravityOn = false;
                }
            }

            if (stack.isEmpty()) {
                remove(game, world);
            }

            if (!collision(world, speed.X, 0)) {
                position.X += speed.X;
            } else {
                speed.X = 0;
            }

            if (!collision(world, 0, speed.Y)) {
                position.Y += speed.Y;
            } else {
                speed.Y = 0;
            }

            if (collision(world, 0, 1)) {

            } else if (gravityOn) {
                speed.Y += gravityAcc;
            }

            pickUpDelay--;
        }
Beispiel #6
0
 public override TextureInfo getTextureInfo(int x, int y, World world, World.TileDepth tileDepth)
 {
     if(renderType == RenderType.custom){
         return new TextureInfo(get8(x8th, y8th), true);
     } else {
         return base.getTextureInfo(x, y, world, tileDepth);
     }
 }
Beispiel #7
0
 public override void updateNearChange(World world, int x, int y, World.TileDepth tileDepth)
 {
     if (world.getTileIndex(x, y + 1, tileDepth) == Tile.TileAir.index) {
         world.setTile(x, y, Tile.TileAir, tileDepth);
         world.EntityAddingList.Add(new EntityFallingTile(x*World.tileSizeInPixels, y*World.tileSizeInPixels, index, tileDepth));
         world.setTileForUpdate(x, y-1, tileDepth);
     }
 }
Beispiel #8
0
 public override void draw(Game game, World world)
 {
     byte a = (byte)MathHelper.Clamp(world.getLight((int)(position.X + (size.X / 2)) / World.tileSizeInPixels, (int)(position.Y + (size.Y / 2)) / World.tileSizeInPixels), 0, 255);
     if (tileDepth==World.TileDepth.wall) {
         Tile t = Tile.getTileObject(stack.getItem().index);
         a = (byte)Clamp(a - (255 - t.wallBrightness), 0, t.wallBrightness);
     }
     stack.drawNoCount(game, new Rectangle((int)position.X - world.viewOffset.X - (World.tileSizeInPixels / 2), (int)position.Y - world.viewOffset.Y - (World.tileSizeInPixels / 2), World.tileSizeInPixels * 2, World.tileSizeInPixels * 2), new Color(a, a, a), Game.RENDER_DEPTH_ENTITY_FALLING_SAND);
 }
Beispiel #9
0
        public override void draw(Game game, World world)
        {
            byte a = (byte)MathHelper.Clamp(world.getLight((int)(position.X + (size.X / 2)) / World.tileSizeInPixels, (int)(position.Y + (size.Y / 2)) / World.tileSizeInPixels), 0, 255);
            Game.drawRectangle(Entity.Texture_Entity_Player, drawBounds, new Rectangle(0, 0, 16, 24), World.grayColors[a], Game.RENDER_DEPTH_PLAYER);

            if (game.inventory.currentItem != null) {
                game.inventory.currentItem.getItem().drawOverPlayer(game, game.inventory.currentItem, facingRight, new Vector2(displayPosition.X - xoff + (facingRight ? renderSize.X*1f : renderSize.X*.5f), displayPosition.Y), World.grayColors[a], game.getMousePosition());
            }
        }
Beispiel #10
0
 public override void mine(World world, int x, int y, int data, ItemPick pick, World.TileDepth tileDepth)
 {
     if (world.isTileSolid(x, y + 1, tileDepth)) {
         if (world.getTileIndex(x + 1, y, tileDepth) == index) {
             world.mineTile(x + 1, y, pick, tileDepth);
         }
         if (world.getTileIndex(x - 1, y, tileDepth) == index) {
             world.mineTile(x - 1, y, pick, tileDepth);
         }
     }
 }
Beispiel #11
0
        public static void Generate(World world, int type, Random rand)
        {
            switch(type){
                case (TypeEmpty): { break; };
                case (TypeFlat): { GenerateFlat(world, rand); break; };
                case (TypeNatural): { GenerateNatural(world, rand); break; };
            }

            for (int i = 0; i < 100; i++) {
                world.SimUpdate(0);
            }
        }
Beispiel #12
0
 public override bool canBePlacedHereOverridable(World world, int x, int y, World.TileDepth tileDepth)
 {
     if (world.getTileIndex(x, y, tileDepth) != Tile.TileAir.index) {
         return false;
     }
     for (int i = 0; i < restOns.Length;i++ ) {
         if (world.getTileObject(x + restOnX, y + restOnY, tileDepth).index == restOns[i].index) {
             return true;
         }
     }
     return false;
 }
Beispiel #13
0
        public bool collision(World world, int xTile, int yTile, bool isSolid)
        {
            Rectangle r = new Rectangle((xTile * World.tileSizeInPixels), (yTile * World.tileSizeInPixels), World.tileSizeInPixels, World.tileSizeInPixels);
            foreach(Entity e in world.EntityList){
                if (e.isSolid || (e is EntityPlayer && isSolid) || e is EntityFallingTile) {
                    if (r.Intersects(new Rectangle((int)(e.position.X), (int)(e.position.Y), (int)(e.size.X), (int)(e.size.Y)))) {
                        return true;
                    }
                }

            }
            return false;
        }
Beispiel #14
0
 public bool collisionCustom(World world, float x, float y, World.TileDepth tileDepth)
 {
     Rectangle r = new Rectangle((int)(position.X + x), (int)(position.Y + y), (int)size.X, (int)size.Y);
     for (int i = (r.Left / World.tileSizeInPixels); i < (r.Right / World.tileSizeInPixels) + 1; i++) {
         for (int j = (r.Top / World.tileSizeInPixels); j < (r.Bottom / World.tileSizeInPixels) + 1; j++) {
             Tile t = world.getTileObject(i, j, tileDepth);
             if (t != null) {
                 if (t.isSolid(world, i, j)) {
                     return true;
                 }
             }
         }
     }
     return false;
 }
Beispiel #15
0
        public override TextureInfo getTextureInfo(int x, int y, World world, World.TileDepth tileDepth)
        {
            bool left = world.getTileObject(x - 1, y, tileDepth).index == index;
            bool right = world.getTileObject(x + 1, y, tileDepth).index == index;
            bool down = world.getTileObject(x, y + 1, tileDepth).index == index;
            bool up = world.getTileObject(x, y - 1, tileDepth).index == index;

            bool leftSolid = world.isTileSolid(x - 1, y, tileDepth);
            bool rightSolid = world.isTileSolid(x + 1, y, tileDepth);
            bool downSolid = world.isTileSolid(x, y + 1, tileDepth);
            bool upSolid = world.isTileSolid(x, y - 1, tileDepth);

            Rectangle r;
            bool t = transparent;
            if(left && right){
                if (downSolid) {
                    r = get8(1, 2);
                } else {
                    r = get8(1, 1);
                }
            } else if (right) {
                if (downSolid) {
                    r = get8(0, 2);
                } else if (down) {
                    r = get8(0, 0);
                } else {
                    r = get8(0, 1);
                }
            } else if (left) {
                if (downSolid) {
                    r = get8(2, 2);
                } else if (down) {
                    r = get8(2, 0);
                } else {
                    r = get8(2, 1);
                }
            } else {
                if (downSolid) {
                    r = get8(1, 2);
                } else if (down) {
                    r = get8(1, 0);
                } else {
                    r = get8(3, 3);
                }
            }
            return new TextureInfo(r, t);
        }
Beispiel #16
0
 private void growTo(World world, int x, int y, World.TileDepth tileDepth)
 {
     bool grow = false;
     if (world.getTileObject(x - 1, y, tileDepth).transparent) {
         grow = true;
     }
     if (world.getTileObject(x + 1, y, tileDepth).transparent) {
         grow = true;
     }
     if (world.getTileObject(x, y - 1, tileDepth).transparent) {
         grow = true;
     }
     if (world.getTileObject(x, y + 1, tileDepth).transparent) {
         grow = true;
     }
     if (grow) {
         world.setTile(x, y, Tile.TileGrass, tileDepth);
     }
 }
Beispiel #17
0
        public bool collision(World world, float x, float y, bool ignorePlatforms = false)
        {
            Rectangle r = new Rectangle((int)(position.X + x), (int)(position.Y + y), (int)size.X, (int)size.Y);
            if (collisionOnlyTiles(world, x, y, r, ignorePlatforms)) {
                return true;
            }
            foreach (Entity e in world.EntityList) {
                if(e==null){
                    continue;
                }
                if (e.isSolid) {
                    if (r.Intersects(new Rectangle((int)(e.position.X), (int)(e.position.Y), (int)(e.size.X), (int)(e.size.Y)))) {
                        return true;
                    }
                }

            }
            return false;
        }
Beispiel #18
0
 public bool collisionOnlyTiles(World world, float x, float y, Rectangle r, bool ignorePlatforms = false)
 {
     for (int i = (r.Left / World.tileSizeInPixels); i < (r.Right / World.tileSizeInPixels) + 1; i++) {
         for (int j = (r.Top / World.tileSizeInPixels); j < (r.Bottom / World.tileSizeInPixels) + 1; j++) {
             Tile t = world.getTileObject(i, j, World.TileDepth.tile);
             if (t != null) {
                 if (t.isSolid(world, i, j)) {
                     return true;
                 }
                 if (!ignorePlatforms && t.isPlatform(world, i, j, World.TileDepth.tile)) {
                     if (r.Bottom <= ((j+1) * World.tileSizeInPixels) && speed.Y>=0) {
                         return true;
                     }
                 }
             }
         }
     }
     return false;
 }
Beispiel #19
0
        public override bool canBePlacedHereOverridable(World world, int x, int y, World.TileDepth tileDepth)
        {
            for (int i = 0; i < size.X; i++) {
                for (int j = size.Y - 1; j >= 0; j--) {

                    if (!world.getTileObject(x + i, y + j - (size.Y - 1), tileDepth).isAir()) {
                        return false;
                    }
                }
            }

            for (int i = 0; i < size.X; i++) {
                if (!world.isTileSolid(x + i, y + 1, tileDepth)) {
                    return false;
                }
            }

            return true;
        }
Beispiel #20
0
 public static void GenerateFlat(World world, Random rand)
 {
     for (int x = 0; x < world.sizeInTiles.X; x++) {
         for (int y = 0; y < world.sizeInTiles.Y; y++) {
             if (y < 100) {
                 continue;
             } else if (y == 100) {
                 world.TileMatrix[x, y, (int)World.TileDepth.tile] = Tile.TileGrass.index;
             } else if (y < 120) {
                 world.TileMatrix[x, y, (int)World.TileDepth.tile] = Tile.TileDirt.index;
                 world.TileMatrix[x, y, (int)World.TileDepth.wall] = Tile.TileDirt.index;
             } else {
                 bool a = rand.Next(2) == 0;
                 world.TileMatrix[x, y, (int)World.TileDepth.tile] = ((a) ? Tile.TileDirt : Tile.TileStone).index;
                 world.TileMatrix[x, y, (int)World.TileDepth.wall] = ((a) ? Tile.TileDirt : Tile.TileStone).index;
             }
             world.LiquidNeedsUpdateMatrix[x, y] = true;
         }
     }
 }
Beispiel #21
0
        public bool mine(Game game, ItemStack stack, int xTile, int yTile, int distance, World.TileDepth tileDepth)
        {
            int del = delay;
            Tile.Material mat = game.currentWorld.getTileObjectNoCheck(xTile, yTile, tileDepth).material;

            if (mat == Tile.Material.furniture) {
                del = 20;
            }
            int power = getPower(mat);
            if (power <= 0) {
                return false;
            }
            game.inventory.t++;
            if (game.inventory.t >= del && distance <= reach) {
                game.inventory.t = 0;
                Tile tile = game.currentWorld.getTileObject(xTile, yTile, tileDepth);
                if (tile.index != Tile.TileAir.index) {
                    SoundEffectPlayer.playSoundWithRandomPitch(SoundEffectPlayer.SoundTink);
                    int m = ((int)game.currentWorld.getCrackNoCheck(xTile, yTile));
                    if (m == 0) {
                        game.inventory.t = 0;
                    }
                    int n = m + power;
                    int max = (Tile.getTileObject(tile.index)).toughness;
                    if (n > max) {
                        n = max;
                    }
                    game.currentWorld.setCrackNoCheck(xTile, yTile, (byte)n);

                    if (n == max) {
                        if (game.currentWorld.mineTile(xTile, yTile, this, tileDepth)) {
                            game.currentWorld.setCrackNoCheck(xTile, yTile, 0);
                        }
                    }
                    return true;
                }
            }
            return false;
        }
Beispiel #22
0
        public override void update(Game game, World world)
        {
            if(index == Tile.TileAir.index){
                remove(game, world);
                return;
            }
            if (collisionCustom(world, 0, 0, tileDepth)) {
                int x = (int)(position.X / World.tileSizeInPixels);
                int y = (int)(position.Y / World.tileSizeInPixels);
                remove(game, world);
                if (world.getTileIndex(x, y, tileDepth) == Tile.TileAir.index) {
                    world.setTile(x, y, index, tileDepth);
                } else {
                    world.EntityAddingList.Add(new EntityItem(position, new ItemStack(Item.itemTile, 1, index)));
                }
            }
            if(speed.Y < terminalVelocity){
                speed.Y += gravityAcc;
            }

            position += speed;
        }
Beispiel #23
0
 public override TextureInfo getTextureInfo(int x, int y, World world, World.TileDepth tileDepth)
 {
     if (renderType == RenderType.placed) {
         bool left = world.isTileSolid(x - 1, y, tileDepth);
         bool right = world.isTileSolid(x + 1, y, tileDepth);
         bool down = world.isTileSolid(x, y + 1, tileDepth);
         bool up = world.isTileSolid(x, y - 1, tileDepth);
         bool data = world.getTileData(x, y, tileDepth)!=0;
         Rectangle r;
         if (down) {
             r = get8(data?2:0, 0);
         } else if (left) {
             r = get8(data ? 3 : 1, 0);
         } else if (right) {
             r = get8(data ? 3 : 1, 1);
         } else if (up) {
             r = get8(data ? 2 : 0, 1);
         } else {
             r = get8(data ? 2 : 0, 0);
         }
         return new TextureInfo(r, true);
     }
     return new TextureInfo(Game.OnexOneRect, true);
 }
Beispiel #24
0
 public override ItemStack use(Game game, ItemStack currentItem, int mouseTileX, int mouseTileY, int mouseTileDistanceFromPlayer, World.TileDepth tileDepth)
 {
     return base.use(game, currentItem, mouseTileX, mouseTileY, mouseTileDistanceFromPlayer, tileDepth);
 }
Beispiel #25
0
        public override void update(Game game, World world)
        {
            if (swingTime >= 0) {
                swingTime -= 1;
            }

            drawBounds = new Rectangle((int)(displayPosition.X - world.viewOffset.X - xoff + (facingRight ? 0 : renderSize.X)), (int)displayPosition.Y - world.viewOffset.Y - (yoff), (int)((renderSize.X) * (facingRight ? 1 : -1)), (int)renderSize.Y);

            #region Movement

            inWater = world.getLiquid((int)((position.X + (size.X / 2)) / World.tileSizeInPixels), (int)((position.Y + (size.Y / 2)) / World.tileSizeInPixels)) > 50;

            bool walking = false;

            bool liquidBelow = (world.getLiquid((int)((position.X + (size.X / 2)) / World.tileSizeInPixels), (int)((position.Y + (size.Y)) / World.tileSizeInPixels)) > 50);

            if (inWater) {

                if (movement.left) {
                    if (speed.X > -swimSpeed) speed.X += -swimAcc;
                    walking = true;
                    facingRight = false;
                }
                if (movement.right) {
                    if (speed.X < swimSpeed) speed.X += swimAcc;
                    walking = true;
                    facingRight = true;
                }
                if (movement.jump) {
                    if (speed.Y > -swimSpeed) {
                        speed.Y -= swimSpeed;
                    }
                }
            } else {

                if (movement.left) {
                    if (speed.X > -walkSpeed) speed.X += -walkAcc;
                    facingRight = false;
                    walking = true;
                }
                if (movement.right) {
                    if (speed.X < walkSpeed) speed.X += walkAcc;
                    facingRight = true;
                    walking = true;
                }

                if (collision(world, 0, 1, movement.down)) {
                    if (movement.jump) {
                        speed.Y = -initalJumpSpeed;
                    }

                }

                if (speed.Y < 0) {
                    if (movement.jump) {
                        speed.Y -= jumpInAirAcc;
                    }
                }

                if(liquidBelow){
                    if (movement.jump) {
                        speed.Y -= jumpInWaterSpeed;
                    }
                }

            }

            if (!collision(world, 0, 1, movement.down)) {
                speed.Y += gravityAcc;
            }

            if (speed.X != 0 && !walking) {
                speed.X *= friction;
            }

            if (inWater) {
                //speed *= waterFriction;
            }

            int a = (speed.X > 0 ? 1 : (speed.X < 0 ? -1 : 0));

            walkUpPosition *= .7f;

            Vector2 finalSpeed = Vector2.Zero;

            if(!collision(world, speed.X, 0, movement.down)){
                finalSpeed.X += speed.X;
            } else {
                bool moved = false;
                bool goingRight = speed.X > 0;
                if (!movement.down) {
                    if (collision(world, 0, 4) && !collision(world, (goingRight ? World.tileSizeInPixels : -World.tileSizeInPixels) + speed.X, -(int)(World.tileSizeInPixels * 1.2))) {

                        finalSpeed.X += speed.X;
                        position.Y -= World.tileSizeInPixels * 1.2f;

                        walkUpPosition.X += speed.X;
                        walkUpPosition.Y -= World.tileSizeInPixels * 1.2f;

                        moved = true;

                    } else if (collision(world, 0, 4) && !collision(world, (goingRight ? World.tileSizeInPixels : -World.tileSizeInPixels), -(int)(World.tileSizeInPixels * 1.2))) {
                        position.Y -= World.tileSizeInPixels * 1.2f;

                        walkUpPosition.Y -= World.tileSizeInPixels * 1.2f;

                        moved = true;
                    }
                }
                if(!moved){
                    speed.X = 0;
                }
            }

            if (!collision(world, 0, speed.Y, movement.down)) {
                finalSpeed.Y += speed.Y;
            } else {
                speed.Y = 0;
            }

            position += finalSpeed;

            #endregion

            //displayPosition += (position - displayPosition)/4;
            displayPosition = position - (displayPositionOff + (walkUpPosition - displayPositionOff));

            //Game.updateMessage += "Player Position: "+position.X+", "+position.Y;
        }
Beispiel #26
0
 public override void beforeRemoval(Game game, World world)
 {
 }
Beispiel #27
0
 public override bool isPlatform(World world, int x, int y, World.TileDepth tileDepth)
 {
     return topIsPlatform && Math.Abs(world.getTileData(x, y, tileDepth))%size.Y==0;
 }
Beispiel #28
0
 public override ItemStack dropStack(World world, ItemPick itemPick, Random rand, int x, int y, World.TileDepth tileDepth)
 {
     return new ItemStack(Item.itemTile, 1, index);
 }
Beispiel #29
0
 public override void updateNearChange(World world, int x, int y, World.TileDepth tileDepth)
 {
     if (!(world.isTileSolid(x, y + 1, tileDepth) || world.getTileIndex(x, y + 1, tileDepth) == index)) {
         world.mineTile(x, y, Item.itemSupick, tileDepth);
     }
 }
Beispiel #30
0
        public override void mine(World world, int x, int y, int data, ItemPick pick, World.TileDepth tileDepth)
        {
            int k = 1;

            int ii = 0;
            int jj = 0;
            bool kk = false;

            for (int i = 0; i < size.X; i++) {
                for (int j = size.Y-1; j >=0 ; j--) {
                    if (k == data || k == -data) {
                        ii = i;
                        jj = j;
                        kk = true;
                        break;
                    }
                    k++;
                }
                if (kk) {
                    break;
                }
            }

            for (int i = 0; i < size.X; i++) {
                for (int j = size.Y - 1; j >= 0; j--) {
                    world.setTileWithUpdate(x + i - ii, y + j - jj, Tile.TileAir.index, tileDepth);
                }
            }
        }