Changeset 8578 for 2017


Ignore:
Timestamp:
2017-06-13 13:05:11 (2 years ago)
Author:
npo17_28
Message:
 
Location:
2017/24/JaakkoK/Pong/Pong
Files:
8 edited

Legend:

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

    r8529 r8578  
    11using System; 
    22using System.Collections.Generic; 
     3using System.Linq; 
     4using System.Text; 
    35using Jypeli; 
    46using Jypeli.Assets; 
     
    810 
    911public class Pong : PhysicsGame 
    10 {  
     12{ 
    1113    Vector nopeusYlos = new Vector(0, 200); 
    1214    Vector nopeusAlas = new Vector(0, -200); 
    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(); 
     29        AsetaOhjaimet(); 
     30        LisaaLaskurit(); 
    2331        AloitaPeli(); 
    24         Vector impulssi = new Vector(500.0, 0.0); 
    25         pallo.Hit(impulssi); 
    26         PhoneBackButton.Listen(ConfirmExit, "Lopeta peli"); 
    27          
    2832    } 
     33 
    2934    void LuoKentta() 
    3035    { 
    31         pallo = new PhysicsObject(40.0, 40.0); 
     36        pallo = new PhysicsObject(80.0, 80.0); 
    3237        pallo.Shape = Shape.Circle; 
    3338        pallo.X = -200.0; 
    3439        pallo.Y = 0.0; 
    3540        pallo.Restitution = 1.0; 
     41        pallo.KineticFriction = 0.0; 
     42        pallo.MomentOfInertia = Double.PositiveInfinity; 
     43        pallo.AngularVelocity += 5; 
     44        Add(pallo); 
     45        AddCollisionHandler(pallo, KasittelePallonTormays); 
    3646 
    37       maila1 = LuoMaila(Level.Left + 20.0, 0.0); 
    38       maila2 = LuoMaila(Level.Right - 20.0, 0.0); 
     47        maila1 = LuoMaila(Level.Left + 20.0, 0.0); 
     48        maila2 = LuoMaila(Level.Right - 20.0, 0.0); 
    3949 
    40         Level.CreateBorders(1.0, false); 
    41         Level.Background.Color = Color.Black; 
     50        vasenReuna = Level.CreateLeftBorder(); 
     51        vasenReuna.Restitution = 1.0; 
     52        vasenReuna.KineticFriction = 0.0; 
     53        vasenReuna.IsVisible = false; 
     54 
     55        oikeaReuna = Level.CreateRightBorder(); 
     56        oikeaReuna.Restitution = 1.0; 
     57        oikeaReuna.KineticFriction = 0.0; 
     58        oikeaReuna.IsVisible = false; 
     59 
     60        PhysicsObject ylaReuna = Level.CreateTopBorder(); 
     61        ylaReuna.Restitution = 1.0; 
     62        ylaReuna.KineticFriction = 0.0; 
     63        ylaReuna.IsVisible = false; 
     64 
     65        PhysicsObject alaReuna = Level.CreateBottomBorder(); 
     66        alaReuna.Restitution = 1.0; 
     67        alaReuna.IsVisible = false; 
     68        alaReuna.KineticFriction = 0.0; 
     69 
     70        Level.Background.Color = Color.Aqua; 
     71 
    4272        Camera.ZoomToLevel(); 
    43         Add(pallo); 
     73    } 
     74 
     75    PhysicsObject LuoMaila(double x, double y) 
     76    { 
     77        PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0); 
     78        maila.Shape = Shape.Rectangle; 
     79        maila.X = x; 
     80        maila.Y = y; 
     81        maila.Restitution = 1.0; 
     82        maila.KineticFriction = 0.0; 
     83        Add(maila); 
     84        return maila; 
     85    } 
     86 
     87    void LisaaLaskurit() 
     88    { 
     89        pelaajan1Pisteet = LuoPisteLaskuri(Screen.Left + 100.0, Screen.Top - 100.0); 
     90        pelaajan2Pisteet = LuoPisteLaskuri(Screen.Right - 100.0, Screen.Top - 100.0); 
     91    } 
     92 
     93    IntMeter LuoPisteLaskuri(double x, double y) 
     94    { 
     95        IntMeter laskuri = new IntMeter(0); 
     96        laskuri.MaxValue = 10; 
     97 
     98        Label naytto = new Label(); 
     99        naytto.BindTo(laskuri); 
     100        naytto.X = x; 
     101        naytto.Y = y; 
     102        naytto.TextColor = Color.White; 
     103        naytto.BorderColor = Level.Background.Color; 
     104        naytto.Color = Level.Background.Color; 
     105        Add(naytto); 
     106 
     107        return laskuri; 
     108    } 
     109 
     110    void KasittelePallonTormays(PhysicsObject pallo, PhysicsObject kohde) 
     111    { 
     112        if (kohde == oikeaReuna) 
     113        { 
     114            pelaajan1Pisteet.Value += 1; 
     115        } 
     116        else if (kohde == vasenReuna) 
     117        { 
     118            pelaajan2Pisteet.Value += 1; 
     119        } 
    44120    } 
    45121 
     
    50126    } 
    51127 
    52     void PhysicsObject LuoMaila(double x, double y) 
    53     { 
    54         PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0); 
    55         maila.Shape = Shape.Rectangle; 
    56         maila.X = x; 
    57         maila.Y = y; 
    58         maila.Restitution = 1.0; 
    59         Add(maila); 
    60         return maila; 
    61     } 
    62128    void AsetaOhjaimet() 
    63129    { 
    64     Keyboard.Listen(Key.A, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa ylös", maila1, nopeusYlos); 
    65     Keyboard.Listen(Key.A, ButtonState.Released, AsetaNopeus, Null, maila1 Vector.Zero); 
     130        Keyboard.Listen(Key.A, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa ylös", maila1, nopeusYlos); 
     131        Keyboard.Listen(Key.A, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 
     132        Keyboard.Listen(Key.Z, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa alas", maila1, nopeusAlas); 
     133        Keyboard.Listen(Key.Z, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 
    66134 
     135        Keyboard.Listen(Key.Up, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa ylös", maila2, nopeusYlos); 
     136        Keyboard.Listen(Key.Up, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 
     137        Keyboard.Listen(Key.Down, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa alas", maila2, nopeusAlas); 
     138        Keyboard.Listen(Key.Down, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 
     139 
     140        Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet"); 
    67141        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 
     142 
     143        ControllerOne.Listen(Button.DPadUp, ButtonState.Down, AsetaNopeus, "Liikuta mailaa ylös", maila1, nopeusYlos); 
     144        ControllerOne.Listen(Button.DPadUp, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 
     145        ControllerOne.Listen(Button.DPadDown, ButtonState.Down, AsetaNopeus, "Liikuta mailaa alas", maila1, nopeusAlas); 
     146        ControllerOne.Listen(Button.DPadDown, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 
     147 
     148        ControllerTwo.Listen(Button.DPadUp, ButtonState.Down, AsetaNopeus, "Liikuta mailaa ylös", maila2, nopeusYlos); 
     149        ControllerTwo.Listen(Button.DPadUp, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 
     150        ControllerTwo.Listen(Button.DPadDown, ButtonState.Down, AsetaNopeus, "Liikuta mailaa alas", maila2, nopeusAlas); 
     151        ControllerTwo.Listen(Button.DPadDown, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 
     152 
     153        ControllerOne.Listen(Button.Back, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 
     154        ControllerTwo.Listen(Button.Back, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 
    68155    } 
     156 
    69157    void AsetaNopeus(PhysicsObject maila, Vector nopeus) 
    70158    { 
     159        if ((nopeus.Y < 0) && (maila.Bottom < Level.Bottom)) 
     160        { 
     161            maila.Velocity = Vector.Zero; 
     162            return; 
     163        } 
     164        if ((nopeus.Y > 0) && (maila.Top > Level.Top)) 
     165        { 
     166            maila.Velocity = Vector.Zero; 
     167            return; 
     168        } 
     169 
    71170        maila.Velocity = nopeus; 
    72171    } 
    73  
    74  
    75  
    76         } 
     172} 
  • 2017/24/JaakkoK/Pong/Pong/Pong/obj/x86/Debug/ContentPipeline-{5A1FC657-CFC7-4AFD-BF92-FC5E5CE17D2E}.xml

    r8513 r8578  
    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-06T09:54:48.1175627+03:00</Value> 
     19        <Value>2017-06-10T12:57:03.6416824+03:00</Value> 
    2020      </Assembly> 
    2121    </Assemblies> 
Note: See TracChangeset for help on using the changeset viewer.