Ignore:
Timestamp:
2012-07-03 20:04:30 (9 years ago)
Author:
dezhidki
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 2012/27/DenisZ/TheDungeonGame/TheDungeonGame/TheDungeonGame/TheDungeonGame.cs

    r3489 r3515  
    1717    public static Vector roomSize = new Vector(ROOMWIDTH, ROOMHEIGHT); 
    1818    private Player player; 
     19    private LevelGenerator generator; 
    1920 
    2021    public override void Begin() 
     
    2425        Level.Width = ROOMWIDTH * 20; 
    2526        Level.Height = ROOMHEIGHT * 20; 
    26      //   Level.CreateBorders(); 
     27        //   Level.CreateBorders(); 
    2728        Camera.ZoomToLevel(); 
    2829 
    29         LevelGenerator generator = new LevelGenerator(this, Level.Size, new Vector(20, 20)); 
    30         generator.generateRandomLevel(5, 10); 
    31         generator.buildLevel(); 
     30        generator = new LevelGenerator(this, Level.Size, new Vector(20, 20)); 
     31        generator.generateRandomLevel(1, 10); 
     32        generator.buildDungeon(); 
    3233 
    33         player = new Player(Vector.Zero); 
     34        player = new Player(this, Vector.Zero); 
    3435        Add(player, 1); 
    3536 
    36         Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Lopeta peli");    
     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(); 
    3747    } 
    3848 
    3949    protected override void Update(Time time) 
    4050    { 
    41         player.Update(time); 
    42         base.Update(time); 
     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(); 
    4361    } 
    4462} 
Note: See TracChangeset for help on using the changeset viewer.