Changeset 2370


Ignore:
Timestamp:
2011-06-30 14:53:07 (12 years ago)
Author:
jojumuho
Message:

Talletus.

Location:
2011/26/JouniM/MatoPeli/MatoPeli
Files:
10 added
2 edited

Legend:

Unmodified
Added
Removed
  • 2011/26/JouniM/MatoPeli/MatoPeli/MatoPeli/Peli.cs

    r2301 r2370  
    1717    Timer sadeajastin; 
    1818    Timer aikaLaskuri; 
     19    IntMeter pisteLaskuri; 
     20 
     21    Image MadonKuva = LoadImage("Mato"); 
     22    Image SaaliinKuva = LoadImage("Saalis"); 
     23    Image GameOver = LoadImage("game over"); 
    1924 
    2025    bool kuolematon = false; 
     
    2328    { 
    2429        // TODO: Kirjoita ohjelmakoodisi tähän 
    25          
     30 
    2631        ajastin = new Timer(); 
    2732        ajastin.Interval = 0.1; 
     
    3641        aikaLaskuri.Trigger += LaskeAlaspain; 
    3742 
    38          
    39  
    40  
    41 Aloitapeli(); 
    42  
    43  
    44   
    45  
     43        Aloitapeli(); 
    4644 
    4745    } 
     
    7371    void LuoMato() 
    7472    { 
    75      Mato = new PhysicsObject(30.0, 40.0); 
    76      Mato.Tag = "Mato"; 
    77      Add(Mato); 
    78      Mato.Shape = Shape.Heart; 
    79      AddCollisionHandler(Mato, KasitteleMadonTormays); 
     73        Mato = new PhysicsObject(30.0, 40.0); 
     74        Mato.Tag = "Mato"; 
     75        Add(Mato); 
     76        Mato.Shape = Shape.Heart; 
     77        Mato.Image = MadonKuva; 
     78 
     79        AddCollisionHandler(Mato, KasitteleMadonTormays); 
    8080 
    8181    } 
    8282 
    8383    void KasitteleMadonTormays(PhysicsObject Mato, PhysicsObject kohde) 
    84  
    85     
    86     { 
    87  
    88      if (kohde.Tag.ToString() == "saalis") 
    89      { 
    90          kohde.Destroy(); 
    91          Saalis_Destroyed(); 
    92      } 
     84    { 
     85 
     86        if (kohde.Tag.ToString() == "saalis") 
     87        { 
     88            kohde.Destroy(); 
     89            SaalisDestroyed(); 
     90        } 
    9391 
    9492    } 
     
    9694 
    9795    void AsetaOhjaimet() 
    98  
    9996    { 
    10097        Mouse.IsCursorVisible = true; 
    101         Keyboard.Listen(Key.G, ButtonState.Down, TuleeKuolemattomaksi,null); 
    102         Keyboard.Listen(Key.G, ButtonState.Up, Kuolemattomuusloppuu,null); 
     98        Keyboard.Listen(Key.G, ButtonState.Down, TuleeKuolemattomaksi, null); 
     99        Keyboard.Listen(Key.G, ButtonState.Up, Kuolemattomuusloppuu, null); 
    103100        Keyboard.Listen(Key.R, ButtonState.Released, uudestaan, "aloitus"); 
    104101 
     
    107104 
    108105 
    109      void TuleeKuolemattomaksi() 
    110       { 
    111           kuolematon = true; 
    112       } 
     106    void TuleeKuolemattomaksi() 
     107    { 
     108        kuolematon = true; 
     109    } 
    113110 
    114111    void Kuolemattomuusloppuu() 
     
    126123    } 
    127124 
    128     void LiikutaMatoa (Timer sender ) 
     125    void LiikutaMatoa(Timer sender) 
    129126    { 
    130127        Vector etaisyys = Mouse.PositionOnWorld - Mato.Position; 
    131         Mato.MoveTo(Mouse.PositionOnWorld, etaisyys.Magnitude*1.5 ); 
    132         Mato.Angle = etaisyys.Angle+Angle.RightAngle; 
    133          
     128        Mato.MoveTo(Mouse.PositionOnWorld, etaisyys.Magnitude * 1.5); 
     129        Mato.Angle = etaisyys.Angle + Angle.FromDegrees(270); 
     130 
    134131    } 
    135132 
     
    138135        Saalis = new PhysicsObject(30, 30); 
    139136        Saalis.Tag = "saalis"; 
     137        Saalis.Image = SaaliinKuva; 
    140138        Add(Saalis); 
    141139        Saalis.Shape = Shape.Star; 
    142140        Saalis.X = RandomGen.NextDouble(Level.Left, Level.Right); 
    143141        Saalis.Y = RandomGen.NextDouble(Level.Bottom, Level.Top); 
    144         FollowerBrain karkuunSaalis = new FollowerBrain(Mato, -50); 
    145         karkuunSaalis.Target = Mato; 
    146         Saalis.Brain = karkuunSaalis; 
     142        //FollowerBrain karkuunSaalis = new FollowerBrain(Mato, -50); 
     143        //karkuunSaalis.Target = Mato; 
     144        //Saalis.Brain = karkuunSaalis; 
     145        Saalis.Hit(new Vector(RandomGen.NextDouble(-600, 600), RandomGen.NextDouble(-600, 600))); 
     146        AddCollisionHandler(Saalis, KasitteleSaaliinTormays); 
    147147        //Saalis.Destroyed += new Action(Saalis_Destroyed); 
    148         
    149  
    150  
    151  
    152  
    153     } 
    154  
    155     void Saalis_Destroyed()   
    156     {  
    157         LuoSaalis(RandomGen.NextDouble(Level.Left, Level.Right), RandomGen.NextDouble(Level.Bottom, Level.Top) ); 
     148    } 
     149 
     150    void KasitteleSaaliinTormays(PhysicsObject saalis, PhysicsObject kohde) 
     151    { 
     152        if(kohde.Tag.ToString() != "saalis") saalis.Hit(-1/2*saalis.Position); 
     153    } 
     154 
     155    void SaalisDestroyed() 
     156    { 
    158157        LuoSaalis(RandomGen.NextDouble(Level.Left, Level.Right), RandomGen.NextDouble(Level.Bottom, Level.Top)); 
    159         pisteLaskuri.Value = pisteLaskuri.Value + 1; 
    160     } 
    161    
    162     IntMeter pisteLaskuri; 
     158        LuoSaalis(RandomGen.NextDouble(Level.Left, Level.Right), RandomGen.NextDouble(Level.Bottom, Level.Top)); 
     159        pisteLaskuri.Value = pisteLaskuri.Value + 1 ; 
     160        // KasvataMatoa(); 
     161    } 
    163162 
    164163    void LuoLaskuri() 
     
    185184    void LuoVihollinen(Timer sender) 
    186185    { 
    187         sender.Interval = sender.Interval-0.019; 
     186        sender.Interval = sender.Interval - 0.019; 
    188187 
    189188        Vector suunta = new Vector(0, 1); 
    190         
     189 
    191190        Vector position; 
    192191        if (RandomGen.NextBool()) 
    193192        { 
    194             position = new Vector(RandomGen.NextDouble(Level.Left, Level.Right), Level.Top); 
     193            double x = RandomGen.NextDouble(Level.Left, Level.Right); 
     194            while (Math.Abs(Mato.X - x) <100 ) 
     195            { 
     196                x = RandomGen.NextDouble(Level.Left, Level.Right); 
     197            } 
     198            position = new Vector(x, Level.Top); 
    195199            suunta = new Vector(0.0, -1); 
    196200        } 
     
    198202        else 
    199203        { 
    200             position = new Vector ( Level.Left, RandomGen.NextDouble(Level.Bottom, Level.Top)); 
    201             suunta = new Vector(1, 0); 
    202         } 
    203     PhysicsObject Vihollinen = new PhysicsObject(new RaySegment(position, suunta, 2000) ); 
    204     Vihollinen.MaximumLifetime = TimeSpan.FromSeconds(2.0); 
    205  
    206          AddCollisionHandler(Vihollinen, KasitteleVihollisenTormays); 
    207  
     204        double y = RandomGen.NextDouble(Level.Bottom, Level.Top); 
     205            while (Math.Abs(Mato.Y - y) <100 ) 
     206            { 
     207                y = RandomGen.NextDouble(Level.Bottom, Level.Top); 
     208            } 
     209            position = new Vector(Level.Left, y); 
     210            suunta = new Vector(1,0); 
     211        } 
     212 
     213        
     214        PhysicsObject Vihollinen = new PhysicsObject(new RaySegment(position, suunta, 2000)); 
     215        Vihollinen.MaximumLifetime = TimeSpan.FromSeconds(2.0); 
     216        Vihollinen.Color = Color.Red; 
     217        AddCollisionHandler(Vihollinen, KasitteleVihollisenTormays); 
    208218        Add(Vihollinen); 
    209       
     219 
    210220    } 
    211221 
    212222    void KasitteleVihollisenTormays(PhysicsObject Vihollinen, PhysicsObject kohde) 
    213223    { 
    214  
    215224        if (kohde.Tag.ToString() == "Mato" && kuolematon == false) 
    216225        { 
    217226            kohde.Destroy(); 
    218  
    219         } 
    220  
    221     } 
    222         
    223  
     227        } 
     228    } 
    224229 
    225230    void LuoAikaLaskuri() 
    226231    { 
    227         alaspainLaskuri = new DoubleMeter(30); 
    228  
    229          
     232        alaspainLaskuri = new DoubleMeter(35); 
    230233 
    231234        Label aikaNaytto = new Label(); 
     
    244247        if (alaspainLaskuri.Value <= 0) 
    245248        { 
    246             MessageDisplay.Add("total anhilation"); 
     249            MessageDisplay.Add("Peli Loppui"); 
    247250            timer.Stop(); 
     251            ClearAll(); 
     252            Widget lopputeksti = new Widget(Screen.Width, Screen.Height); 
     253            lopputeksti.Image = GameOver; 
     254            Add(lopputeksti); 
    248255 
    249256            // täydennä mitä tapahtuu, kun aika loppuu 
  • 2011/26/JouniM/MatoPeli/MatoPeli/MatoPeliContent/MatoPeliContent.contentproj

    r2242 r2370  
    4242    </Reference> 
    4343  </ItemGroup> 
     44  <ItemGroup> 
     45    <Compile Include="Mato.png"> 
     46      <Name>Mato</Name> 
     47      <Importer>TextureImporter</Importer> 
     48      <Processor>TextureProcessor</Processor> 
     49    </Compile> 
     50  </ItemGroup> 
     51  <ItemGroup> 
     52    <Compile Include="Saalis.png"> 
     53      <Name>Saalis</Name> 
     54      <Importer>TextureImporter</Importer> 
     55      <Processor>TextureProcessor</Processor> 
     56    </Compile> 
     57  </ItemGroup> 
     58  <ItemGroup> 
     59    <Compile Include="game over.jpg"> 
     60      <Name>game over</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.