1 | using System; |
---|
2 | using Jypeli; |
---|
3 | using Jypeli.Widgets; |
---|
4 | using Jypeli.Assets; |
---|
5 | |
---|
6 | |
---|
7 | class Tasohyppely : PhysicsGame |
---|
8 | { |
---|
9 | const int ruudunLeveys = 50; |
---|
10 | const int ruudunKorkeus = 50; |
---|
11 | |
---|
12 | const double nopeus = 200; |
---|
13 | const double hyppyVoima = 5000; |
---|
14 | |
---|
15 | PlatformCharacter erska; |
---|
16 | |
---|
17 | protected override void Begin() |
---|
18 | { |
---|
19 | LuoKentta(); |
---|
20 | |
---|
21 | HeitaKranaatti(); |
---|
22 | |
---|
23 | Gravity = new Vector(0, -1000); |
---|
24 | |
---|
25 | luoKentta(); |
---|
26 | lisaaNappaimet(); |
---|
27 | |
---|
28 | Camera.Follow(erska); |
---|
29 | Camera.ZoomFactor = 2.0; |
---|
30 | Camera.StayInLevel = true; |
---|
31 | } |
---|
32 | |
---|
33 | void luoKentta() |
---|
34 | { |
---|
35 | Level.CreateBorders(); |
---|
36 | Level.BackgroundColor = Color.White; |
---|
37 | |
---|
38 | } |
---|
39 | void lisaaNappaimet() |
---|
40 | |
---|
41 | { |
---|
42 | Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet"); |
---|
43 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Poistu pelistä"); |
---|
44 | |
---|
45 | Keyboard.Listen(Key.Left, ButtonState.Down, liikuta, "Liikkuu vasemmalle", erska, -nopeus); |
---|
46 | Keyboard.Listen(Key.Right, ButtonState.Down, liikuta, "Liikkuu oikealle", erska, nopeus); |
---|
47 | Keyboard.Listen(Key.Up, ButtonState.Pressed, hyppaa, "Hyppää", erska, hyppyVoima); |
---|
48 | Keyboard.Listen(Key.Space, ButtonState.Down, erska.Weapon.Use, "Ammu"); |
---|
49 | Keyboard.Listen(Key.G, ButtonState.Down, HeitaKranaatti, "kranaatti"); |
---|
50 | |
---|
51 | } |
---|
52 | |
---|
53 | void liikuta(PlatformCharacter hahmo, double nopeus) |
---|
54 | { |
---|
55 | hahmo.Walk(nopeus); |
---|
56 | } |
---|
57 | |
---|
58 | void hyppaa(PlatformCharacter hahmo, double voima) |
---|
59 | { |
---|
60 | hahmo.Jump(voima); |
---|
61 | } |
---|
62 | void LuoKentta() |
---|
63 | { |
---|
64 | TileMap ruudut = TileMap.FromFile("kentta.txt"); |
---|
65 | ruudut['='] = LuoPalikka; |
---|
66 | ruudut['1'] = LuoErska; |
---|
67 | ruudut['x'] = LuoRyssa; |
---|
68 | ruudut['P'] = LuoPaakka; |
---|
69 | ruudut.Insert(ruudunLeveys, ruudunKorkeus); |
---|
70 | } |
---|
71 | PhysicsObject LuoPalikka() |
---|
72 | { |
---|
73 | PhysicsObject palikka = PhysicsObject.CreateStaticObject(50.0, 50.0); |
---|
74 | palikka.Image = LoadImage("palikka"); |
---|
75 | return palikka; |
---|
76 | } |
---|
77 | PlatformCharacter LuoErska() |
---|
78 | { |
---|
79 | erska = new PlatformCharacter(90, 120); |
---|
80 | erska.Mass = 4.0; |
---|
81 | erska.Image = LoadImage("erska"); |
---|
82 | erska.X = 0; |
---|
83 | erska.Y = Level.Bottom + 120; |
---|
84 | LaserGun laserPyssy = new LaserGun(80, 20); |
---|
85 | laserPyssy.LaserCollision = LaserSadeOsuu; |
---|
86 | erska.Weapon = laserPyssy; |
---|
87 | |
---|
88 | erska.Weapon.Y -= 15; |
---|
89 | |
---|
90 | return erska; |
---|
91 | } |
---|
92 | PlatformCharacter LuoRyssa() |
---|
93 | { |
---|
94 | PlatformCharacter ryssa = new PlatformCharacter(90, 120); |
---|
95 | ryssa.Mass = 4.0; |
---|
96 | ryssa.Image = LoadImage("ryssa"); |
---|
97 | ryssa.Tag = "vihu"; |
---|
98 | ryssa.X = 0; |
---|
99 | ryssa.Y = Level.Bottom + 120; |
---|
100 | ryssa.Weapon = new PlasmaCannon(80, 20); |
---|
101 | ryssa.Weapon.Y -= 22; |
---|
102 | |
---|
103 | Timer ajastin = new Timer(); |
---|
104 | ajastin.Interval = 9.0; |
---|
105 | ajastin.Trigger += RyssaAmpuu; |
---|
106 | ajastin.Tag = ryssa; |
---|
107 | ajastin.Start(); |
---|
108 | |
---|
109 | return ryssa; |
---|
110 | } |
---|
111 | void HeitaKranaatti() |
---|
112 | { |
---|
113 | ClusterGrenade kranaatti = new ClusterGrenade(100.0, 1); |
---|
114 | kranaatti.X = erska.X + 0; |
---|
115 | kranaatti.Y = erska.Y + 0; |
---|
116 | Add(kranaatti); |
---|
117 | Vector heittoVoima = Vector.FromLengthAndAngle(40000, Angle.Degrees(45)); |
---|
118 | kranaatti.Hit(heittoVoima); |
---|
119 | kranaatti.NumberOfClusters = 1; |
---|
120 | kranaatti.Image = LoadImage("kranu"); |
---|
121 | } |
---|
122 | void RyssaAmpuu( Timer LauennutAjastin ) |
---|
123 | { |
---|
124 | PlatformCharacter ryssa = LauennutAjastin.Tag as PlatformCharacter; |
---|
125 | |
---|
126 | if (ryssa != null) |
---|
127 | { |
---|
128 | ryssa.Weapon.Shoot(); |
---|
129 | } |
---|
130 | } |
---|
131 | void LaserSadeOsuu( PhysicsObject Laser, PhysicsObject toinen ) |
---|
132 | { |
---|
133 | if (toinen != erska) |
---|
134 | { |
---|
135 | Laser.Destroy(); |
---|
136 | Explosion rajahdys = new Explosion(4000); |
---|
137 | rajahdys.Position = Laser.Position; |
---|
138 | Add(rajahdys); |
---|
139 | rajahdys.Speed = 2000.0; |
---|
140 | rajahdys.Force = 100000; |
---|
141 | rajahdys.ShockwaveColor = Color.Black; |
---|
142 | } |
---|
143 | if (toinen.Tag.ToString() == "vihu") |
---|
144 | { |
---|
145 | toinen.Destroy(); |
---|
146 | } |
---|
147 | |
---|
148 | } |
---|
149 | PlatformCharacter LuoPaakka() |
---|
150 | { |
---|
151 | PlatformCharacter paakka = new PlatformCharacter(90, 120); |
---|
152 | paakka.Mass = 4.0; |
---|
153 | paakka.Image = LoadImage("paakka"); |
---|
154 | paakka.X = 0; |
---|
155 | paakka.Y = Level.Bottom + 120; |
---|
156 | paakka.Weapon = new PlasmaCannon(80, 20); |
---|
157 | paakka.Weapon.Y -= 22; |
---|
158 | |
---|
159 | Timer ajastin = new Timer(); |
---|
160 | ajastin.Interval = 0.1; |
---|
161 | ajastin.Trigger += PaakkaAmpuu; |
---|
162 | ajastin.Tag = paakka; |
---|
163 | ajastin.Start(); |
---|
164 | |
---|
165 | return paakka; |
---|
166 | } |
---|
167 | void PaakkaAmpuu(Timer LauennutAjastin) |
---|
168 | { |
---|
169 | PlatformCharacter paakka = LauennutAjastin.Tag as PlatformCharacter; |
---|
170 | |
---|
171 | if (paakka != null) |
---|
172 | { |
---|
173 | paakka.Weapon.Shoot(); |
---|
174 | } |
---|
175 | } |
---|
176 | |
---|
177 | } |
---|