Changeset 5297 for 2014/27/PekkaR


Ignore:
Timestamp:
2014-07-02 14:58:01 (5 years ago)
Author:
pealrist
Message:
 
Location:
2014/27/PekkaR/D2x_2d
Files:
4 added
11 edited

Legend:

Unmodified
Added
Removed
  • 2014/27/PekkaR/D2x_2d/D2x_2d/D2x_2d/D2x_2d.cs

    r5274 r5297  
    1 using System; 
     1#undef DEBUG 
     2 
     3using System; 
    24using System.Collections.Generic; 
    35using Jypeli; 
     
    1113    public class Shieldable : PhysicsObject 
    1214    { 
    13         protected int shield; 
     15        public IntMeter shield = new IntMeter(0); 
    1416 
    1517        public Shieldable(int w, int h) : base(w, h) 
     
    1820        } 
    1921 
     22        public IntMeter getShieldMeter() 
     23        { 
     24            return shield; 
     25        } 
     26 
    2027        public int getShield() 
    2128        { 
    22             return shield; 
     29            return shield.Value; 
    2330        } 
    2431 
    2532        public void setShield(int t) 
    2633        { 
    27             if(t > 0) shield = t; 
    28             else Destroy(); 
     34            if (t > 0) shield.Value = t; 
     35            else 
     36            { 
     37                shield.Value = 0; 
     38                Destroy(); 
     39            } 
    2940        } 
    3041    } 
     
    3243    public class Pelaaja : Shieldable 
    3344    { 
    34         private int energy = 100; 
     45        private IntMeter energy = new IntMeter(100); 
    3546 
    3647        public Pelaaja(int w, int h) : base(w, h) 
    3748        { 
    38             shield = 100; 
     49            shield.Value = 100; 
    3950            Tag = "pelaaja"; 
    40         } 
    41  
    42         private void Ammu() 
    43         { 
    44             if(energy > 0) 
     51            MomentOfInertia = Double.PositiveInfinity; 
     52            Restitution = 0; 
     53            KineticFriction = 1; 
     54        } 
     55 
     56        public IntMeter getEnergyMeter() 
     57        { 
     58            return energy; 
     59        } 
     60 
     61        public Ammus Ammu() 
     62        { 
     63#if DEBUG 
     64            if (energy.Value > 0) 
    4565            { 
    46                 //Ammus a = new Ammus(1, Angle.); 
    47                 energy--; 
    48                 //Add(a); 
     66#endif 
     67                Ammus a = new Ammus(1, "ToV", Angle.GetVector()); 
     68                a.Position = Position; 
     69                energy.Value--; 
     70                return a; 
     71#if DEBUG 
    4972            } 
     73            else return null; 
     74#endif 
    5075        } 
    5176    } 
     
    6186        } 
    6287 
    63         public void Ammu(PhysicsObject kohde) 
     88        public Ammus Ammu(PhysicsObject kohde) 
    6489        { 
    6590            Vector s = (kohde.Position - Position).Normalize(); 
    66             Ammus a = new Ammus(deal, s); 
    67             Add(a); 
     91            Ammus a = new Ammus(deal, "ToP", s); 
     92            a.Position = Position; 
     93            return a; 
    6894        } 
    6995    } 
     
    7399        private int deal; 
    74100 
    75         public Ammus(int d, Vector suunta) : base(10, 3) 
     101        public Ammus(int d, string t, Vector suunta) : base(3, 3) 
    76102        { 
    77103            deal = d; 
    78             Tag = "ammus"; 
     104            Tag = "ammus" + t; 
     105            Shape = Shape.Circle; 
     106            Restitution = 0; 
     107            KineticFriction = 1; 
     108            MomentOfInertia = Double.PositiveInfinity; 
     109            Timer.SingleShot(2.0, Destroy); 
    79110            Hit(suunta * 100); 
    80111        } 
     
    89120 
    90121    private bool playeradded = false; 
     122 
     123    private bool altpressed; 
     124    private bool ctrlpressed; 
    91125 
    92126    public override void Begin() 
     
    100134    private void LuoKuuntelijat() 
    101135    { 
    102         //Keyboard.Listen(Key.A, ButtonState.Pressed, delegate { pelaaja.Move(new Vector(20, 20)); }, null); 
     136        Keyboard.Listen(Key.A, ButtonState.Down, delegate { pelaaja.Velocity = pelaaja.Angle.GetVector() * 50; }, null); 
     137        Keyboard.Listen(Key.A, ButtonState.Released, delegate { pelaaja.Velocity = Vector.Zero; }, null); 
     138        Keyboard.Listen(Key.Z, ButtonState.Down, delegate { pelaaja.Velocity = pelaaja.Angle.GetVector() * -50; }, null); 
     139        Keyboard.Listen(Key.Z, ButtonState.Released, delegate { pelaaja.Velocity = Vector.Zero; }, null); 
     140        Keyboard.Listen(Key.Left, ButtonState.Down, delegate { if (altpressed) pelaaja.Velocity = (pelaaja.Angle + Angle.RightAngle).GetVector() * 50; else pelaaja.Angle = pelaaja.Angle + (Angle.RightAngle / 50); }, null); 
     141        Keyboard.Listen(Key.Left, ButtonState.Released, delegate { pelaaja.Velocity = Vector.Zero; }, null); 
     142        Keyboard.Listen(Key.Right, ButtonState.Down, delegate { if (altpressed) pelaaja.Velocity = (pelaaja.Angle - Angle.RightAngle).GetVector() * 50; else pelaaja.Angle = pelaaja.Angle - (Angle.RightAngle / 50); }, null); 
     143        Keyboard.Listen(Key.Right, ButtonState.Released, delegate { pelaaja.Velocity = Vector.Zero; }, null); 
     144        Keyboard.Listen(Key.LeftAlt, ButtonState.Pressed, delegate { altpressed = true; }, null); 
     145        Keyboard.Listen(Key.LeftAlt, ButtonState.Released, delegate { altpressed = false; }, null); 
     146 
     147        Keyboard.Listen(Key.LeftControl, ButtonState.Pressed, delegate { ctrlpressed = true; Timer j = new Timer(); j.Interval = 0.5; j.Timeout += delegate { if(ctrlpressed) { Ammus a = pelaaja.Ammu(); if (a != null) Add(a); } }; j.Start(); }, null); 
     148        Keyboard.Listen(Key.LeftControl, ButtonState.Released, delegate { ctrlpressed = false; }, null); 
    103149 
    104150        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Exit the game"); 
     
    130176            ruudut.SetTileMethod('|', LuoPystySeina); 
    131177            ruudut.SetTileMethod('-', LuoVaakaSeina); 
    132             ruudut.Execute(20, 20); 
     178            ruudut.Execute(40, 40); 
    133179        } 
    134180        catch (Exception) 
     
    140186    private void LuoVihollinen(Vector paikka, double leveys, double korkeus) 
    141187    { 
    142         Vihollinen vih = new Vihollinen(20, 10, 10); 
     188        Vihollinen vih = new Vihollinen(1, 10, 10); 
    143189        vih.Position = paikka; 
    144190        vih.Tag = "vihollinen"; 
    145         vih.setShield(100); 
     191        vih.setShield(10); 
    146192        Timer ajastin = new Timer(); 
    147193        ajastin.Interval = 1.5; 
    148         ajastin.Timeout += delegate { if(!pelaaja.IsDestroyed) vih.Ammu(pelaaja); }; 
     194        ajastin.Timeout += delegate { if(!(pelaaja.IsDestroyed || vih.IsDestroyed)) Add(vih.Ammu(pelaaja)); }; 
    149195        ajastin.Start(); 
     196        AddCollisionHandler<Vihollinen, Ammus>(vih, "ammusToV", Osuma); 
    150197        Add(vih); 
    151198    } 
     
    171218        pelaaja.Position = paikka; 
    172219        pelaaja.setShield(100); 
    173         AddCollisionHandler<Pelaaja, Ammus>(pelaaja, "ammus", Osuma); 
     220 
     221        Label shieldNaytto = new Label(); 
     222        shieldNaytto.X = Screen.Left + 100; 
     223        shieldNaytto.Y = Screen.Top - 100; 
     224        shieldNaytto.TextColor = Color.Black; 
     225        shieldNaytto.Color = Color.White; 
     226        shieldNaytto.BindTo(pelaaja.shield); 
     227        Add(shieldNaytto); 
     228 
     229        Label eNaytto = new Label(); 
     230        eNaytto.X = Screen.Left + 200; 
     231        eNaytto.Y = Screen.Top - 100; 
     232        eNaytto.TextColor = Color.Black; 
     233        eNaytto.Color = Color.White; 
     234        eNaytto.BindTo(pelaaja.getEnergyMeter()); 
     235        Add(eNaytto); 
     236        AddCollisionHandler<Pelaaja, Ammus>(pelaaja, "ammusToP", Osuma); 
    174237        Add(pelaaja); 
    175238        playeradded = true; 
     
    182245        kohde.Destroy(); 
    183246    } 
     247    private void Osuma(Vihollinen vih, Ammus kohde) 
     248    { 
     249        vih.setShield(vih.getShield() - kohde.getDeal()); 
     250        kohde.Destroy(); 
     251    } 
    184252} 
  • 2014/27/PekkaR/D2x_2d/D2x_2d/D2x_2d/D2x_2d.csproj.Debug.cachefile

    r5274 r5297  
    11Content\1.xnb 
     2Content\2.xnb 
  • 2014/27/PekkaR/D2x_2d/D2x_2d/D2x_2d/obj/x86/Debug/ContentPipeline-{D8F805CA-FFFC-4C76-8CBF-A2C6D544F284}.xml

    r5274 r5297  
    1010      <Output>C:\MyTemp\PekkaR\D2x_2d\D2x_2d\D2x_2d\bin\x86\Debug\Content\1.xnb</Output> 
    1111      <Time>2014-07-02T10:44:19.4955557+03:00</Time> 
     12    </Item> 
     13    <Item> 
     14      <Source>2.txt</Source> 
     15      <Name>2</Name> 
     16      <Importer>TextFileImporter</Importer> 
     17      <Processor>TextFileContentProcessor</Processor> 
     18      <Options>None</Options> 
     19      <Output>C:\MyTemp\PekkaR\D2x_2d\D2x_2d\D2x_2d\bin\x86\Debug\Content\2.xnb</Output> 
     20      <Time>2014-07-02T14:56:14.1428428+03:00</Time> 
    1221    </Item> 
    1322    <BuildSuccessful>true</BuildSuccessful> 
  • 2014/27/PekkaR/D2x_2d/D2x_2d/D2x_2d/obj/x86/Debug/D2x_2d.csproj.FileListAbsolute.txt

    r5274 r5297  
    88C:\MyTemp\PekkaR\D2x_2d\D2x_2d\D2x_2d\obj\x86\Debug\D2x_2d.pdb 
    99C:\MyTemp\PekkaR\D2x_2d\D2x_2d\D2x_2d\bin\x86\Debug\Content\1.xnb 
     10C:\MyTemp\PekkaR\D2x_2d\D2x_2d\D2x_2d\bin\x86\Debug\Content\2.xnb 
  • 2014/27/PekkaR/D2x_2d/D2x_2d/D2x_2d/obj/x86/Debug/cachefile-{D8F805CA-FFFC-4C76-8CBF-A2C6D544F284}-targetpath.txt

    r5274 r5297  
    11Content\1.xnb 
     2Content\2.xnb 
  • 2014/27/PekkaR/D2x_2d/D2x_2d/D2x_2dContent/D2x_2dContent.contentproj

    r5274 r5297  
    5252    </Compile> 
    5353  </ItemGroup> 
     54  <ItemGroup> 
     55    <Compile Include="2.txt"> 
     56      <Name>2</Name> 
     57      <Importer>TextFileImporter</Importer> 
     58      <Processor>TextFileContentProcessor</Processor> 
     59    </Compile> 
     60  </ItemGroup> 
    5461  <Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" /> 
    5562  <!--  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.