1 | using System; |
---|
2 | using Jypeli; |
---|
3 | using Jypeli.Widgets; |
---|
4 | using Jypeli.Assets; |
---|
5 | using System.Collections.Generic; |
---|
6 | |
---|
7 | public class Peli : PhysicsGame |
---|
8 | { |
---|
9 | const int ruudunLeveys = 90; |
---|
10 | const int ruudunKorkeus = 90; |
---|
11 | Image palikanKuva = LoadImage("Palikka"); |
---|
12 | PlatformCharacter pelaaja1; |
---|
13 | double nopeus = 600; |
---|
14 | double hyppyVoima = 10000; |
---|
15 | Image pelaajanKuva = LoadImage("hahmo 2"); |
---|
16 | |
---|
17 | |
---|
18 | |
---|
19 | |
---|
20 | protected override void Begin() |
---|
21 | { |
---|
22 | LuoPelaaja(); |
---|
23 | LuoKentta(); |
---|
24 | LuoPalikka(); |
---|
25 | |
---|
26 | |
---|
27 | Gravity = new Vector(0, -1200); |
---|
28 | |
---|
29 | LisaaNappaimet(); |
---|
30 | |
---|
31 | Camera.ZoomToLevel(); |
---|
32 | |
---|
33 | Level.CreateBorders(1.0, false); |
---|
34 | Level.BackgroundColor = Color.Black; |
---|
35 | |
---|
36 | |
---|
37 | } |
---|
38 | void LuoKentta() |
---|
39 | { |
---|
40 | TileMap ruudut = TileMap.FromFile("kentta.txt"); |
---|
41 | ruudut['='] = LuoPalikka; |
---|
42 | ruudut.Insert(ruudunLeveys, ruudunKorkeus); |
---|
43 | |
---|
44 | |
---|
45 | |
---|
46 | |
---|
47 | } |
---|
48 | PhysicsObject LuoPalikka() |
---|
49 | { |
---|
50 | PhysicsObject palikka = PhysicsObject.CreateStaticObject(ruudunLeveys, ruudunKorkeus); |
---|
51 | palikka.Image = palikanKuva; |
---|
52 | palikka.Tag = "palikka"; |
---|
53 | palikka.Restitution = 0.1; |
---|
54 | return palikka; |
---|
55 | |
---|
56 | } |
---|
57 | |
---|
58 | PhysicsObject LuoPelaaja() |
---|
59 | { |
---|
60 | pelaaja1 = new PlatformCharacter(150, 150); |
---|
61 | pelaaja1.Shape = Shapes.Rectangle; |
---|
62 | pelaaja1.Mass = 4.0; |
---|
63 | Add(pelaaja1); |
---|
64 | pelaaja1.X = -200; |
---|
65 | pelaaja1.Y = -800; |
---|
66 | pelaaja1.Color = Color.Lime; |
---|
67 | pelaaja1.CanRotate = false; |
---|
68 | |
---|
69 | PlasmaCannon plasmaTykki = new PlasmaCannon(180, 100); |
---|
70 | pelaaja1.Weapon = plasmaTykki; |
---|
71 | plasmaTykki.PlasmaParticleCollision = PlasmaPalloOsuu; |
---|
72 | plasmaTykki.TimeBetweenUse = new TimeSpan(300); |
---|
73 | |
---|
74 | |
---|
75 | LaserGun laserPyssy = new LaserGun(190, 80); |
---|
76 | pelaaja1.Weapon = laserPyssy; |
---|
77 | laserPyssy.LaserCollision = LaserSadeOsuu; |
---|
78 | laserPyssy.TimeBetweenUse = new TimeSpan(100); |
---|
79 | |
---|
80 | pelaaja1.Restitution = 0.1; |
---|
81 | pelaaja1.Image = pelaajanKuva; |
---|
82 | |
---|
83 | Image pelaajaOikealle = pelaajanKuva; |
---|
84 | Image pelaajaVasemmalle = Image.Mirror(pelaajaOikealle); |
---|
85 | |
---|
86 | |
---|
87 | pelaaja1.LeftIdleAnimation = new Animation(pelaajaVasemmalle); |
---|
88 | pelaaja1.RightIdleAnimation = new Animation(pelaajaOikealle); |
---|
89 | |
---|
90 | pelaaja1.LeftWalkingAnimation = new Animation(pelaajaVasemmalle); |
---|
91 | pelaaja1.RightWalkingAnimation = new Animation(pelaajaOikealle); |
---|
92 | |
---|
93 | |
---|
94 | return pelaaja1; |
---|
95 | } |
---|
96 | |
---|
97 | void LisaaNappaimet() |
---|
98 | { |
---|
99 | |
---|
100 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Poistu pelistä"); |
---|
101 | Keyboard.Listen(Key.Left, ButtonState.Down, liikuta, "Liikkuu vasemmalle", pelaaja1, -nopeus); |
---|
102 | Keyboard.Listen(Key.Right, ButtonState.Down, liikuta, "Liikkuu oikealle", pelaaja1, nopeus); |
---|
103 | Keyboard.Listen(Key.Up, ButtonState.Pressed, hyppaa, "Hyppää", pelaaja1, hyppyVoima); |
---|
104 | |
---|
105 | Keyboard.Listen(Key.J, ButtonState.Pressed, tahtain, "tähtäys alas", pelaaja1); |
---|
106 | Keyboard.Listen(Key.L, ButtonState.Pressed, tahtain, "tähtäys ylös", pelaaja1); |
---|
107 | Keyboard.Listen(Key.K, ButtonState.Down, Ammu, "ampu tulee", pelaaja1); |
---|
108 | Keyboard.Listen(Key.U, ButtonState.Pressed, vaihto, "aseen vaihto", pelaaja1); |
---|
109 | Keyboard.Listen(Key.O, ButtonState.Pressed, vaihto, "aseen vaihto", pelaaja1); |
---|
110 | |
---|
111 | } |
---|
112 | |
---|
113 | void liikuta(PlatformCharacter pelaaja, double nopeus) |
---|
114 | { |
---|
115 | pelaaja.Walk(nopeus); |
---|
116 | } |
---|
117 | |
---|
118 | void hyppaa(PlatformCharacter pelaaja, double voima) |
---|
119 | { |
---|
120 | pelaaja.Jump(voima); |
---|
121 | } |
---|
122 | void tahtain(PlatformCharacter pelaaja) |
---|
123 | { |
---|
124 | |
---|
125 | } |
---|
126 | |
---|
127 | void vaihto(PlatformCharacter pelaaja) |
---|
128 | { |
---|
129 | |
---|
130 | } |
---|
131 | |
---|
132 | |
---|
133 | |
---|
134 | |
---|
135 | void Ammu(PlatformCharacter pelaaja) |
---|
136 | { |
---|
137 | PhysicsObject ammus = pelaaja.Weapon.Shoot(); |
---|
138 | if (ammus != null) |
---|
139 | { |
---|
140 | ammus.Tag = pelaaja; |
---|
141 | ammus.Size = new Vector(30, 30); |
---|
142 | //ammus.MaximumLifetime = new TimeSpan(20000); |
---|
143 | } |
---|
144 | |
---|
145 | |
---|
146 | |
---|
147 | } |
---|
148 | |
---|
149 | void PlasmaPalloOsuu(PhysicsObject ammus, PhysicsObject kohde) |
---|
150 | { |
---|
151 | if (ammus.Tag != kohde && kohde.Tag.ToString() != "palikka") |
---|
152 | |
---|
153 | kohde.Destroy(); |
---|
154 | } |
---|
155 | |
---|
156 | void LaserSadeOsuu(PhysicsObject ammus, PhysicsObject kohde) |
---|
157 | { |
---|
158 | if (ammus.Tag != kohde && kohde.Tag.ToString() != "palikka") |
---|
159 | |
---|
160 | kohde.Destroy(); |
---|
161 | } |
---|
162 | |
---|
163 | } |
---|