Changeset 8560


Ignore:
Timestamp:
2017-06-13 11:38:19 (2 years ago)
Author:
npo17_21
Message:

Ponk

Location:
2017/24/AaronL/Ponk/Ponk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • 2017/24/AaronL/Ponk/Ponk/Ponk/Ponk.cs

    r8549 r8560  
    11using System; 
    22using System.Collections.Generic; 
     3using System.Linq; 
     4using System.Text; 
    35using Jypeli; 
    46using Jypeli.Assets; 
     
    1315 
    1416    PhysicsObject pallo; 
    15  
    1617    PhysicsObject maila1; 
    1718    PhysicsObject maila2; 
    1819 
     20    PhysicsObject vasenReuna; 
     21    PhysicsObject oikeaReuna; 
     22 
     23    IntMeter pelaajan1Pisteet; 
     24    IntMeter pelaajan2Pisteet; 
     25 
    1926    public override void Begin() 
    2027    { 
    21         // TODO: Kirjoita ohjelmakoodisi tähän 
    2228        LuoKentta(); 
    2329        AsetaOhjaimet(); 
     30        LisaaLaskurit(); 
    2431        AloitaPeli(); 
    2532    } 
    26  
    27  
    28  
    2933 
    3034    void LuoKentta() 
     
    3236        pallo = new PhysicsObject(40.0, 40.0); 
    3337        pallo.Shape = Shape.Circle; 
    34         pallo.X = 0.0; 
     38        pallo.X = -200.0; 
    3539        pallo.Y = 0.0; 
    3640        pallo.Restitution = 1.0; 
     41        pallo.KineticFriction = 0.0; 
     42        pallo.MomentOfInertia = Double.PositiveInfinity; 
    3743        Add(pallo); 
     44        AddCollisionHandler(pallo, KasittelePallonTormays); 
    3845 
    3946        maila1 = LuoMaila(Level.Left + 20.0, 0.0); 
    4047        maila2 = LuoMaila(Level.Right - 20.0, 0.0); 
    4148 
    42         Level.CreateBorders(1.0, false); 
     49        vasenReuna = Level.CreateLeftBorder(); 
     50        vasenReuna.Restitution = 1.0; 
     51        vasenReuna.KineticFriction = 0.0; 
     52        vasenReuna.IsVisible = false; 
     53 
     54        oikeaReuna = Level.CreateRightBorder(); 
     55        oikeaReuna.Restitution = 1.0; 
     56        oikeaReuna.KineticFriction = 0.0; 
     57        oikeaReuna.IsVisible = false; 
     58 
     59        PhysicsObject ylaReuna = Level.CreateTopBorder(); 
     60        ylaReuna.Restitution = 1.0; 
     61        ylaReuna.KineticFriction = 0.0; 
     62        ylaReuna.IsVisible = false; 
     63 
     64        PhysicsObject alaReuna = Level.CreateBottomBorder(); 
     65        alaReuna.Restitution = 1.0; 
     66        alaReuna.IsVisible = false; 
     67        alaReuna.KineticFriction = 0.0; 
     68 
    4369        Level.Background.Color = Color.Black; 
    4470 
    4571        Camera.ZoomToLevel(); 
    4672    } 
    47  
    4873 
    4974    PhysicsObject LuoMaila(double x, double y) 
     
    5479        maila.Y = y; 
    5580        maila.Restitution = 1.0; 
     81        maila.KineticFriction = 0.0; 
    5682        Add(maila); 
    5783        return maila; 
     84    } 
     85 
     86    void LisaaLaskurit() 
     87    { 
     88        pelaajan1Pisteet = LuoPisteLaskuri(Screen.Left + 100.0, Screen.Top - 100.0); 
     89        pelaajan2Pisteet = LuoPisteLaskuri(Screen.Right - 100.0, Screen.Top - 100.0); 
     90    } 
     91 
     92    IntMeter LuoPisteLaskuri(double x, double y) 
     93    { 
     94        IntMeter laskuri = new IntMeter(0); 
     95        laskuri.MaxValue = 10; 
     96 
     97        Label naytto = new Label(); 
     98        naytto.BindTo(laskuri); 
     99        naytto.X = x; 
     100        naytto.Y = y; 
     101        naytto.TextColor = Color.White; 
     102        naytto.BorderColor = Level.Background.Color; 
     103        naytto.Color = Level.Background.Color; 
     104        Add(naytto); 
     105 
     106        return laskuri; 
     107    } 
     108 
     109    void KasittelePallonTormays(PhysicsObject pallo, PhysicsObject kohde) 
     110    { 
     111        if (kohde == oikeaReuna) 
     112        { 
     113            pelaajan1Pisteet.Value += 1; 
     114        } 
     115        else if (kohde == vasenReuna) 
     116        { 
     117            pelaajan2Pisteet.Value += 1; 
     118        } 
    58119    } 
    59120 
     
    62123        Vector impulssi = new Vector(500.0, 0.0); 
    63124        pallo.Hit(impulssi); 
    64  
    65125    } 
    66126 
     
    69129        Keyboard.Listen(Key.A, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa ylös", maila1, nopeusYlos); 
    70130        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; 
     167        } 
     168 
     169        maila.Velocity = nopeus; 
     170    } 
     171} 
    71172 
    72173 
    73  
    74         Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 
    75  
    76     } 
    77     void AsetaNopeus(PhysicsObject maila,Vector nopeus) 
    78     { 
    79         maila.Velocity = nopeus; 
    80     } 
    81  
    82  
    83 } 
  • 2017/24/AaronL/Ponk/Ponk/Ponk/obj/x86/Debug/ContentPipeline-{D5CB20A4-ACFA-4AB7-B06D-47CE90DD528A}.xml

    r8549 r8560  
    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:07:25.939519+03:00</Value> 
     19        <Value>2017-06-07T09:21:00.3687337+03:00</Value> 
    2020      </Assembly> 
    2121    </Assemblies> 
Note: See TracChangeset for help on using the changeset viewer.