Esempio n. 1
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            time = DateTime.Now.Ticks / 10000;

            do_networking();

            switch (input.process_input(this, gameTime.ElapsedGameTime.Milliseconds))
            {
            case -1:
                if (Exilania.input.current_input_type != InputConsume.Normal)
                {
                    Exilania.input.current_input_type = InputConsume.Normal;
                    display.show_messages             = false;
                }
                else
                {
                    if (gstate != 10)
                    {
                        state_progression();
                    }
                    else
                    {
                        exit_game();
                    }
                }
                break;

            case -2:     //F12 causes this to occur
                take_screen_shot = true;
                break;

            case 1:     //F11 causes this to occur.

                break;

            case 2:     //F2
                if (game_server)
                {
                    world.world_time -= world.world_time % world.day_length;
                    network_server.send_world_time(world.world_time);
                }
                break;

            case 4:    // f3
                if (world != null)
                {
                    int tot = 0;
                    for (int i = 0; i < world.liquid_simulator.liquid_cells.Count; i++)
                    {
                        if (!world.liquid_simulator.liquid_cells[i].empty)
                        {
                            tot += world.liquid_simulator.liquid_cells[i].tot_liquid_level;
                        }
                    }
                    Exilania.display.add_message("@10Total Liquid: " + tot);
                    world.npcs.Add(new Actor(body_templates[Exilania.rand.Next(1, body_templates.Count)], false));
                    world.npcs[world.npcs.Count - 1].world_loc = world.players[game_my_user_id].avatar.world_loc;
                }
                break;

            case 5:    // pressed F10, save a picture of the world!
                if (world != null)
                {
                    world.minimap.save_to_file(world);
                }
                break;

            case 20:
                /*if (world != null && game_my_user_id > -1)
                 * {
                 *  display.fading_text.Add(new FadeText("@00+1000 Water", 620,
                 *      (int)world.players[game_my_user_id].avatar.world_loc.X, (int)world.players[game_my_user_id].avatar.world_loc.Y, true, true));
                 *  world.players[game_my_user_id].avatar.items.pickup_block(block_types.get_block_by_name("Water"), 1000);
                 *  world.players[game_my_user_id].avatar.stats.get_experience_crafting(world.players[game_my_user_id].avatar.stats.level + 1, world.players[game_my_user_id].avatar);
                 *  for (int x = 0; x < world.map.GetLength(0); x++)
                 *  {
                 *      for (int y = 0; y < world.map.GetLength(1); y++)
                 *      {
                 *          if (world.map[x, y].bkd_block != -1)
                 *              world.remove_block(new Point(x, y), true);
                 *      }
                 *  }
                 * }
                 * for (int x = 0; x < world.map.GetLength(0); x++)
                 * {
                 *  for (int y = 0; y < world.map.GetLength(1); y++)
                 *  {
                 *      world.map[x, y].liquid_cell_id = -1;
                 *      world.map[x, y].liquid_id = 0;
                 *      world.map[x, y].liquid_level = 0;
                 *  }
                 * }
                 * world.liquid_simulator.liquid_cells.Clear();*/
                break;

            default:
                break;
            }

            if (Keyboard.GetState().IsKeyDown(Microsoft.Xna.Framework.Input.Keys.F11) && !input.keys_previous.Contains(Microsoft.Xna.Framework.Input.Keys.F11))
            {
                changing_graphics_state = true;
                ToggleDisplay();
            }

            switch (gstate)
            {
            //main menu
            case 10:
                menu.update_menu(input, this);
                break;

            case 60:     //character selection menu
                saved_players.update(input, this);
                break;

            case 70:
                saved_players.update_create_character(input, this);
                break;

            case 80:
                //initializing game with chosen character
                if (game_server)
                {
                    gstate = 90;
                }
                else
                {
                    network_client.send_user_info(saved_players.players[cur_using_local_id]);
                    gstate = 95;
                }
                break;

            case 90:     //choosing world to use (if host)
                if (game_server)
                {
                    world_manager.update(input, this);
                }
                else
                {
                    gstate = 95;
                }
                break;

            case 91:     //naming a new world and choosing world type to be created.
                world_definition_manager.update_choose_name(input, this);
                break;

            case 92:     //generating a new world
                world_definition_manager.creating_world_update();
                break;

            case 99:     //server initializing game
                if (game_my_user_id != -1)
                {
                    gstate = 100;
                }
                break;

            //in game
            case 100:
                //the code below makes people flash!

                /*  float transfer_speed = 3f;
                 * long p2 = System.DateTime.Now.Ticks / 10000;
                 * float pos = (float)(p2 % (int)(transfer_speed * 1000)); //milliseconds passed total
                 * pos /= 1000f * transfer_speed;
                 *
                 * if (pos > .5f)
                 * {
                 *    pos = 1f - pos;
                 * }
                 * pos *= 2f;
                 * cur_showing = pos;*/

                cur_leftover_time += (gameTime.ElapsedGameTime.Milliseconds / 1000f);
                while (cur_leftover_time >= time_wedge)
                {
                    cur_leftover_time -= time_wedge;
                    world.world_update_logic(time_wedge, input, display, this);
                }
                if (settings.use_hardware_lighting)
                {
                    world.light_time.start();
                    lighting.update_lighting(world);
                    world.light_time.stop();
                }

                break;
            }


            if (world == null || game_my_user_id == -1 || world.players.Count <= game_my_user_id)
            {
                display.input_message_display(input, settings, null, null);
            }
            else
            {
                display.input_message_display(input, settings, world.players[game_my_user_id].avatar, world);
            }



            // TODO: Add your update logic here
            display.update(gameTime.ElapsedGameTime.Milliseconds, world);

            input.finish_input();
            base.Update(gameTime);
        }