source: 2016/30/AleksiN/name/name/name/name.cs @ 8168

Revision 8168, 2.7 KB checked in by almajono, 4 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 name : PhysicsGame
10{
11
12    Image motorbike = LoadImage("motorbike");
13    Image tire = LoadImage("tire");
14    PhysicsObject bikePhysicsObject;
15    PhysicsStructure bike;
16    public override void Begin()
17
18    {
19
20        SmoothTextures = true;
21        //IsFullScreen = true;
22        Camera.Follow(bikePhysicsObject);
23
24        AddPlayer();
25        Points();
26        Keys();
27
28        Surface level = Surface.CreateBottom(Level, 30, 100, 10, 100);
29        Add(level);
30        Gravity = new Vector(0.0, -800.0);
31
32        Wind = new Vector(-25, 0);
33        Smoke smoke = new Smoke();
34        Timer smokeTimer = new Timer();
35        smokeTimer.Interval = 0.1;
36        smokeTimer.Timeout += delegate { smoke.Position = bike.Objects[0].Position; };
37        smokeTimer.Start();
38        Add(smoke);
39
40    }
41
42    void AddPlayer()
43    {
44        PhysicsObject leftTire = new PhysicsObject(57.5, 57.5, Shape.Circle);
45        PhysicsObject rightTire = new PhysicsObject(57.5, 57.5, Shape.Circle);
46        bikePhysicsObject = new PhysicsObject(250.0, 200.0);
47        leftTire.X = -70.0;
48        leftTire.Y = -260.0;
49        rightTire.X = 65.0;
50        rightTire.Y = -260.0;
51        bikePhysicsObject.X = 0;
52        bikePhysicsObject.Y = -200;
53        leftTire.Image = tire;
54        rightTire.Image = tire;
55        bikePhysicsObject.Image = motorbike;
56        this.bike = new PhysicsStructure(leftTire, rightTire, bikePhysicsObject);
57        bikePhysicsObject.IgnoresCollisionResponse = true;
58        Add(this.bike);
59        Add(bikePhysicsObject);
60    }
61    void Keys()
62    {
63        Keyboard.Listen(Key.Down, ButtonState.Down, Movement, null, new Vector(-2000, 0));
64        Keyboard.Listen(Key.Up, ButtonState.Down, Movement, null, new Vector(2000, 0));
65        Keyboard.Listen(Key.Left, ButtonState.Down, ChangeAngle, null, 2.5);
66        Keyboard.Listen(Key.Right, ButtonState.Down, ChangeAngle, null, -2.5);
67        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli");
68    }
69    void Movement(Vector movement)
70    {
71        bike.Push(movement);
72    }
73    void ChangeAngle(double ammount)
74    {
75        bike.AngularVelocity = ammount;
76    }
77    IntMeter pointCounter;
78    void Points()
79    {
80        pointCounter = new IntMeter(0);
81        Label pointLabel = new Label();
82        pointLabel.X = Screen.Left + 100;
83        pointLabel.Y = Screen.Top - 100;
84        pointLabel.TextColor = Color.Black;
85        pointLabel.Color = Color.White;
86        pointLabel.BindTo(pointCounter);
87        Add(pointLabel);
88    }
89
90}
Note: See TracBrowser for help on using the repository browser.