Beispiel #1
0
        protected override void Update(GameTime gameTime)
        {
            tick++;
            updateMessage = "";
            inputState.set(Keyboard.GetState(), Mouse.GetState());

            if (needToResetUserInput)
            {
                needToResetUserInput = false;
                userInputList.Clear();
                userInputList.Add(console);
                userInputList.Add(inventory);
                if (currentWorld != null)
                {
                    if (currentWorld.player != null)
                    {
                        userInputList.Add(currentWorld.player.movement);
                    }
                }
            }

            foreach (InputUser i in userInputList)
            {
                inputState = i.update(this, inputState);
            }
            inputState.regergitateKeyboardAndMouse();

            if (inputState.down(Keys.X))
            {
                currentWorld.player.position.Y += 16;
            }

            if (inputState.pressed(Game.KEY_ESCAPE))
            {
                this.Exit();
            }
            if (inputState.pressed(Game.KEY_DEBUG_MENU))
            {
                debugEnabled = !debugEnabled;
            }

            SoundEffectPlayer.update();

            if (currentWorld != null)
            {
                currentWorld.Update(this, tick);
                if (inputState.getKeyboardState().IsKeyDown(Game.KEY_FAST_FORWARD_CLOCK))
                {
                    currentWorld.time += 10;
                }
            }

            EntityItem.playedSoundEffectRecently = false;

            inputState.setLast(Keyboard.GetState(), Mouse.GetState());
            base.Update(gameTime);
            updateFps.update();
        }
Beispiel #2
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 #3
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 #4
0
 private void loadSounds()
 {
     SoundEffectPlayer.loadSounds(Content);
 }