1 | #region Usings |
---|
2 | using System; |
---|
3 | using System.Collections.Generic; |
---|
4 | using System.Linq; |
---|
5 | using Microsoft.Xna.Framework; |
---|
6 | using Microsoft.Xna.Framework.Audio; |
---|
7 | using Microsoft.Xna.Framework.Content; |
---|
8 | using Microsoft.Xna.Framework.Graphics; |
---|
9 | using Microsoft.Xna.Framework.Input; |
---|
10 | using Microsoft.Xna.Framework.Media; |
---|
11 | using Jypeli; |
---|
12 | using Jypeli.ScreenObjects; |
---|
13 | using Jypeli.Assets; |
---|
14 | using AdvanceMath; |
---|
15 | using Physics2DDotNet; |
---|
16 | using Physics2DDotNet.Shapes; |
---|
17 | #endregion |
---|
18 | |
---|
19 | namespace pengJ |
---|
20 | { |
---|
21 | public class Peli : PhysicsGame |
---|
22 | { |
---|
23 | Tank tankki; |
---|
24 | |
---|
25 | protected override void LoadContent() |
---|
26 | { |
---|
27 | // Luodaan tankki ja lisätään se peliin |
---|
28 | tankki = new Tank(this, "tankki"); |
---|
29 | Level.Objects.Add(tankki); |
---|
30 | |
---|
31 | // Luodaan maasto |
---|
32 | Level.CreateGround(10, 50, 20, Color.LightGreen); |
---|
33 | |
---|
34 | // Luodaan reunat |
---|
35 | Level.CreateBorder(); |
---|
36 | |
---|
37 | // Asemoidaan tankki |
---|
38 | tankki.Y = Level.Bottom + 100; |
---|
39 | |
---|
40 | // Asetetaan painovoima |
---|
41 | Gravity = new Vector2D(0, -200); |
---|
42 | |
---|
43 | // Asetetaan näppäimet |
---|
44 | Controls.Listen(Keys.Left, ButtonPosition.Down, aja, "Liiku vasemmalle", tankki, Tank.MaxTorque / 2); |
---|
45 | Controls.Listen(Keys.Right, ButtonPosition.Down, aja, "Liiku oikealle", tankki, -Tank.MaxTorque / 2); |
---|
46 | Controls.Listen(Keys.Up, ButtonPosition.Down, kaannaPutkea, "Käännä putkea vastapäivään", tankki, Angle.Degrees(1)); |
---|
47 | Controls.Listen(Keys.Down, ButtonPosition.Down, kaannaPutkea, "Käännä putkea myötäpäivään", tankki, Angle.Degrees(-1)); |
---|
48 | } |
---|
49 | |
---|
50 | bool aja(ControlEvent e) |
---|
51 | { |
---|
52 | Tank t = e.Parameter0 as Tank; |
---|
53 | double vaanto = e.Parameter1.ToDouble(); |
---|
54 | |
---|
55 | // Kiihdytetään tankin vauhtia; |
---|
56 | t.Accelerate(vaanto); |
---|
57 | |
---|
58 | |
---|
59 | } |
---|
60 | |
---|
61 | |
---|
62 | |
---|
63 | |
---|
64 | } |
---|
65 | } |
---|