Changeset 8585


Ignore:
Timestamp:
2017-06-13 13:08:10 (2 years ago)
Author:
npo17_13
Message:
 
Location:
2017/24/SebastianH/Pong/Pong
Files:
10 edited

Legend:

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

    r8540 r8585  
    1313 
    1414    PhysicsObject pallo; 
    15  
    1615    PhysicsObject maila1; 
    1716    PhysicsObject maila2; 
     17 
     18    PhysicsObject vasenReuna; 
     19    PhysicsObject oikeaReuna; 
     20 
     21    IntMeter pelaajan1Pisteet; 
     22    IntMeter pelaajan2Pisteet; 
    1823    public override void Begin() 
    1924    { 
    2025        LuoKentta(); 
    2126        AsetaOhjaimet(); 
     27        LisaaLaskurit(); 
    2228        AloitaPeli(); 
    2329         
     
    3440        Add(pallo); 
    3541 
    36         LuoMaila(Level.Left + 20.0, 0.0); 
    37         LuoMaila(Level.Right - 20.0, 0.0); 
     42        AddCollisionHandler(pallo, KasittelePallonTormays); 
    3843 
    39         Level.CreateBorders(1.0, false); 
     44        maila1 = LuoMaila(Level.Left + 20.0, 0.0); 
     45        maila2 = LuoMaila(Level.Right - 20.0, 0.0); 
     46 
     47        vasenReuna = Level.CreateLeftBorder(); 
     48        vasenReuna.Restitution = 1.0; 
     49        vasenReuna.IsVisible = false; 
     50 
     51        oikeaReuna = Level.CreateRightBorder(); 
     52        oikeaReuna.Restitution = 1.0; 
     53        vasenReuna.IsVisible = false; 
     54 
     55        PhysicsObject alareuna = Level.CreateBottomBorder(); 
     56        alareuna.Restitution = 1.0; 
     57        alareuna.IsVisible = false; 
     58 
     59        PhysicsObject ylaReuna = Level.CreateTopBorder(); 
     60        ylaReuna.Restitution = 1.0; 
     61        ylaReuna.IsVisible = false; 
     62 
    4063        Level.Background.Color = Color.Black; 
    4164 
     
    4770        pallo.Hit(impulssi); 
    4871    } 
    49     void LuoMaila(double x, double y) 
     72    PhysicsObject LuoMaila(double x, double y) 
    5073    { 
    5174        PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0); 
     
    5578        maila.Restitution = 1.0; 
    5679        Add(maila); 
     80        return maila; 
    5781    } 
    5882    void AsetaOhjaimet() 
    5983    { 
    60         Keyboard.Listen(Key.W, ButtonState.Down, LiikutaMaila1Ylos, "Pelaaja 1: Liikuta mailaa ylös"); 
    61         Keyboard.Listen(Key.W, ButtonState.Released, PysaytaMaila1, null); 
     84        Keyboard.Listen(Key.W, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa ylös", maila1, nopeusYlos); 
     85        Keyboard.Listen(Key.W, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 
     86        Keyboard.Listen(Key.S, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa alas", maila1, nopeusAlas); 
     87        Keyboard.Listen(Key.S, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 
     88 
     89        Keyboard.Listen(Key.Up, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa ylös", maila2, nopeusYlos); 
     90        Keyboard.Listen(Key.Up, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 
     91        Keyboard.Listen(Key.Down, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa alas", maila2, nopeusAlas); 
     92        Keyboard.Listen(Key.Down, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 
     93 
     94        Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet"); 
    6295        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 
    6396    } 
    6497    void AsetaNopeus(PhysicsObject maila, Vector nopeus) 
    6598    { 
     99        if ((nopeus.Y < 0) && (maila.Bottom < Level.Bottom)) 
     100        { 
     101            maila.Velocity = Vector.Zero; 
     102            return; 
     103        } 
     104        if ((nopeus.Y > 0) && (maila.Top > Level.Top)) 
     105        { 
     106            maila.Velocity = Vector.Zero; 
     107            return; 
     108        } 
     109 
    66110        maila.Velocity = nopeus; 
    67111    } 
     112    void LisaaLaskurit() 
     113    { 
     114        pelaajan1Pisteet = LuoPisteLaskuri(Screen.Left + 100.0, Screen.Top - 100.0); 
     115        pelaajan2Pisteet = LuoPisteLaskuri(Screen.Right - 100.0, Screen.Top - 100.0); 
     116    } 
     117    IntMeter LuoPisteLaskuri(double x, double y) 
     118    { 
     119        IntMeter laskuri = new IntMeter(0); 
     120        laskuri.MaxValue = 10; 
     121 
     122        Label naytto = new Label(); 
     123        naytto.BindTo(laskuri); 
     124        naytto.X = x; 
     125        naytto.Y = y; 
     126        naytto.TextColor = Color.White; 
     127        naytto.BorderColor = Level.Background.Color; 
     128        naytto.Color = Level.Background.Color; 
     129        Add(naytto); 
     130 
     131        return laskuri; 
     132    } 
     133    void KasittelePallonTormays(PhysicsObject pallo, PhysicsObject kohde) 
     134    { 
     135        if (kohde == oikeaReuna) 
     136        { 
     137            pelaajan1Pisteet.Value += 1; 
     138        } 
     139        else if (kohde == vasenReuna) 
     140        { 
     141            pelaajan2Pisteet.Value += 1; 
     142        } 
     143    } 
    68144} 
  • 2017/24/SebastianH/Pong/Pong/Pong/obj/x86/Debug/ContentPipeline-{0A35FA10-CC5B-4A14-91E0-8CF99771CD54}.xml

    r8540 r8585  
    99      <BuildConfiguration>Debug</BuildConfiguration> 
    1010      <CompressContent>false</CompressContent> 
    11       <RootDirectory>C:\MyTemp\Pong\Pong\PongContent\</RootDirectory> 
    12       <LoggerRootDirectory>C:\MyTemp\Pong\Pong\Pong\</LoggerRootDirectory> 
    13       <IntermediateDirectory>C:\MyTemp\Pong\Pong\Pong\obj\x86\Debug\</IntermediateDirectory> 
    14       <OutputDirectory>C:\MyTemp\Pong\Pong\Pong\bin\x86\Debug\Content\</OutputDirectory> 
     11      <RootDirectory>C:\MyTemp\SebastianH\Pong\Pong\PongContent\</RootDirectory> 
     12      <LoggerRootDirectory>C:\MyTemp\SebastianH\Pong\Pong\Pong\</LoggerRootDirectory> 
     13      <IntermediateDirectory>C:\MyTemp\SebastianH\Pong\Pong\Pong\obj\x86\Debug\</IntermediateDirectory> 
     14      <OutputDirectory>C:\MyTemp\SebastianH\Pong\Pong\Pong\bin\x86\Debug\Content\</OutputDirectory> 
    1515    </Settings> 
    1616    <Assemblies> 
  • 2017/24/SebastianH/Pong/Pong/Pong/obj/x86/Debug/Pong.csproj.FileListAbsolute.txt

    r8540 r8585  
    77C:\MyTemp\Pong\Pong\Pong\obj\x86\Debug\Pong.exe 
    88C:\MyTemp\Pong\Pong\Pong\obj\x86\Debug\Pong.pdb 
     9C:\MyTemp\SebastianH\Pong\Pong\Pong\obj\x86\Debug\Pong.csprojResolveAssemblyReference.cache 
     10C:\MyTemp\SebastianH\Pong\Pong\Pong\obj\x86\Debug\Microsoft.Xna.Framework.RuntimeProfile.txt 
     11C:\MyTemp\SebastianH\Pong\Pong\Pong\obj\x86\Debug\Pong.exe 
     12C:\MyTemp\SebastianH\Pong\Pong\Pong\obj\x86\Debug\Pong.pdb 
     13C:\MyTemp\SebastianH\Pong\Pong\Pong\bin\x86\Debug\Pong.exe 
     14C:\MyTemp\SebastianH\Pong\Pong\Pong\bin\x86\Debug\Pong.pdb 
     15C:\MyTemp\SebastianH\Pong\Pong\Pong\bin\x86\Debug\Jypeli.dll 
     16C:\MyTemp\SebastianH\Pong\Pong\Pong\bin\x86\Debug\Jypeli.xml 
  • 2017/24/SebastianH/Pong/Pong/PongContent/obj/x86/Debug/PongContent.contentproj.FileListAbsolute.txt

    r8540 r8585  
    11C:\MyTemp\Pong\Pong\PongContent\obj\x86\Debug\PongContent.contentprojResolveAssemblyReference.cache 
     2C:\MyTemp\SebastianH\Pong\Pong\PongContent\obj\x86\Debug\PongContent.contentprojResolveAssemblyReference.cache 
Note: See TracChangeset for help on using the changeset viewer.