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

Revision 7374, 7.0 KB checked in by armahiek, 3 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    IntMeter Killer;
23
24    public override void Begin()
25    {
26
27        Assets(); //enemies
28        Things(); //Players n stuff
29        Controll(); //Controls
30        Timee();
31        redo();
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.95;
47        Player1.AngularDamping = 0.90;
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(10);
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(-10);
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        Target.Destroy();
102        Killer.Value += 1;
103    }
104    void Cannonhits(PhysicsObject Plasma, PhysicsObject Target)
105    {   //Plasmacannon hit detection
106       
107        Target.Destroy();
108        Killer.Value += 1;
109    }
110    void Assets()
111    {
112
113
114        //Random generators
115        Vector RandomPoint = Level.GetRandomPosition();
116        Vector Randompoint2 = Level.GetRandomPosition();
117        Vector Randompoint1 = Level.GetRandomPosition();
118        Vector voima = Vector.FromLengthAndAngle(RandomGen.NextDouble(1.0, 300.0), RandomGen.NextAngle());
119        Vector voima1 = Vector.FromLengthAndAngle(RandomGen.NextDouble(1.0, 300.0), RandomGen.NextAngle());
120
121
122        //Asteroids
123        PhysicsObject Asteroid1 = new PhysicsObject(100.0, 100.0);
124        Asteroid1.Mass = 1.0;
125        Asteroid1.Position = RandomPoint;
126        Asteroid1.Image = Asteroid10;
127        Asteroid1.Shape = Shape.Hexagon;
128        Asteroid1.Tag = "Target";
129        Asteroid1.Velocity = voima;
130        RandomGen.NextDirection();
131        Add(Asteroid1);
132
133        PhysicsObject Asteroid2 = new PhysicsObject(100.0, 100.0);
134        Asteroid2.Mass = 1.0;
135        Asteroid2.Image = Asteroid30;
136        Asteroid2.Shape = Shape.Hexagon;
137        Asteroid2.Position = Randompoint2;
138        Asteroid2.Tag = "Target";
139        Asteroid2.Velocity = voima;
140        RandomGen.NextDirection();
141        Add(Asteroid2);
142
143        PhysicsObject Asteroid3 = new PhysicsObject(100.0, 100.0);
144        Asteroid3.Mass = 1.0;
145        Asteroid3.Image = Asteroid30;
146        Asteroid3.Shape = Shape.Hexagon;
147        Asteroid3.Position = Randompoint1;
148        Asteroid3.Tag = "Target";
149        Asteroid3.Velocity = voima1;
150        RandomGen.NextDirection();
151        Add(Asteroid3);
152    }
153    void Timee()
154    {
155        Timer Timr = new Timer();
156        Timr.Interval = 3;
157        Timr.Timeout += Assets;
158        Timr.Start(100);
159
160        Label aikaNaytto = new Label();
161        aikaNaytto.TextColor = Color.White;
162        aikaNaytto.X = Screen.Left + 100;
163        aikaNaytto.Y = Screen.Top - 100;
164        aikaNaytto.DecimalPlaces = 1;
165       
166        aikaNaytto.BindTo(Timr.SecondCounter);
167   
168        Add(aikaNaytto);
169    }
170    void redo()
171    {
172        Killer = new IntMeter(0);
173
174        Label Kills = new Label();
175        Kills.BindTo(Killer);
176        Kills.X = Screen.Right - 100;
177        Kills.Y = Screen.Top - 100;
178        Kills.TextColor = Color.LightGreen;
179        Add(Kills);
180    }
181    void Controll()
182    {
183        //Controls
184        Keyboard.Listen(Key.W, ButtonState.Down, MoveSomewhere1, null);
185        Keyboard.Listen(Key.S, ButtonState.Down, MoveSomewhere2, null);
186        Keyboard.Listen(Key.A, ButtonState.Down, RotateSomewhere1, null);
187        Keyboard.Listen(Key.D, ButtonState.Down, RotateSomewhere2, null);
188        Keyboard.Listen(Key.Space, ButtonState.Down, Shoot1, null, Zapper0);
189        Keyboard.Listen(Key.Space, ButtonState.Down, Shoot1, null, Zapper1);
190        Keyboard.Listen(Key.Space, ButtonState.Down, Shoot1, null, Zapper2);
191        Keyboard.Listen(Key.C, ButtonState.Down, Shoot2, null, Sidecannon1);
192        Keyboard.Listen(Key.C, ButtonState.Down, Shoot2, null, Sidecannon2);
193        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli");
194    }
195    void Shoot1(LaserGun Gun) 
196    {
197        PhysicsObject Laser = Gun.Shoot();
198    }
199    void Shoot2(PlasmaCannon Gun)
200    {
201        PhysicsObject Plasma = Gun.Shoot();
202    }
203    void MoveSomewhere1()
204    {
205        Vector Forward = Vector.FromLengthAndAngle(100.0, Player1.Angle);
206        Player1.Push(Forward);
207    }
208    void MoveSomewhere2()
209    {
210        Vector Backwards = Vector.FromLengthAndAngle(-75.0, Player1.Angle);
211        Player1.Push(Backwards);
212    }
213    void RotateSomewhere1()
214    {
215        Player1.ApplyTorque(1250.0);
216    }
217    void RotateSomewhere2()
218    {
219        Player1.ApplyTorque(-1250.0);
220    }
221
222}
223
Note: See TracBrowser for help on using the repository browser.