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 | private Animation Havulento; |
---|
12 | |
---|
13 | public override void Begin() |
---|
14 | { |
---|
15 | Havulento = LoadAnimation("havusaurus"); |
---|
16 | //... |
---|
17 | } |
---|
18 | |
---|
19 | Image maisema = LoadImage("havutausta"); |
---|
20 | Image havusaurus = LoadImage("havusaurus"); |
---|
21 | PhysicsObject pelaaja; |
---|
22 | public override void Begin() |
---|
23 | { |
---|
24 | Level.Width = 800; |
---|
25 | Level.Height = 600; |
---|
26 | SetWindowSize(800, 600, false); |
---|
27 | LuoKentta(); |
---|
28 | LuoHavusaurus(); |
---|
29 | LiikutaPelaajaa(); |
---|
30 | Camera.ZoomToLevel(); |
---|
31 | PhoneBackButton.Listen(ConfirmExit, "Lopeta peli"); |
---|
32 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); |
---|
33 | } |
---|
34 | |
---|
35 | void LuoKentta() |
---|
36 | { |
---|
37 | Level.BackgroundColor = Color.Red; |
---|
38 | Level.Background.Image = maisema; |
---|
39 | Level.Background.FitToLevel(); |
---|
40 | Surface alareuna = new Surface(Level.Width, 30, 50, 60, 10); |
---|
41 | alareuna.Color = Color.Green; |
---|
42 | alareuna.Bottom = Level.Bottom; |
---|
43 | Add(alareuna); |
---|
44 | |
---|
45 | } |
---|
46 | void LuoHavusaurus() |
---|
47 | { |
---|
48 | PhysicsObject pelaaja = new PhysicsObject(235.0, 283.0); |
---|
49 | pelaaja.Shape = Shape.FromImage(havusaurus); |
---|
50 | pelaaja.Image = havusaurus; |
---|
51 | Add(pelaaja); |
---|
52 | |
---|
53 | } |
---|
54 | void LiikutaPelaajaa() |
---|
55 | { |
---|
56 | pelaaja.LinearDamping = 0.95; |
---|
57 | Vector pelaajanSuunta = Vector.FromLengthAndAngle(500.0, pelaaja.Angle); |
---|
58 | pelaaja.Push(pelaajanSuunta); |
---|
59 | |
---|
60 | Keyboard.Listen(Key.W, ButtonState.Down, AsetaNopeus, "Pelaaja 1 Mailaa ylös", pelaaja, nopeusYlos); |
---|
61 | Keyboard.Listen(Key.W, ButtonState.Released, AsetaNopeus, null, pelaaja, Vector.Zero); |
---|
62 | Keyboard.Listen(Key.S, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa alas", pelaaja, nopeusAlas); |
---|
63 | Keyboard.Listen(Key.S, ButtonState.Released, AsetaNopeus, null, pelaaja, Vector.Zero); |
---|
64 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "PLS DOLAN STAAPH"); |
---|
65 | } |
---|
66 | void AsetaNopeus() |
---|
67 | { |
---|
68 | if ((nopeus.Y < 0) && (pelaaja.Bottom < Level.Bottom)) |
---|
69 | { |
---|
70 | pelaaja.Velocity = Vector.Zero; |
---|
71 | return; |
---|
72 | } |
---|
73 | if ((nopeus.Y > 0) && (pelaaja.Top > Level.Top)) |
---|
74 | { |
---|
75 | pelaaja.Velocity = Vector.Zero; |
---|
76 | return; |
---|
77 | } |
---|
78 | } |
---|