Changeset 8561


Ignore:
Timestamp:
2017-06-13 11:43:42 (2 years ago)
Author:
npo17_23
Message:

Tiistai pong VALMIS

Location:
2017/24/LeeviE/Pong/Pong
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • 2017/24/LeeviE/Pong/Pong/Pong/Pong.cs

    r8550 r8561  
    88 
    99public class Pong : PhysicsGame 
     10    
     11 
    1012 
    1113 
    1214{ 
    13     Vector nopeusYlos = new Vector(0, 200); 
    14     Vector nopeusAlas = new Vector(0, -200); 
     15    Vector nopeusYlos = new Vector(0, 500); 
     16    Vector nopeusAlas = new Vector(0, -500); 
    1517 
    1618    PhysicsObject pallo; 
    1719    PhysicsObject maila1; 
    18     PhysicsObject maila2;  
     20    PhysicsObject maila2; 
     21 
     22    PhysicsObject vasenReuna; 
     23    PhysicsObject oikeaReuna; 
     24 
     25    IntMeter pelaajan1Pisteet; 
     26    IntMeter pelaajan2Pisteet; 
     27 
    1928    const double PALLON_MIN_NOPEUS = 500; 
    2029 
     
    3241        LuoKentta(); 
    3342        AsetaOhjaimet(); 
     43        LisaaLaskurit(); 
    3444        AloitaPeli(); 
    3545    } 
    36  
    37  
    38  
    3946 
    4047    void LuoKentta() 
     
    4552        pallo.Y = 0.0; 
    4653        pallo.Restitution = 1.0; 
     54        pallo.KineticFriction = 0.0; 
     55        pallo.MomentOfInertia = Double.PositiveInfinity; 
    4756        Add(pallo); 
     57        AddCollisionHandler(pallo, KasittelePallonTormays); 
    4858 
    4959        maila1 = LuoMaila(Level.Left + 20.0, 0.0); 
    5060        maila2 = LuoMaila(Level.Right - 20.0, 0.0); 
    5161 
    52         Level.CreateBorders(1.0, false); 
     62        vasenReuna = Level.CreateLeftBorder(); 
     63        vasenReuna.Restitution = 1.0; 
     64        vasenReuna.KineticFriction = 0.0; 
     65        vasenReuna.IsVisible = false; 
     66 
     67        oikeaReuna = Level.CreateRightBorder(); 
     68        oikeaReuna.Restitution = 1.0; 
     69        oikeaReuna.KineticFriction = 0.0; 
     70        oikeaReuna.IsVisible = false; 
     71 
     72        PhysicsObject ylaReuna = Level.CreateTopBorder(); 
     73        ylaReuna.Restitution = 1.0; 
     74        ylaReuna.KineticFriction = 0.0; 
     75        ylaReuna.IsVisible = false; 
     76 
     77        PhysicsObject alaReuna = Level.CreateBottomBorder(); 
     78        alaReuna.Restitution = 1.0; 
     79        alaReuna.IsVisible = false; 
     80        alaReuna.KineticFriction = 0.0; 
     81 
    5382        Level.Background.Color = Color.Black; 
    5483 
     84        Camera.ZoomToLevel(); 
     85    } 
    5586 
    56         Camera.ZoomToLevel(); 
    57  
    58     } 
    5987    PhysicsObject LuoMaila(double x, double y) 
    6088    { 
     
    6492        maila.Y = y; 
    6593        maila.Restitution = 1.0; 
     94        maila.KineticFriction = 0.0; 
    6695        Add(maila); 
    6796        return maila; 
    6897    } 
    6998 
     99    void LisaaLaskurit() 
     100    { 
     101        pelaajan1Pisteet = LuoPisteLaskuri(Screen.Left + 100.0, Screen.Top - 100.0); 
     102        pelaajan2Pisteet = LuoPisteLaskuri(Screen.Right - 100.0, Screen.Top - 100.0); 
     103    } 
     104 
     105    IntMeter LuoPisteLaskuri(double x, double y) 
     106    { 
     107        IntMeter laskuri = new IntMeter(0); 
     108        laskuri.MaxValue = 10; 
     109 
     110        Label naytto = new Label(); 
     111        naytto.BindTo(laskuri); 
     112        naytto.X = x; 
     113        naytto.Y = y; 
     114        naytto.TextColor = Color.White; 
     115        naytto.BorderColor = Level.BackgroundColor; 
     116        naytto.Color = Level.BackgroundColor; 
     117        Add(naytto); 
     118 
     119        return laskuri; 
     120    } 
     121 
     122    void KasittelePallonTormays(PhysicsObject pallo, PhysicsObject kohde) 
     123    { 
     124        if (kohde == oikeaReuna) 
     125        { 
     126            pelaajan1Pisteet.Value += 1; 
     127        } 
     128        else if (kohde == vasenReuna) 
     129        { 
     130            pelaajan2Pisteet.Value += 1; 
     131        } 
     132    } 
    70133 
    71134    void AloitaPeli() 
     
    76139 
    77140    void AsetaOhjaimet() 
    78  
    79141    { 
    80         Keyboard.Listen(Key.A, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa ylös",maila1, new Vector(0, 100)); 
     142        Keyboard.Listen(Key.A, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa ylös", maila1, nopeusYlos); 
    81143        Keyboard.Listen(Key.A, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 
    82         Keyboard.Listen(Key.Z, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa alas", maila1, new Vector(0, -100)); 
     144        Keyboard.Listen(Key.Z, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa alas", maila1, nopeusAlas); 
    83145        Keyboard.Listen(Key.Z, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 
    84146 
    85         Keyboard.Listen(Key.Up, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa ylös", maila2, new Vector(0, 100)); 
    86         Keyboard.Listen(Key.Up, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 
    87         Keyboard.Listen(Key.Down, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa alas", maila2, new Vector(0, -100)); 
    88         Keyboard.Listen(Key.Down, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 
     147        Keyboard.Listen(Key.Up, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa ylös", maila2, nopeusYlos); 
     148        Keyboard.Listen(Key.Up, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 
     149        Keyboard.Listen(Key.Down, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa alas", maila2, nopeusAlas); 
     150        Keyboard.Listen(Key.Down, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 
    89151 
     152        Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet"); 
    90153        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 
     154 
     155        ControllerOne.Listen(Button.DPadUp, ButtonState.Down, AsetaNopeus, "Liikuta mailaa ylös", maila1, nopeusYlos); 
     156        ControllerOne.Listen(Button.DPadUp, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 
     157        ControllerOne.Listen(Button.DPadDown, ButtonState.Down, AsetaNopeus, "Liikuta mailaa alas", maila1, nopeusAlas); 
     158        ControllerOne.Listen(Button.DPadDown, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 
     159 
     160        ControllerTwo.Listen(Button.DPadUp, ButtonState.Down, AsetaNopeus, "Liikuta mailaa ylös", maila2, nopeusYlos); 
     161        ControllerTwo.Listen(Button.DPadUp, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 
     162        ControllerTwo.Listen(Button.DPadDown, ButtonState.Down, AsetaNopeus, "Liikuta mailaa alas", maila2, nopeusAlas); 
     163        ControllerTwo.Listen(Button.DPadDown, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 
     164 
     165        ControllerOne.Listen(Button.Back, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 
     166        ControllerTwo.Listen(Button.Back, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 
    91167    } 
     168 
    92169    void AsetaNopeus(PhysicsObject maila, Vector nopeus) 
    93     { maila.Velocity = nopeus; 
     170    { 
     171        if ((nopeus.Y < 0) && (maila.Bottom < Level.Bottom)) 
     172        { 
     173            maila.Velocity = Vector.Zero; 
     174            return; 
     175        } 
     176        if ((nopeus.Y > 0) && (maila.Top > Level.Top)) 
     177        { 
     178            maila.Velocity = Vector.Zero; 
     179            return; 
     180        } 
     181 
     182        maila.Velocity = nopeus; 
    94183    } 
    95      
    96184} 
    97185     
  • 2017/24/LeeviE/Pong/Pong/Pong/obj/x86/Debug/ContentPipeline-{884096D4-FAA8-4FF3-B956-3912C4AA2028}.xml

    r8550 r8561  
    1717      <Assembly> 
    1818        <Key>C:\WINDOWS\Microsoft.Net\assembly\GAC_32\Microsoft.Xna.Framework.Content.Pipeline\v4.0_4.0.0.0__842cf8be1de50553\Microsoft.Xna.Framework.Content.Pipeline.dll</Key> 
    19         <Value>2016-09-06T10:28:15.6512578+03:00</Value> 
     19        <Value>2017-06-07T09:40:27.2293184+03:00</Value> 
    2020      </Assembly> 
    2121    </Assemblies> 
Note: See TracChangeset for help on using the changeset viewer.