Changeset 5297
- Timestamp:
- 2014-07-02 14:58:01 (9 years ago)
- 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 3 using System; 2 4 using System.Collections.Generic; 3 5 using Jypeli; … … 11 13 public class Shieldable : PhysicsObject 12 14 { 13 p rotected int shield;15 public IntMeter shield = new IntMeter(0); 14 16 15 17 public Shieldable(int w, int h) : base(w, h) … … 18 20 } 19 21 22 public IntMeter getShieldMeter() 23 { 24 return shield; 25 } 26 20 27 public int getShield() 21 28 { 22 return shield ;29 return shield.Value; 23 30 } 24 31 25 32 public void setShield(int t) 26 33 { 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 } 29 40 } 30 41 } … … 32 43 public class Pelaaja : Shieldable 33 44 { 34 private int energy = 100;45 private IntMeter energy = new IntMeter(100); 35 46 36 47 public Pelaaja(int w, int h) : base(w, h) 37 48 { 38 shield = 100;49 shield.Value = 100; 39 50 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) 45 65 { 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 49 72 } 73 else return null; 74 #endif 50 75 } 51 76 } … … 61 86 } 62 87 63 public voidAmmu(PhysicsObject kohde)88 public Ammus Ammu(PhysicsObject kohde) 64 89 { 65 90 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; 68 94 } 69 95 } … … 73 99 private int deal; 74 100 75 public Ammus(int d, Vector suunta) : base(10, 3)101 public Ammus(int d, string t, Vector suunta) : base(3, 3) 76 102 { 77 103 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); 79 110 Hit(suunta * 100); 80 111 } … … 89 120 90 121 private bool playeradded = false; 122 123 private bool altpressed; 124 private bool ctrlpressed; 91 125 92 126 public override void Begin() … … 100 134 private void LuoKuuntelijat() 101 135 { 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); 103 149 104 150 Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Exit the game"); … … 130 176 ruudut.SetTileMethod('|', LuoPystySeina); 131 177 ruudut.SetTileMethod('-', LuoVaakaSeina); 132 ruudut.Execute( 20, 20);178 ruudut.Execute(40, 40); 133 179 } 134 180 catch (Exception) … … 140 186 private void LuoVihollinen(Vector paikka, double leveys, double korkeus) 141 187 { 142 Vihollinen vih = new Vihollinen( 20, 10, 10);188 Vihollinen vih = new Vihollinen(1, 10, 10); 143 189 vih.Position = paikka; 144 190 vih.Tag = "vihollinen"; 145 vih.setShield(10 0);191 vih.setShield(10); 146 192 Timer ajastin = new Timer(); 147 193 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)); }; 149 195 ajastin.Start(); 196 AddCollisionHandler<Vihollinen, Ammus>(vih, "ammusToV", Osuma); 150 197 Add(vih); 151 198 } … … 171 218 pelaaja.Position = paikka; 172 219 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); 174 237 Add(pelaaja); 175 238 playeradded = true; … … 182 245 kohde.Destroy(); 183 246 } 247 private void Osuma(Vihollinen vih, Ammus kohde) 248 { 249 vih.setShield(vih.getShield() - kohde.getDeal()); 250 kohde.Destroy(); 251 } 184 252 } -
2014/27/PekkaR/D2x_2d/D2x_2d/D2x_2d/D2x_2d.csproj.Debug.cachefile
r5274 r5297 1 1 Content\1.xnb 2 Content\2.xnb -
2014/27/PekkaR/D2x_2d/D2x_2d/D2x_2d/obj/x86/Debug/ContentPipeline-{D8F805CA-FFFC-4C76-8CBF-A2C6D544F284}.xml
r5274 r5297 10 10 <Output>C:\MyTemp\PekkaR\D2x_2d\D2x_2d\D2x_2d\bin\x86\Debug\Content\1.xnb</Output> 11 11 <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> 12 21 </Item> 13 22 <BuildSuccessful>true</BuildSuccessful> -
2014/27/PekkaR/D2x_2d/D2x_2d/D2x_2d/obj/x86/Debug/D2x_2d.csproj.FileListAbsolute.txt
r5274 r5297 8 8 C:\MyTemp\PekkaR\D2x_2d\D2x_2d\D2x_2d\obj\x86\Debug\D2x_2d.pdb 9 9 C:\MyTemp\PekkaR\D2x_2d\D2x_2d\D2x_2d\bin\x86\Debug\Content\1.xnb 10 C:\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 1 1 Content\1.xnb 2 Content\2.xnb -
2014/27/PekkaR/D2x_2d/D2x_2d/D2x_2dContent/D2x_2dContent.contentproj
r5274 r5297 52 52 </Compile> 53 53 </ItemGroup> 54 <ItemGroup> 55 <Compile Include="2.txt"> 56 <Name>2</Name> 57 <Importer>TextFileImporter</Importer> 58 <Processor>TextFileContentProcessor</Processor> 59 </Compile> 60 </ItemGroup> 54 61 <Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" /> 55 62 <!-- 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.