Changeset 1548


Ignore:
Timestamp:
2010-08-03 11:06:11 (9 years ago)
Author:
paaaanro
Message:
 
Location:
2010/31/eeveturu/pong
Files:
2 added
2 edited

Legend:

Unmodified
Added
Removed
  • 2010/31/eeveturu/pong/Content/Content.contentproj

    r1522 r1548  
    1 <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5"> 
     1<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5"> 
    22  <PropertyGroup> 
    33    <ProjectGuid>578922f1-1cc2-40e0-8fab-78f26b55f67e</ProjectGuid> 
     
    3434    <Reference Include="Microsoft.Xna.Framework.Content.Pipeline.XImporter, Version=3.1.0.0, Culture=neutral, PublicKeyToken=6d5c3888ef60e27d" /> 
    3535  </ItemGroup> 
     36  <ItemGroup> 
     37    <Compile Include="ping%2520pong%2520ball%2520copy[1].jpg"> 
     38      <Name>ping%2520pong%2520ball%2520copy[1]</Name> 
     39      <Importer>TextureImporter</Importer> 
     40      <Processor>TextureProcessor</Processor> 
     41    </Compile> 
     42  </ItemGroup> 
    3643</Project> 
  • 2010/31/eeveturu/pong/Peli.cs

    r1522 r1548  
    1212    PhysicsObject maila2; 
    1313 
     14    PhysicsObject vasenReuna; 
     15    PhysicsObject oikeaReuna; 
     16 
    1417    IntMeter pelaajan1Pisteet; 
    1518    IntMeter pelaajan2Pisteet; 
    16  
    1719 
    1820    protected override void Begin() 
    1921    { 
    2022        LuoKentta(); 
    21         LisaaLaskuri(); 
    2223        AsetaOhjaimet(); 
     24        LisaaLaskurit(); 
    2325        AloitaPeli(); 
    2426    } 
     
    2830        pallo = new PhysicsObject(40.0, 40.0); 
    2931        pallo.Shape = Shapes.Circle; 
     32        pallo.Color = Color.Yellow; 
    3033        pallo.X = -200.0; 
    3134        pallo.Y = 0.0; 
    3235        pallo.Restitution = 1.0; 
    3336        Add(pallo); 
     37        AddCollisionHandler(pallo, KasittelePallonTormays); 
    3438 
    3539        maila1 = LuoMaila(Level.Left + 20.0, 0.0); 
    3640        maila2 = LuoMaila(Level.Right - 20.0, 0.0); 
    3741 
    38         PhysicsObject vasenReuna = Level.CreateLeftBorder(); 
     42        vasenReuna = Level.CreateLeftBorder(); 
    3943        vasenReuna.Restitution = 1.0; 
    4044        vasenReuna.IsVisible = false; 
    41         PhysicsObject oikeaReuna = Level.CreateRightBorder(); 
    42         oikeaReuna = 1.0; 
     45        oikeaReuna = Level.CreateRightBorder(); 
     46        oikeaReuna.Restitution = 1.0; 
    4347        oikeaReuna.IsVisible = false; 
    44          
     48        PhysicsObject ylaReuna = Level.CreateTopBorder(); 
     49        ylaReuna.Restitution = 1.0; 
     50        ylaReuna.IsVisible = false; 
     51        PhysicsObject alaReuna = Level.CreateBottomBorder(); 
     52        alaReuna.Restitution = 1.0; 
     53        alaReuna.IsVisible = false; 
    4554 
    46          
    47         Level.BackgroundColor = Color.Black; 
     55        Level.BackgroundColor = Color.Green; 
    4856 
    4957        Camera.ZoomToLevel(); 
    50          
    51         AddCollisionHandler(pallo, KasittelePallonTormays); 
    52  
    5358    } 
    5459 
     
    6267        Add(maila); 
    6368        return maila; 
     69    } 
     70 
     71    void LisaaLaskurit() 
     72    { 
     73        pelaajan1Pisteet = LuoPisteLaskuri(Screen.Left + 100.0, Screen.Top - 100.0); 
     74        pelaajan2Pisteet = LuoPisteLaskuri(Screen.Right - 100.0, Screen.Top - 100.0); 
     75    } 
     76 
     77    IntMeter LuoPisteLaskuri(double x, double y) 
     78    { 
     79        IntMeter laskuri = new IntMeter(0); 
     80        laskuri.MaxValue = 10; 
     81        Label naytto = new Label(); 
     82        naytto.BindTo(laskuri); 
     83        naytto.X = x; 
     84        naytto.Y = y; 
     85        naytto.TextColor = Color.White; 
     86        Add(naytto); 
     87        return laskuri; 
     88    } 
     89 
     90    void KasittelePallonTormays(PhysicsObject pallo, PhysicsObject kohde) 
     91    { 
     92        if (kohde == oikeaReuna) 
     93        { 
     94            pelaajan1Pisteet.Value += 1; 
     95        } 
     96        else if (kohde == vasenReuna) 
     97        { 
     98            pelaajan2Pisteet.Value += 1; 
     99        } 
    64100    } 
    65101 
     
    84120        Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet"); 
    85121        Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Poistu"); 
     122 
     123        ControllerOne.Listen(Button.DPadUp, ButtonState.Down, AsetaNopeus, "Liikuta mailaa ylös", maila1, nopeusYlos); 
     124        ControllerOne.Listen(Button.DPadUp, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 
     125        ControllerOne.Listen(Button.DPadDown, ButtonState.Down, AsetaNopeus, "Liikuta mailaa alas", maila1, nopeusAlas); 
     126        ControllerOne.Listen(Button.DPadDown, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 
     127 
     128        ControllerTwo.Listen(Button.DPadUp, ButtonState.Down, AsetaNopeus, "Liikuta mailaa ylös", maila2, nopeusYlos); 
     129        ControllerTwo.Listen(Button.DPadUp, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 
     130        ControllerTwo.Listen(Button.DPadDown, ButtonState.Down, AsetaNopeus, "Liikuta mailaa alas", maila2, nopeusAlas); 
     131        ControllerTwo.Listen(Button.DPadDown, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 
     132 
     133        ControllerOne.Listen(Button.Back, ButtonState.Pressed, Exit, "Poistu"); 
     134        ControllerTwo.Listen(Button.Back, ButtonState.Pressed, Exit, "Poistu"); 
    86135    } 
    87136 
     
    100149 
    101150        maila.Velocity = nopeus; 
    102  
    103151    } 
    104     void LisaaLaskuri() 
    105     { 
    106         pelaajan1Pisteet = LuoPisteLaskuri(Screen.Left + 100.0, Screen.Top - 100.0); 
    107         pelaajan2Pisteet = LuoPisteLaskuri(Screen.Right - 100.0, Screen.Top - 100.0); 
    108     } 
    109      
    110     IntMeter LuoPisteLaskuri( double x, double y ) 
    111     { 
    112         IntMeter laskuri = new IntMeter(0); 
    113         laskuri.MaxValue = 10; 
    114         Label naytto = new Label(); 
    115         naytto.BindTo(laskuri); 
    116         naytto.X = x; 
    117         naytto.Y = y; 
    118         naytto.TextColor = Color.White; 
    119         Add(naytto); 
    120         return laskuri; 
    121  
    122     } 
    123     void KasittelePallonTormays(PhysicsObject pallo, PhysicsObject kohde) 
    124     { 
    125     } 
    126  
    127152} 
    128  
    129  
Note: See TracChangeset for help on using the changeset viewer.