source: 2016/24/AnttuK/SUO/SUO/SUO/SUO.cs @ 7270

Revision 7270, 1.8 KB checked in by jotapoti, 5 years ago (diff)

New Files Game got updated.

Line 
1using System;
2using System.Collections.Generic;
3using Jypeli;
4using Jypeli.Assets;
5using Jypeli.Controls;
6using Jypeli.Effects;
7using Jypeli.Widgets;
8
9public class SUO : PhysicsGame
10{
11    Image plImg = LoadImage("Untitled");
12    PhysicsObject player;
13    public override void Begin()
14    {
15        SetKeys();
16        SetLevel();
17    }
18    void SetKeys()
19    {
20        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli");
21        Keyboard.Listen(Key.Left, ButtonState.Down, MovePlayer, null, new Vector(-20, 0));
22        Keyboard.Listen(Key.Right, ButtonState.Down, MovePlayer, null, new Vector(20, 0));
23        Keyboard.Listen(Key.Up, ButtonState.Down, MovePlayer, null, new Vector(0, 20));
24        Keyboard.Listen(Key.Down, ButtonState.Down, MovePlayer, null, new Vector(0, -20));
25    }
26    void SetLevel()
27    {
28       
29        TileMap tiles = TileMap.FromLevelAsset("level1");
30        tiles.SetTileMethod('#', CreateRect, Color.Gray);
31        tiles.SetTileMethod('P', CreatePlayer);
32        tiles.Execute(32,32);
33    }
34    void CreateRect(Vector pos, double width, double height, Color clr)
35    {
36        PhysicsObject tile = PhysicsObject.CreateStaticObject(width, height);
37        tile.Position = pos;
38        tile.Shape = Shape.Rectangle;
39        tile.Color = clr;
40        Add(tile);
41    }
42    void CreatePlayer(Vector pos, double width, double height)
43    {
44        player = new PhysicsObject(width/2,height/2);
45        player.Position = pos;
46        player.Shape = Shape.Circle;
47        player.Image = plImg;
48        player.Restitution = 1.0;
49        player.LinearDamping = 1.0;
50        player.CanRotate = false;
51        Add(player);
52    }
53    void MovePlayer(Vector vect)
54    {
55        player.Hit(vect);
56    }
57}
Note: See TracBrowser for help on using the repository browser.