Changeset 8622 for 2017/24


Ignore:
Timestamp:
2017-06-14 10:12:40 (2 years ago)
Author:
npo17_9
Message:

joo

Location:
2017/24/VesaT
Files:
102 added
2 edited

Legend:

Unmodified
Added
Removed
  • 2017/24/VesaT/HasuPonkiPeli/HasuPonkiPeli/HasuPonkiPeli/HasuPonkiPeli.cs

    r8568 r8622  
    11using System; 
    22using System.Collections.Generic; 
    3 using System.Linq; 
    4 using System.Text; 
    53using Jypeli; 
    64using Jypeli.Assets; 
     
    97using Jypeli.Widgets; 
    108 
    11 public class Pong : PhysicsGame 
     9public class HasuPonkiPeli : PhysicsGame 
    1210{ 
    1311    Vector nopeusYlos = new Vector(0, 200); 
     
    1513 
    1614    PhysicsObject pallo; 
     15 
    1716    PhysicsObject maila1; 
    1817    PhysicsObject maila2; 
     
    2322    IntMeter pelaajan1Pisteet; 
    2423    IntMeter pelaajan2Pisteet; 
    25  
    2624    public override void Begin() 
    2725    { 
     
    3028        LisaaLaskurit(); 
    3129        AloitaPeli(); 
     30 
     31 
     32        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 
    3233    } 
    33  
    3434    void LuoKentta() 
    3535    { 
    3636        pallo = new PhysicsObject(40.0, 40.0); 
     37        Add(pallo); 
     38 
    3739        pallo.Shape = Shape.Circle; 
    38         pallo.X = -200.0; 
    39         pallo.Y = 0.0; 
    40         pallo.Restitution = 1.0; 
    41         pallo.KineticFriction = 0.0; 
    42         pallo.MomentOfInertia = Double.PositiveInfinity; 
    43         Add(pallo); 
    44         AddCollisionHandler(pallo, KasittelePallonTormays); 
    45  
    46         maila1 = LuoMaila(Level.Left + 20.0, 0.0); 
    47         maila2 = LuoMaila(Level.Right - 20.0, 0.0); 
    48  
     40        pallo.X = 0; 
     41        pallo.Y = 11; 
    4942        vasenReuna = Level.CreateLeftBorder(); 
    5043        vasenReuna.Restitution = 1.0; 
    51         vasenReuna.KineticFriction = 0.0; 
    5244        vasenReuna.IsVisible = false; 
    53  
     45        pallo.Restitution = 1.0; 
    5446        oikeaReuna = Level.CreateRightBorder(); 
    5547        oikeaReuna.Restitution = 1.0; 
    56         oikeaReuna.KineticFriction = 0.0; 
    5748        oikeaReuna.IsVisible = false; 
    58  
    59         PhysicsObject ylaReuna = Level.CreateTopBorder(); 
    60         ylaReuna.Restitution = 1.0; 
    61         ylaReuna.KineticFriction = 0.0; 
    62         ylaReuna.IsVisible = false; 
    63  
    6449        PhysicsObject alaReuna = Level.CreateBottomBorder(); 
    6550        alaReuna.Restitution = 1.0; 
    6651        alaReuna.IsVisible = false; 
    67         alaReuna.KineticFriction = 0.0; 
     52        PhysicsObject yläReuna = Level.CreateTopBorder(); 
     53        yläReuna.Restitution = 1.0; 
     54        yläReuna.IsVisible = false; 
     55        AddCollisionHandler(pallo, KasittelePallonTormays); 
     56        Level.Background.Color = Color.Ultramarine; 
     57        Camera.ZoomToLevel(); 
    6858 
    69         Level.BackgroundColor = Color.Black; 
     59        maila1 = LuoMaila(Level.Left + 20.0, 0.0); 
     60        maila2 = LuoMaila(Level.Right + 20.0, 0.0); 
    7061 
    71         Camera.ZoomToLevel(); 
     62 
     63 
     64 
     65    } 
     66 
     67    void AloitaPeli() 
     68    { 
     69        Vector impulssi = new Vector(500.0, 0.0); 
     70        pallo.Hit(impulssi); 
    7271    } 
    7372 
     
    7978        maila.Y = y; 
    8079        maila.Restitution = 1.0; 
    81         maila.KineticFriction = 0.0; 
    8280        Add(maila); 
    8381        return maila; 
    8482    } 
     83 
     84 
     85    void AsetaNopeus(PhysicsObject maila, Vector nopeus) 
     86    { 
     87        if ((nopeus.Y > 0) && (maila.Top > Level.Top)) 
     88        { 
     89            maila.Velocity = Vector.Zero; 
     90            return; 
     91        } 
     92        if ((nopeus.Y > 0) && (maila.Top > Level.Top)) 
     93        { 
     94 
     95 
     96        
     97        } 
     98        maila.Velocity = nopeus; 
     99    } 
     100 
     101 
     102 
    85103 
    86104    void LisaaLaskurit() 
     
    89107        pelaajan2Pisteet = LuoPisteLaskuri(Screen.Right - 100.0, Screen.Top - 100.0); 
    90108    } 
    91  
    92109    IntMeter LuoPisteLaskuri(double x, double y) 
    93110    { 
     
    100117        naytto.Y = y; 
    101118        naytto.TextColor = Color.White; 
    102         naytto.BorderColor = Level.BackgroundColor; 
    103         naytto.Color = Level.BackgroundColor; 
     119        naytto.BorderColor = Level.Background.Color; 
     120        naytto.Color = Level.Background.Color; 
    104121        Add(naytto); 
    105122 
    106123        return laskuri; 
    107124    } 
     125 
     126 
     127 
     128 
     129 
     130    void AsetaOhjaimet() 
     131    { 
     132        Keyboard.Listen(Key.W, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa ylös", maila1, nopeusYlos); 
     133        Keyboard.Listen(Key.W, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 
     134        Keyboard.Listen(Key.S, ButtonState.Down, AsetaNopeus, "Pelaaja 1 Liikuta mailaa alas", maila1, nopeusAlas); 
     135        Keyboard.Listen(Key.S, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 
     136        Keyboard.Listen(Key.Up, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa ylös", maila2, nopeusYlos); 
     137        Keyboard.Listen(Key.Up, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 
     138        Keyboard.Listen(Key.Down, ButtonState.Down, AsetaNopeus, "Pelaaja 2 Liikuta mailaa alas", maila2, nopeusAlas); 
     139        Keyboard.Listen(Key.Down, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 
     140        Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet"); 
     141        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 
     142 
     143    } 
     144 
    108145 
    109146    void KasittelePallonTormays(PhysicsObject pallo, PhysicsObject kohde) 
     
    115152        else if (kohde == vasenReuna) 
    116153        { 
    117             pelaajan2Pisteet.Value += 1; 
    118         } 
    119     } 
    120  
    121     void AloitaPeli() 
    122     { 
    123         Vector impulssi = new Vector(500.0, 0.0); 
    124         pallo.Hit(impulssi); 
    125     } 
    126  
    127     void AsetaOhjaimet() 
    128     { 
    129         Keyboard.Listen(Key.A, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa ylös", maila1, nopeusYlos); 
    130         Keyboard.Listen(Key.A, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 
    131         Keyboard.Listen(Key.Z, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa alas", maila1, nopeusAlas); 
    132         Keyboard.Listen(Key.Z, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 
    133  
    134         Keyboard.Listen(Key.Up, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa ylös", maila2, nopeusYlos); 
    135         Keyboard.Listen(Key.Up, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 
    136         Keyboard.Listen(Key.Down, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa alas", maila2, nopeusAlas); 
    137         Keyboard.Listen(Key.Down, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 
    138  
    139         Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet"); 
    140         Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 
    141  
    142         ControllerOne.Listen(Button.DPadUp, ButtonState.Down, AsetaNopeus, "Liikuta mailaa ylös", maila1, nopeusYlos); 
    143         ControllerOne.Listen(Button.DPadUp, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 
    144         ControllerOne.Listen(Button.DPadDown, ButtonState.Down, AsetaNopeus, "Liikuta mailaa alas", maila1, nopeusAlas); 
    145         ControllerOne.Listen(Button.DPadDown, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 
    146  
    147         ControllerTwo.Listen(Button.DPadUp, ButtonState.Down, AsetaNopeus, "Liikuta mailaa ylös", maila2, nopeusYlos); 
    148         ControllerTwo.Listen(Button.DPadUp, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 
    149         ControllerTwo.Listen(Button.DPadDown, ButtonState.Down, AsetaNopeus, "Liikuta mailaa alas", maila2, nopeusAlas); 
    150         ControllerTwo.Listen(Button.DPadDown, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 
    151  
    152         ControllerOne.Listen(Button.Back, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 
    153         ControllerTwo.Listen(Button.Back, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 
    154     } 
    155  
    156     void AsetaNopeus(PhysicsObject maila, Vector nopeus) 
    157     { 
    158         if ((nopeus.Y < 0) && (maila.Bottom < Level.Bottom)) 
    159         { 
    160             maila.Velocity = Vector.Zero; 
    161             return; 
    162         } 
    163         if ((nopeus.Y > 0) && (maila.Top > Level.Top)) 
    164         { 
    165             maila.Velocity = Vector.Zero; 
    166             return; 
     154            pelaajan2Pisteet.Value+= 1; 
    167155        } 
    168156 
    169         maila.Velocity = nopeus; 
    170157    } 
    171158} 
Note: See TracChangeset for help on using the changeset viewer.