Changeset 5241
- Timestamp:
- 2014-07-01 14:55:55 (9 years ago)
- Location:
- 2014/27/PekkaR/D2x-2d
- Files:
-
- 11 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
2014/27/PekkaR/D2x-2d/D2x-2d/D2x-2d/D2x_2d.cs
r5208 r5241 1 using System; 1 #define DEBUG 2 3 using System; 2 4 using System.Collections.Generic; 3 5 using Jypeli; … … 9 11 public class D2x_2d : PhysicsGame 10 12 { 13 public class Shieldable : PhysicsObject 14 { 15 protected int shield; 16 17 public Shieldable() : base(20, 20) 18 { 19 20 } 21 22 public int getShield() 23 { 24 return shield; 25 } 26 27 public void setShield(int t) 28 { 29 if (t > 0) shield = t; 30 else Destroy(); 31 } 32 } 33 34 public class Pelaaja : Shieldable 35 { 36 private int energy = 100; 37 38 public Pelaaja() 39 { 40 shield = 100; 41 Tag = "pelaaja"; 42 } 43 44 private void Ammu() 45 { 46 if (energy > 0) 47 { 48 Ammus a = new Ammus(1); 49 energy--; 50 Add(a); 51 } 52 } 53 } 54 55 public class Vihollinen : Shieldable 56 { 57 private int deal; 58 59 public Vihollinen(int d) 60 { 61 deal = d; 62 Tag = "vihollinen"; 63 } 64 65 private void Ammu() 66 { 67 Ammus a = new Ammus(deal); 68 Add(a); 69 } 70 } 71 72 public class Ammus : PhysicsObject 73 { 74 public Ammus(int deal): base(10, 3) 75 { 76 Tag = "ammus"; 77 } 78 } 79 80 private Pelaaja pelaaja; 81 82 private bool playeradded = false; 83 11 84 public override void Begin() 12 85 { 86 Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Exit the game"); 13 87 NaytaValikko(); 14 15 PhoneBackButton.Listen(ConfirmExit, "Lopeta peli");16 Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli");17 88 } 18 89 19 90 private void NaytaValikko() 20 91 { 21 MultiSelectWindow alkuValikko = new MultiSelectWindow("Alkuvalikko", "Aloita peli", "Parhaat pisteet", "Lopeta"); 92 MultiSelectWindow alkuValikko = new MultiSelectWindow("", "Start game", "Exit"); 93 alkuValikko.AddItemHandler(0, AloitaPeli); 94 alkuValikko.AddItemHandler(1, ConfirmExit); 95 alkuValikko.DefaultCancel = 1; 22 96 Add(alkuValikko); 23 97 } 24 98 25 private void LuoKentta()99 private void AloitaPeli() 26 100 { 101 InputWindow kysymysIkkuna = new InputWindow("Enter the level name"); 102 kysymysIkkuna.TextEntered += ProcessInput; 103 Add(kysymysIkkuna); 104 } 105 106 private void ProcessInput(InputWindow ikkuna) 107 { 108 #if DEBUG 109 MessageDisplay.Add(ikkuna.InputBox.Text); 110 #endif 111 try 112 { 113 TileMap ruudut = TileMap.FromLevelAsset("kentta1"); 114 ruudut.SetTileMethod('P', LuoPelaaja); 115 ruudut.SetTileMethod('V', LuoVihollinen); 116 ruudut.SetTileMethod('|', LuoPystySeina); 117 ruudut.SetTileMethod('-', LuoVaakaSeina); 118 ruudut.Execute(20, 20); 119 } 120 catch(Exception e) 121 { 122 MessageDisplay.Add(e.StackTrace); 123 } 124 } 125 126 private void LuoVihollinen(Vector paikka, double leveys, double korkeus) 127 { 128 Vihollinen vih = new Vihollinen(1); 129 vih.Width = leveys; 130 vih.Height = korkeus; 131 vih.Position = paikka; 132 vih.Tag = "vihollinen"; 133 vih.setShield(100); 134 Add(vih); 135 } 136 137 private void LuoPystySeina(Vector paikka, double leveys, double korkeus) 138 { 139 PhysicsObject seina = PhysicsObject.CreateStaticObject(leveys, korkeus); 140 seina.Position = paikka; 141 Add(seina); 142 } 143 144 private void LuoVaakaSeina(Vector paikka, double leveys, double korkeus) 145 { 146 PhysicsObject seina = PhysicsObject.CreateStaticObject(leveys, korkeus); 147 seina.Position = paikka; 148 Add(seina); 149 } 150 151 private void LuoPelaaja(Vector paikka, double leveys, double korkeus) 152 { 153 if (playeradded) throw new Exception("Too many players"); 154 pelaaja = new Pelaaja(); 155 pelaaja.Width = leveys; 156 pelaaja.Height = korkeus; 157 pelaaja.Position = paikka; 158 pelaaja.setShield(100); 159 AddCollisionHandler<Pelaaja, PhysicsObject>(pelaaja, "ammus", Osuma); 160 Add(pelaaja); 161 playeradded = true; 27 162 28 163 } 164 165 private void Osuma(Pelaaja pelaaja, PhysicsObject kohde) 166 { 167 pelaaja.setShield(pelaaja.getShield() - 1); 168 kohde.Destroy(); 169 } 29 170 } -
2014/27/PekkaR/D2x-2d/D2x-2d/D2x-2dContent/D2x-2dContent.contentproj
r5208 r5241 45 45 <Reference Include="AnimationExtension" /> 46 46 </ItemGroup> 47 <ItemGroup> 48 <Compile Include="kentta1.txt"> 49 <Name>kentta1</Name> 50 <Importer>TextFileImporter</Importer> 51 <Processor>TextFileContentProcessor</Processor> 52 <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> 53 </Compile> 54 </ItemGroup> 47 55 <Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" /> 48 56 <!-- 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.