Changeset 2048 for 2011/24


Ignore:
Timestamp:
2011-06-16 15:01:20 (12 years ago)
Author:
paaaanro
Message:
 
Location:
2011/24/PauliN
Files:
21 added
4 edited

Legend:

Unmodified
Added
Removed
  • 2011/24/PauliN/Jalkapallopeli/Jalkapallopeli/Jalkapallopeli/Jalkapallopeli.csproj

    r1991 r2048  
    119119    <Content Include="Game.ico" /> 
    120120    <Content Include="GameThumbnail.png" /> 
     121    <Content Include="ground.png" /> 
    121122    <Content Include="imagesCA9N94Z4.jpg" /> 
     123    <Content Include="pelaaja1oik.png" /> 
     124    <Content Include="pelaaja2.png" /> 
     125    <Content Include="pelaaja2vas.png" /> 
     126    <Content Include="tausta.png" /> 
    122127  </ItemGroup> 
    123128  <ItemGroup> 
  • 2011/24/PauliN/Jalkapallopeli/Jalkapallopeli/Jalkapallopeli/Ohjelma.cs

    r1991 r2048  
    1111            game.IsFullScreen = true; 
    1212#endif 
    13             game.Run(); 
    14         } 
     13            game.Run();        } 
    1514    } 
    1615#endif 
  • 2011/24/PauliN/Jalkapallopeli/Jalkapallopeli/Jalkapallopeli/Peli.cs

    r2022 r2048  
    99public class Peli : PhysicsGame 
    1010{ 
    11     Image pallonKuva = LoadImage("football"); 
     11    Image pallonKuva = LoadImage("football");     
     12    Image pelaaja1Kuva = LoadImage("pelaaja1");    
     13    Image pelaaja1oikKuva = LoadImage("pelaaja1oik"); 
     14    Image pelaaja2Kuva = LoadImage("pelaaja2"); 
     15    Image pelaaja2vasKuva = LoadImage("pelaaja2vas"); 
     16    Image tausta = LoadImage("tausta"); 
     17 
    1218    PhysicsObject pallo; 
    13  
     19    PhysicsObject nurmi; 
     20    PhysicsObject maali1; 
     21    PhysicsObject maali2; 
    1422    PhysicsObject pelaaja1; 
    1523    PhysicsObject pelaaja2; 
    1624 
    17     Vector NopeusVasemmalle = new Vector(-200, 0); 
    18     Vector NopeusOikealle = new Vector(200, 0); 
    19  
     25    IntMeter Pelaajan1Pisteet; 
     26    IntMeter Pelaajan2Pisteet; 
     27 
     28     
     29 
     30    Vector NopeusVasemmalle = new Vector(-150, 0); 
     31    Vector NopeusOikealle = new Vector(150, 0); 
    2032    Vector HyppyVoima = new Vector(0, 400); 
    21      
    22  
    23      
    24  
     33        
    2534    public override void Begin() 
    2635    { 
    2736        LuoKentta(); 
    2837        AloitaPeli(); 
    29         AsetaOhjaimet();        
     38        AsetaOhjaimet(); 
     39        LisaaLaskurit(); 
     40 
    3041                 
    31  
    3242    } 
    3343    void LuoKentta() 
    3444    { 
    35         pallo = new PhysicsObject(60, 60); 
     45        pallo = new PhysicsObject(45, 45); 
    3646        pallo.Image = pallonKuva; 
    3747        pallo.X = 0; 
    3848        pallo.Y = 300; 
     49        pallo.Mass = 1; 
    3950        Add(pallo); 
    4051 
    41         Level.CreateLeftBorder(1, false); 
    42         Level.CreateBottomBorder(); 
     52        Level.Background.Image = tausta; 
     53        Level.Background.FitToLevel(); 
     54 
     55        PhysicsObject nurmi = PhysicsObject.CreateStaticObject(1000, 50); 
     56        nurmi.Shape = Shape.Rectangle; 
     57        nurmi.X = 0; 
     58        nurmi.Y = Level.Bottom; 
     59        nurmi.Color = Color.Green;         
     60        Add(nurmi); 
     61 
     62         
     63        maali1 = PhysicsObject.CreateStaticObject(20, 120); 
     64        maali1.Shape = Shape.Rectangle; 
     65        maali1.X = Level.Left + 20; 
     66        maali1.Y = Level.Bottom + 75; 
     67        Add(maali1); 
     68 
     69        maali2 = PhysicsObject.CreateStaticObject(20, 120); 
     70        maali2.Shape = Shape.Rectangle; 
     71        maali2.X = Level.Right - 20; 
     72        maali2.Y = Level.Bottom + 75; 
     73        Add(maali2); 
     74         
     75        Level.CreateLeftBorder(1, false);         
    4376        Level.CreateTopBorder(1, false); 
    4477        Level.CreateRightBorder(1, false); 
     78        Level.CreateBottomBorder(1, false); 
    4579 
    4680        Camera.ZoomToLevel(); 
     81        Camera.Follow(pallo);         
    4782 
    4883        pelaaja1 = LuoPelaaja(Level.Left + 200, 0); 
    4984        pelaaja2 = LuoPelaaja(Level.Right - 200, 0); 
    5085 
    51  
    52  
     86        pelaaja1.Image = pelaaja1oikKuva; 
     87        pelaaja2.Image = pelaaja2vasKuva; 
     88 
     89        AddCollisionHandler(pallo, KasittelePallonTormays); 
     90 
     91        pelaaja1.CanRotate = false; 
     92        pelaaja2.CanRotate = false; 
     93                 
    5394 
    5495    } 
     
    60101    PhysicsObject LuoPelaaja(double x, double y) 
    61102    { 
    62         PhysicsObject pelaaja = new PhysicsObject(80, 80); 
    63         pelaaja.Shape = Shape.Star; 
     103        PhysicsObject pelaaja = new PhysicsObject(40, 40); 
     104        pelaaja.Shape = Shape.Circle; 
    64105        pelaaja.X = x; 
    65         pelaaja.Y = y;         
     106        pelaaja.Y = y; 
    66107        Add(pelaaja); 
    67108 
    68109        return pelaaja; 
    69110    } 
     111 
     112    void LisaaLaskurit() 
     113    { 
     114        Pelaajan1Pisteet = LuoPisteLaskuri ( Screen.Left + 50, Screen.Top - 50); 
     115        Pelaajan2Pisteet = LuoPisteLaskuri ( Screen.Right - 50, Screen.Top - 50); 
     116    } 
     117 
     118    IntMeter LuoPisteLaskuri(double x, double y) 
     119    { 
     120        IntMeter laskuri = new IntMeter(0); 
     121        laskuri.MaxValue = 10; 
     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 = Color.LightBlue; 
     128        naytto.Color = Color.LightBlue; 
     129        Add(naytto); 
     130 
     131        return laskuri; 
     132 
     133    } 
     134     
     135 
    70136    void AsetaOhjaimet() 
    71137    { 
     
    84150        Keyboard.Listen(Key.Right, ButtonState.Released, AsetaNopeus, null, pelaaja2, NopeusOikealle); 
    85151 
     152        Keyboard.Listen(Key.W, ButtonState.Pressed, AsetaHyppy, "Pelaaja1: Hyppaa", pelaaja1, HyppyVoima); 
     153 
    86154        Keyboard.Listen(Key.Up, ButtonState.Pressed, AsetaHyppy, "Pelaaja2: Hyppaa", pelaaja2, HyppyVoima); 
    87155         
     
    95163 
    96164    void AsetaNopeus(PhysicsObject pelaaja, Vector nopeus) 
    97     { 
     165    {                
    98166        pelaaja.Velocity = nopeus; 
     167        if (nopeus.X > 0) 
     168        { 
     169            if (pelaaja == pelaaja1) 
     170 
     171               pelaaja1.Image = pelaaja1oikKuva; 
     172            if (pelaaja == pelaaja2) 
     173 
     174            pelaaja2.Image = pelaaja2Kuva; 
     175        } 
     176        if (nopeus.X < 0) 
     177        { 
     178            if (pelaaja == pelaaja1) 
     179            pelaaja1.Image = pelaaja1Kuva; 
     180 
     181            if (pelaaja == pelaaja2) 
     182            pelaaja2.Image = pelaaja2vasKuva; 
     183        } 
     184         
     185         
    99186    } 
    100187 
     
    105192    } 
    106193 
     194    void KasittelePallonTormays(PhysicsObject pallo, PhysicsObject kohde) 
     195    { 
     196        if(kohde == maali2) 
     197        { 
     198            Pelaajan1Pisteet.Value += 1; 
     199            pallo.X = 0; 
     200            pallo.Y = 300; 
     201            pelaaja1.X = -200; 
     202            pelaaja2.X = 200; 
     203        } 
     204        else if (kohde == maali1) 
     205        { 
     206            pallo.X = 0; 
     207            pallo.Y = 300; 
     208            pelaaja1.X = -200; 
     209            pelaaja2.X = 200; 
     210            Pelaajan2Pisteet.Value += 1; 
     211        } 
     212 
     213         
     214 
     215 
     216    } 
     217    
    107218              
    108219} 
  • 2011/24/PauliN/Jalkapallopeli/Jalkapallopeli/JalkapallopeliContent/JalkapallopeliContent.contentproj

    r1991 r2048  
    4949    </Compile> 
    5050  </ItemGroup> 
     51  <ItemGroup> 
     52    <Compile Include="ground.png"> 
     53      <Name>ground</Name> 
     54      <Importer>TextureImporter</Importer> 
     55      <Processor>TextureProcessor</Processor> 
     56    </Compile> 
     57  </ItemGroup> 
     58  <ItemGroup> 
     59    <Compile Include="pelaaja1.png"> 
     60      <Name>pelaaja1</Name> 
     61      <Importer>TextureImporter</Importer> 
     62      <Processor>TextureProcessor</Processor> 
     63    </Compile> 
     64  </ItemGroup> 
     65  <ItemGroup> 
     66    <Compile Include="pelaaja1oik.png"> 
     67      <Name>pelaaja1oik</Name> 
     68      <Importer>TextureImporter</Importer> 
     69      <Processor>TextureProcessor</Processor> 
     70    </Compile> 
     71  </ItemGroup> 
     72  <ItemGroup> 
     73    <Compile Include="pelaaja2.png"> 
     74      <Name>pelaaja2</Name> 
     75      <Importer>TextureImporter</Importer> 
     76      <Processor>TextureProcessor</Processor> 
     77    </Compile> 
     78  </ItemGroup> 
     79  <ItemGroup> 
     80    <Compile Include="pelaaja2vas.png"> 
     81      <Name>pelaaja2vas</Name> 
     82      <Importer>TextureImporter</Importer> 
     83      <Processor>TextureProcessor</Processor> 
     84    </Compile> 
     85  </ItemGroup> 
     86  <ItemGroup> 
     87    <Compile Include="tausta.png"> 
     88      <Name>tausta</Name> 
     89      <Importer>TextureImporter</Importer> 
     90      <Processor>TextureProcessor</Processor> 
     91    </Compile> 
     92  </ItemGroup> 
    5193  <Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" /> 
    5294  <!--  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.