1 | using System; |
---|
2 | using System.Collections.Generic; |
---|
3 | using Jypeli; |
---|
4 | using Jypeli.Assets; |
---|
5 | using Jypeli.Controls; |
---|
6 | using Jypeli.Effects; |
---|
7 | using Jypeli.Widgets; |
---|
8 | |
---|
9 | class CrisisFire : PhysicsGame |
---|
10 | { |
---|
11 | Vector VelocityUp = new Vector(0.0, 250.0); |
---|
12 | Vector FocusedVelocityUp = new Vector(0.0, 125.0); |
---|
13 | Vector VelocityDown = new Vector(0.0, -250.0); |
---|
14 | Vector FocusedVelocityDown = new Vector(0.0, -125.0); |
---|
15 | Vector VelocityLeft = new Vector(-250.0, 0.0); |
---|
16 | Vector FocusedVelocityLeft = new Vector(-125.0, 0.0); |
---|
17 | Vector VelocityRight = new Vector(250.0, 0.0); |
---|
18 | Vector FocusedVelocityRight = new Vector(125.0, 0.0); |
---|
19 | PhysicsObject Player; |
---|
20 | PhysicsObject SmallEnemy; |
---|
21 | PhysicsObject Enemy; |
---|
22 | PhysicsObject LargeEnemy; |
---|
23 | PhysicsObject Boss; |
---|
24 | PhysicsObject BorderTop; |
---|
25 | PhysicsObject BorderBottom; |
---|
26 | IntMeter PowerGauge; |
---|
27 | |
---|
28 | public override void Begin() |
---|
29 | { |
---|
30 | Field(); |
---|
31 | SetControls(); |
---|
32 | CreatePowerGauge(); |
---|
33 | } |
---|
34 | |
---|
35 | void Field() |
---|
36 | { |
---|
37 | Level.CreateBorders(false); |
---|
38 | Level.BackgroundColor = Color.Gray; |
---|
39 | Camera.ZoomToLevel(); |
---|
40 | |
---|
41 | BorderTop = new PhysicsObject(1000.0, 150.0, Shape.Rectangle); |
---|
42 | BorderTop.Y = Screen.Top - 150.0; |
---|
43 | BorderTop.X = 0.0; |
---|
44 | BorderTop.Color = Color.Black; |
---|
45 | BorderTop.Restitution = 0.0; |
---|
46 | BorderTop.Mass = 9999999999999.0; |
---|
47 | Add(BorderTop); |
---|
48 | |
---|
49 | BorderBottom = new PhysicsObject(1000.0, 150.0, Shape.Rectangle); |
---|
50 | BorderBottom.Y = Screen.Bottom + 150.0; |
---|
51 | BorderBottom.X = 0.0; |
---|
52 | BorderBottom.Color = Color.Black; |
---|
53 | BorderBottom.Restitution = 0.0; |
---|
54 | BorderBottom.Mass = 99999999999999.0; |
---|
55 | Add(BorderBottom); |
---|
56 | |
---|
57 | Player = new PhysicsObject(10.0, 10.0, Shape.Circle); |
---|
58 | double massP1 = 10.0; |
---|
59 | Player.Mass = massP1; |
---|
60 | Player.Color = Color.Red; |
---|
61 | Player.X = -400.0; |
---|
62 | Player.Y = 0.0; |
---|
63 | |
---|
64 | Add(Player); |
---|
65 | } |
---|
66 | |
---|
67 | void SetControls() |
---|
68 | { |
---|
69 | // ControllerOne.Listen(Button.A, ButtonState.Pressed, FocusedVelocity, null, Player, null); |
---|
70 | ControllerOne.Listen(Button.DPadUp, ButtonState.Down, SetVelocity, null, Player, VelocityUp); |
---|
71 | ControllerOne.Listen(Button.DPadUp, ButtonState.Released, SetVelocity, null, Player, Vector.Zero); |
---|
72 | ControllerOne.Listen(Button.DPadDown, ButtonState.Down, SetVelocity, null, Player, VelocityDown); |
---|
73 | ControllerOne.Listen(Button.DPadDown, ButtonState.Released, SetVelocity, null, Player, Vector.Zero); |
---|
74 | ControllerOne.Listen(Button.DPadLeft, ButtonState.Down, SetVelocity, null, Player, VelocityLeft); |
---|
75 | ControllerOne.Listen(Button.DPadLeft, ButtonState.Released, SetVelocity, null, Player, Vector.Zero); |
---|
76 | ControllerOne.Listen(Button.DPadRight, ButtonState.Down, SetVelocity, null, Player, VelocityRight); |
---|
77 | ControllerOne.Listen(Button.DPadRight, ButtonState.Released, SetVelocity, null, Player, Vector.Zero); |
---|
78 | ControllerOne.Listen(Button.Back, ButtonState.Pressed, Exit, null); |
---|
79 | ControllerOne.Listen(Button.RightTrigger, ButtonState.Pressed, FirePrimary, null, Player, 10.0, 5.0, Shape.Rectangle); |
---|
80 | ControllerOne.Listen(Button.LeftTrigger, ButtonState.Pressed, FireSecondary, null, Player, 25.0, 10.0, Shape.Diamond); |
---|
81 | } |
---|
82 | |
---|
83 | void FirePrimary(PhysicsObject Player, double ShotWidth, double ShotHeight, Shape ShotShape) |
---|
84 | { |
---|
85 | PhysicsObject Primary1 = new PhysicsObject(ShotWidth, ShotHeight, ShotShape); |
---|
86 | Primary1.X = Player.X + 15; |
---|
87 | Primary1.Y = Player.Y + 5; |
---|
88 | PhysicsObject Primary2 = new PhysicsObject(ShotWidth, ShotHeight, ShotShape); |
---|
89 | Primary2.X = Player.X + 15; |
---|
90 | Primary2.Y = Player.Y - 5; |
---|
91 | Add(Primary1); |
---|
92 | Add(Primary2); |
---|
93 | Primary1.Hit(new Vector(1200.0, 0.0)); |
---|
94 | Primary2.Hit(new Vector(1200.0, 0.0)); |
---|
95 | } |
---|
96 | |
---|
97 | void FireSecondary(PhysicsObject Player, double ShotWidth, double ShotHeight, Shape ShotShape) |
---|
98 | { |
---|
99 | PhysicsObject Secondary = new PhysicsObject(ShotWidth, ShotHeight, ShotShape); |
---|
100 | Secondary.X = Player.X + 15; |
---|
101 | Secondary.Y = Player.Y; |
---|
102 | Add(Secondary); |
---|
103 | Secondary.Hit(new Vector(500.0, 0.0)); |
---|
104 | } |
---|
105 | |
---|
106 | void SetVelocity(PhysicsObject Player, Vector velocity) |
---|
107 | { |
---|
108 | Player.Velocity = velocity; |
---|
109 | } |
---|
110 | |
---|
111 | void CreatePowerGauge() |
---|
112 | { |
---|
113 | PowerGauge = new IntMeter(0); |
---|
114 | |
---|
115 | Label PowerMeter = new Label(); |
---|
116 | PowerMeter.X = Screen.Left + 150; |
---|
117 | PowerMeter.Y = Screen.Top - 100; |
---|
118 | PowerMeter.TextColor = Color.White; |
---|
119 | PowerMeter.Color = Color.Red; |
---|
120 | |
---|
121 | PowerMeter.BindTo(PowerGauge); |
---|
122 | Add(PowerMeter); |
---|
123 | |
---|
124 | Label PowerText = new Label("Power: "); |
---|
125 | PowerText.X = Screen.Left + 100; |
---|
126 | PowerText.Y = Screen.Top - 100; |
---|
127 | PowerText.TextColor = Color.White; |
---|
128 | PowerText.Color = Color.Red; |
---|
129 | Add(PowerText); |
---|
130 | } |
---|
131 | } |
---|
132 | |
---|