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 | |
---|
9 | public class Lentokone : PhysicsGame |
---|
10 | { |
---|
11 | |
---|
12 | |
---|
13 | |
---|
14 | |
---|
15 | Image maisema = LoadImage("havutausta"); |
---|
16 | Image havusaurus = LoadImage("havusaurus"); |
---|
17 | Vector nopeusYlos = new Vector(0, 1000); |
---|
18 | Vector nopeusAlas = new Vector(0, -1000); |
---|
19 | PhysicsObject pelaaja; |
---|
20 | |
---|
21 | public override void Begin() |
---|
22 | { |
---|
23 | Level.Width = 800; |
---|
24 | Level.Height = 600; |
---|
25 | SetWindowSize(800, 600, false); |
---|
26 | LuoKentta(); |
---|
27 | LuoPelaaja(); |
---|
28 | LiikutaPelaajaa(); |
---|
29 | Camera.ZoomToLevel(); |
---|
30 | PhoneBackButton.Listen(ConfirmExit, "Lopeta peli"); |
---|
31 | |
---|
32 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); |
---|
33 | |
---|
34 | Keyboard.Listen(Key.Left, ButtonState.Down, |
---|
35 | LiikutaPelaajaa, null, -1); |
---|
36 | Keyboard.Listen(Key.Right, ButtonState.Down, |
---|
37 | LiikutaPelaajaa, null, 1); |
---|
38 | Keyboard.Listen(Key.Up, ButtonState.Down, |
---|
39 | KaannaPelaajaa, null, 1.0); |
---|
40 | Keyboard.Listen(Key.Up, ButtonState.Released, |
---|
41 | KaannaPelaajaa, null, 0.0); |
---|
42 | Keyboard.Listen(Key.Down, ButtonState.Down, |
---|
43 | KaannaPelaajaa, null, -1.0); |
---|
44 | Keyboard.Listen(Key.Down, ButtonState.Released, |
---|
45 | KaannaPelaajaa, null, 0.0); |
---|
46 | } |
---|
47 | |
---|
48 | void KaannaPelaajaa(double kaannos) |
---|
49 | { |
---|
50 | pelaaja.AngularVelocity = kaannos; |
---|
51 | |
---|
52 | } |
---|
53 | |
---|
54 | |
---|
55 | void LiikutaPelaajaa(int suunta) |
---|
56 | { |
---|
57 | pelaaja.Push(Vector.FromLengthAndAngle(1000*suunta, pelaaja.Angle)); |
---|
58 | } |
---|
59 | |
---|
60 | |
---|
61 | void LuoKentta() |
---|
62 | { |
---|
63 | Level.BackgroundColor = Color.Red; |
---|
64 | Level.Background.Image = maisema; |
---|
65 | Level.Background.FitToLevel(); |
---|
66 | Surface alareuna = new Surface(Level.Width, 30, 50, 60, 10); |
---|
67 | alareuna.Color = Color.Green; |
---|
68 | alareuna.Bottom = Level.Bottom; |
---|
69 | Add(alareuna); |
---|
70 | |
---|
71 | } |
---|
72 | void LuoPelaaja() |
---|
73 | { |
---|
74 | pelaaja = new PhysicsObject(235.0, 283.0); |
---|
75 | pelaaja.Shape = Shape.FromImage(havusaurus); |
---|
76 | pelaaja.Image = havusaurus; |
---|
77 | pelaaja.MirrorImage(); |
---|
78 | Add(pelaaja); |
---|
79 | |
---|
80 | } |
---|
81 | void LiikutaPelaajaa() |
---|
82 | { |
---|
83 | pelaaja.LinearDamping = 0.95; |
---|
84 | Vector pelaajanSuunta = Vector.FromLengthAndAngle(500.0, pelaaja.Angle); |
---|
85 | pelaaja.Push(pelaajanSuunta); |
---|
86 | |
---|
87 | |
---|
88 | } |
---|
89 | } |
---|