source: 2011/31/TeemuM/FysiikkaPeli1/FysiikkaPeli1/FysiikkaPeli1/Peli.cs @ 2510

Revision 2510, 3.3 KB checked in by teematma, 12 years ago (diff)

Talletus.

Line 
1using System;
2using System.Collections.Generic;
3using Jypeli;
4using Jypeli.Assets;
5using Jypeli.Controls;
6using Jypeli.Effects;
7using Jypeli.Widgets;
8
9public class Peli : PhysicsGame
10{
11    PhysicsObject alus;
12    LaserGun laser;
13    PhysicsObject vihu1;
14
15    public override void Begin()
16    {
17
18        luokentta();
19        asetaohjaimet();
20        Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "poistu");
21        luovihu1();
22
23   }
24    void luokentta()
25    {
26        this.Level.Height = 3000;
27        this.Level.Width = 3500;
28        Level.CreateBorders(true);
29        Gravity = new Vector(0, -600);
30        Level.CreateGround(10, 30, 100, Color.Brown);
31
32        tausta();
33        Level.BackgroundColor = Color.Black;
34
35        alus = new PhysicsObject(30, 50);
36        Add(alus);
37        alus.Restitution = 0;
38        alus.LinearDamping = 0.95;
39        alus.AngularDamping = 0.75;
40        Camera.Follow(alus);
41        Camera.StayInLevel = true;
42        alus.Shape = Shape.Triangle;
43        alus.Y = -1350;
44        alus.X = 0;
45        LaserGun laser = new LaserGun(10, 10);
46        alus.Add(laser);
47       
48
49    }
50
51    void luovihu1()
52    {
53        vihu1 = new PhysicsObject(30, 50);
54        Add(vihu1);
55        vihu1.Color = Color.Red;
56        vihu1.Restitution = 0;
57        vihu1.LinearDamping = 0.95;
58        vihu1.AngularDamping = 0.75;
59        //Camera.Follow(alus);
60        //Camera.StayInLevel = true;
61        vihu1.Shape = Shape.Triangle;
62        vihu1.Y = 1350;
63        vihu1.X = 0;
64        FollowerBrain aivo1 = new FollowerBrain();
65        aivo1.Active = true;
66        aivo1.Target = alus;
67        aivo1.Speed = 400;
68        aivo1.TargetFollowDistance = 15000;
69        //aivo1.TargetCloseDistance = 10;
70        //aivo1.StopWhenTargetClose = true;
71        vihu1.Brain = aivo1;
72
73    }
74
75    void tausta()
76    {
77
78        for (int i = 0; i < 1100; i++)
79        {
80            GameObject tahti = new GameObject(3, 3);
81            tahti.Shape = Shape.Star;
82            Add(tahti, -3);
83            tahti.Y = RandomGen.NextDouble(Level.Bottom, Level.Top);
84            tahti.X = RandomGen.NextDouble(Level.Left, Level.Right);
85            GetLayer(-3).RelativeTransition = new Vector(0.5, 0.5);
86        }
87       
88
89    }
90
91    void kaasu()
92    {
93        Vector voima = new Vector();
94        voima = Vector.FromLengthAndAngle(2200, alus.Angle - Angle.FromDegrees(-90));       
95        alus.Push(voima);
96       
97    }
98    void pyoroik()
99    {
100        alus.AngularVelocity = -4;
101    }
102
103    void pyorvas()
104    {
105        alus.AngularVelocity = 4;
106    }
107
108    void asetaohjaimet()
109   {
110       Keyboard.Listen(Key.Up, ButtonState.Down, kaasu, null);
111       Keyboard.Listen(Key.W, ButtonState.Down, kaasu, null);
112       Keyboard.Listen(Key.Right, ButtonState.Down, pyoroik, null);
113       Keyboard.Listen(Key.D, ButtonState.Down, pyoroik, null);
114       Keyboard.Listen(Key.Left, ButtonState.Down, pyorvas, null);
115       Keyboard.Listen(Key.A, ButtonState.Down, pyorvas, null);
116       Keyboard.Listen(Key.Space, ButtonState.Pressed, laser, null);
117
118   }
119
120    protected override void Update(Time time)
121    {
122        vihu1.Angle = vihu1.Velocity.Angle + Angle.FromDegrees(-90);
123
124        base.Update(time);
125    }
126
127}
Note: See TracBrowser for help on using the repository browser.