Changeset 1231 for 2010/27


Ignore:
Timestamp:
2010-07-09 13:05:21 (13 years ago)
Author:
paaaanro
Message:
 
Location:
2010/27/patammi/Autopeli1
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • 2010/27/patammi/Autopeli1/Autopeli2.csproj

    r1155 r1231  
    5757  </PropertyGroup> 
    5858  <ItemGroup> 
    59     <Reference Include="Jypeli2, Version=1.0.0.0, Culture=neutral, processorArchitecture=x86"> 
     59    <Reference Include="Jypeli2, Version=2.2.4.0, Culture=neutral, processorArchitecture=x86"> 
    6060      <SpecificVersion>False</SpecificVersion> 
    6161      <HintPath>..\..\lib\Jypeli2.dll</HintPath> 
  • 2010/27/patammi/Autopeli1/Content/Content.contentproj

    r1174 r1231  
    4545    </Compile> 
    4646  </ItemGroup> 
     47  <ItemGroup> 
     48    <Compile Include="Untitled.png"> 
     49      <Name>Untitled</Name> 
     50      <Importer>TextureImporter</Importer> 
     51      <Processor>TextureProcessor</Processor> 
     52    </Compile> 
     53  </ItemGroup> 
    4754  <Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" /> 
    4855  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
  • 2010/27/patammi/Autopeli1/Peli.cs

    r1174 r1231  
    44using Jypeli.Assets; 
    55using Jypeli.Effects; 
    6  
     6//Janne Ja Paveli 
    77public class Peli : TopDownPhysicsGame 
    88{ 
     
    1414 
    1515    PhysicsObject OilBarrel; 
     16    PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0); 
     17 
     18    BarGauge auton1palkki, auton2palkki; 
     19    DoubleMeter auton1hp, auton2hp; 
    1620 
    1721    ExplosionSystem es; 
     
    1923    protected override void Begin() 
    2024    { 
    21         KineticFriction = 1.0; // Asetetaan kitka 
     25        Level.Background.Image = LoadImage("Untitled"); 
     26        Level.Background.Size = new Vector(Level.Width, Level.Height); 
     27        KineticFriction = 100.00; // Asetetaan kitka 
     28 
     29        PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0); 
     30        maila.Shape = Shapes.Rectangle; 
     31        maila.X = Level.Left + 150.0; 
     32        maila.Y = 0.0; 
     33        maila.Restitution = 1.0; 
     34        Add(maila); 
     35        maila.Color = Color.Black; 
     36 
     37        PhysicsObject maila2 = PhysicsObject.CreateStaticObject(20.0, 100.0); 
     38        maila2.Shape = Shapes.Rectangle; 
     39        maila2.X = Level.Right - 150.0; 
     40        maila2.Y = 0.0; 
     41        maila2.Restitution = 1.0; 
     42        Add(maila2); 
     43        maila2.Color = Color.Red; 
    2244 
    2345        auto = new Automobile(40, 20); 
    24         auto.Mass = 1.0; 
     46        auto.Mass = 25.0; 
    2547        auto.Maneuverability = Angle.Degrees(120); 
    2648        auto.Color = new Color(0, 0, 0); 
    2749        auto.AngularDamping = 0.9; 
     50        auto.X = Level.Right - 20.0; 
    2851        Add(auto); 
    2952 
    30         laserPyssy1 = new LaserGun(20, 5); 
    31         laserPyssy1.TimeBetweenUse = TimeSpan.FromSeconds(0.5); 
    32         auto.Add(laserPyssy1); 
    33         laserPyssy2 = new LaserGun(20, 5); 
     53 
    3454 
    3555        auto2 = new Automobile(40, 20); 
    36         auto2.Mass = 10.0; 
     56        auto2.Mass = 25.0; 
    3757        auto2.Maneuverability = Angle.Degrees(120); 
    3858        auto2.Color = new Color(192, 192, 255); 
    3959        auto2.AngularDamping = 0.9; 
     60        auto2.X = Level.Left + 20.0; 
     61 
    4062        Add(auto2); 
    4163 
    42         auto2.Add(laserPyssy2); 
    43  
    44  
    45         for (int a = 0; a < 10; a++) 
     64        LisaaAseet(); 
     65 
     66        for (int a = 0; a < 21; a++) 
    4667        { 
    4768            LisaaOilBarrel(); 
    4869        } 
    49  
    5070 
    5171        Camera.ZoomToLevel(5); 
    5272        Level.CreateBorders(1.0, false); 
    53         Level.BackgroundColor = Color.Gray; 
    54  
     73 
     74 
     75        luoHpMittarit(); 
    5576        AsetaNappaimet(); 
    5677        AsetaXBoxOhjaimet(); 
     78 
     79 
    5780        LataaRajahdys(); 
    58  
     81        ControllerOne.Vibrate(0.5, 0.5, 0.0, 0.0, 0.1); 
     82    } 
     83    void LisaaAseet() 
     84    { 
     85        laserPyssy1 = new LaserGun(20, 15); 
     86        laserPyssy1.Color = Color.Green; 
     87        laserPyssy1.TimeBetweenUse = TimeSpan.FromSeconds(0.6); 
     88        laserPyssy1.LaserCollision += laserOsuu; 
     89        auto.Add(laserPyssy1); 
     90 
     91        laserPyssy2 = new LaserGun(40, 5); 
     92        laserPyssy2.TimeBetweenUse = TimeSpan.FromSeconds(0.6 ); 
     93        laserPyssy2.LaserCollision += laserOsuu; 
     94        auto2.Add(laserPyssy2); 
     95    } 
     96 
     97    //Controller 
     98 
     99    void luoHpMittarit() 
     100    { 
     101        auton1hp = new DoubleMeter(100); 
     102        auton1hp.MaxValue = 100; 
     103        auton1hp.MinValue = 0; 
     104        auton1hp.LowerLimit += new Meter<double>.OnLimitHandler(auto1kuoli); 
     105        auton1palkki = new BarGauge(100, 15); 
     106        auton1palkki.BarColor = Color.Red; 
     107        auton1palkki.BorderColor = Color.Black; 
     108        auton1palkki.Position = new Vector(Screen.Right - 100, Screen.Top - 100); 
     109        auton1palkki.BindTo(auton1hp); 
     110        Add(auton1palkki); 
     111 
     112        auton2hp = new DoubleMeter(100); 
     113        auton2hp.MaxValue = 100; 
     114        auton2hp.MinValue = 0; 
     115        auton2hp.LowerLimit += new Meter<double>.OnLimitHandler(auto2kuoli); 
     116        auton2palkki = new BarGauge(100, 15); 
     117        auton2palkki.BarColor = Color.Red; 
     118        auton2palkki.BorderColor = Color.Black; 
     119        auton2palkki.Position = new Vector(Screen.Left + 100, Screen.Top - 100); 
     120        auton2palkki.BindTo(auton2hp); 
     121        Add(auton2palkki); 
     122    } 
     123 
     124    void auto2kuoli(double value) 
     125    { 
     126        auto2.Position = new Vector(Level.Left + 20, 0); 
     127        auton2hp.Value = 100; 
     128    } 
     129 
     130    void auto1kuoli(double value) 
     131    { 
     132        auto.Position = new Vector(Level.Right - 20, 0); 
     133        auton1hp.Value = 100; 
    59134    } 
    60135 
     
    62137    { 
    63138        Image expl = LoadImage("Red"); 
    64         es = new ExplosionSystem(expl, 1000); 
     139        es = new ExplosionSystem(expl, 500); 
    65140        Add(es); 
    66141 
     
    69144    void AsetaXBoxOhjaimet() 
    70145    { 
     146 
    71147        ControllerOne.ListenAnalog(AnalogControl.LeftStick, 0.1, LiikutaPelaajaa, "Liikuta pelaajaa tattia pyörittämällä."); 
    72  
    73  
     148        ControllerOne.Listen(Button.RightTrigger, ButtonState.Down, kiihdyta, null, auto); 
     149        ControllerOne.Listen(Button.LeftTrigger, ButtonState.Down, jarruta, null, auto); 
     150        ControllerTwo.ListenAnalog(AnalogControl.LeftStick, 0.1, LiikutaPelaajaa2, "Liikuta pelaajaa tattia pyörittämällä."); 
     151        ControllerTwo.Listen(Button.RightTrigger, ButtonState.Down, kiihdyta, null, auto2); 
     152        ControllerTwo.Listen(Button.LeftTrigger, ButtonState.Down, jarruta, null, auto2); 
     153 
     154 
     155        ControllerOne.Listen(Button.A, ButtonState.Down, Ammu, null, laserPyssy1, auto); 
     156        ControllerTwo.Listen(Button.A, ButtonState.Down, Ammu, null, laserPyssy2, auto2); 
    74157    } 
    75158    void LiikutaPelaajaa(AnalogState state) 
    76159    { 
    77160        auto.Turn(Angle.Degrees(state.StateVector.X * -4), Time.SinceLastUpdate.TotalSeconds); 
     161    } 
     162    void LiikutaPelaajaa2(AnalogState state) 
     163    { 
     164        auto2.Turn(Angle.Degrees(state.StateVector.X * -4), Time.SinceLastUpdate.TotalSeconds); 
    78165    } 
    79166    void AsetaNappaimet() 
     
    92179 
    93180 
    94         Keyboard.Listen(Key.M, ButtonState.Down, laserPyssy1.Use, "ammu"); 
    95         Keyboard.Listen(Key.V, ButtonState.Down, laserPyssy2.Use, "ammu"); 
    96  
    97     } 
    98  
    99  
    100     void laaserase() 
    101     { 
    102         //laserPyssy.LaserCollision = LaserSadeOsuu; 
    103     } 
    104  
    105  
    106  
     181        Keyboard.Listen(Key.M, ButtonState.Down, Ammu, "ammu", laserPyssy1, auto); 
     182        Keyboard.Listen(Key.V, ButtonState.Down, Ammu, "ammu", laserPyssy2, auto2); 
     183 
     184    } 
     185 
     186    void Ammu(LaserGun ase, PhysicsObject ampuja) 
     187    { 
     188        PhysicsObject ammus = ase.Shoot(); 
     189        if (ammus != null) 
     190        { 
     191            ammus.Width *= 2; 
     192            ammus.Height *=2; 
     193            ammus.Tag = ampuja; 
     194            AddCollisionHandler(ammus, laserOsuu); 
     195        } 
     196    } 
     197 
     198    void laserOsuu(PhysicsObject laser, PhysicsObject kohde) 
     199    { 
     200        if (kohde == auto && laser.Tag != auto) 
     201        { 
     202            auton1hp.Value -= 15; 
     203        } 
     204        if (kohde == auto2 && laser.Tag != auto2) 
     205        { 
     206            auton2hp.Value -= 15; 
     207        } 
     208        if (kohde.Tag.ToString() == "oilbarrel") 
     209        { 
     210            double etaisyys = Etaisyys(kohde.Position, auto.Position); 
     211            double etaisyys2 = Etaisyys(kohde.Position, auto2.Position); 
     212            if (etaisyys < 150) 
     213            { 
     214                VahennaHP(auto); 
     215            } 
     216            if (etaisyys2 < 150) 
     217            { 
     218                VahennaHP(auto2); 
     219            } 
     220        } 
     221    } 
    107222 
    108223 
     
    122237    } 
    123238 
     239    double Etaisyys(Vector p1, Vector p2) 
     240    { 
     241        double dx = Math.Abs(p1.X - p2.X); 
     242        double dy = Math.Abs(p1.Y - p2.Y); 
     243        return Math.Sqrt(dx * dx + dy * dy); 
     244    } 
    124245 
    125246 
    126247    void Rajahdys(PhysicsObject tormaaja, PhysicsObject kohde) 
    127248    { 
    128         es.AddEffect(tormaaja.X, tormaaja.Y, 20); 
     249        es.AddEffect(tormaaja.X, tormaaja.Y, 984); 
    129250        tormaaja.Destroy(); 
     251        //if (kohde == auto && OilBarrel.Tag != auto) 
     252 
     253        VahennaHP(kohde); 
     254        LisaaOilBarrel(); 
     255 
     256 
     257    } 
     258 
     259    void VahennaHP(PhysicsObject kohde) 
     260    { 
     261        if (kohde == auto) 
     262        { 
     263            auton1hp.Value -= 75; 
     264            return; 
     265        } 
     266        //        if (kohde == auto2 && OilBarrel.Tag != auto2) 
     267        if (kohde == auto2) 
     268        { 
     269            auton2hp.Value -= 75; 
     270            return; 
     271 
     272        } 
    130273    } 
    131274 
     
    133276    { 
    134277        OilBarrel = new PhysicsObject(15, 15, Shapes.Circle); 
    135         OilBarrel.Color = Color.Red; 
    136         OilBarrel.Mass = 100; 
     278        OilBarrel.Mass = 1000; 
    137279        OilBarrel.LinearDamping = 0.9; 
     280        OilBarrel.Tag = "oilbarrel"; 
    138281        Add(OilBarrel); 
    139282        AddCollisionHandler(OilBarrel, Rajahdys); 
    140283        OilBarrel.X = RandomGen.NextDouble(Level.Left, Level.Right); 
    141284        OilBarrel.Y = RandomGen.NextDouble(Level.Bottom, Level.Top); 
     285        OilBarrel.Color = RandomGen.NextColor(); 
    142286    } 
    143287 
Note: See TracChangeset for help on using the changeset viewer.