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