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 Dreamcast : PhysicsGame |
---|
10 | { |
---|
11 | |
---|
12 | PlatformCharacter character; |
---|
13 | PlatformCharacter character2; |
---|
14 | Image player1Picture = LoadImage("Player1"); |
---|
15 | Image player2picture= LoadImage("player2"); |
---|
16 | AssaultRifle Player1Gun; |
---|
17 | AssaultRifle Player2Gun; |
---|
18 | Image wallpaper = LoadImage("cool"); |
---|
19 | int characterHealth; |
---|
20 | int character2Health; |
---|
21 | |
---|
22 | |
---|
23 | public override void Begin() |
---|
24 | |
---|
25 | |
---|
26 | { |
---|
27 | startMenu(); |
---|
28 | |
---|
29 | |
---|
30 | |
---|
31 | |
---|
32 | |
---|
33 | |
---|
34 | } |
---|
35 | |
---|
36 | void CreateLevel() |
---|
37 | { |
---|
38 | TileMap boxes = TileMap.FromLevelAsset ("Hassebproject"); |
---|
39 | boxes.SetTileMethod('i', Obstacles ); |
---|
40 | boxes.SetTileMethod('W', Wall); |
---|
41 | boxes.SetTileMethod('#', Ground); |
---|
42 | boxes.SetTileMethod('C', Character); |
---|
43 | boxes.SetTileMethod('D', Character2); |
---|
44 | boxes.Execute(); |
---|
45 | |
---|
46 | } |
---|
47 | void Obstacles(Vector place, double width, double height) |
---|
48 | { |
---|
49 | PhysicsObject obstacles = PhysicsObject.CreateStaticObject(width, height); |
---|
50 | obstacles.Position = place; |
---|
51 | obstacles.Shape = Shape.Rectangle; |
---|
52 | obstacles.Color = Color.OrangeRed; |
---|
53 | |
---|
54 | Add(obstacles); |
---|
55 | } |
---|
56 | |
---|
57 | void Wall(Vector place, double width, double height) |
---|
58 | { |
---|
59 | PhysicsObject wall = PhysicsObject.CreateStaticObject(width, height); |
---|
60 | wall.Position = place; |
---|
61 | wall.Shape = Shape.Rectangle; |
---|
62 | wall.Color = Color.DarkGray; |
---|
63 | wall.CollisionIgnoreGroup = 1; |
---|
64 | wall.IsVisible = true; |
---|
65 | Add(wall); |
---|
66 | } |
---|
67 | void Ground(Vector place, double width, double height) |
---|
68 | { |
---|
69 | PhysicsObject ground = PhysicsObject.CreateStaticObject(width, height); |
---|
70 | ground.Position = place; |
---|
71 | ground.Color = Color.Black; |
---|
72 | ground.Shape = Shape.Rectangle; |
---|
73 | ground.IsVisible = false; |
---|
74 | //ground.CollisionIgnoreGroup = 1; |
---|
75 | Add(ground); |
---|
76 | } |
---|
77 | void Character(Vector place, double height, double width) |
---|
78 | { |
---|
79 | character = new PlatformCharacter(30, 30); |
---|
80 | character.Position = place; |
---|
81 | character.X = -50.0; |
---|
82 | character.Color = Color.Black; |
---|
83 | character.Shape = Shape.Rectangle; |
---|
84 | character.CollisionIgnoreGroup = 1; |
---|
85 | character.Image = player1Picture; |
---|
86 | character.Tag = "character"; |
---|
87 | characterHealth = 5; |
---|
88 | AddCollisionHandler(character, "character2", PlayerIsHit); |
---|
89 | Add(character); |
---|
90 | |
---|
91 | createGun(); |
---|
92 | } |
---|
93 | |
---|
94 | void Character2(Vector place, double height, double width) |
---|
95 | { |
---|
96 | character2 = new PlatformCharacter(30, 30); |
---|
97 | character2.Position = place; |
---|
98 | character2.X = 70.0; |
---|
99 | character2.Color = Color.Black; |
---|
100 | character2.Shape = Shape.Rectangle; |
---|
101 | character2.CollisionIgnoreGroup = 1; |
---|
102 | character2.Image = Image.Mirror(player2picture); |
---|
103 | character2.Tag = "character2"; |
---|
104 | AddCollisionHandler(character2, "character", PlayerIsHit); |
---|
105 | character2Health = 5; |
---|
106 | Add(character2); |
---|
107 | |
---|
108 | createGun2(); |
---|
109 | } |
---|
110 | |
---|
111 | void createGun() |
---|
112 | { |
---|
113 | Player1Gun = new AssaultRifle(30, 10); |
---|
114 | Player1Gun.Ammo.Value = 1000; |
---|
115 | Player1Gun.MaxAmmoLifetime = TimeSpan.FromSeconds(0.9); |
---|
116 | Player1Gun.ProjectileCollision = ProjectileHit; |
---|
117 | //Add(Player1Gun); |
---|
118 | character.Weapon = Player1Gun; |
---|
119 | } |
---|
120 | void createGun2() |
---|
121 | { |
---|
122 | Player2Gun = new AssaultRifle(30, 10); |
---|
123 | Player2Gun.Ammo.Value = 1000; |
---|
124 | Player2Gun.ProjectileCollision = ProjectileHit; |
---|
125 | Player2Gun.MaxAmmoLifetime = TimeSpan.FromSeconds(0.9); |
---|
126 | character2.Weapon = Player2Gun; |
---|
127 | } |
---|
128 | void ProjectileHit(PhysicsObject ammunition, PhysicsObject target) |
---|
129 | { |
---|
130 | ammunition.Destroy(); |
---|
131 | } |
---|
132 | void Shootthegun(AssaultRifle weapon) |
---|
133 | { |
---|
134 | PhysicsObject ammo = weapon.Shoot(); |
---|
135 | if (ammo != null) |
---|
136 | { |
---|
137 | ammo.Size *= 0.8; |
---|
138 | } |
---|
139 | } |
---|
140 | |
---|
141 | void addControl() |
---|
142 | { |
---|
143 | |
---|
144 | Keyboard.Listen(Key.W, ButtonState.Down,jump, "Player1 will jump", character,new Vector(0.0, 200.0)); |
---|
145 | Keyboard.Listen(Key.A, ButtonState.Down, movement, "Player1 will turn left", character, new Vector(-100.0, 0.0)); |
---|
146 | Keyboard.Listen(Key.D,ButtonState.Down, movement, "Player1 will turn right", character,new Vector(100.0, 0.0)); |
---|
147 | |
---|
148 | Keyboard.Listen(Key.LeftControl, ButtonState.Pressed, Shootthegun, "Shoot button", Player1Gun); |
---|
149 | |
---|
150 | |
---|
151 | Keyboard.Listen(Key.Up, ButtonState.Down, jump, "Player 2 will jump", character2, new Vector(0.0, 200.0)); |
---|
152 | Keyboard.Listen(Key.Left, ButtonState.Down, movement, "Player 2 will turn left", character2, new Vector(-100.0, 0.0)); |
---|
153 | Keyboard.Listen(Key.Right, ButtonState.Down, movement, "Player 2 will move right", character2, new Vector(100.0, 0.0)); |
---|
154 | Keyboard.Listen(Key.Space, ButtonState.Pressed, Shootthegun, "Shoot button for Player2", Player2Gun ); |
---|
155 | |
---|
156 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); |
---|
157 | |
---|
158 | |
---|
159 | } |
---|
160 | void movement(PlatformCharacter player, Vector move) |
---|
161 | { |
---|
162 | player.Walk(move.X); |
---|
163 | } |
---|
164 | void jump (PlatformCharacter player, Vector jump) |
---|
165 | { |
---|
166 | player.Jump(jump.Y); |
---|
167 | } |
---|
168 | void PlayerIsHit(PhysicsObject player, PhysicsObject target) |
---|
169 | { |
---|
170 | characterHealth--; |
---|
171 | |
---|
172 | if (characterHealth <= 0) |
---|
173 | { |
---|
174 | player.Destroy(); |
---|
175 | } |
---|
176 | } |
---|
177 | void startMenu() |
---|
178 | { |
---|
179 | MultiSelectWindow alkuValikko = new MultiSelectWindow("Pelin alkuvalikko", |
---|
180 | "Start Game", "Instructions", "Exit"); |
---|
181 | alkuValikko.AddItemHandler(0, startGame); |
---|
182 | alkuValikko.AddItemHandler(1, instruction); |
---|
183 | alkuValikko.AddItemHandler(2, Exit); |
---|
184 | Add(alkuValikko); |
---|
185 | |
---|
186 | alkuValikko.Color = Color.Red; |
---|
187 | } |
---|
188 | void startGame() |
---|
189 | { |
---|
190 | CreateLevel(); |
---|
191 | Camera.ZoomToAllObjects(); |
---|
192 | addControl(); |
---|
193 | Gravity = new Vector(0.0, -420.0); |
---|
194 | Level.Background.Image = wallpaper; |
---|
195 | IsFullScreen = true; |
---|
196 | |
---|
197 | |
---|
198 | |
---|
199 | } |
---|
200 | void instruction() |
---|
201 | { |
---|
202 | Label instruction = new Label(); |
---|
203 | instruction.Text = "Both player have 5 lives."; |
---|
204 | Add(instruction); |
---|
205 | } |
---|
206 | void exit() |
---|
207 | { |
---|
208 | |
---|
209 | } |
---|
210 | |
---|
211 | } |
---|