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 olioharjoituksia |
---|
20 | { |
---|
21 | public class Peli : PhysicsGame |
---|
22 | { |
---|
23 | Tank tankki; |
---|
24 | CannonBall kuula1; |
---|
25 | CannonBall kuula2; |
---|
26 | |
---|
27 | protected override void LoadContent() |
---|
28 | { |
---|
29 | kuula1 = new CannonBall(150, 20); |
---|
30 | Level.Objects.Add(kuula1); |
---|
31 | kuula1.X = 0; |
---|
32 | kuula1.Y = 100; |
---|
33 | |
---|
34 | kuula2 = new CannonBall(1, 20); |
---|
35 | Level.Objects.Add(kuula2); |
---|
36 | kuula2.X = 200; |
---|
37 | kuula2.Y = 100; |
---|
38 | |
---|
39 | // Luodaan tankki ja lisätään se peliin |
---|
40 | tankki = new Tank(this, "tankki"); |
---|
41 | Level.Objects.Add(tankki); |
---|
42 | |
---|
43 | // Luodaan maasto |
---|
44 | Level.CreateGround(100, 50, 20, Color.LightGreen); |
---|
45 | |
---|
46 | // Luodaan reunat |
---|
47 | Level.CreateBorder(); |
---|
48 | |
---|
49 | // Asemoidaan tankki |
---|
50 | tankki.Y = Level.Bottom + 100; |
---|
51 | |
---|
52 | // Asetetaan painovoima |
---|
53 | Gravity = new Vector2D(0, -200); |
---|
54 | |
---|
55 | // Asetetaan näppäimet |
---|
56 | Controls.Listen(Keys.Left, ButtonPosition.Down, aja, "Liiku vasemmalle", tankki, Tank.MaxTorque / 2); |
---|
57 | Controls.Listen(Keys.Right, ButtonPosition.Down, aja, "Liiku oikealle", tankki, -Tank.MaxTorque / 2); |
---|
58 | Controls.Listen(Keys.Up, ButtonPosition.Down, kaannaPutkea, "Käännä putkea vastapäivään", tankki, Angle.Degrees(1)); |
---|
59 | Controls.Listen(Keys.Down, ButtonPosition.Down, kaannaPutkea, "Käännä putkea myötäpäivään", tankki, Angle.Degrees(-1)); |
---|
60 | } |
---|
61 | |
---|
62 | bool aja(ControlEvent e) |
---|
63 | { |
---|
64 | Tank t = e.Parameter0 as Tank; |
---|
65 | double vaanto = e.Parameter1.ToDouble(); |
---|
66 | |
---|
67 | // Kiihdytetään tankin vauhtia |
---|
68 | t.Accelerate(vaanto); |
---|
69 | |
---|
70 | return false; |
---|
71 | } |
---|
72 | |
---|
73 | bool kaannaPutkea(ControlEvent e) |
---|
74 | { |
---|
75 | Tank t = e.Parameter0 as Tank; |
---|
76 | Angle kaanto = e.Parameter1.ToAngle(); |
---|
77 | |
---|
78 | // Tässä käännetään tankin piippua |
---|
79 | t.TurnCannon(kaanto); |
---|
80 | |
---|
81 | return false; |
---|
82 | } |
---|
83 | } |
---|
84 | } |
---|