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 SpaceInvanders : PhysicsGame |
---|
10 | { |
---|
11 | |
---|
12 | PhysicsObject pelaaja; |
---|
13 | PhysicsObject Pahis; |
---|
14 | public override void Begin() |
---|
15 | { |
---|
16 | // TODO: Kirjoita ohjelmakoodisi tähän |
---|
17 | LuoPelaaja(); |
---|
18 | LuoPahis(); |
---|
19 | Asteroidit(); |
---|
20 | Level.Background.Image = LoadImage ("tahtitaivas"); |
---|
21 | Level.Background.Size = Screen.Size; |
---|
22 | |
---|
23 | |
---|
24 | Keyboard.Listen(Key.Left, ButtonState.Down, LiikutaPelaajaa, null, new Vector(-1000, 0)); |
---|
25 | Keyboard.Listen(Key.Right, ButtonState.Down, LiikutaPelaajaa, null, new Vector(1000, 0)); |
---|
26 | Keyboard.Listen(Key.Up, ButtonState.Down, LiikutaPelaajaa, null, new Vector(0, 1000)); |
---|
27 | Keyboard.Listen(Key.Down, ButtonState.Down, LiikutaPelaajaa, null, new Vector(0, -1000)); |
---|
28 | |
---|
29 | Level.Width = Screen.Width; |
---|
30 | Level.Height = Screen.Height; |
---|
31 | Level.CreateBorders(); |
---|
32 | |
---|
33 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); |
---|
34 | } |
---|
35 | void LiikutaPelaajaa(Vector suunta) |
---|
36 | { |
---|
37 | |
---|
38 | pelaaja.Move(suunta); |
---|
39 | pelaaja.Angle = suunta.Angle - Angle.RightAngle; |
---|
40 | |
---|
41 | |
---|
42 | } |
---|
43 | void LuoPelaaja() |
---|
44 | { |
---|
45 | |
---|
46 | pelaaja = new PhysicsObject(75.0, 75.0); |
---|
47 | pelaaja.Image = LoadImage("avaruusalus"); |
---|
48 | AddCollisionHandler(pelaaja, "pahapoika", BOOM); |
---|
49 | |
---|
50 | |
---|
51 | |
---|
52 | |
---|
53 | Add(pelaaja); |
---|
54 | |
---|
55 | |
---|
56 | |
---|
57 | |
---|
58 | |
---|
59 | } |
---|
60 | |
---|
61 | void BOOM(PhysicsObject pelaaja, PhysicsObject pahis) |
---|
62 | { |
---|
63 | |
---|
64 | |
---|
65 | } |
---|
66 | void LuoPahis() |
---|
67 | { |
---|
68 | Pahis = new PhysicsObject(75.0, 75.0); |
---|
69 | //Pahis.Tag "kelju"; |
---|
70 | Add(Pahis); |
---|
71 | Pahis.Image = LoadImage("ufokuva2"); |
---|
72 | |
---|
73 | |
---|
74 | |
---|
75 | } |
---|
76 | |
---|
77 | void Asteroidit() |
---|
78 | { |
---|
79 | PhysicsObject asteroidi = new PhysicsObject(100.0, 100.0); |
---|
80 | asteroidi.Image = LoadImage("komeetta"); |
---|
81 | asteroidi.X = 600.0; |
---|
82 | asteroidi.Y = -300.0; |
---|
83 | asteroidi.Tag = "pahapoika"; |
---|
84 | Add(asteroidi); |
---|
85 | |
---|
86 | } |
---|
87 | |
---|
88 | } |
---|