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 AdventureOfStarKid : PhysicsGame |
---|
10 | { |
---|
11 | private Image[] running = LoadImages("running1", "running2"); |
---|
12 | private Image[] standinganimation = LoadImages("standinganimation"); |
---|
13 | private Image[] shootinganimation = LoadImages("shootinganimation"); |
---|
14 | const double nopeus = 200; |
---|
15 | const double hyppyNopeus = 750; |
---|
16 | const int RUUDUN_KOKO = 40; |
---|
17 | PlasmaCannon pelaajan1Ase; |
---|
18 | |
---|
19 | |
---|
20 | PlatformCharacter pelaaja1; |
---|
21 | |
---|
22 | Image pelaajanKuva = LoadImage("Standinganimation"); |
---|
23 | Image tahtiKuva = LoadImage("stumper(Enemy)"); |
---|
24 | |
---|
25 | SoundEffect maaliAani = LoadSoundEffect("maali"); |
---|
26 | |
---|
27 | public override void Begin() |
---|
28 | { |
---|
29 | Gravity = new Vector(0, -1000); |
---|
30 | SmoothTextures = false; |
---|
31 | |
---|
32 | LuoKentta(); |
---|
33 | LisaaNappaimet(); |
---|
34 | |
---|
35 | Camera.Follow(pelaaja1); |
---|
36 | Camera.ZoomFactor = 1.2; |
---|
37 | Camera.StayInLevel = true; |
---|
38 | } |
---|
39 | |
---|
40 | void LuoKentta() |
---|
41 | { |
---|
42 | TileMap kentta = TileMap.FromLevelAsset("kentta1"); |
---|
43 | kentta.SetTileMethod('#', LisaaTaso); |
---|
44 | kentta.SetTileMethod('*', Lisaastumper); |
---|
45 | kentta.SetTileMethod('N', LisaaPelaaja); |
---|
46 | kentta.Execute(RUUDUN_KOKO, RUUDUN_KOKO); |
---|
47 | Level.CreateBorders(); |
---|
48 | Level.Background.CreateGradient(Color.White, Color.SkyBlue); |
---|
49 | } |
---|
50 | |
---|
51 | void LisaaTaso(Vector paikka, double leveys, double korkeus) |
---|
52 | { |
---|
53 | PhysicsObject taso = PhysicsObject.CreateStaticObject(leveys, korkeus); |
---|
54 | taso.Position = paikka; |
---|
55 | taso.Color = Color.Green; |
---|
56 | Add(taso); |
---|
57 | } |
---|
58 | |
---|
59 | void Lisaastumper(Vector paikka, double leveys, double korkeus) |
---|
60 | { |
---|
61 | PhysicsObject tahti = PhysicsObject.CreateStaticObject(leveys, korkeus); |
---|
62 | tahti.IgnoresCollisionResponse = false; |
---|
63 | tahti.Position = paikka; |
---|
64 | tahti.Image = tahtiKuva; |
---|
65 | tahti.Tag = "stumper"; |
---|
66 | Add(tahti); |
---|
67 | } |
---|
68 | |
---|
69 | void LisaaPelaaja(Vector paikka, double leveys, double korkeus) |
---|
70 | { |
---|
71 | pelaaja1 = new PlatformCharacter(leveys*0.5, korkeus); |
---|
72 | pelaaja1.Position = paikka; |
---|
73 | pelaaja1.Mass = 4.0; |
---|
74 | pelaaja1.Image = pelaajanKuva; |
---|
75 | AddCollisionHandler(pelaaja1, "stumper", TormaaTahteen); |
---|
76 | Add(pelaaja1); |
---|
77 | pelaaja1.AnimWalk = new Animation(running); |
---|
78 | pelaaja1.AnimIdle = new Animation(standinganimation); |
---|
79 | pelaajan1Ase = new PlasmaCannon(1.0, 1.0); |
---|
80 | pelaajan1Ase.InfiniteAmmo = true; |
---|
81 | pelaaja1.Weapon = pelaajan1Ase; |
---|
82 | } |
---|
83 | |
---|
84 | void LisaaNappaimet() |
---|
85 | { |
---|
86 | Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet"); |
---|
87 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); |
---|
88 | |
---|
89 | Keyboard.Listen(Key.Left, ButtonState.Down, Liikuta, "Liikkuu vasemmalle", pelaaja1, -nopeus); |
---|
90 | Keyboard.Listen(Key.Right, ButtonState.Down, Liikuta, "Liikkuu vasemmalle", pelaaja1, nopeus); |
---|
91 | Keyboard.Listen(Key.Up, ButtonState.Pressed, Hyppaa, "Pelaaja hyppää", pelaaja1, hyppyNopeus); |
---|
92 | Keyboard.Listen(Key. C, ButtonState.Pressed, Ammu, "Ampuu", pelaajan1Ase); |
---|
93 | |
---|
94 | |
---|
95 | ControllerOne.Listen(Button.Back, ButtonState.Pressed, Exit, "Poistu pelistä"); |
---|
96 | |
---|
97 | ControllerOne.Listen(Button.DPadLeft, ButtonState.Down, Liikuta, "Pelaaja liikkuu vasemmalle", pelaaja1, -nopeus); |
---|
98 | ControllerOne.Listen(Button.DPadRight, ButtonState.Down, Liikuta, "Pelaaja liikkuu oikealle", pelaaja1, nopeus); |
---|
99 | ControllerOne.Listen(Button.A, ButtonState.Pressed, Hyppaa, "Pelaaja hyppää", pelaaja1, hyppyNopeus); |
---|
100 | |
---|
101 | PhoneBackButton.Listen(ConfirmExit, "Lopeta peli"); |
---|
102 | } |
---|
103 | |
---|
104 | void Liikuta(PlatformCharacter hahmo, double nopeus) |
---|
105 | { |
---|
106 | hahmo.Walk(nopeus); |
---|
107 | } |
---|
108 | |
---|
109 | void Hyppaa(PlatformCharacter hahmo, double nopeus) |
---|
110 | { |
---|
111 | hahmo.Jump(nopeus); |
---|
112 | } |
---|
113 | |
---|
114 | void TormaaTahteen(PhysicsObject hahmo, PhysicsObject stumper) |
---|
115 | { |
---|
116 | maaliAani.Play(); |
---|
117 | MessageDisplay.Add("Ouch!"); |
---|
118 | //stumper.Destroy(); |
---|
119 | } |
---|
120 | void Ammu(PlasmaCannon Ase) |
---|
121 | { |
---|
122 | Ase.Shoot(); |
---|
123 | pelaaja1.Animation = new Animation(shootinganimation); |
---|
124 | pelaaja1.Animation.Start(); |
---|
125 | } |
---|
126 | } |
---|