source: 2017/24/AaroM/TheLegendOfSpikey/TheLegendOfSpikey/TheLegendOfSpikey/TheLegendOfSpikey.cs @ 8623

Revision 8623, 3.7 KB checked in by npo17_8, 6 years ago (diff)
Line 
1using System;
2using System.Collections.Generic;
3using Jypeli;
4using Jypeli.Assets;
5using Jypeli.Controls;
6using Jypeli.Effects;
7using Jypeli.Widgets;
8
9public class TheLegendOfSpikey : PhysicsGame
10{
11    const double nopeus = 200;
12    const double hyppyNopeus = 750;
13    const int RUUDUN_KOKO = 40;
14
15    PlatformCharacter pelaaja1; 
16
17    Image pelaajanKuva = LoadImage("norsu");
18    Image tahtiKuva = LoadImage("tahti");
19
20    SoundEffect maaliAani = LoadSoundEffect("maali");
21
22    public override void Begin()
23    {
24        Gravity = new Vector(0, -1000);
25
26        LuoKentta();
27        LisaaNappaimet();
28        LisaaTaso(100.0, 0.0);
29        LisaaTaso(-100.0, 0.0);
30        LisaaTaso(0.0, 100.0);
31        LisaaTaso(200.0, 0.0);
32        LisaaTaso(0.0, -100.0);
33        LisaaTaso(-200.0, 0.0);
34        LisaaTaso(0.0, 200.0);
35        LisaaTaso(0.0, -200.0);
36        LisaaTaso(300, 0.0);
37        LisaaTaso(-300, 0.0);
38        LisaaTaso(0.0, 300.0);
39        LisaaTaso(0.0, -300.0);
40        LisaaTaso(400, 0.0);
41        LisaaTaso(-400, 0.0);
42        LisaaTaso(0.0, 400);
43        LisaaTaso(0.0, -400);
44        LisaaTaso(100.0, 100.0);
45        LisaaTaso(200.0, 200.0);
46        LisaaTaso(300.0, 300.0);
47        LisaaTaso(400.0, 400.0);
48        LisaaTaso(-100.0, 100.0);
49        LisaaTaso(-200.0, 200.0);
50        LisaaTaso(-300.0, 300.0);
51        LisaaTaso(-400.0, 400.0);
52        Camera.Follow(pelaaja1);
53        Camera.ZoomFactor = 1.2;
54        Camera.StayInLevel = true;
55    }
56
57    void LuoKentta()
58    {
59        TileMap kentta = TileMap.FromLevelAsset("kentta1");
60        kentta.Execute(RUUDUN_KOKO, RUUDUN_KOKO);
61        Level.CreateBorders();
62        Level.Background.CreateGradient(Color.JungleGreen, Color.SkyBlue);
63    }
64
65
66
67
68
69    void LisaaPelaaja(Vector paikka, double leveys, double korkeus)
70    {
71        pelaaja1 = new PlatformCharacter(leveys, korkeus);
72        pelaaja1.Mass = 4.0;
73        pelaaja1.Image = pelaajanKuva;
74        AddCollisionHandler(pelaaja1, "tahti", TormaaTahteen);
75        pelaaja1. X = 0.0;
76        pelaaja1. Y = 100.0;
77        Add(pelaaja1);
78    }
79
80    void LisaaNappaimet()
81    {
82        Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet");
83        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli");
84
85        Keyboard.Listen(Key.Left, ButtonState.Down, Liikuta, "Liikkuu vasemmalle", pelaaja1, -nopeus);
86        Keyboard.Listen(Key.Right, ButtonState.Down, Liikuta, "Liikkuu vasemmalle", pelaaja1, nopeus);
87        Keyboard.Listen(Key.Up, ButtonState.Pressed, Hyppaa, "Pelaaja hyppää", pelaaja1, hyppyNopeus);
88
89        ControllerOne.Listen(Button.Back, ButtonState.Pressed, Exit, "Poistu pelistä");
90
91        ControllerOne.Listen(Button.DPadLeft, ButtonState.Down, Liikuta, "Pelaaja liikkuu vasemmalle", pelaaja1, -nopeus);
92        ControllerOne.Listen(Button.DPadRight, ButtonState.Down, Liikuta, "Pelaaja liikkuu oikealle", pelaaja1, nopeus);
93        ControllerOne.Listen(Button.A, ButtonState.Pressed, Hyppaa, "Pelaaja hyppää", pelaaja1, hyppyNopeus);
94
95        PhoneBackButton.Listen(ConfirmExit, "Lopeta peli");
96    }
97
98    void Liikuta(PlatformCharacter hahmo, double nopeus)
99    {
100
101    }
102
103    void Hyppaa(PlatformCharacter hahmo, double nopeus)
104    {
105
106    }
107
108    void TormaaTahteen(PhysicsObject hahmo, PhysicsObject tahti)
109    {
110        maaliAani.Play();
111        MessageDisplay.Add("Keräsit kolikon!");
112        tahti.Destroy();
113    }
114
115
116    void LisaaTaso(double x, double y)
117    {
118        PhysicsObject taso = PhysicsObject.CreateStaticObject(80.0, 20.0);
119        taso.Shape = Shape.Rectangle;
120        taso.X = x;
121        taso.Y = y;
122        taso.Color = Color.DarkForestGreen;
123        Add(taso);
124    }
125
126
127
128}
Note: See TracBrowser for help on using the repository browser.