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

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