Changeset 955 for 2010/23/hniemi/ShootEmUp/ShootEmUp/Peli.cs
- Timestamp:
- 2010-06-17 15:59:38 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
2010/23/hniemi/ShootEmUp/ShootEmUp/Peli.cs
r944 r955 15 15 //Liikkumisnopeudet 16 16 private const double NOPEUS = 300; 17 private const int OLETUSASE = 0; 17 18 private Vector nopeusPysty = new Vector(0,NOPEUS); 18 19 private Vector nopeusVaaka = new Vector(NOPEUS, 0); … … 26 27 private PhysicsObject exitZone; 27 28 29 private GameObject[] tahdet; 30 28 31 //Viholliset 29 private const int VIHOLLISKUVIA = 3;32 private const int VIHOLLISKUVIA = 4; 30 33 31 34 //Statistiikka 32 35 private int kentannro = 0; 33 36 private IntMeter score = new IntMeter(0); 37 private IntMeter lives = new IntMeter(3); 38 private TextDisplay[] aseNimet; 34 39 private Weapon[] weapons; 35 40 36 41 #endregion 37 42 43 /// <summary> 44 /// Aloittaa pelin 45 /// </summary> 38 46 protected override void Begin() 39 47 { 40 48 LataaKentta(kentannro); 49 } 50 51 /// <summary> 52 /// Päivityssilmukka, hoitaa tällä hetkellä manuaalisesti vain 53 /// taustan liikuttamisen 54 /// </summary> 55 /// <param name="time"></param> 56 protected override void Update(Time time) 57 { 58 if (tahdet != null) 59 { 60 for (int i = 0; i < tahdet.Length; i++) 61 { 62 tahdet[i].Y -= 30; 63 if (tahdet[i].Y < Level.Bottom - 40) tahdet[i].Y = Level.Top + 100; 64 } 65 } 66 67 base.Update(time); 41 68 } 42 69 … … 55 82 56 83 Camera.Move(new Vector(250, 0)); 57 84 //Camera.Zoom(0.2); 85 58 86 //Laidat 59 87 LisaData tieto; … … 61 89 tieto.Rajahtaa = true; 62 90 tieto.Damage = 5; 91 92 PhysicsObject[] kulmat = new PhysicsObject[4]; 93 94 for (int i = 0; i < kulmat.Length; i++) 95 { 96 kulmat[i] = PhysicsObject.CreateStaticObject(60, 60); 97 kulmat[i].Image = LoadImage("seina/seinaKulma"); 98 kulmat[i].Tag = tieto; 99 kulmat[i].Angle = Angle.Degrees(i * 90); 100 Add(kulmat[i]); 101 } 102 kulmat[3].Position = new Vector(Level.Left - 30, Level.Top+30); 103 kulmat[2].Position = new Vector(Level.Right + 30, Level.Top + 30); 104 kulmat[0].Position = new Vector(Level.Left - 30, Level.Bottom - 30); 105 kulmat[1].Position = new Vector(Level.Right + 30, Level.Bottom - 30); 106 107 108 //Seinät 109 Level.BackgroundColor = Color.Black; 63 110 vasenLaita = Level.CreateLeftBorder(); 111 vasenLaita.Image = LoadImage("seina/seinaOikea"); 112 vasenLaita.Angle = Angle.Degrees(270); 113 64 114 vasenLaita.Tag = tieto; 65 115 oikeaLaita = Level.CreateRightBorder(); 116 oikeaLaita.Image = LoadImage("seina/seinaOikea"); 117 oikeaLaita.Angle = Angle.Degrees(90); 118 66 119 oikeaLaita.Tag = tieto; 67 120 pohja = Level.CreateBottomBorder(); 121 pohja.Image = LoadImage("seina/seinaOikea"); 122 pohja.Angle = Angle.Degrees(0); 123 pohja.Size = new Vector(pohja.Width - 120, pohja.Height); 124 68 125 pohja.Tag = tieto; 69 126 katto = Level.CreateTopBorder(); 127 katto.Image = LoadImage("seina/seinaOikea"); 128 katto.Angle = Angle.Degrees(180); 129 katto.Size = new Vector(katto.Width - 120, katto.Height); 130 70 131 katto.Tag = tieto; 71 132 … … 74 135 exitZone.Position = new Vector(Level.Center.X, Level.Bottom - exitZone.Size.Y / 2 - 5); 75 136 exitZone.Tag = tieto; 137 exitZone.IsVisible = false; 76 138 Add(exitZone); 77 139 140 78 141 LuoPelaaja(); 142 LataaHUD(); 79 143 LataaKontrollit(pelaajaAlus); 80 //LataaTausta(kentanNumero);144 LataaTausta(kentanNumero); 81 145 LataaViholliset(20, 4,10); 82 LataaHUD();146 83 147 } 84 148 … … 88 152 void LataaHUD() 89 153 { 90 ValueDisplay hpNaytto = new ValueDisplay(); 91 hpNaytto.BindTo(pelaajaAlus.HpMeter); 92 Add(hpNaytto); 93 hpNaytto.Position = new Vector(Level.Right + 40, Level.Top - 80); 94 hpNaytto.Text = "HP: "; 95 96 ValueDisplay scoreNaytto = new ValueDisplay(); 97 scoreNaytto.BindTo(score); 98 Add(scoreNaytto); 99 scoreNaytto.Position = new Vector(Level.Right + 40, Level.Top - 100); 100 scoreNaytto.Text = "SCORE: "; 101 154 ValueDisplay[] naytot = new ValueDisplay[3]; 155 for (int i = 0; i < naytot.Length; i++) 156 { 157 naytot[i] = new ValueDisplay(); 158 Add(naytot[i]); 159 naytot[i].TextColor = Color.White; 160 naytot[i].ValueColor = Color.Yellow; 161 naytot[i].Position = new Vector(Level.Right + 40, Level.Top - 80 - (30*i)); 162 } 163 164 naytot[0].BindTo(pelaajaAlus.HpMeter); 165 naytot[1].BindTo(score); 166 naytot[2].BindTo(lives); 167 naytot[0].Text = "HP: "; 168 naytot[1].Text = "SCORE: "; 169 naytot[2].Text = "LIVES: "; 170 171 aseNimet = new TextDisplay[3]; 172 for (int i = 0; i < aseNimet.Length; i++) 173 { 174 aseNimet[i] = new TextDisplay(); 175 aseNimet[i].TextColor = Color.White; 176 aseNimet[i].Position = new Vector(Level.Right + 40, Level.Top - 200 - (30 * i)); 177 Add(aseNimet[i]); 178 } 179 aseNimet[OLETUSASE].TextColor = Color.Yellow; 180 aseNimet[0].Text = "Beam"; 181 aseNimet[1].Text = "Missile"; 182 aseNimet[2].Text = "Photon"; 183 184 } 185 186 /// <summary> 187 /// Lataa taustalle tähdet 188 /// </summary> 189 /// <param name="kentanNumero"></param> 190 void LataaTausta(int kentanNumero) 191 { 192 tahdet = new GameObject[15]; 193 for (int i = 0; i < tahdet.Length; i++) 194 { 195 GameObject tahti = new GameObject(3, 3); 196 tahti.Color = Color.White; 197 tahti.Position = new Vector(RandomGen.NextDouble(Level.Left, Level.Right), 198 RandomGen.NextDouble(Level.Top +20, Level.Top + 2000)); 199 tahdet[i] = tahti; 200 201 Add(tahti); 202 } 102 203 } 103 204 … … 140 241 for (int i = 0; i < weapons.Length; i++) 141 242 { 243 weapons[i].IsVisible = false; 142 244 pelaajaAlus.Add(weapons[i]); 143 245 } 144 246 145 247 Add(pelaajaAlus); 146 pelaajaAlus.SetWeapon(weapons[ 2]);248 pelaajaAlus.SetWeapon(weapons[OLETUSASE]); 147 249 148 250 AddCollisionHandler(pelaajaAlus, PelaajaTormaa); 149 150 251 } 151 252 … … 193 294 { 194 295 if (aseenNumero > 0 && aseenNumero < 4) 195 pelaajaAlus.SetWeapon(weapons[aseenNumero-1]); 296 { 297 pelaajaAlus.SetWeapon(weapons[aseenNumero-1]); 298 for (int i = 0; i < aseNimet.Length; i++) 299 { 300 aseNimet[i].TextColor = Color.White; 301 } 302 aseNimet[aseenNumero-1].TextColor = Color.Yellow; 303 } 196 304 } 197 305 … … 262 370 Timer ampumaAjastin = new Timer(); 263 371 ampumaAjastin.Interval = 0.7; 264 ampumaAjastin.Trigger += alukset[0]. TimerShoot;372 ampumaAjastin.Trigger += alukset[0].Shoot; 265 373 Add(ampumaAjastin); 266 374 ampumaAjastin.Start();
Note: See TracChangeset
for help on using the changeset viewer.