Ignore:
Timestamp:
2010-07-09 13:09:04 (13 years ago)
Author:
paaaanro
Message:

viimeistelin pelin

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 2010/27/eesaarjo/The Dungeon/Peli.cs

    r1191 r1241  
    66public class Peli : PhysicsGame 
    77{ 
    8     
     8    HighScoreList topLista; 
     9    IntMeter pisteLaskuri; 
    910    const int ruudunLeveys = 35; 
    1011    const int ruudunKorkeus = 35; 
    11     PhysicsObject pelaaja1; 
     12    PlatformCharacter pelaaja; 
    1213     
    1314 
    1415    protected override void Begin() 
    1516    { 
    16         LuoKentta(); 
    17         Gravity = new Vector(0.0, -650.0); 
     17        topLista = HighScoreList.LoadOrCreate("topten.dat", 10); 
     18        topLista.ScreenList.ItemColor = Color.Red; 
     19        topLista.ScreenList.BackGroundColor = Color.Black; 
     20 
     21        AloitaAlusta(); 
    1822    } 
    1923 
     
    2327    { 
    2428        TileMap ruudut = TileMap.FromFile("dungeon.txt"); 
     29         
    2530        Level.BackgroundColor = Color.DarkGray; 
    2631        ruudut['='] = LuoPalikka; 
    2732        ruudut['0'] = LuoTahti; 
    2833        ruudut['v'] = LuoVihollinen; 
    29         ruudut['1'] = LuoPelaaja1; 
     34        ruudut['1'] = LuoPelaaja; 
    3035         
    3136        ruudut.Insert(ruudunLeveys, ruudunKorkeus); 
     37 
    3238      } 
     39 
     40     void KasittelePelaajanTormays(PhysicsObject pelaaja, PhysicsObject kohde) 
     41     { 
     42         if (kohde.Tag.ToString() == "tahti") 
     43         { 
     44             kohde.Destroy(); 
     45             pisteLaskuri.Value++; 
     46 
     47         } 
     48         if (kohde.Tag.ToString() == "vihollinen") 
     49         { 
     50             pelaaja.Destroy(); 
     51             topLista.Show(pisteLaskuri.Value); 
     52             Keyboard.Listen(Key.Space, ButtonState.Pressed, AloitaAlusta, null); 
     53              
     54         } 
     55     } 
     56 
     57     void AloitaAlusta() 
     58     { 
     59         ClearAll(); 
     60 
     61         LuoKentta(); 
     62         LuoLaskuri(); 
     63         AddCollisionHandler(pelaaja, KasittelePelaajanTormays); 
     64         Gravity = new Vector(0.0, -650.0); 
     65     } 
     66 
    3367 
    3468      
     
    4175         vihollinen.Shape = Shapes.Triangle; 
    4276         vihollinen.Color = Color.DarkGreen; 
     77         vihollinen.Tag = "vihollinen"; 
    4378         Add(vihollinen); 
    4479         return vihollinen;  
     
    6095        PhysicsObject tahti = PhysicsObject.CreateStaticObject(25.0, 25.0); 
    6196        tahti.Color = Color.Yellow; 
    62  
     97        tahti.Tag = "tahti"; 
    6398        return tahti; 
    6499    } 
    65100 
    66     PhysicsObject LuoPelaaja1() 
     101    PhysicsObject LuoPelaaja() 
    67102    { 
    68         pelaaja1 = new PhysicsObject(20, 20); 
    69         pelaaja1.Color = Color.DarkTurquoise; 
    70         pelaaja1.Shape = Shapes.Circle; 
    71         Camera.Follow(pelaaja1); 
     103        pelaaja = new PlatformCharacter(20, 20); 
     104        pelaaja.Color = Color.DarkTurquoise; 
     105        pelaaja.Shape = Shapes.Circle; 
     106        Camera.Follow(pelaaja); 
    72107         
    73108 
    74         Keyboard.Listen(Key.Left, ButtonState.Down, LiikutaPelaajaa1, null, new Vector(-1000, 0)); 
    75         Keyboard.Listen(Key.Right, ButtonState.Down, LiikutaPelaajaa1, null, new Vector(1000, 0)); 
    76         Keyboard.Listen(Key.Up, ButtonState.Down, LiikutaPelaajaa1, null, new Vector(0, 1000)); 
    77         Keyboard.Listen(Key.Down, ButtonState.Down, LiikutaPelaajaa1, null, new Vector(0, -1000)); 
    78         Add(pelaaja1); 
    79         return pelaaja1; 
     109        Keyboard.Listen(Key.Left, ButtonState.Down, LiikutaPelaajaa, null, -250.0); 
     110        Keyboard.Listen(Key.Right, ButtonState.Down, LiikutaPelaajaa,null, 250.0); 
     111        Keyboard.Listen(Key.Up, ButtonState.Down, Hyppaa, null,705.0); 
     112         
     113        Add(pelaaja); 
     114        return pelaaja; 
     115    } 
     116    void Hyppaa(double hyppyvoima) 
     117    { 
     118        pelaaja.Jump(hyppyvoima); 
    80119    } 
    81120 
    82     void LiikutaPelaajaa1(Vector vektori) 
     121    void LiikutaPelaajaa(double nopeus) 
    83122    { 
    84         pelaaja1.Push(vektori); 
     123        pelaaja.Walk(nopeus); 
     124        //pelaaja.Push(vektori); 
    85125    } 
     126 
     127    void LuoLaskuri() 
     128    { 
     129        pisteLaskuri = new IntMeter(0); 
     130 
     131        Label pisteNaytto = new Label(); 
     132        pisteNaytto.X = Screen.Left + 100; 
     133        pisteNaytto.Y = Screen.Top - 100; 
     134        pisteNaytto.TextColor = Color.Red; 
     135 
     136        pisteNaytto.BindTo(pisteLaskuri); 
     137        Add(pisteNaytto); 
     138 
     139        Label pisteTeksti = new Label("Pisteitä: "); 
     140        pisteTeksti.X = Screen.Left + 50; 
     141        pisteTeksti.Y = Screen.Top - 100; 
     142        pisteTeksti.TextColor = Color.LightGreen; 
     143        Add(pisteTeksti); 
     144 
     145    } 
     146 
     147 
     148     
     149 
     150     
     151 
     152} 
     153 
     154 
    86155     
    87156 
     
    92161 
    93162     
    94     
    95 } 
     163   
     164 
Note: See TracChangeset for help on using the changeset viewer.