Changeset 1543 for 2010/30/tekrjant/Seikkailu/Peli.cs
- Timestamp:
- 2010-08-03 09:55:25 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
2010/30/tekrjant/Seikkailu/Peli.cs
r1542 r1543 36 36 const double PelaajanKulmanopeus = 3.0; 37 37 38 List<GameObject> ruohot = new List<GameObject>(); 39 38 40 Timer energiaAmpumisAjastin = new Timer() { Interval = 0.1 }; 39 41 ObjectIgnorer energiaIgnorer = new ObjectIgnorer(); … … 64 66 Timer lyhtyAjastin; 65 67 68 const double ruudunLeveys = 5; 69 const double ruudunKorkeus = 5; 70 71 const int MaanTaso = 0; 72 const int TavaraTaso = 1; 73 const int OtusTaso = 2; 74 66 75 67 76 protected override void Begin() … … 92 101 Level.Height = 20; 93 102 103 TileMap kartta = TileMap.FromFile( "kentat\\luola1.txt" ); 104 kartta['#'] = LuoSeina; 105 kartta['.'] = LuoLattia; 106 kartta['\''] = LuoRuoho; 107 kartta.Insert( ruudunLeveys, ruudunKorkeus ); 108 94 109 Level.AmbientLight = 0.2; 95 110 lyhdynValo = new Light(); … … 103 118 energiaAmpumisAjastin.Trigger += AmmuEnergiaPallo; 104 119 105 double ruohonLeveys = 5;106 double ruohonKorkeus = 5;107 int ruohojaVaakasuunnassa = (int)Math.Ceiling( Level.Width / ruohonLeveys );108 int ruohojaPystysuunnassa = (int)Math.Ceiling( Level.Height / ruohonKorkeus );109 110 for ( int y = 0; y < ruohojaPystysuunnassa; y++ )111 {112 for ( int x = 0; x < ruohojaVaakasuunnassa; x++ )113 {114 GameObject ruoho = new GameObject( ruohonLeveys, ruohonKorkeus );115 ruoho.X = Level.Left + x * ruohonLeveys + ruohonLeveys / 2;116 ruoho.Y = Level.Bottom + y * ruohonKorkeus + ruohonKorkeus / 2;117 ruoho.Image = ruohoTekstuuri;118 Add( ruoho, -2 );119 }120 }121 122 //tuli = new Flames( liekinKuva, 40, Angle.Zero );123 //tuli.MinScale = 0.03;124 //tuli.MaxScale = 0.04;125 //tuli.MinVelocity = 0.01;126 //tuli.MaxVelocity = 0.1;127 //tuli.MinAcceleration = 0.1;128 //tuli.MaxAcceleration = 2;129 //Add( tuli );130 131 120 tuliJaLeimaus = new Lieska( liekinKuva ); 132 121 Add( tuliJaLeimaus ); … … 137 126 PhysicsObject alaSeina = Level.CreateBottomBorder(); 138 127 139 PhysicsObject seina = PhysicsObject.CreateStaticObject( 4, 4, Shapes.Rectangle ); 140 seina.Color = Color.DarkGray; 141 seina.X = Level.Center.X - Level.Width / 4; 142 seina.Y = Level.Center.Y; 143 Add( seina ); 144 145 for ( int i = 0; i < 100; i++ ) 146 { 147 PhysicsObject omena = new PhysicsObject( 0.1, 0.1, Shapes.Circle ); 148 omena.Tag = "ruoka"; 149 omena.IgnoresCollisionResponse = true; 150 omena.X = RandomGen.NextDouble( Level.Left, Level.Right ); 151 omena.Y = RandomGen.NextDouble( Level.Bottom, Level.Top ); 152 omena.Color = Color.Red; 153 Add( omena ); 154 } 128 //for ( int i = 0; i < 100; i++ ) 129 //{ 130 // PhysicsObject omena = new PhysicsObject( 0.1, 0.1, Shapes.Circle ); 131 // omena.Tag = "ruoka"; 132 // omena.IgnoresCollisionResponse = true; 133 // omena.X = RandomGen.NextDouble( Level.Left, Level.Right ); 134 // omena.Y = RandomGen.NextDouble( Level.Bottom, Level.Top ); 135 // omena.Color = Color.Red; 136 // Add( omena, TavaraTaso ); 137 //} 155 138 156 139 Esine taikasauva = new Esine( 0.8, 0.1, Shapes.Rectangle, EsineenTyyppi.TuliSauva ); … … 158 141 taikasauva.X = 2; 159 142 taikasauva.Y = 0; 160 Add( taikasauva, -1);143 Add( taikasauva, TavaraTaso ); 161 144 162 145 Esine energiaSauva = new Esine( 0.8, 0.1, Shapes.Rectangle, EsineenTyyppi.EnergiaSauva ); … … 164 147 energiaSauva.X = -1; 165 148 energiaSauva.Y = -1; 166 Add( energiaSauva, -1);149 Add( energiaSauva, TavaraTaso ); 167 150 168 151 Esine lyhty = new Esine( 0.6, 0.6, Shapes.Circle, EsineenTyyppi.Lyhty ); … … 170 153 lyhty.X = 2; 171 154 lyhty.Y = -1; 172 Add( lyhty, -1);155 Add( lyhty, TavaraTaso ); 173 156 174 157 pelaaja = new PhysicsObject( 0.8, 0.8, Shapes.Circle ); … … 177 160 pelaaja.LinearDamping = 0.96; 178 161 pelaaja.AngularDamping = 0.96; 179 Add( pelaaja );162 Add( pelaaja, OtusTaso ); 180 163 181 164 AddCollisionHandler( pelaaja, PelaajaOsuu ); … … 186 169 pelaaja.Add( suuntaTikku ); 187 170 188 for ( int i = 0; i < 30; i++)171 foreach ( GameObject ruoho in ruohot ) 189 172 { 190 173 Otus otti = LuoOttiainen(); 191 otti.X = RandomGen.NextDouble( Level.Left + 1, Level.Right - 1);192 otti.Y = RandomGen.NextDouble( Level.Bottom + 1, Level.Top - 1);174 otti.X = ruoho.X + RandomGen.NextDouble( -ruudunLeveys / 2, ruudunLeveys / 2 ); 175 otti.Y = ruoho.Y + RandomGen.NextDouble( -ruudunKorkeus / 2, ruudunKorkeus / 2 ); 193 176 } 194 177 … … 197 180 timantti.Y = RandomGen.NextDouble( Level.Bottom, Level.Top ); 198 181 timantti.Image = timantinKuva; 199 Add( timantti, -1);182 Add( timantti, TavaraTaso ); 200 183 201 184 Camera.StayInLevel = true; 185 Camera.ZoomFactor = 50.0; 202 186 Camera.Follow( pelaaja ); 187 } 188 189 GameObject LuoRuoho() 190 { 191 GameObject ruoho = new GameObject( ruudunLeveys, ruudunKorkeus ); 192 ruoho.Image = ruohoTekstuuri; 193 ruohot.Add( ruoho ); 194 return ruoho; 195 } 196 197 GameObject LuoLattia() 198 { 199 GameObject lattia = new GameObject( ruudunLeveys, ruudunKorkeus ); 200 lattia.Color = Color.Brown; 201 return lattia; 202 } 203 204 GameObject LuoSeina() 205 { 206 PhysicsObject seina = PhysicsObject.CreateStaticObject( ruudunLeveys, ruudunKorkeus ); 207 seina.Color = Color.DarkGray; 208 return seina; 203 209 } 204 210 … … 221 227 ottiainen.PalanutKuva = ottiainenPalanutKuva; 222 228 ottiainen.Angle = RandomGen.NextAngle(); 223 Add( ottiainen );229 Add( ottiainen, OtusTaso ); 224 230 return ottiainen; 225 231 } … … 240 246 { 241 247 Keyboard.Listen( Key.Escape, ButtonState.Pressed, Exit, null ); 248 Keyboard.Listen( Key.F11, ButtonState.Pressed, TogglaaValaistusta, null ); 242 249 243 250 Keyboard.Listen( Key.Up, ButtonState.Down, Etene, null ); … … 254 261 255 262 Keyboard.Listen( Key.P, ButtonState.Pressed, Keraa, null ); 263 } 264 265 void TogglaaValaistusta() 266 { 267 if ( Level.AmbientLight < 0.3 ) 268 { 269 Level.AmbientLight = 0.9; 270 } 271 else 272 { 273 Level.AmbientLight = 0.2; 274 } 256 275 } 257 276 … … 297 316 energia.Velocity = suunta * 3; 298 317 energia.Angle = pelaaja.Angle; 299 Add( energia );318 Add( energia, OtusTaso ); 300 319 } 301 320 … … 385 404 liekinSade.Color = Color.Red; 386 405 liekinSade.IsVisible = false; 387 Add( liekinSade );406 Add( liekinSade, OtusTaso ); 388 407 389 408 AddCollisionHandler( liekinSade, LiekkiSadeOsuu );
Note: See TracChangeset
for help on using the changeset viewer.