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

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