source: 2012/27/DenisZ/TheDungeonGame/TheDungeonGame/TheDungeonGame/TheDungeonGame.cs @ 3515

Revision 3515, 1.9 KB checked in by dezhidki, 9 years ago (diff)
Line 
1using System;
2using System.Collections.Generic;
3using Jypeli;
4using Jypeli.Assets;
5using Jypeli.Controls;
6using Jypeli.Effects;
7using Jypeli.Widgets;
8using MathHelper;
9using Entity;
10using Rooms;
11
12public class TheDungeonGame : PhysicsGame
13{
14    public const double ROOMWIDTH = 850;
15    public const double ROOMHEIGHT = 500;
16    public const double ROOMTHICKNESS = 70;
17    public static Vector roomSize = new Vector(ROOMWIDTH, ROOMHEIGHT);
18    private Player player;
19    private LevelGenerator generator;
20
21    public override void Begin()
22    {
23        IsMouseVisible = true;
24        SetWindowSize(800, 600);
25        Level.Width = ROOMWIDTH * 20;
26        Level.Height = ROOMHEIGHT * 20;
27        //   Level.CreateBorders();
28        Camera.ZoomToLevel();
29
30        generator = new LevelGenerator(this, Level.Size, new Vector(20, 20));
31        generator.generateRandomLevel(1, 10);
32        generator.buildDungeon();
33
34        player = new Player(this, Vector.Zero);
35        Add(player, 1);
36
37        Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Lopeta peli");
38        Keyboard.Listen(Key.R, ButtonState.Pressed, regenerateLevel, null);
39    }
40
41    private void regenerateLevel()
42    {
43        generator.destroyDungeon();
44        generator = new LevelGenerator(this, Level.Size, new Vector(20, 20));
45        generator.generateRandomLevel(1, 10);
46        generator.buildDungeon();
47    }
48
49    protected override void Update(Time time)
50    {
51        try  // Tapa pakottaa Updatea toimimaan LevelGeneratorin kanssa
52        {
53            base.Update(time);
54        }
55        catch (FormatException) // Kaatuu tähän melkein kokoajan kun yrittää luoda tasoa. Mun koodi liian "likainen", tai hidas?
56        {
57            return; // Skipataan "virheelisiä" tickea ja huijataan peliä niin kuin pahat merimiehet (dirty pirates, Arr)
58        }
59
60        player.tick();
61    }
62}
Note: See TracBrowser for help on using the repository browser.