Changeset 6185


Ignore:
Timestamp:
2015-06-23 14:57:02 (8 years ago)
Author:
sieerinn
Message:
 
Location:
2015/26/SanteriP
Files:
56 added
11 edited

Legend:

Unmodified
Added
Removed
  • 2015/26/SanteriP/Pong/Pong/Pong/Pong.cs

    r6144 r6185  
    99public class Pong : PhysicsGame 
    1010{ 
     11 
     12    Vector nopeusYlös = new Vector(0, 200); 
     13    Vector nopeusAlas = new Vector(0, -200); 
     14 
    1115    PhysicsObject pallo; 
     16 
     17    PhysicsObject maila1; 
     18    PhysicsObject maila2; 
     19 
     20    PhysicsObject vasenReuna; 
     21    PhysicsObject oikeaReuna; 
     22 
     23    IntMeter pelaajan1Pisteet; 
     24    IntMeter pelaajan2Pisteet; 
    1225 
    1326    public override void Begin() 
    1427    { 
    15         // TODO: Kirjoita ohjelmakoodisi tähän 
    1628        LuoKentta(); 
     29        asetaohjaimet(); 
     30        LisaaLaskurit(); 
    1731        AloitaPeli(); 
     32    } 
    1833 
    19         Keyboard.Listen(Key.A, ButtonState.Down,LiikutaMaila1Ylos, "Pelaaja 1: Liikuta mailaa ylös"); 
     34    void LisaaLaskurit() 
     35    { 
     36        pelaajan1Pisteet = LuoPisteLaskuri(Screen.Left + 100.0, Screen.Top - 100.0); 
     37        pelaajan2Pisteet = LuoPisteLaskuri(Screen.Right - 100.0, Screen.Top - 100.0); 
     38    } 
    2039 
     40    IntMeter LuoPisteLaskuri(double x, double y) 
     41    { 
     42        IntMeter laskuri = new IntMeter(0); 
     43        laskuri.MaxValue = 10; 
     44 
     45        Label nayttö = new Label(); 
     46        nayttö.BindTo(laskuri); 
     47        nayttö.X = x; 
     48        nayttö.Y = y; 
     49        nayttö.TextColor = Color.White; 
     50        nayttö.BorderColor = Level.Background.Color; 
     51        nayttö.Color = Level.Background.Color; 
     52        Add(nayttö); 
     53 
     54        return laskuri; 
     55    } 
     56    void asetaohjaimet() 
     57    { 
     58        Keyboard.Listen(Key.A, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa ylös", maila1, nopeusYlös); 
     59        Keyboard.Listen(Key.A, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 
     60 
     61        Keyboard.Listen(Key.Z, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa alas", maila1, nopeusAlas); 
     62        Keyboard.Listen(Key.Z, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 
     63 
     64 
     65 
     66        Keyboard.Listen(Key.Up, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa ylös", maila2, nopeusYlös); 
     67        Keyboard.Listen(Key.Up, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 
     68        Keyboard.Listen(Key.Down, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa alas", maila2, nopeusAlas); 
     69        Keyboard.Listen(Key.Down, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 
     70 
     71 
     72 
     73        Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet"); 
    2174 
    2275        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 
     
    3285        Add(pallo); 
    3386 
     87        AddCollisionHandler(pallo, KasittelePallonTormaus); 
     88        maila1 = LuoMaila(Level.Left + 20.0, 0.0); 
     89        maila2 = LuoMaila(Level.Right - 20.0, 0.0); 
    3490 
    35         LuoMaila(Level.Left + 20.0, 0.0); 
    36         LuoMaila(Level.Right - 20.0, 0.0); 
     91        vasenReuna = Level.CreateLeftBorder(); 
     92        vasenReuna.Restitution = 1.0; 
     93        vasenReuna.KineticFriction = 0.0; 
     94        vasenReuna.IsVisible = false; 
    3795 
    38         Level.CreateBorders(1.0, false); 
     96        oikeaReuna = Level.CreateRightBorder(); 
     97        oikeaReuna.Restitution = 1.0; 
     98        oikeaReuna.KineticFriction = 0.0; 
     99        oikeaReuna.IsVisible = false; 
     100 
     101        PhysicsObject ylaReuna = Level.CreateTopBorder(); 
     102        ylaReuna.Restitution = 1.0; 
     103        ylaReuna.KineticFriction = 0.0; 
     104        ylaReuna.IsVisible = false; 
     105 
     106        PhysicsObject alaReuna = Level.CreateBottomBorder(); 
     107        alaReuna.Restitution = 1.0; 
     108        alaReuna.IsVisible = false; 
     109        alaReuna.KineticFriction = 0.0; 
    39110 
    40111        Level.Background.Color = Color.Black; 
    41  
    42  
    43  
    44  
    45112 
    46113        Camera.ZoomToLevel(); 
    47114 
    48115    } 
    49  
    50     void LuoMaila(double x, double y) 
     116     
     117    PhysicsObject LuoMaila(double x, double y) 
    51118    { 
    52119        PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0); 
     
    56123        maila.Restitution = 1.0; 
    57124        Add(maila); 
     125        return maila; 
     126    } 
     127    void KasittelePallonTormaus(PhysicsObject pallo, PhysicsObject kohde) 
     128    { 
     129        if (kohde == oikeaReuna) 
     130        { 
     131            pelaajan1Pisteet.Value += 1; 
     132        } 
     133        else if (kohde == vasenReuna) 
     134        { 
     135            pelaajan2Pisteet.Value += 1; 
     136        } 
    58137    } 
    59138 
     
    64143        pallo.Hit(impulssi); 
    65144    } 
     145    void AsetaNopeus(PhysicsObject maila, Vector nopeus) 
     146    { 
     147        if ((nopeus.Y < 0) && (maila.Bottom < Level.Bottom)) 
     148        { 
     149            maila.Velocity = Vector.Zero; 
     150            return; 
     151        } 
     152        if ((nopeus.Y > 0) && (maila.Top > Level.Top)) 
     153        { 
     154            maila.Velocity = Vector.Zero; 
     155            return; 
     156 
     157        } 
     158         
     159        maila.Velocity = nopeus; 
     160    } 
     161 
    66162 
    67163} 
  • 2015/26/SanteriP/Pong/Pong/Pong/obj/x86/Debug/ContentPipeline-{44E55511-5866-492E-BFE2-174CEE65073D}.xml

    r6144 r6185  
    99      <BuildConfiguration>Debug</BuildConfiguration> 
    1010      <CompressContent>false</CompressContent> 
    11       <RootDirectory>C:\MyTemp\santerip\Pong\Pong\PongContent\</RootDirectory> 
    12       <LoggerRootDirectory>C:\MyTemp\santerip\Pong\Pong\Pong\</LoggerRootDirectory> 
    13       <IntermediateDirectory>C:\MyTemp\santerip\Pong\Pong\Pong\obj\x86\Debug\</IntermediateDirectory> 
    14       <OutputDirectory>C:\MyTemp\santerip\Pong\Pong\Pong\bin\x86\Debug\Content\</OutputDirectory> 
     11      <RootDirectory>C:\MyTemp\SanteriP\Pong\Pong\PongContent\</RootDirectory> 
     12      <LoggerRootDirectory>C:\MyTemp\SanteriP\Pong\Pong\Pong\</LoggerRootDirectory> 
     13      <IntermediateDirectory>C:\MyTemp\SanteriP\Pong\Pong\Pong\obj\x86\Debug\</IntermediateDirectory> 
     14      <OutputDirectory>C:\MyTemp\SanteriP\Pong\Pong\Pong\bin\x86\Debug\Content\</OutputDirectory> 
    1515    </Settings> 
    1616    <Assemblies> 
    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>2012-03-16T14:33:41.9515583+02:00</Value> 
     19        <Value>2014-04-23T00:30:18.4504836+03:00</Value> 
    2020      </Assembly> 
    2121    </Assemblies> 
Note: See TracChangeset for help on using the changeset viewer.