- Timestamp:
- 2014-07-23 11:19:11 (9 years ago)
- Location:
- 2014/30/AtteB
- Files:
-
- 20 added
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
2014/30/AtteB/Peli/Peli/Peli/Peli.cs
r5540 r5574 19 19 } 20 20 21 class Inventory : Widget 22 { 23 24 /// Tapahtuma, kun esine on valittu. 25 public event Action<PhysicsObject> ItemSelected; 26 27 /// Luo uuden esinevalikon. 28 public Inventory() 29 : base(new HorizontalLayout()) 30 { 31 } 32 33 /// Lisää esineen. 34 public void AddItem(PhysicsObject item, Image kuva) 35 { 36 PushButton icon = new PushButton(kuva); 37 Add(icon); 38 icon.Clicked += delegate() { SelectItem(item); }; 39 } 40 41 void SelectItem(PhysicsObject item) 42 { 43 if (ItemSelected != null) 44 { 45 ItemSelected(item); 46 } 47 } 48 } 49 21 50 public class Peli : PhysicsGame 22 51 { 23 int pelaajanTerveys = 100;24 25 DoubleMeter P1Elämät;52 DoubleMeter elämäLaskuri; 53 54 AssaultRifle P1FireBall; 26 55 27 56 const double nopeus = 200; … … 30 59 31 60 PlatformCharacter pelaaja1; 32 PlatformCharacter vihollinen1;33 61 34 62 Image tahtiKuva = LoadImage("tahti"); … … 39 67 Image Pelaaja_Juoksee = LoadImage("Pelaaja_Juoksee"); 40 68 Image StoneBrickTaso = LoadImage("Stone_brick_tile"); 41 Image Slime = LoadImage("Slime"); 69 Image Slime1 = LoadImage("Slime"); 70 Image FireBall1 = LoadImage("FireBall_1"); 71 Image FireBall2 = LoadImage("FireBall_2"); 72 Image FireBall3 = LoadImage("FireBall_3"); 73 Image FireBall4 = LoadImage("FireBall_4"); 74 Image Clear = LoadImage("Clear"); 75 Image Heart1 = LoadImage("heart"); 42 76 43 77 SoundEffect maaliAani = LoadSoundEffect("maali"); … … 59 93 SmoothTextures = false; 60 94 61 P1Elämät= new DoubleMeter(100); 62 P1Elämät.MaxValue = 100; 63 64 BarGauge P1Elämä = new BarGauge(20, Screen.Width / 3); 65 P1Elämä.X = Screen.Left + Screen.Width / 2; 66 P1Elämä.Y = Screen.Top - 200; 67 P1Elämä.Angle = Angle.FromDegrees(90); 68 P1Elämä.BindTo(P1Elämät); 69 P1Elämä.Color = Color.BloodRed; 70 P1Elämä.BarColor = Color.Cyan; 71 Add(P1Elämä); 72 95 Inventory inventory = new Inventory(); 96 Add(inventory); 73 97 } 74 98 … … 77 101 TileMap kentta = TileMap.FromLevelAsset("kentta1"); 78 102 kentta.SetTileMethod('#', LisaaTaso); 79 kentta.SetTileMethod('*', LisaaTahti);80 103 kentta.SetTileMethod('N', LisaaPelaaja); 81 104 kentta.SetTileMethod('P', LisaaStoneLattia); … … 83 106 kentta.SetTileMethod('?', LisaaStoneBrickLattia); 84 107 kentta.SetTileMethod('S', LuoSlime); 108 kentta.SetTileMethod('H', LisaaHeart); 85 109 kentta.Execute(RUUDUN_KOKO, RUUDUN_KOKO); 86 110 Level.CreateBorders(); … … 117 141 } 118 142 119 120 143 void LisaaStoneKatto(Vector paikka, double leveys, double korkeus) 121 144 { … … 128 151 } 129 152 130 131 void LisaaTahti(Vector paikka, double leveys, double korkeus) 132 { 133 PhysicsObject tahti = PhysicsObject.CreateStaticObject(leveys, korkeus); 134 tahti.IgnoresCollisionResponse = true; 135 tahti.Position = paikka; 136 tahti.Image = tahtiKuva; 137 tahti.Tag = "tahti"; 138 Add(tahti); 153 void LisaaHeart(Vector paikka, double leveys, double korkeus) 154 { 155 PhysicsObject heart = PhysicsObject.CreateStaticObject(leveys, korkeus); 156 heart.IgnoresCollisionResponse = true; 157 heart.Position = paikka; 158 heart.Image = Heart1; 159 heart.Tag = "health"; 160 Add(heart); 139 161 } 140 162 … … 145 167 pelaaja1.Mass = 10.0; 146 168 pelaaja1.Image = Pelaaja_Seisoo; 147 AddCollisionHandler(pelaaja1, "tahti", TormaaTahteen); 169 AddCollisionHandler(pelaaja1, "vihollinen", PelaajaOsuuViholliseen); 170 AddCollisionHandler(pelaaja1, "health", PelaajaOsuuHeart); 148 171 Add(pelaaja1); 172 173 P1FireBall = new AssaultRifle(30, 10); 174 175 // Ammusten määrä 176 P1FireBall.Ammo.Value = 100000; 177 178 // Ammus osuu = mitä tapahtuu 179 P1FireBall.ProjectileCollision = AmmusOsuiViholliseen; 180 P1FireBall.Image = Clear; 181 182 pelaaja1.Add(P1FireBall); 149 183 } 150 184 … … 153 187 Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet"); 154 188 Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 155 156 Keyboard.Listen(Key.Left, ButtonState.Down, Liikuta, "Liikkuu vasemmalle", pelaaja1, -nopeus); 157 Keyboard.Listen(Key.Right, ButtonState.Down, Liikuta, "Liikkuu vasemmalle", pelaaja1, nopeus); 158 Keyboard.Listen(Key.Up, ButtonState.Pressed, Hyppaa, "Pelaaja hyppää", pelaaja1, hyppyNopeus); 189 Keyboard.Listen(Key.LeftShift, ButtonState.Down, AmmuAseella, "Ammu", P1FireBall); 190 191 Keyboard.Listen(Key.A, ButtonState.Down, Liikuta, "Liikkuu vasemmalle", pelaaja1, -nopeus); 192 Keyboard.Listen(Key.D, ButtonState.Down, Liikuta, "Liikkuu vasemmalle", pelaaja1, nopeus); 193 Keyboard.Listen(Key.W, ButtonState.Pressed, Hyppaa, "Pelaaja hyppää", pelaaja1, hyppyNopeus); 194 Keyboard.Listen(Key.Space, ButtonState.Pressed, Hyppaa, "Pelaaja hyppää", pelaaja1, hyppyNopeus); 159 195 160 196 ControllerOne.Listen(Button.Back, ButtonState.Pressed, Exit, "Poistu pelistä"); … … 177 213 } 178 214 179 void TormaaTahteen(PhysicsObject hahmo, PhysicsObject tahti)180 {181 maaliAani.Play();182 MessageDisplay.Add("Keräsit tähden!");183 tahti.Destroy();184 }185 186 215 void LuoVihollinen(Vector paikka, double leveys, double korkeus) 187 216 { 188 217 PhysicsObject vihollinen = new PhysicsObject(leveys, korkeus); 189 218 vihollinen.Position = paikka; 190 vihollinen.Tag = " pahis";219 vihollinen.Tag = "vihollinen"; 191 220 Add(vihollinen); 192 221 } … … 200 229 } 201 230 202 void TörmäysKäsittelijät() 203 { 204 AddCollisionHandler(pelaaja1, "pahis", PelaajaOsuu); 205 AddCollisionHandler(pelaaja1, "health", PelaajaParantuu); 206 } 207 208 void PelaajaOsuu(PhysicsObject pelaaja1, PhysicsObject kohde) 209 { 210 pelaajanTerveys--; 211 212 if (pelaajanTerveys <= 0) 231 void PelaajaOsuuViholliseen(PhysicsObject pelaaja1, PhysicsObject kohde) 232 { 233 elämäLaskuri.Value -= 10; 234 235 if (elämäLaskuri <= 0) 213 236 pelaaja1.Destroy(); 214 237 } 215 238 216 void PelaajaParantuu(PhysicsObject pelaaja1, PhysicsObject kohde) 217 { 218 pelaajanTerveys++; 239 void PelaajaOsuuHeart(PhysicsObject pelaaja1, PhysicsObject kohde) 240 { 241 if (elämäLaskuri < 65) 242 { 243 elämäLaskuri.Value += 30; 244 } 219 245 } 220 246 221 247 void LuoSlime(Vector paikka, double leveys, double korkeus) 222 248 { 223 Vihollinen Slime1 = new Vihollinen(40, 40); 224 Slime1.X = 20; 225 Slime1.Y = 20; 226 Slime1.Image = Slime; 227 228 } 249 PhysicsObject Slime = new PhysicsObject(leveys, korkeus); 250 Slime.CanRotate = false; 251 Slime.Position = paikka; 252 Slime.Tag = "vihollinen"; 253 Slime.Image = Slime1; 254 Add(Slime); 255 } 256 257 void AmmusOsuiViholliseen(PhysicsObject ammus, PhysicsObject kohde) 258 { 259 ammus.Destroy(); 260 261 } 262 263 void AmmuAseella(AssaultRifle ase) 264 { 265 PhysicsObject ammus = ase.Shoot(); 266 267 if (ammus != null) 268 { 269 ammus.Image = FireBall1; 270 ammus.Size = new Vector(40, 40); 271 } 272 } 273 274 void LuoElämäLaskuri() 275 { 276 elämäLaskuri = new DoubleMeter(100); 277 elämäLaskuri.MaxValue = 100; 278 elämäLaskuri.LowerLimit += ElämäLoppui; 279 280 ProgressBar elämäPalkki = new ProgressBar(150, 20); 281 elämäPalkki.X = Screen.Left + 150; 282 elämäPalkki.Y = Screen.Top - 20; 283 elämäPalkki.BindTo(elämäLaskuri); 284 elämäPalkki.Color = Color.Transparent; 285 elämäPalkki.BarColor = Color.Red; 286 elämäPalkki.BorderColor = Color.Black; 287 Add(elämäPalkki); 288 } 289 290 void ElämäLoppui() 291 { 292 MessageDisplay.Add("Elämät loppuivat, voi voi."); 293 Remove(pelaaja1); 294 } 295 229 296 } -
2014/30/AtteB/Peli/Peli/Peli/Peli.csproj.Debug.cachefile
r5540 r5574 12 12 Content\Stonewall.xnb 13 13 Content\Slime.xnb 14 Content\Fireball_1.xnb 15 Content\Fireball_2.xnb 16 Content\Fireball_3.xnb 17 Content\Fireball_4.xnb 18 Content\Clear.xnb 19 Content\heart.xnb -
2014/30/AtteB/Peli/Peli/Peli/obj/x86/Debug/ContentPipeline-{2D86B228-748C-44C7-93B1-DCBD6910317C}.xml
r5540 r5574 36 36 <Options>None</Options> 37 37 <Output>C:\MyTemp\AtteB\Peli\Peli\Peli\bin\x86\Debug\Content\kentta1.xnb</Output> 38 <Time>2014-07-2 2T14:35:50.3392059+03:00</Time>38 <Time>2014-07-23T10:47:44.2742229+03:00</Time> 39 39 </Item> 40 40 <Item> … … 118 118 <Output>C:\MyTemp\AtteB\Peli\Peli\Peli\bin\x86\Debug\Content\Slime.xnb</Output> 119 119 <Time>2014-07-22T14:06:10.9162814+03:00</Time> 120 </Item> 121 <Item> 122 <Source>Fireball_1.png</Source> 123 <Name>Fireball_1</Name> 124 <Importer>TextureImporter</Importer> 125 <Processor>TextureProcessor</Processor> 126 <Options>None</Options> 127 <Output>C:\MyTemp\AtteB\Peli\Peli\Peli\bin\x86\Debug\Content\Fireball_1.xnb</Output> 128 <Time>2014-07-23T10:17:37.7835919+03:00</Time> 129 </Item> 130 <Item> 131 <Source>Fireball_2.png</Source> 132 <Name>Fireball_2</Name> 133 <Importer>TextureImporter</Importer> 134 <Processor>TextureProcessor</Processor> 135 <Options>None</Options> 136 <Output>C:\MyTemp\AtteB\Peli\Peli\Peli\bin\x86\Debug\Content\Fireball_2.xnb</Output> 137 <Time>2014-07-23T10:17:37.7795915+03:00</Time> 138 </Item> 139 <Item> 140 <Source>Fireball_3.png</Source> 141 <Name>Fireball_3</Name> 142 <Importer>TextureImporter</Importer> 143 <Processor>TextureProcessor</Processor> 144 <Options>None</Options> 145 <Output>C:\MyTemp\AtteB\Peli\Peli\Peli\bin\x86\Debug\Content\Fireball_3.xnb</Output> 146 <Time>2014-07-23T10:17:37.7805916+03:00</Time> 147 </Item> 148 <Item> 149 <Source>Fireball_4.png</Source> 150 <Name>Fireball_4</Name> 151 <Importer>TextureImporter</Importer> 152 <Processor>TextureProcessor</Processor> 153 <Options>None</Options> 154 <Output>C:\MyTemp\AtteB\Peli\Peli\Peli\bin\x86\Debug\Content\Fireball_4.xnb</Output> 155 <Time>2014-07-23T10:17:37.7815917+03:00</Time> 156 </Item> 157 <Item> 158 <Source>Clear.png</Source> 159 <Name>Clear</Name> 160 <Importer>TextureImporter</Importer> 161 <Processor>TextureProcessor</Processor> 162 <Options>None</Options> 163 <Output>C:\MyTemp\AtteB\Peli\Peli\Peli\bin\x86\Debug\Content\Clear.xnb</Output> 164 <Time>2014-07-23T10:21:25.007312+03:00</Time> 165 </Item> 166 <Item> 167 <Source>heart.jpg</Source> 168 <Name>heart</Name> 169 <Importer>TextureImporter</Importer> 170 <Processor>TextureProcessor</Processor> 171 <Options>None</Options> 172 <Output>C:\MyTemp\AtteB\Peli\Peli\Peli\bin\x86\Debug\Content\heart.xnb</Output> 173 <Time>2014-07-23T10:48:27.5205471+03:00</Time> 120 174 </Item> 121 175 <BuildSuccessful>true</BuildSuccessful> -
2014/30/AtteB/Peli/Peli/Peli/obj/x86/Debug/Peli.csproj.FileListAbsolute.txt
r5540 r5574 20 20 C:\MyTemp\AtteB\Peli\Peli\Peli\bin\x86\Debug\Content\Stonewall.xnb 21 21 C:\MyTemp\AtteB\Peli\Peli\Peli\bin\x86\Debug\Content\Slime.xnb 22 C:\MyTemp\AtteB\Peli\Peli\Peli\bin\x86\Debug\Content\Fireball_1.xnb 23 C:\MyTemp\AtteB\Peli\Peli\Peli\bin\x86\Debug\Content\Fireball_2.xnb 24 C:\MyTemp\AtteB\Peli\Peli\Peli\bin\x86\Debug\Content\Fireball_3.xnb 25 C:\MyTemp\AtteB\Peli\Peli\Peli\bin\x86\Debug\Content\Fireball_4.xnb 26 C:\MyTemp\AtteB\Peli\Peli\Peli\bin\x86\Debug\Content\Clear.xnb 27 C:\MyTemp\AtteB\Peli\Peli\Peli\bin\x86\Debug\Content\heart.xnb -
2014/30/AtteB/Peli/Peli/Peli/obj/x86/Debug/cachefile-{2D86B228-748C-44C7-93B1-DCBD6910317C}-targetpath.txt
r5540 r5574 12 12 Content\Stonewall.xnb 13 13 Content\Slime.xnb 14 Content\Fireball_1.xnb 15 Content\Fireball_2.xnb 16 Content\Fireball_3.xnb 17 Content\Fireball_4.xnb 18 Content\Clear.xnb 19 Content\heart.xnb -
2014/30/AtteB/Peli/Peli/PeliContent/PeliContent.contentproj
r5540 r5574 130 130 </Compile> 131 131 </ItemGroup> 132 <ItemGroup> 133 <Compile Include="Fireball_1.png"> 134 <Name>Fireball_1</Name> 135 <Importer>TextureImporter</Importer> 136 <Processor>TextureProcessor</Processor> 137 </Compile> 138 <Compile Include="Fireball_2.png"> 139 <Name>Fireball_2</Name> 140 <Importer>TextureImporter</Importer> 141 <Processor>TextureProcessor</Processor> 142 </Compile> 143 <Compile Include="Fireball_3.png"> 144 <Name>Fireball_3</Name> 145 <Importer>TextureImporter</Importer> 146 <Processor>TextureProcessor</Processor> 147 </Compile> 148 <Compile Include="Fireball_4.png"> 149 <Name>Fireball_4</Name> 150 <Importer>TextureImporter</Importer> 151 <Processor>TextureProcessor</Processor> 152 </Compile> 153 </ItemGroup> 154 <ItemGroup> 155 <Compile Include="Clear.png"> 156 <Name>Clear</Name> 157 <Importer>TextureImporter</Importer> 158 <Processor>TextureProcessor</Processor> 159 </Compile> 160 </ItemGroup> 161 <ItemGroup> 162 <Compile Include="heart.jpg"> 163 <Name>heart</Name> 164 <Importer>TextureImporter</Importer> 165 <Processor>TextureProcessor</Processor> 166 </Compile> 167 </ItemGroup> 132 168 <Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" /> 133 169 <!-- To modify your build process, add your task inside one of the targets below and uncomment it. -
2014/30/AtteB/Peli/Peli/PeliContent/kentta1.txt
r5540 r5574 6 6 ????? 7 7 ?????? 8 ???????...... ........?.....?.8 ???????......H.......?.....?. 9 9 ????????.............?..S..?. 10 10 ###########################################################
Note: See TracChangeset
for help on using the changeset viewer.