1 | using System; |
---|
2 | using System.Collections.Generic; |
---|
3 | using Jypeli; |
---|
4 | using Jypeli.Assets; |
---|
5 | using Jypeli.Controls; |
---|
6 | using Jypeli.Effects; |
---|
7 | using Jypeli.Widgets; |
---|
8 | using FysiikkaPeli1; |
---|
9 | |
---|
10 | public class Snake : PhysicsGame |
---|
11 | { |
---|
12 | |
---|
13 | PhysicsObject mato = new PhysicsObject(150.0, 10.0); |
---|
14 | const int Ruudunkoko = 50; |
---|
15 | const int Leveys = 30; |
---|
16 | const int Korkeus = 20; |
---|
17 | |
---|
18 | public override void Begin() |
---|
19 | { |
---|
20 | |
---|
21 | |
---|
22 | LuoMato(); |
---|
23 | LuoMaailma(); |
---|
24 | Komennot(); |
---|
25 | |
---|
26 | |
---|
27 | |
---|
28 | |
---|
29 | } |
---|
30 | void LuoMato() |
---|
31 | { |
---|
32 | |
---|
33 | Add(mato); |
---|
34 | mato.Shape = Shape.Rectangle; |
---|
35 | mato.Color = Color.Green; |
---|
36 | Vector pelaajansuunta = Vector.FromLengthAndAngle(9000.0, mato.Angle); |
---|
37 | mato.Push(pelaajansuunta); |
---|
38 | mato.MaxVelocity = 9000.0; |
---|
39 | mato.LinearDamping = 1; |
---|
40 | mato.Restitution = 0.0; |
---|
41 | |
---|
42 | |
---|
43 | } |
---|
44 | void LuoMaailma() |
---|
45 | { |
---|
46 | Level.CreateBorders(); |
---|
47 | Level.Background.Color = Color.Black; |
---|
48 | |
---|
49 | |
---|
50 | |
---|
51 | |
---|
52 | } |
---|
53 | void Komennot() |
---|
54 | { |
---|
55 | |
---|
56 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); |
---|
57 | Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä Ohjeet"); |
---|
58 | Keyboard.Listen(Key.Left, ButtonState.Down, LiikuVasen, "Käänny vasemmalle",new Vector(-1000.0, 0.0) ); |
---|
59 | Keyboard.Listen(Key.Left, ButtonState.Released, LopetaKäännös, null); |
---|
60 | Keyboard.Listen(Key.Right, ButtonState.Down, LiikuOikea, "Käänny oikealle",new Vector(1000.0, 0.0)); |
---|
61 | Keyboard.Listen(Key.Right, ButtonState.Released, LopetaKäännös, null); |
---|
62 | |
---|
63 | |
---|
64 | |
---|
65 | } |
---|
66 | void LiikuVasen(Vector suunta) |
---|
67 | { |
---|
68 | mato.Push(suunta); |
---|
69 | } |
---|
70 | void LiikuOikea(Vector suunta) |
---|
71 | { |
---|
72 | mato.Push(suunta); |
---|
73 | } |
---|
74 | void LopetaKäännös() |
---|
75 | { |
---|
76 | Vector pelaajansuunta = Vector.FromLengthAndAngle(9000.0, mato.Angle); |
---|
77 | mato.Push(pelaajansuunta); |
---|
78 | } |
---|
79 | |
---|
80 | |
---|
81 | |
---|
82 | |
---|
83 | |
---|
84 | } |
---|
85 | |
---|
86 | |
---|
87 | |
---|
88 | |
---|
89 | |
---|
90 | |
---|
91 | |
---|
92 | |
---|
93 | |
---|
94 | namespace FysiikkaPeli1 |
---|
95 | { |
---|
96 | |
---|
97 | } |
---|