Changeset 5646 for 2014/30/AarniAR/AdventureOfStarKid/AdventureOfStarKid/AdventureOfStarKid/AdventureOfStarKid.cs
- Timestamp:
- 2014-07-24 15:01:38 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
2014/30/AarniAR/AdventureOfStarKid/AdventureOfStarKid/AdventureOfStarKid/AdventureOfStarKid.cs
r5627 r5646 22 22 public class AdventureOfStarKid : PhysicsGame 23 23 { 24 int kenttaNro = 1; 24 25 private Image[] running = LoadImages("running1", "running2"); 25 26 private Image[] standinganimation = LoadImages("shootinganimation"); … … 28 29 private Image[] lifelost = LoadImages("LifeLost"); 29 30 private Image[] damage = LoadImages("Damage"); 31 private Image OneUP = LoadImage("1UP"); 32 private Image Healing = LoadImage("Healing"); 30 33 const double nopeus = 200; 31 34 const double hyppyNopeus = 750; 32 35 const int RUUDUN_KOKO = 40; 33 PlasmaCannon pelaajan1Ase;34 DoubleMeter health;35 36 PlasmaCannon pelaajan1Ase; 37 DoubleMeter health; 38 36 39 37 40 PlatformCharacter pelaaja1; … … 52 55 { 53 56 ClearAll(); 54 Gravity = new Vector(0, -1000);55 56 LuoKentta();57 58 59 SeuraavaKentta(); 57 60 LisaaNappaimet(); 58 LuoPistelaskuri(); 59 60 Camera.Follow(pelaaja1); 61 Camera.ZoomFactor = 1.2; 62 Camera.StayInLevel = true; 63 } 64 65 void LuoKentta() 66 { 67 TileMap kentta = TileMap.FromLevelAsset("kentta1"); 61 62 } 63 64 void LuoKentta(string kenttaTiedostonNimi) 65 { 66 TileMap kentta = TileMap.FromLevelAsset(kenttaTiedostonNimi); 68 67 kentta.SetTileMethod('#', LisaaTaso); 69 68 kentta.SetTileMethod('*', Lisaastumper); 70 69 kentta.SetTileMethod('N', LisaaPelaaja); 70 kentta.SetTileMethod('1', Lisaa1UP); 71 kentta.SetTileMethod('H', LisaaHealing); 71 72 kentta.Execute(RUUDUN_KOKO, RUUDUN_KOKO); 72 73 Level.CreateBorders(); 73 74 Level.Background.CreateGradient(Color.White, Color.SkyBlue); 75 } 76 void Lisaa1UP(Vector paikka, double leveys, double korkeus) 77 { 78 AddItem(paikka, leveys, korkeus, OneUP, "1UP"); 79 } 80 void LisaaHealing(Vector paikka, double leveys, double korkeus) 81 { 82 AddItem(paikka, leveys, korkeus, Healing, "Heal"); 83 84 } 85 86 void AddItem(Vector paikka, double leveys, double korkeus, Image Kuva, String tagi) 87 { 88 PhysicsObject Item = new PhysicsObject(leveys, korkeus); 89 Item.Position = paikka; 90 Add(Item); 91 Item.Image = Kuva; 92 Item.Tag = tagi; 74 93 } 75 94 … … 84 103 void Lisaastumper(Vector paikka, double leveys, double korkeus) 85 104 { 86 Vihu stumper = new Vihu(leveys -4, korkeus-4);105 Vihu stumper = new Vihu(leveys - 4, korkeus - 4); 87 106 stumper.IgnoresCollisionResponse = false; 88 107 stumper.Position = paikka; … … 99 118 void LisaaPelaaja(Vector paikka, double leveys, double korkeus) 100 119 { 101 pelaaja1 = new PlatformCharacter(leveys *0.5, korkeus);120 pelaaja1 = new PlatformCharacter(leveys * 0.5, korkeus); 102 121 pelaaja1.Position = paikka; 103 122 pelaaja1.Mass = 4.0; … … 105 124 AddCollisionHandler(pelaaja1, "stumper", TormaaTahteen); 106 125 Add(pelaaja1); 126 AddCollisionHandler(pelaaja1, "1UP", tormaaOneUP); 127 AddCollisionHandler(pelaaja1, "Heal", tormaaHealingiin); 107 128 pelaaja1.AnimWalk = new Animation(running); 108 129 pelaaja1.AnimIdle = new Animation(shootinganimation); 109 130 pelaaja1.AnimJump = new Animation(jumpinganimation); 110 131 pelaaja1.AnimFall = new Animation(jumpinganimation); 111 132 112 133 pelaajan1Ase = new PlasmaCannon(1.0, 1.0); 113 134 pelaajan1Ase.InfiniteAmmo = true; … … 134 155 Keyboard.Listen(Key.Right, ButtonState.Down, Liikuta, "Liikkuu vasemmalle", pelaaja1, nopeus); 135 156 Keyboard.Listen(Key.Space, ButtonState.Pressed, Hyppaa, "Pelaaja hyppää", pelaaja1, hyppyNopeus); 136 Keyboard.Listen(Key. 157 Keyboard.Listen(Key.C, ButtonState.Pressed, Ammu, "Ampuu", pelaajan1Ase); 137 158 138 159 … … 180 201 health.MinValue = 0; 181 202 health.LowerLimit += PelaajaHaviaa; 182 203 183 204 health.Changed += delegate 184 205 { … … 189 210 Timer.SingleShot(1, delegate { invincible = false; }); 190 211 }; 191 212 192 213 ProgressBar healthMeter = new ProgressBar(150, 20); 193 214 healthMeter.X = Screen.Left + 150; … … 195 216 healthMeter.BindTo(health); 196 217 Add(healthMeter); 197 218 198 219 healthMeter.Angle = Angle.RightAngle; 199 220 healthMeter.Color = Color.Transparent; … … 202 223 203 224 204 225 205 226 } 206 227 void PelaajaHaviaa() … … 216 237 Timer.SingleShot(5, AloitaPeli); 217 238 } 239 void tormaaOneUP(PhysicsObject pelaaja1, PhysicsObject OneUP) 240 { 241 health.Value = health.MaxValue; 242 OneUP.Destroy(); 243 } 244 void tormaaHealingiin(PhysicsObject pelaaja1, PhysicsObject Healing) 245 { 246 health.Value += 3; 247 Healing.Destroy(); 248 249 } 250 void SeuraavaKentta() 251 { 252 ClearAll(); 253 Gravity = new Vector(0, -1000); 254 if (kenttaNro == 1) LuoKentta("kentta1"); 255 else if (kenttaNro == 2) LuoKentta("kentta2"); 256 else if (kenttaNro == 3) LuoKentta("kentta3"); 257 else if (kenttaNro > 3) Exit(); 258 259 LisaaNappaimet(); 260 LuoPistelaskuri(); 261 262 Camera.Follow(pelaaja1); 263 Camera.ZoomFactor = 1.2; 264 Camera.StayInLevel = true; 265 } 218 266 }
Note: See TracChangeset
for help on using the changeset viewer.