Changeset 1670 for 2010


Ignore:
Timestamp:
2010-08-06 13:03:08 (13 years ago)
Author:
niostuom
Message:
 
Location:
2010/31/niostuom
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • 2010/31/niostuom/80kmh/Content/Content.contentproj

    r1601 r1670  
    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>78f89037-81ad-4931-b3bc-3079ba5150a5</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="bussi.png"> 
     38      <Name>bussi</Name> 
     39      <Importer>TextureImporter</Importer> 
     40      <Processor>TextureProcessor</Processor> 
     41    </Compile> 
     42  </ItemGroup> 
     43  <ItemGroup> 
     44    <Compile Include="tausta1.png"> 
     45      <Name>tausta1</Name> 
     46      <Importer>TextureImporter</Importer> 
     47      <Processor>TextureProcessor</Processor> 
     48    </Compile> 
     49  </ItemGroup> 
     50  <ItemGroup> 
     51    <Compile Include="tausta2.png"> 
     52      <Name>tausta2</Name> 
     53      <Importer>TextureImporter</Importer> 
     54      <Processor>TextureProcessor</Processor> 
     55    </Compile> 
     56  </ItemGroup> 
     57  <ItemGroup> 
     58    <Compile Include="tausta3.png"> 
     59      <Name>tausta3</Name> 
     60      <Importer>TextureImporter</Importer> 
     61      <Processor>TextureProcessor</Processor> 
     62    </Compile> 
     63  </ItemGroup> 
    3664</Project> 
  • 2010/31/niostuom/80kmh/Peli.cs

    r1601 r1670  
    77{ 
    88    PhysicsObject bussi; 
     9    Image bussinKuva = LoadImage ( "bussi" ); 
     10    Image TaustaKuva1 = LoadImage ( "tausta1" ); 
     11    Image TaustaKuva2 = LoadImage ( "tausta2" ); 
     12    Image TaustaKuva3 = LoadImage ( "tausta3" ); 
    913 
    10     Vector nopeusYlos = new Vector(0, 200); 
    11     Vector nopeusAlas = new Vector(0, -200); 
     14    Vector nopeusVasemmalle = new Vector(0, 200); 
     15    Vector nopeuOikealle = new Vector(0, -200); 
     16 
     17     
    1218 
    1319 
    1420    protected override void Begin() 
    1521    { 
    16         LuoKentta (0, -350); 
     22        LuoKentta (0, -300); 
    1723        AsetaOhjaimet (); 
     24        LuoAikaLaskuri (); 
     25 
     26        MessageDisplay.Add("80 Km/h  by Niko Tuominen"); 
     27        MessageDisplay.Position = new Vector(-120.0, 0.0); 
     28        MessageDisplay.TextColor = RandomGen.NextColor(); 
    1829 
    1930    } 
     
    2132    void LuoKentta(double x, double y) 
    2233    { 
    23         bussi = PhysicsObject.CreateStaticObject(40.0, 80.0); 
     34        bussi = new PhysicsObject (70.0, 120.0); 
     35        bussi.Mass = 30; 
     36        bussi.Restitution = 2.5; 
     37        bussi.AngularDamping = 0.95; 
     38        bussi.Tag = "bussi"; 
     39        bussi.Image = bussinKuva; 
    2440        Add(bussi); 
    2541        bussi.X = x; 
    2642        bussi.Y = y; 
    27         bussi.IgnoresGravity = true; // static ei ole muutenkaan painovoiman alaisena, voi poistaa. 
     43        bussi.IgnoresGravity = true; 
    2844        Gravity = new Vector(0, -800); 
    29          
    3045 
    31         Level.BackgroundColor = Color.Black;  
     46        AddCollisionHandler(bussi, KasitteleBussinTormays); 
     47        Level.Background.Image = TaustaKuva1; 
     48        Level.Background.FitToLevel(); 
     49        Camera.ZoomToLevel(); 
     50 
    3251    } 
    3352 
     
    3554    { 
    3655        Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Poistu"); 
     56        Keyboard.Listen(Key.Left, ButtonState.Down, AsetaNopeus, "Liikuta bussia vasemmalle", new Vector(-400, 0), false); 
    3757 
    38         Keyboard.Listen(Key.Left, ButtonState.Down, AsetaNopeus , "Liikuta bussia vasemmalle", new Vector (-200, 0)); 
    39         Keyboard.Listen(Key.Left, ButtonState.Released, AsetaNopeus, null, new Vector (0, 0)); 
     58        Keyboard.Listen(Key.Left, ButtonState.Pressed, Kaannavasemmalle, "Liikuta bussia vasemmalle"); 
     59        Keyboard.Listen(Key.Left, ButtonState.Released, AsetaNopeus, null, new Vector (0, 0), true); 
    4060 
    41         Keyboard.Listen(Key.Right, ButtonState.Down, AsetaNopeus , "Liikuta bussia oikealle", new Vector(200, 0)); 
    42         Keyboard.Listen(Key.Right, ButtonState.Released, AsetaNopeus , null, new Vector (0, 0)); 
     61        Keyboard.Listen(Key.Right, ButtonState.Pressed, Kaannaoikealle, "Liikuta bussia vasemmalle"); 
     62        Keyboard.Listen(Key.Right, ButtonState.Down, AsetaNopeus , "Liikuta bussia oikealle", new Vector(400, 0), false); 
     63        Keyboard.Listen(Key.Right, ButtonState.Released, AsetaNopeus , null, new Vector (0, 0), true); 
    4364 
    44         Keyboard.Listen(Key.Space, ButtonState.Pressed , LuoAuto, null); 
     65        Keyboard.Listen(Key.Up, ButtonState.Down, AsetaNopeus, "Liikuta bussia oikealle", new Vector(0, 200), false); 
     66        Keyboard.Listen(Key.Up, ButtonState.Released, AsetaNopeus, null, new Vector(0, 0), true); 
     67 
     68        Keyboard.Listen(Key.Down, ButtonState.Down, AsetaNopeus, "Liikuta bussia oikealle", new Vector(0, -200), false); 
     69        Keyboard.Listen(Key.Down, ButtonState.Released, AsetaNopeus, null, new Vector(0, 0), true); 
     70 
     71        Keyboard.Listen(Key.Space, ButtonState.Pressed, LuoAuto, null); 
     72        Keyboard.Listen(Key.R, ButtonState.Pressed, AloitaUusiPeli, "Restart"); 
    4573 
    4674 
    4775    } 
     76    void Kaannavasemmalle() 
     77    { 
     78        bussi.Angle += Angle.Degrees (30); 
     79    } 
    4880 
    49     void AsetaNopeus(Vector nopeus) 
     81    void Kaannaoikealle() 
    5082    { 
     83        bussi.Angle += Angle.Degrees (-30); 
     84    } 
     85 
     86    void AsetaNopeus(Vector nopeus, bool suorista) 
     87    { 
     88        if (suorista) 
     89        { 
     90            bussi.Angle = Angle.Zero;  
     91        } 
    5192        bussi.Velocity = nopeus; 
    5293         
    5394    } 
    5495 
     96    void AloitaUusiPeli() 
     97    { 
     98        ClearAll(); 
     99        Begin(); 
     100    } 
     101     
    55102    void LuoAuto() 
    56103    { 
    57         PhysicsObject auto = new PhysicsObject(30, 50); 
     104        PhysicsObject auto = new PhysicsObject(50, 100); 
    58105        auto.Position = new Vector(RandomGen.NextDouble(-200, 200), Screen.Top); 
     106        auto.Tag = "auto"; 
     107        auto.Mass = 300; 
     108        auto.Color = RandomGen.NextColor() ; 
     109        auto.Restitution = 1; 
    59110        Add (auto); 
    60111    } 
    61      
     112 
     113    void KasitteleBussinTormays(PhysicsObject bussi, PhysicsObject auto) 
     114    { 
     115        if (auto.Tag.ToString() == "auto") 
     116        { 
     117            MessageDisplay.Add("GAME OVER - To Retry, press R"); 
     118            MessageDisplay.Position = new Vector(-120.0, 0.0); 
     119            MessageDisplay.TextColor = Color.Red; 
     120 
     121            Explosion rajahdys = new Explosion(500); 
     122            rajahdys.Position = bussi.Position; 
     123            rajahdys.Speed = 500.0; 
     124            rajahdys.Force = 100000; 
     125            Add(rajahdys); 
     126 
     127             
     128        } 
     129     } 
     130    void LuoAikaLaskuri() 
     131    { 
     132        Timer aikaLaskuri = new Timer(); 
     133        aikaLaskuri.Interval = 0.5; 
     134        aikaLaskuri.Trigger += LisääAuto; 
     135        aikaLaskuri.Start(); 
     136 
     137        Label aikaNaytto = new Label(); 
     138        aikaNaytto.TextColor = Color.White; 
     139        aikaNaytto.DecimalPlaces = 1; 
     140        aikaNaytto.BindTo(aikaLaskuri.SecondCounter); 
     141        aikaNaytto.Position = new Vector (-500, 500); 
     142        //Add(aikaNaytto); 
     143 
     144        Timer aikaLaskuri2 = new Timer(); 
     145        aikaLaskuri2.Interval = 0.1; 
     146        aikaLaskuri2.Trigger += TaustanVaihto; 
     147        aikaLaskuri2.Start(); 
     148    } 
     149    void LisääAuto (Timer sender) 
     150    { 
     151        if (sender.Interval > 0.25) 
     152        { 
     153            sender.Interval -= 0.005; 
     154        } 
     155        LuoAuto(); 
     156    } 
     157 
     158    void TaustanVaihto(Timer sender) 
     159    { 
     160        if (Level.Background.Image == TaustaKuva1) 
     161        { 
     162            Level.Background.Image = TaustaKuva2; 
     163        } 
     164        else if (Level.Background.Image == TaustaKuva2) 
     165        { 
     166            Level.Background.Image = TaustaKuva3; 
     167        } 
     168        else 
     169        { 
     170            Level.Background.Image = TaustaKuva1; 
     171        } 
     172            Level.Background.FitToLevel(); 
     173    } 
     174         
    62175} 
  • 2010/31/niostuom/Pong/Peli.cs

    r1547 r1670  
    3636        pallo.X = -200.0; 
    3737        pallo.Y = 0.0; 
     38        pallo.StaticFriction = 100; 
    3839 
    3940        maila1 = LuoMaila (Level.Left + 20.0, 0.0); 
Note: See TracChangeset for help on using the changeset viewer.