source: 2012/24/JaakkoL/Crisis Fire/FysiikkaPeli1/FysiikkaPeli1/Peli.cs @ 2908

Revision 2908, 2.8 KB checked in by jaollipa, 9 years ago (diff)
Line 
1using System;
2using System.Collections.Generic;
3using Jypeli;
4using Jypeli.Assets;
5using Jypeli.Controls;
6using Jypeli.Effects;
7using Jypeli.Widgets;
8
9class CrisisFire : PhysicsGame
10{
11    Vector VelocityUp = new Vector(0.0, 250.0);
12    Vector VelocityDown = new Vector(0.0, -250.0);
13    Vector VelocityLeft = new Vector(-250.0, 0.0);
14    Vector VelocityRight = new Vector(250.0, 0.0);
15    PhysicsObject Player;
16    IntMeter PowerGauge;
17
18    public override void Begin()
19    {
20        Field();
21        SetControls();
22    }
23   
24    void Field()
25    {
26        Level.CreateBorders(false);
27        Level.BackgroundColor = Color.DarkGreen;
28        Camera.ZoomToLevel();
29       
30        Player = new PhysicsObject(10.0, 10.0, Shape.Circle);
31        double massP1 = 75.0;
32        Player.Mass = massP1;
33        Player.Color = Color.Red;
34        Player.X = -400.0;
35        Player.Y = 0.0;
36 
37        Add(Player);
38    }
39
40    void SetControls()
41    {
42        ControllerOne.Listen(Button.DPadUp, ButtonState.Down, SetVelocity, null, Player, VelocityUp);
43        ControllerOne.Listen(Button.DPadUp, ButtonState.Released, SetVelocity, null, Player, Vector.Zero);
44        ControllerOne.Listen(Button.DPadDown, ButtonState.Down, SetVelocity, null, Player, VelocityDown);
45        ControllerOne.Listen(Button.DPadDown, ButtonState.Released, SetVelocity, null, Player, Vector.Zero);
46        ControllerOne.Listen(Button.DPadLeft, ButtonState.Down, SetVelocity, null, Player, VelocityLeft);
47        ControllerOne.Listen(Button.DPadLeft, ButtonState.Released, SetVelocity, null, Player, Vector.Zero);
48        ControllerOne.Listen(Button.DPadRight, ButtonState.Down, SetVelocity, null, Player, VelocityRight);
49        ControllerOne.Listen(Button.DPadRight, ButtonState.Released, SetVelocity, null, Player, Vector.Zero);
50        ControllerOne.Listen(Button.Back, ButtonState.Pressed, Exit, null);
51        // ControllerOne.Listen(Button.RightTrigger, ButtonState.Down, FirePrimary, null, Player, null);
52        // ControllerOne.Listen(Button.LeftTrigger, ButtonState.Down, FireSecondary, null, Player, null);
53    }
54
55    void SetVelocity(PhysicsObject Player, Vector velocity)
56    {
57        Player.Velocity = velocity;
58    }
59
60    void CreatePowerGauge()
61    {
62        PowerGauge = new IntMeter(0);
63 
64        Label PowerMeter = new Label();
65        PowerMeter.X = Screen.Left + 100;
66        PowerMeter.Y = Screen.Top - 100;
67        PowerMeter.TextColor = Color.White;
68        PowerMeter.Color = Color.Red;
69
70        PowerMeter.BindTo(PowerGauge);
71        Add(PowerMeter);
72
73        Label PowerText = new Label("Power: ");
74        PowerText.X = Screen.Left + 50;
75        PowerText.Y = Screen.Top - 100;
76        PowerText.TextColor = Color.White;
77        PowerText.Color = Color.Red;
78    }
79}
80   
Note: See TracBrowser for help on using the repository browser.