source: 2016/27/PaavoH/CopsAndRobbers/CopsAndRobbers/CopsAndRobbers/CopsAndRobbers.cs @ 9474

Revision 9474, 1.7 KB checked in by rikavila, 18 months 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 CopsAndRobbers : PhysicsGame
10{
11    public override void Begin()
12    {
13        AddPlayer();
14        //AddCop();
15        Level.CreateBorders();
16    }
17    void AddPlayer()
18    {
19        PhysicsObject Player = new PhysicsObject(40, 40);
20        Player.Shape = Shape.Circle;
21        Player.Color = Color.Red;
22        Player.Restitution = 0.1;
23        Player.LinearDamping = 0.95;
24        Player.Tag = "player";
25        Add(Player);
26
27        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli");
28        Keyboard.Listen(Key.A, ButtonState.Down, MovePlayer, null, new Vector(-1000, 0), Player);
29        Keyboard.Listen(Key.D, ButtonState.Down, MovePlayer, null, new Vector(1000, 0), Player);
30        Keyboard.Listen(Key.W, ButtonState.Down, MovePlayer, null, new Vector(0, 1000), Player);
31        Keyboard.Listen(Key.S, ButtonState.Down, MovePlayer, null, new Vector(0, -1000), Player);
32    }
33
34    void MovePlayer(Vector vector, PhysicsObject Player)
35    {
36        Player.Push(vector);
37    }
38
39    void AddCop()
40    {
41        PhysicsObject Cop = new PhysicsObject(40, 40);
42        Cop.Shape = Shape.Circle;
43        Cop.Color = Color.Blue;
44        Cop.X = 100;
45        Cop.Restitution = 0.1;
46        Cop.LinearDamping = 0.95;
47        Add(Cop);
48
49        FollowerBrain CopBrain = new FollowerBrain("player");
50
51        CopBrain.Speed = 200;               
52        CopBrain.DistanceFar = 600;
53        //CopBrain.DistanceClose = 200;
54        //CopBrain.StopWhenTargetClose = true
55
56        Cop.Brain = CopBrain;
57    }
58}
Note: See TracBrowser for help on using the repository browser.