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

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