Changeset 1969


Ignore:
Timestamp:
2011-06-13 14:56:56 (12 years ago)
Author:
tojukarp
Message:

Valmis

Location:
2011/24/LeeviK/Pong/Pong
Files:
4 added
2 edited

Legend:

Unmodified
Added
Removed
  • 2011/24/LeeviK/Pong/Pong/Pong/Peli.cs

    r1955 r1969  
    1313    Vector nopeusYlos = new Vector(0, 200); 
    1414    Vector nopeusAlas = new Vector(0, -200); 
     15    Image taustaKuva = LoadImage("tausta"); 
    1516 
    16     PhysicsObject pallo; 
    17     PhysicsObject maila1; 
    18     PhysicsObject maila2; 
    1917 
    20     PhysicsObject vasenReuna; 
    21     PhysicsObject oikeaReuna; 
     18    PhysicsObject pelaaja1; 
     19     
    2220 
    23     IntMeter pelaajan1Pisteet; 
    24     IntMeter pelaajan2Pisteet; 
     21     
     22     
    2523 
    2624    public override void Begin() 
     
    2826        LuoKentta(); 
    2927        AsetaOhjaimet(); 
    30         LisaaLaskurit(); 
    3128        AloitaPeli(); 
     29        Mouse.IsCursorVisible = true; 
     30        Mouse.ListenMovement(0.1, KuunteleLiiketta, null); 
     31 
     32         
     33        //                                                                                                         x, y 
     34        Keyboard.Listen(Key.Left, ButtonState.Down, LiikutaPelaajaa, "Liikuta pelaajaa vasemmalle", new Vector(-1000, 0)); 
     35        Keyboard.Listen(Key.Right, ButtonState.Down, LiikutaPelaajaa, null, new Vector(1000, 0)); 
     36        Keyboard.Listen(Key.Up, ButtonState.Down, LiikutaPelaajaa, null, new Vector(0, 1000)); 
     37        Keyboard.Listen(Key.Down, ButtonState.Down, LiikutaPelaajaa, null, new Vector(0, -1000)); 
    3238    } 
    3339 
     40    void LiikutaPelaajaa(Vector kakkakasa) 
     41    { 
     42        pelaaja1.Push(kakkakasa); 
     43    }    
     44   
    3445    void LuoKentta() 
    3546    { 
    36         pallo = new PhysicsObject(40.0, 40.0); 
    37         pallo.Shape = Shape.Circle; 
    38         pallo.X = -200.0; 
    39         pallo.Y = 0.0; 
    40         pallo.Restitution = 1.0; 
    41         pallo.KineticFriction = 0.0; 
    42         Add(pallo); 
    43         AddCollisionHandler(pallo, KasittelePallonTormays); 
     47        pelaaja1 = new PhysicsObject(200.0, 200.0); 
     48        pelaaja1.Shape = Shape.Circle; 
     49        pelaaja1.X = -200.0; 
     50        pelaaja1.Y = 0.0; 
     51        pelaaja1.Restitution = 1.0; 
     52        pelaaja1.KineticFriction = 0.0; 
     53        Add(pelaaja1); 
     54        pelaaja1.Image = LoadImage("jenkki"); 
    4455 
    45         maila1 = LuoMaila(Level.Left + 20.0, 0.0); 
    46         maila2 = LuoMaila(Level.Right - 20.0, 0.0); 
    47  
    48         vasenReuna = Level.CreateLeftBorder(); 
    49         vasenReuna.Restitution = 1.0; 
    50         vasenReuna.IsVisible = false; 
    51         oikeaReuna = Level.CreateRightBorder(); 
    52         oikeaReuna.Restitution = 1.0; 
    53         oikeaReuna.IsVisible = false; 
    54         PhysicsObject ylaReuna = Level.CreateTopBorder(); 
    55         ylaReuna.Restitution = 1.0; 
    56         ylaReuna.IsVisible = false; 
    57         PhysicsObject alaReuna = Level.CreateBottomBorder(); 
    58         alaReuna.Restitution = 1.0; 
    59         alaReuna.IsVisible = false; 
    60  
    61         Level.BackgroundColor = Color.Black; 
    62  
    63         Camera.ZoomToLevel(); 
     56        Level.Background.Image = taustaKuva; 
     57        Camera.Follow(pelaaja1); 
    6458    } 
    6559 
    66     PhysicsObject LuoMaila(double x, double y) 
    67     { 
    68         PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0); 
    69         maila.Shape = Shape.Rectangle; 
    70         maila.X = x; 
    71         maila.Y = y; 
    72         maila.Restitution = 1.0; 
    73         Add(maila); 
    74         return maila; 
    75     } 
     60     
    7661 
    77     void LisaaLaskurit() 
    78     { 
    79         pelaajan1Pisteet = LuoPisteLaskuri(Screen.Left + 100.0, Screen.Top - 100.0); 
    80         pelaajan2Pisteet = LuoPisteLaskuri(Screen.Right - 100.0, Screen.Top - 100.0); 
    81     } 
     62       
    8263 
    8364    IntMeter LuoPisteLaskuri(double x, double y) 
     
    9576        return laskuri; 
    9677    } 
     78     
     79    
     80     
    9781 
    98     void KasittelePallonTormays(PhysicsObject pallo, PhysicsObject kohde) 
    99     { 
    100         if (kohde == oikeaReuna) 
    101         { 
    102             pelaajan1Pisteet.Value += 1; 
    103         } 
    104         else if (kohde == vasenReuna) 
    105         { 
    106             pelaajan2Pisteet.Value += 1; 
    107         } 
    108     } 
     82     
    10983 
    11084    void AloitaPeli() 
    11185    { 
    112         Vector impulssi = new Vector(500.0, 0.0); 
    113         pallo.Hit(impulssi); 
     86         
     87         
    11488    } 
    11589 
    11690    void AsetaOhjaimet() 
    11791    { 
    118         Keyboard.Listen(Key.A, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa ylös", maila1, nopeusYlos); 
    119         Keyboard.Listen(Key.A, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 
    120         Keyboard.Listen(Key.Z, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa alas", maila1, nopeusAlas); 
    121         Keyboard.Listen(Key.Z, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 
    122  
    123         Keyboard.Listen(Key.Up, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa ylös", maila2, nopeusYlos); 
    124         Keyboard.Listen(Key.Up, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 
    125         Keyboard.Listen(Key.Down, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa alas", maila2, nopeusAlas); 
    126         Keyboard.Listen(Key.Down, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 
    127  
    128         Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet"); 
    12992        Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Poistu"); 
    130  
    131         ControllerOne.Listen(Button.DPadUp, ButtonState.Down, AsetaNopeus, "Liikuta mailaa ylös", maila1, nopeusYlos); 
    132         ControllerOne.Listen(Button.DPadUp, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 
    133         ControllerOne.Listen(Button.DPadDown, ButtonState.Down, AsetaNopeus, "Liikuta mailaa alas", maila1, nopeusAlas); 
    134         ControllerOne.Listen(Button.DPadDown, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 
    135  
    136         ControllerTwo.Listen(Button.DPadUp, ButtonState.Down, AsetaNopeus, "Liikuta mailaa ylös", maila2, nopeusYlos); 
    137         ControllerTwo.Listen(Button.DPadUp, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 
    138         ControllerTwo.Listen(Button.DPadDown, ButtonState.Down, AsetaNopeus, "Liikuta mailaa alas", maila2, nopeusAlas); 
    139         ControllerTwo.Listen(Button.DPadDown, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 
    140  
    141         ControllerOne.Listen(Button.Back, ButtonState.Pressed, Exit, "Poistu"); 
    142         ControllerTwo.Listen(Button.Back, ButtonState.Pressed, Exit, "Poistu"); 
     93        //Keyboard.Listen(Key.Left, ButtonState.Down, 
     94     
    14395    } 
    14496 
    145     void AsetaNopeus(PhysicsObject maila, Vector nopeus) 
     97 
     98    void KuunteleLiiketta(AnalogState hiirenTila) 
    14699    { 
    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         } 
    157100 
    158         maila.Velocity = nopeus; 
     101        Mouse.IsCursorVisible = true; 
     102        Vector hiirenLiike = hiirenTila.MouseMovement; 
     103        pelaaja1.Angle = hiirenLiike.Angle; 
    159104    } 
     105 
     106 
     107 
    160108} 
  • 2011/24/LeeviK/Pong/Pong/PongContent/PongContent.contentproj

    r1955 r1969  
    4242    </Reference> 
    4343  </ItemGroup> 
     44  <ItemGroup> 
     45    <Compile Include="jenkki.png"> 
     46      <Name>jenkki</Name> 
     47      <Importer>TextureImporter</Importer> 
     48      <Processor>TextureProcessor</Processor> 
     49    </Compile> 
     50  </ItemGroup> 
     51  <ItemGroup> 
     52    <Compile Include="tausta.png"> 
     53      <Name>tausta</Name> 
     54      <Importer>TextureImporter</Importer> 
     55      <Processor>TextureProcessor</Processor> 
     56    </Compile> 
     57  </ItemGroup> 
     58  <ItemGroup> 
     59    <Compile Include="crosshair.png"> 
     60      <Name>crosshair</Name> 
     61      <Importer>TextureImporter</Importer> 
     62      <Processor>TextureProcessor</Processor> 
     63    </Compile> 
     64  </ItemGroup> 
    4465  <Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" /> 
    4566  <!--  To modify your build process, add your task inside one of the targets below and uncomment it.  
Note: See TracChangeset for help on using the changeset viewer.