Changeset 8171


Ignore:
Timestamp:
2016-07-27 15:01:17 (7 years ago)
Author:
pybesilt
Message:

tein pelaajalle kontrollit ja viholliselle tekoälyn, jonka avulla se osaa ampua

Location:
2016/30/PyryS
Files:
47 added
6 edited

Legend:

Unmodified
Added
Removed
  • 2016/30/PyryS/Pinkiponki/Pinkiponki/Pinkiponki/Pinkiponki.cs

    r8087 r8171  
    1111    Vector nopeusYlos = new Vector(0, 200); 
    1212    Vector nopeusAlas = new Vector(0, -200); 
     13    Vector lahtonopeus = new Vector(-500.0, 100.0); 
     14 
     15 
     16    const int pistemaksimi = 10; 
    1317 
    1418 
     
    1721    PhysicsObject maila2; 
    1822 
     23    PhysicsObject vasenReuna; 
     24    PhysicsObject oikeaReuna; 
     25 
     26    Level.Background.color taustavari = Color.Black; 
     27 
     28    const double PALLO_MIN_NOPEUS = 550; 
     29 
    1930    IntMeter P1Pisteet; 
    2031    IntMeter P2Pisteet; 
     
    2435        Ohjaimet(); 
    2536        LisääLaskurit(); 
    26         AloitaPeli(); 
    27          
    28                       
    29          
     37        Timer.SingleShot(5.0, AloitaPeli); 
     38 
     39 
     40 
    3041    } 
    3142 
     
    3546        Add(pallo); 
    3647        pallo.Shape = Shape.Circle; 
    37         pallo.X = -300.0; 
     48        pallo.X = 0.0; 
    3849        pallo.Y = 0.0; 
    39         pallo.Restitution = 1.0; 
     50        pallo.Restitution = 1.1; 
    4051 
    4152        maila1 = LuoMaila(Level.Left + 20.0, 0.0); 
     
    4455        AddCollisionHandler(pallo, KasittelePallonTormays); 
    4556 
    46         PhysicsObject vasenReuna = Level.CreateLeftBorder(); 
     57        vasenReuna = Level.CreateLeftBorder(); 
    4758        vasenReuna.Restitution = 1.0; 
    4859        vasenReuna.IsVisible = true; 
    4960 
    50         PhysicsObject oikeaReuna = Level.CreateRightBorder(); 
     61        oikeaReuna = Level.CreateRightBorder(); 
    5162        oikeaReuna.Restitution = 1.0; 
    5263        vasenReuna.IsVisible = true; 
     
    6273 
    6374 
    64         Level.Background.Color = Color.Black; 
     75        Level.Background.Color = taustavari; 
    6576 
    6677        Camera.ZoomToLevel(); 
     
    6879    void AloitaPeli() 
    6980    { 
    70         Vector impulssi = new Vector(500.0, 0.0); 
     81        Vector impulssi = lahtonopeus; 
    7182        pallo.Hit(impulssi); 
    7283    } 
     
    90101        Keyboard.Listen(Key.S, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 
    91102 
     103 
    92104        Keyboard.Listen(Key.Up, ButtonState.Down, AsetaNopeus, "P2 maila ylös", maila2, nopeusYlos); 
    93105        Keyboard.Listen(Key.Up, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 
     
    102114    { 
    103115        if ((nopeus.Y > 0) && (maila.Top > Level.Top)) 
    104         {maila.Velocity = Vector.Zero; 
     116        { 
     117            maila.Velocity = Vector.Zero; 
    105118            return; 
    106                      } 
    107  
    108         { 
     119        } 
     120 
    109121            if ((nopeus.Y < 0) && (maila.Bottom < Level.Bottom)) 
    110             { maila.Velocity = Vector.Zero; 
     122            { 
     123                maila.Velocity = Vector.Zero; 
    111124                return; 
    112125            } 
    113         } 
     126         
    114127        maila.Velocity = nopeus; 
     128 
     129        if (maila == maila2 && Keyboard.IsShiftDown()) 
     130        { 
     131            maila2.Velocity = nopeus * 2.0; 
     132        } 
     133        if ( maila == maila1 && Keyboard.IsCtrlDown()) 
     134        { 
     135            maila1.Velocity = nopeus * 2.0; 
     136        } 
     137         
     138          
     139 
    115140    } 
    116141 
     
    118143    { 
    119144        P1Pisteet = LuoLaskuri(Screen.Left + 100.0, Screen.Top - 100.0); 
     145        P1Pisteet.UpperLimit += delegate { LopetaPeli("P1 voitti pelin"); }; 
     146 
    120147        P2Pisteet = LuoLaskuri(Screen.Right - 100.0, Screen.Top - 100.0); 
    121     } 
     148        P2Pisteet.UpperLimit += delegate { LopetaPeli("P2 voitti pelin"); }; 
     149        
     150 
     151    } 
     152 
    122153    IntMeter LuoLaskuri(double x, double y) 
    123154    { 
    124155        IntMeter laskuri = new IntMeter(0); 
    125         laskuri.MaxValue = 10; 
     156        laskuri.MaxValue = pistemaksimi; 
    126157 
    127158        Label naytto = new Label(); 
     
    139170    void KasittelePallonTormays(PhysicsObject pallo, PhysicsObject kohde) 
    140171    { 
    141         if  (kohde == oikeaReuna) 
     172        if (kohde == oikeaReuna) 
    142173        { 
    143174            P1Pisteet.Value += 1; 
     
    148179        } 
    149180    } 
     181     
     182 
     183    protected override void Update(Time time) 
     184    { 
     185        if (pallo != null && Math.Abs(pallo.Velocity.X) < PALLO_MIN_NOPEUS) 
     186        { 
     187            pallo.Velocity = new Vector(pallo.Velocity.X * 1.1, pallo.Velocity.Y); 
     188        } 
     189 
     190        base.Update(time); 
     191    } 
     192 
     193    void LopetaPeli(String viesti) 
     194    { 
     195        MessageWindow voittofanfaari = new MessageWindow(viesti); 
     196        Add(voittofanfaari); 
     197 
     198        IsPaused = true; 
     199        voittofanfaari.Closed += delegate { Exit(); }; 
     200    } 
     201    
     202 
    150203} 
Note: See TracChangeset for help on using the changeset viewer.