source: 2014/27/BenjaminE/AttackOfTheChicken/AttackOfTheChicken/AttackOfTheChicken/AttackOfTheChicken.cs @ 5249

Revision 5249, 2.4 KB checked in by beamechi, 5 years ago (diff)

On tehny se pelajaa. Se osaa kavella ja hyyppia. Kansa se level on loppu.

Line 
1using System;
2using System.Collections.Generic;
3using Jypeli;
4using Jypeli.Assets;
5using Jypeli.Controls;
6using Jypeli.Effects;
7using Jypeli.Widgets;
8
9public class AttackOfTheChicken : PhysicsGame
10{
11
12    PlatformCharacter player;
13
14    public override void Begin()
15    {
16        CreateLevel();
17
18        KeyInput();
19
20        Camera.Follow(player);
21        Camera.Zoom(1);
22        Camera.StayInLevel = true;
23
24        Gravity = new Vector(0, -200.0);
25       
26    }
27
28    /// <summary>
29    /// Creating the Level and all it's assets
30    /// </summary>
31
32    void CreateLevel() {
33        ColorTileMap level = ColorTileMap.FromLevelAsset("Level");
34
35        level.SetTileMethod(Color.ForestGreen, CreateGrass);
36        level.SetTileMethod(Color.Brown, CreateDirt);
37        level.SetTileMethod(Color.Gray, CreateStone);
38        level.SetTileMethod(Color.Red, CreatePlayer);
39
40        level.Execute(32, 32);
41    }
42
43    void CreateGrass(Vector place, double width, double height) {
44        PhysicsObject grass = PhysicsObject.CreateStaticObject(32.0, 32.0);
45        grass.Image = LoadImage("Grass");
46        grass.Position = place;
47        Add(grass);
48    }
49
50    void CreateDirt(Vector place, double width, double height) {
51        GameObject dirt = new GameObject(32.0, 32.0);
52        dirt.Image = LoadImage("Dirt");
53        dirt.Position = place;
54        Add(dirt);
55    }
56
57    void CreateStone(Vector place, double width, double height) {
58        PhysicsObject stone = PhysicsObject.CreateStaticObject(32.0, 32.0);
59        stone.Image = LoadImage("Stone");
60        stone.Position = place;
61        Add(stone);
62    }
63
64    void CreatePlayer(Vector place, double width, double height) {
65        player = new PlatformCharacter(32.0, 32.0);
66        player.Image = LoadImage("Player");
67        player.Position = place;
68        Add(player);
69    }
70
71
72
73    void PlayerJump(double speed) {
74        player.Jump(speed);
75    }
76
77    void MovePlayer(double direction) {
78        player.Walk(direction);
79    }
80
81    void KeyInput() {
82        Keyboard.Listen(Key.Right, ButtonState.Down, MovePlayer, "Key Right pressed", 300.0);
83        Keyboard.Listen(Key.Left, ButtonState.Down, MovePlayer, "Key Right pressed", -300.0);
84
85        Keyboard.Listen(Key.Space, ButtonState.Pressed, PlayerJump, "Key Space pressed", 100.0);
86
87        Keyboard.Listen(Key.Escape, ButtonState.Down, Exit, "Sionara Bitch!");
88    }
89
90}
Note: See TracBrowser for help on using the repository browser.