- Timestamp:
- 2013-06-26 14:50:45 (9 years ago)
- Location:
- 2013/26/ChristianS/Testi/Testi
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
2013/26/ChristianS/Testi/Testi/Testi/Testi.cs
r4228 r4234 9 9 public class Testi : PhysicsGame 10 10 { 11 AssaultRifle rambonAse; 12 11 13 const double nopeus = 300; 12 14 const double hyppyNopeus = 850; 13 15 const int RUUDUN_KOKO = 50; 14 16 15 PhysicsObject pelaaja; 16 17 Image pelaajanKuva = LoadImage("norsu"); 17 Pelaaja pelaaja; 18 19 20 Image pelaajanKuva = LoadImage("rambo"); 18 21 Image tahtiKuva = LoadImage("tahti"); 19 22 20 SoundEffect maaliAani = LoadSoundEffect("maali");21 22 23 public override void Begin() 23 24 { 24 25 Mouse.IsCursorVisible = true; 25 26 LuoKentta(); 26 27 LisaaNappaimet(); 27 28 28 29 Camera.Follow(pelaaja); 29 Camera.ZoomToLevel(); 30 //Camera.ZoomFactor = 1.2; 31 //Camera.StayInLevel = true; 30 Camera.ZoomFactor = 0.7; 31 Camera.StayInLevel = true; 32 33 int laskuri = 0; 34 35 while (laskuri < 25) 36 { 37 LuoSatunnainenPallo(Color.Green, "pahis"); 38 laskuri++; 39 } 40 Timer ajastin = new Timer(); 41 ajastin.Interval = 2; 42 ajastin.Timeout += delegate { LuoSatunnainenPallo(Color.Green, "pahis"); }; 43 ajastin.Start(); 32 44 } 33 45 … … 38 50 ruudut.SetTileMethod(Color.Black, LuoTaso); 39 51 ruudut.SetTileMethod(Color.Yellow, LuoTahti); 40 ruudut.Execute(5 0, 50);52 ruudut.Execute(55, 55); 41 53 Level.CreateBorders(); 42 54 Level.Background.CreateGradient(Color.White, Color.SkyBlue); 55 56 } 57 58 private void LuoSatunnainenPallo(Color vari, String tagi) 59 { 60 double x = RandomGen.NextDouble(Level.Left, Level.Right); 61 double y = RandomGen.NextDouble(Level.Bottom, Level.Top); 62 double r = RandomGen.NextDouble(10, 50); 63 // Color vari = RandomGen.NextColor(); 64 LuoMuoto(Shape.Circle, x, y, r, vari, tagi); 43 65 } 44 66 … … 64 86 void LuoPelaaja(Vector paikka, double leveys, double korkeus) 65 87 { 66 pelaaja = new PhysicsObject(45, 45); 88 pelaaja = new Pelaaja(50, 50); 89 //pelaaja.MakeStatic(); 90 pelaaja.CanRotate = false; 67 91 pelaaja.Position = paikka; 68 92 pelaaja.Image = pelaajanKuva; 69 pelaaja.Tag = "norsu"; 93 pelaaja.CollisionIgnoreGroup = 2; 94 // pelaaja.LinearDamping = 0.95; 95 pelaaja.Tag = "rambo"; 70 96 AddCollisionHandler(pelaaja, "tahti", TormaaTahteen); 97 AddCollisionHandler(pelaaja, "tahti", CollisionHandler.AddMeterValue(pelaaja.ElamaLaskuri, 2)); 98 rambonAse = new AssaultRifle(30, 10); 99 rambonAse.Ammo.Value = 1250; 100 rambonAse.FireRate = 8; 101 rambonAse.ProjectileCollision = AmmusOsui; 102 pelaaja.Add(rambonAse); 103 AddCollisionHandler(pelaaja, "pahis", delegate(PhysicsObject tormaaja, PhysicsObject kohde) { LuoSatunnainenPallo(Color.Green, "pahis"); }); 104 AddCollisionHandler(pelaaja, PelaajaTormasi); 71 105 Add(pelaaja); 106 107 pelaaja.ElamaLaskuri.LowerLimit += Kuolit; 108 109 ProgressBar elamaPalkki = new ProgressBar(150, 20); 110 elamaPalkki.X = Screen.Left + 150; 111 elamaPalkki.Y = Screen.Top - 20; 112 elamaPalkki.BindTo(pelaaja.ElamaLaskuri); 113 Add(elamaPalkki); 114 } 115 116 void Kuolit() 117 { 118 MessageDisplay.Add("Zombi söi sinut!"); 119 pelaaja.Destroy(); 72 120 } 73 121 … … 76 124 Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet"); 77 125 Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 78 Vector nopeus = new Vector(100, 0); 79 80 81 Keyboard.Listen(Key.Left, ButtonState.Down, Liikuta, "Liikkuu vasemmalle", pelaaja, -nopeus); 82 Keyboard.Listen(Key.Left, ButtonState.Released, Liikuta, "Liikkuu vasemmalle", pelaaja, Vector.Zero); 83 Keyboard.Listen(Key.Up, ButtonState.Released, Liikuta, "Liikkuu eteen", pelaaja, Vector.Zero); 84 Keyboard.Listen(Key.Right, ButtonState.Down, Liikuta, "Liikkuu vasemmalle", pelaaja, nopeus); 85 Keyboard.Listen(Key.Right, ButtonState.Released, Liikuta, "Liikkuu oikealle", pelaaja, Vector.Zero); 86 Keyboard.Listen(Key.Up, ButtonState.Down, Liikuta, "Liikkuu eteen", pelaaja, new Vector(0,100)); 87 Keyboard.Listen(Key.Down, ButtonState.Down, Liikuta, "Liikkuu taakse", pelaaja, new Vector(0, -100)); 88 Keyboard.Listen(Key.Down, ButtonState.Released, Liikuta, "Liikkuu taakse", pelaaja, Vector.Zero); 89 90 PhoneBackButton.Listen(ConfirmExit, "Lopeta peli"); 91 } 126 Vector nopeusX = new Vector(150, 0); 127 Vector nopeusYlos = new Vector(0, 150); 128 Vector nopeusAlas = new Vector(0, -135); 129 130 Mouse.ListenMovement(0.1, KuunteleHiirenLiiketta, null); 131 132 Keyboard.Listen(Key.D, ButtonState.Pressed, Liikuta, "Liikkuu oikealle", pelaaja, nopeusX); 133 Keyboard.Listen(Key.D, ButtonState.Released, Liikuta, "Liikkuu oikealle", pelaaja, new Vector(-nopeusX.X, pelaaja.Velocity.Y)); 134 Keyboard.Listen(Key.A, ButtonState.Pressed, Liikuta, "Liikkuu vasemmalle", pelaaja, -nopeusX); 135 Keyboard.Listen(Key.A, ButtonState.Released, Liikuta, "Liikkuu vasemmalle", pelaaja, new Vector(nopeusX.X, pelaaja.Velocity.Y)); 136 Keyboard.Listen(Key.W, ButtonState.Pressed, Liikuta, "Liikkuu eteen", pelaaja, nopeusYlos); 137 Keyboard.Listen(Key.W, ButtonState.Released, Liikuta, "Liikkuu eteen", pelaaja, new Vector(pelaaja.Velocity.X, -nopeusYlos.Y)); 138 Keyboard.Listen(Key.S, ButtonState.Pressed, Liikuta, "Liikkuu taakse", pelaaja, nopeusAlas); 139 Keyboard.Listen(Key.S, ButtonState.Released, Liikuta, "Liikkuu taakse", pelaaja, new Vector(pelaaja.Velocity.X, -nopeusAlas.Y)); 140 Mouse.Listen(MouseButton.Left, ButtonState.Down, AmmuAseella, "Ammu", rambonAse); 141 142 } 143 144 void KuunteleHiirenLiiketta(AnalogState a) 145 { 146 Vector suunta = (Mouse.PositionOnWorld - rambonAse.AbsolutePosition).Normalize(); 147 rambonAse.Angle = suunta.Angle; 148 } 149 92 150 93 151 void Liikuta(PhysicsObject hahmo, Vector nopeus) 94 152 { 95 hahmo.Velocity = nopeus;153 hahmo.Velocity += nopeus; 96 154 } 97 155 98 156 void TormaaTahteen(PhysicsObject hahmo, PhysicsObject tahti) 99 157 { 100 maaliAani.Play();101 158 MessageDisplay.Add("Keräsit tähden!"); 102 159 tahti.Destroy(); 103 160 } 161 void AmmusOsui(PhysicsObject ammus, PhysicsObject kohde) 162 { 163 ammus.Destroy(); 164 if (kohde.Tag.Equals("pahis")) 165 { 166 kohde.Destroy(); 167 } 168 } 169 void AmmuAseella(AssaultRifle ase) 170 { 171 PhysicsObject ammus = ase.Shoot(); 172 173 if (ammus != null) 174 { 175 ammus.CollisionIgnoreGroup = pelaaja.CollisionIgnoreGroup; 176 ammus.Size *= 3; 177 //ammus.Image = ... 178 ammus.LifetimeLeft = TimeSpan.FromSeconds(5.0); 179 } 180 } 181 void LuoMuoto(Shape muoto, double x, double y, double sade, Color vari, String tagi) 182 { 183 PhysicsObject olio = new PhysicsObject(sade, sade); 184 olio.Shape = muoto; 185 olio.Color = vari; 186 olio.Restitution = 1.0; 187 olio.Y = y; 188 olio.X = x; 189 olio.Tag = tagi; 190 olio.Hit(RandomGen.NextVector(10, 100)); 191 Add(olio); 192 } 193 void PelaajaTormasi(PhysicsObject tormaaja, PhysicsObject kohde) 194 { 195 if (kohde.Tag.Equals("pahis")) 196 { 197 //Tässä vähennetään elämää esim elamat.Value -= 5; 198 if (tormaaja is Pelaaja) 199 { 200 ((Pelaaja)tormaaja).ElamaLaskuri.Value -= 2; 201 } 202 } 203 204 } 104 205 } 206 207 class Pelaaja : PhysicsObject 208 { 209 private IntMeter elamaLaskuri = new IntMeter(10, 0, 16); 210 public IntMeter ElamaLaskuri { get { return elamaLaskuri; } } 211 212 public Pelaaja(double leveys, double korkeus) 213 : base(leveys, korkeus) 214 { 215 216 } 217 } -
2013/26/ChristianS/Testi/Testi/TestiContent/TestiContent.contentproj
r4228 r4234 46 46 </ItemGroup> 47 47 <ItemGroup> 48 <Compile Include="maali.wav">49 <Name>maali</Name>50 <Importer>WavImporter</Importer>51 <Processor>SoundEffectProcessor</Processor>52 </Compile>53 48 <Compile Include="norsu.png"> 54 49 <Name>norsu</Name> … … 61 56 <Processor>TextureProcessor</Processor> 62 57 </Compile> 63 <Compile Include="kentta1vanha.txt">64 <Name>kentta1vanha</Name>65 <Importer>TextFileImporter</Importer>66 <Processor>TextFileContentProcessor</Processor>67 </Compile>68 58 </ItemGroup> 69 59 <ItemGroup> 70 60 <Compile Include="kentta1.png"> 71 61 <Name>kentta1</Name> 62 <Importer>TextureImporter</Importer> 63 <Processor>TextureProcessor</Processor> 64 </Compile> 65 </ItemGroup> 66 <ItemGroup> 67 <Compile Include="rambo.png"> 68 <Name>rambo</Name> 72 69 <Importer>TextureImporter</Importer> 73 70 <Processor>TextureProcessor</Processor>
Note: See TracChangeset
for help on using the changeset viewer.