source: 2016/24/ArttuH/anythin/anythin/anythin/anythin.cs @ 7358

Revision 7358, 6.2 KB checked in by armahiek, 4 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
9public class anythin : PhysicsGame
10{
11    PhysicsObject Player1;
12    LaserGun Zapper0;
13    LaserGun Zapper1;
14    LaserGun Zapper2;
15    PlasmaCannon Sidecannon1;
16    PlasmaCannon Sidecannon2;
17    Image playerim = LoadImage("rocket2");
18    Image Asteroid10 = LoadImage("asteroid");
19    Image Asteroid20 = LoadImage("aasteroid");
20    Image Asteroid30 = LoadImage("Aaasteroid");
21    Image Asteroid40 = LoadImage("aaaasteroid");
22    DoubleMeter Plasmameter;
23
24    public override void Begin()
25    {
26
27        Assets(); //enemies
28        Things(); //Players n stuff
29        Controll(); //Controls
30        Plasmatimer();
31        PlasmaGo();
32
33        Level.Background.CreateStars(30000);
34        IsFullScreen = false;
35       
36
37    }
38    void Things()
39    {
40        //Creating Player
41        Player1 = new PhysicsObject(50.0, 30.0);
42        Player1.Mass = 0.10;
43        Player1.MomentOfInertia = 50;
44        Player1.IgnoresGravity = true;
45        Player1.MaxAngularVelocity = 10;
46        Player1.LinearDamping = 0.97;
47        Player1.AngularDamping = 0.97;
48        Player1.Image = playerim;
49        Player1.Shape = Shape.Circle;
50        Add(Player1);
51
52        //Creating Guns
53        //Laser 1
54        Zapper0 = new LaserGun(0, 0);
55        Zapper0.InfiniteAmmo = true;
56        Zapper0.ProjectileCollision = Hits;
57        Zapper0.CanHitOwner = false;
58        Zapper0.Image = null;
59        Zapper0.FireRate = 1.0;
60        Player1.Add(Zapper0);
61        //Laser 2
62        Zapper1 = new LaserGun(0, 0);
63        Zapper1.InfiniteAmmo = true;
64        Zapper1.ProjectileCollision = Hits;
65        Zapper1.CanHitOwner = false;
66        Zapper1.Image = null;
67        Zapper1.FireRate = 1.0;
68        Zapper1.Angle += Angle.FromDegrees(20);
69        Player1.Add(Zapper1);
70        //Laser 3
71        Zapper2 = new LaserGun(0, 0);
72        Zapper2.InfiniteAmmo = true;
73        Zapper2.ProjectileCollision = Hits;
74        Zapper2.CanHitOwner = false;
75        Zapper2.Image = null;
76        Zapper2.FireRate = 1.0;
77        Zapper2.Angle += Angle.FromDegrees(-20);
78        Player1.Add(Zapper2);
79        //Side Plasmacannon 1
80        Sidecannon1 = new PlasmaCannon(0, 0);
81        Sidecannon1.InfiniteAmmo = true;
82        Sidecannon1.ProjectileCollision = Cannonhits;
83        Sidecannon1.CanHitOwner = false;
84        Sidecannon1.Image = null;
85        Sidecannon1.FireRate = 0.333333333333334;
86        Sidecannon1.Angle += Angle.FromDegrees(90);
87        Player1.Add(Sidecannon1);
88        //Side Plasmacannon 2
89        Sidecannon2 = new PlasmaCannon(0, 0);
90        Sidecannon2.InfiniteAmmo = true;
91        Sidecannon2.ProjectileCollision = Cannonhits;
92        Sidecannon2.CanHitOwner = false;
93        Sidecannon2.Image = null;
94        Sidecannon2.FireRate = 0.3333333333333334;
95        Sidecannon2.Angle += Angle.FromDegrees(-90);
96        Player1.Add(Sidecannon2);
97    }
98    void Hits(PhysicsObject Laser, PhysicsObject Target)
99    {   //laser hit detection
100        Laser.Destroy();
101       
102       
103            Target.Destroy();
104       
105       
106    }
107    void Cannonhits(PhysicsObject Plasma, PhysicsObject Target)
108    {   //Plasmacannon hit detection
109        Plasma.Destroy();
110        Target.Destroy();
111    }
112    void Assets()
113    {
114        //Random generators
115        Vector RandomPoint = Level.GetRandomPosition();
116        Vector Randompoint2 = Level.GetRandomPosition();
117
118        //Asteroids
119        PhysicsObject Asteroid1 = new PhysicsObject(100.0, 100.0);
120        Asteroid1.Mass = 1.0;
121        Asteroid1.Position = RandomPoint;
122        Asteroid1.Image = Asteroid10;
123        Asteroid1.Shape = Shape.Hexagon;
124        Asteroid1.Tag = "Target";
125        Add(Asteroid1);
126
127        PhysicsObject Asteroid2 = new PhysicsObject(100.0, 100.0);
128        Asteroid2.Mass = 1.0;
129        Asteroid2.Image = Asteroid30;
130        Asteroid2.Shape = Shape.Hexagon;
131        Asteroid2.Position = Randompoint2;
132        Asteroid2.Tag = "Target";
133        Add(Asteroid2);
134    }
135    void Controll()
136    {
137        //Controls
138        Keyboard.Listen(Key.W, ButtonState.Down, MoveSomewhere1, null);
139        Keyboard.Listen(Key.S, ButtonState.Down, MoveSomewhere2, null);
140        Keyboard.Listen(Key.A, ButtonState.Down, RotateSomewhere1, null);
141        Keyboard.Listen(Key.D, ButtonState.Down, RotateSomewhere2, null);
142        Keyboard.Listen(Key.Space, ButtonState.Down, Shoot1, null, Zapper0);
143        Keyboard.Listen(Key.Space, ButtonState.Down, Shoot1, null, Zapper1);
144        Keyboard.Listen(Key.Space, ButtonState.Down, Shoot1, null, Zapper2);
145        Keyboard.Listen(Key.C, ButtonState.Down, Shoot2, null, Sidecannon1);
146        Keyboard.Listen(Key.C, ButtonState.Down, Shoot2, null, Sidecannon2);
147        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli");
148    }
149    void Shoot1(LaserGun Gun) 
150    {
151        PhysicsObject Laser = Gun.Shoot();
152    }
153    void Shoot2(PlasmaCannon Gun)
154    {
155        PhysicsObject Plasma = Gun.Shoot();
156    }
157    void MoveSomewhere1()
158    {
159        Vector Forward = Vector.FromLengthAndAngle(100.0, Player1.Angle);
160        Player1.Push(Forward);
161    }
162    void MoveSomewhere2()
163    {
164        Vector Backwards = Vector.FromLengthAndAngle(-75.0, Player1.Angle);
165        Player1.Push(Backwards);
166    }
167    void RotateSomewhere1()
168    {
169        Player1.ApplyTorque(500.0);
170    }
171    void RotateSomewhere2()
172    {
173        Player1.ApplyTorque(-500.0);
174    }
175    void PlasmaGo()
176    {
177        Plasmameter = new DoubleMeter(0);
178        Plasmameter.MaxValue = 3;
179
180
181        ProgressBar Thingy = new ProgressBar(200, 20);
182        Thingy.BindTo(Plasmameter);
183        Thingy.X = Screen.Left + 150;
184        Thingy.Y = Screen.Top - 20;
185        Thingy.Color = Color.Gray;
186        Thingy.BarColor = Color.DarkGreen;
187        Thingy.BorderColor = Color.White;
188        Add(Thingy);
189
190   }
191   void Plasmatimer()
192   {
193        Timer Time1 = new Timer();
194        Time1.Interval = 1;
195        Time1.Timeout += Addone;
196   }
197    void Addone()
198    {
199        Plasmameter.Value += 1;
200    }
201}
202
Note: See TracBrowser for help on using the repository browser.