Changeset 3748 for 2012/30/OtsoR/Projekti/Projekti/Projekti/Projekti.cs
- Timestamp:
- 2012-07-25 15:00:24 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
2012/30/OtsoR/Projekti/Projekti/Projekti/Projekti.cs
r3719 r3748 9 9 public class Projekti : PhysicsGame 10 10 { 11 PhysicsObject alus; 12 13 AssaultRifle luoti; 14 PlasmaCannon plasma; 15 LaserGun laser; 16 Grenade miina1; 17 ClusterGrenade miina2; 18 19 Vector nopeusYlos = new Vector(0, 600); 20 Vector nopeusAlas = new Vector(0, -600); 21 Vector nopeusVasen = new Vector(-600, 0); 22 Vector nopeusOikea = new Vector(600, 0); 11 Image shipimage = LoadImage("ship1"); 12 Image shipimage2 = LoadImage("ship2"); 13 14 PhysicsObject ship; 15 Weapon weapon; 16 17 PhysicsObject ship2; 18 Weapon weapon2; 23 19 24 20 public override void Begin() 25 21 { 22 MultiSelectWindow numberofplayersmenu = new MultiSelectWindow("", "Singleplayer", "Multiplayer/Co-op"); 23 numberofplayersmenu.ItemSelected += playeramount; 24 Add(numberofplayersmenu); 25 } 26 void playeramount(int choice) 27 { 28 switch (choice) 29 { 30 case 0: 31 LuoAlus(); 32 break; 33 case 1: 34 35 break; 36 } 37 } 38 void LuoAlus() 39 { 40 ship = new PhysicsObject(16, 16, Shape.FromImage(shipimage)); 41 ship.Image = shipimage; 42 ship.X = -50; 43 ship.Y = 0; 44 ship.Restitution = 1.0; 45 ship.KineticFriction = 0.0; 46 ship.MomentOfInertia = Double.PositiveInfinity; 47 ship.LinearDamping = 0.95; 48 ship.AngularDamping = 0.95; 49 Add(ship); 50 } 51 void Aloitapeli() 52 { 26 53 CreateWorld(); 54 shipimage.ReplaceColor(Color.White, Color.Ruby); 55 shipimage.ReplaceColor(Color.Black, Color.DarkGray); 56 shipimage2.ReplaceColor(Color.White, Color.Silver); 57 shipimage2.ReplaceColor(Color.Black, Color.Azure); 27 58 AsetaOhjaimet(); 28 59 Level.BackgroundColor = Color.Black; 29 60 Mouse.IsCursorVisible = true; 30 Camera.Follow(alus);31 //Camera.ZoomToLevel();61 //Camera.Follow(ship); 62 Camera.ZoomToLevel(); 32 63 Level.CreateBorders(); 33 64 } 34 65 void CreateWorld() 35 { 36 alus = new PhysicsObject(25, 45); 37 alus.Shape = Shape.Pentagon; 38 alus.Color = Color.Green; 39 alus.X = 0; 40 alus.Y = 0; 41 alus.Restitution = 1.0; 42 alus.KineticFriction = 0.0; 43 alus.MomentOfInertia = Double.PositiveInfinity; 44 alus.LinearDamping = 0.95; 45 Add(alus); 66 { 67 MultiSelectWindow menu = new MultiSelectWindow("Choose a weapon type", 68 "Projectiles", "Laser", "Plasma"); 69 menu.ItemSelected += choice2; 70 Add(menu); 71 MultiSelectWindow menu2 = new MultiSelectWindow("Choose weapon type", "Projectiles", "Laser", "Plasma"); 72 menu2.ItemSelected += playeramount; 73 Add(menu2); 46 74 47 luoti = new AssaultRifle(0, 0); 48 alus.Add(luoti); 75 ship2 = new PhysicsObject(16, 16, Shape.FromImage(shipimage2)); 76 ship2.Image = shipimage2; 77 ship2.X = 50; 78 ship2.Y = 0; 79 ship2.Restitution = 1.0; 80 ship2.KineticFriction = 0.0; 81 ship2.MomentOfInertia = Double.PositiveInfinity; 82 ship2.LinearDamping = 0.95; 83 ship2.AngularDamping = 0.95; 84 Add(ship2); 49 85 } 50 void AsetaOhjaimet()86 void choice(int choice) 51 87 { 52 Keyboard.Listen(Key.W, ButtonState.Down, liikuta, "Lopeta peli", nopeusYlos); 53 Keyboard.Listen(Key.S, ButtonState.Down, liikuta, "Lopeta peli", nopeusAlas); 54 Keyboard.Listen(Key.A, ButtonState.Down, liikuta, "Lopeta peli", nopeusVasen); 55 Keyboard.Listen(Key.D, ButtonState.Down, liikuta, "Lopeta peli", nopeusOikea); 56 57 Mouse.ListenMovement(0, katse, "Tähtää"); 58 Keyboard.Listen(Key.Space, ButtonState.Down, Ammu, "Ammu", luoti); 59 60 PhoneBackButton.Listen(ConfirmExit, "Lopeta peli"); 61 Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 88 switch (choice) 89 { 90 case 0: 91 weapon = new AssaultRifle(0, 0); 92 weapon.ProjectileCollision = weaponhit; 93 ship.Add(weapon); 94 break; 95 case 1: 96 weapon = new LaserGun(0, 0); 97 weapon.ProjectileCollision = weaponhit; 98 weapon.Power.Value = 5000; 99 weapon.FireRate = 1.0; 100 ship.Add(weapon); 101 break; 102 case 2: 103 weapon = new PlasmaCannon(0, 0); 104 weapon.ProjectileCollision = weaponhit; 105 ship.Add(weapon); 106 break; 107 } 108 Keyboard.Listen(Key.Space, ButtonState.Down, fire, "Ammu", weapon); 62 109 } 63 void Ammu(AssaultRifle luoti)110 void choice2(int choice) 64 111 { 65 PhysicsObject ammus = luoti.Shoot(); 112 switch (choice) 113 { 114 case 0: 115 weapon2 = new AssaultRifle(0, 0); 116 weapon2.ProjectileCollision = weaponhit; 117 weapon2.Power.Value = 5000; 118 weapon2.FireRate = 4.5; 119 ship2.Add(weapon2); 120 break; 121 case 1: 122 weapon2 = new LaserGun(0, 0); 123 weapon2.ProjectileCollision = weaponhit; 124 weapon2.Power.Value = 100000; 125 weapon2.FireRate = 1.5; 126 ship2.Add(weapon2); 127 break; 128 case 2: 129 weapon2 = new PlasmaCannon(0, 0); 130 weapon2.ProjectileCollision = weaponhit; 131 ship2.Add(weapon2); 132 break; 133 } 134 Keyboard.Listen(Key.Space, ButtonState.Down, fire, "Ammu", weapon2); 135 } 136 void fire(Weapon ase) 137 { 138 PhysicsObject ammus = ase.Shoot(); 66 139 67 140 if (ammus != null) … … 72 145 } 73 146 } 74 void liikuta(Vector suunta)147 void weaponhit(PhysicsObject ammus, PhysicsObject kohde) 75 148 { 76 a lus.Push(suunta);149 ammus.Destroy(); 77 150 } 78 void katse(AnalogState hiirenLiike)151 void AsetaOhjaimet() 79 152 { 80 Vector suunta = (Mouse.PositionOnWorld - alus.AbsolutePosition).Normalize(); 81 alus.Angle = suunta.Angle; 153 Keyboard.Listen(Key.W, ButtonState.Down, thrust, "", 1.0, ship); 154 Keyboard.Listen(Key.S, ButtonState.Down, thrust, "", -1.0, ship); 155 Keyboard.Listen(Key.A, ButtonState.Down, tilt, "", 1.0, ship); 156 Keyboard.Listen(Key.D, ButtonState.Down, tilt, "", -1.0, ship); 157 158 Keyboard.Listen(Key.NumPad8, ButtonState.Down, thrust, "", 1.0, ship2); 159 Keyboard.Listen(Key.NumPad5, ButtonState.Down, thrust, "", -1.0, ship2); 160 Keyboard.Listen(Key.NumPad4, ButtonState.Down, tilt, "", 1.0, ship2); 161 Keyboard.Listen(Key.NumPad6, ButtonState.Down, tilt, "", -1.0, ship2); 162 163 //Keyboard.Listen(Key., ButtonState.Down, Ammu, "Ammu", luoti); 164 165 PhoneBackButton.Listen(ConfirmExit, "Lopeta peli"); 166 Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 167 } 168 void thrust(double direction, PhysicsObject ship) 169 { 170 Vector shipdirection = Vector.FromLengthAndAngle(100.0*direction, ship.Angle); 171 ship.Push(shipdirection); 172 } 173 void tilt(double direction, PhysicsObject ship) 174 { 175 ship.AngularAcceleration = 10.0*direction; 82 176 } 83 177 }
Note: See TracChangeset
for help on using the changeset viewer.