- Timestamp:
- 2011-06-29 14:58:47 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
2011/26/LinusV/SFN/SFN-säätöä/SFN-säätöä/SFN-säätöä/Peli.cs
r2237 r2319 6 6 using Jypeli.Effects; 7 7 using Jypeli.Widgets; 8 using Physics2DDotNet.Ignorers; 8 9 9 10 public class Peli : TopDownPhysicsGame 10 11 { 11 12 Automobile kaara; 12 int engine = 100;13 int tires = 100;13 int engine = 5; 14 int tires = 5; 14 15 PushButton new_game, load_game, quit_game; 15 16 Vector goal = new Vector(0,0); 16 17 Image MenuBackround = LoadImage("MenuBackround"); 18 GameObject nuoli; 19 PhysicsObject[] kisat; 20 17 21 public override void Begin() 18 22 { … … 24 28 } 25 29 30 protected override void Update(Time time) 31 { 32 base.Update(time); 33 34 //MessageDisplay.Add("Pitäs toimia"); 35 if (nuoli != null) { 36 nuoli.Position = kaara.Position; 37 nuoli.Angle = (goal - kaara.Position).Angle; 38 } 39 if (goal != new Vector(0, 0) && (goal - kaara.Position).Magnitude < 25) 40 { 41 LuoKisat(); 42 nuoli.Size = Vector.Zero; 43 } 44 45 } 46 26 47 void CreateMenu() 27 48 { 28 29 //Set menu backround 30 Level.Background.Image = MenuBackround; 49 //Set menu backround 50 Level.Background.Image = MenuBackround; 31 51 32 52 //Quit game button 53 33 54 quit_game = new PushButton("Quit game"); 34 55 quit_game.Clicked += new Action(quit_game_Clicked); … … 47 68 new_game.Position = new Vector(20.0, -50.0); 48 69 Add(new_game); 70 49 71 } 50 72 … … 58 80 load_game.Destroy(); 59 81 quit_game.Destroy(); 60 Keyboard.Listen(Key.Escape, ButtonState.Released, Exit, null);61 Window.AllowUserResizing = true;82 //Keyboard.Listen(Key.Escape, ButtonState.Released, Exit, null); 83 //Window.AllowUserResizing = true; 62 84 kaara = new Automobile(100, 50); 63 85 Add(kaara); 86 LuoKisat(); 87 88 89 //Kontrollit 64 90 Mouse.IsCursorVisible = true; 65 91 Keyboard.Listen(Key.Up, ButtonState.Down, kaasu, null); 66 92 Keyboard.Listen(Key.Left, ButtonState.Down, rattiV, null); 67 93 Keyboard.Listen(Key.Right, ButtonState.Down, rattiO, null); 68 Keyboard.Listen(Key.Down, ButtonState.Down, jarru, null);94 Keyboard.Listen(Key.Down, ButtonState.Down, pakki, null); 69 95 Keyboard.Listen(Key.RightControl, ButtonState.Down, jarru, null); 96 97 //Auton kanssa säätöä 70 98 Camera.FollowedObject = kaara; 71 kaara.TopSpeed = engine * 100;72 kaara.Acceleration = engine * 10;73 kaara.KineticFriction = tires * 10;74 kaara.StaticFriction = tires * 10;75 kaara.Maneuverability = Angle.FromDegrees(tires );76 kaara.BrakeDeceleration = tires * 20 ;99 kaara.TopSpeed = engine * 75; 100 kaara.Acceleration = engine * 50; 101 kaara.KineticFriction = 0.999; 102 //kaara.StaticFriction = tires * 10; 103 kaara.Maneuverability = Angle.FromDegrees(tires * 5); 104 kaara.BrakeDeceleration = tires * 200; 77 105 kaara.Image = LoadImage("Sporttinen2"); 78 kaara.X = Level.Left + 50; 79 kaara.MomentOfInertia = 1000; 80 kaara.LinearDamping = 0.99; 81 kaara.Mass = 1000; 106 //kaara.X = Level.Left + 50; 107 kaara.Y = 50; 108 kaara.MomentOfInertia = 10000; 109 kaara.LinearDamping = 0.9999; 110 kaara.Mass = 10000; 82 111 kaara.AngularDamping = 0.95; 112 113 nuoli = new GameObject(0,0); 114 nuoli.Color = Color.Green; 115 nuoli.Shape = Shape.Triangle; 116 nuoli.Tag = "o"; 117 nuoli.Image = LoadImage("juttu"); 118 Add(nuoli); 83 119 84 120 //Kartan lataus … … 87 123 World.SetTileMethod('B', taloB); 88 124 World.SetTileMethod('C', taloC); 89 World.Execute(101,101); 125 World.Execute(150,150); 126 127 AddCollisionHandler(kaara, KasitteleKaaranTormays); 128 } 129 130 void KasitteleKaaranTormays(PhysicsObject kaara, PhysicsObject kohde) 131 { 132 if (kohde.Tag.ToString() == "0") 133 { 134 goal = new Vector(1, 1); 135 nuoli.Size = new Vector(30, 30); 136 nuoli.Angle = goal.Angle + Angle.FromDegrees(180); 137 for (int i = 0; i < kisat.Length; i++) { kisat[i].Destroy(); } 138 } 139 } 140 141 void LuoKisat() 142 { 143 kisat = new PhysicsObject[1]; 144 145 kisat[0] = PhysicsObject.CreateStaticObject(50,50); 146 kisat[0].Shape = Shape.Circle; 147 kisat[0].Color = Color.Blue; 148 kisat[0].X = 0; 149 kisat[0].Y = 200; 150 kisat[0].Tag = "0"; 151 Add(kisat[0]); 90 152 } 91 153 … … 101 163 } 102 164 165 //Kontrollit 103 166 public void kaasu() 104 167 { … … 116 179 { 117 180 if (kaara.Velocity.Magnitude > 1) {kaara.Brake(Time.SinceLastUpdate.TotalSeconds);} 181 } 182 public void pakki() 183 { 184 if (kaara.Velocity.Magnitude > 1) {kaara.Brake(Time.SinceLastUpdate.TotalSeconds);} 185 else if (kaara.Velocity.Magnitude < 1) { kaara.Push(Vector.FromLengthAndAngle(engine,kaara.Angle + Angle.FromDegrees(180))); } 118 186 } 119 187
Note: See TracChangeset
for help on using the changeset viewer.