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

Revision 8186, 3.0 KB checked in by almajono, 4 years ago (diff)
RevLine 
[8096]1using System;
2using System.Collections.Generic;
3using Jypeli;
4using Jypeli.Assets;
5using Jypeli.Controls;
6using Jypeli.Effects;
7using Jypeli.Widgets;
[8186]8using System.Linq;
[8096]9public class name : PhysicsGame
10{
[8155]11
[8145]12    Image motorbike = LoadImage("motorbike");
[8133]13    Image tire = LoadImage("tire");
[8168]14    PhysicsObject bikePhysicsObject;
[8155]15    PhysicsStructure bike;
[8096]16    public override void Begin()
[8133]17
[8096]18    {
[8115]19
[8186]20        Level.Width = Screen.Width * 25;
21
[8137]22        SmoothTextures = true;
[8186]23        IsFullScreen = false;
24       
[8155]25        AddPlayer();
[8137]26        Points();
27        Keys();
[8163]28
[8186]29        Camera.Follow(bikePhysicsObject);
30
31        Surface level = Surface.CreateBottom(Level, 200, 300, 200, 20);
[8108]32        Add(level);
33        Gravity = new Vector(0.0, -800.0);
34
[8155]35        Wind = new Vector(-25, 0);
36        Smoke smoke = new Smoke();
[8163]37        Timer smokeTimer = new Timer();
38        smokeTimer.Interval = 0.1;
39        smokeTimer.Timeout += delegate { smoke.Position = bike.Objects[0].Position; };
40        smokeTimer.Start();
[8155]41        Add(smoke);
[8145]42
[8133]43    }
[8163]44
[8155]45    void AddPlayer()
[8133]46    {
[8155]47        PhysicsObject leftTire = new PhysicsObject(57.5, 57.5, Shape.Circle);
48        PhysicsObject rightTire = new PhysicsObject(57.5, 57.5, Shape.Circle);
[8168]49        bikePhysicsObject = new PhysicsObject(250.0, 200.0);
[8155]50        leftTire.X = -70.0;
51        leftTire.Y = -260.0;
[8108]52        rightTire.X = 65.0;
[8155]53        rightTire.Y = -260.0;
[8168]54        bikePhysicsObject.X = 0;
55        bikePhysicsObject.Y = -200;
[8137]56        leftTire.Image = tire;
57        rightTire.Image = tire;
[8168]58        bikePhysicsObject.Image = motorbike;
[8186]59        this.bike = new PhysicsStructure(rightTire, leftTire, bikePhysicsObject);
[8168]60        bikePhysicsObject.IgnoresCollisionResponse = true;
[8155]61        Add(this.bike);
[8168]62        Add(bikePhysicsObject);
[8186]63        bike.KineticFriction = 1.0;
64        bike.Restitution = 1;
65        bike.Y += 100;
[8133]66    }
[8137]67    void Keys()
[8133]68    {
[8186]69        Keyboard.Listen(Key.Down, ButtonState.Down, Movement, null, new Vector(-3000, 0));
70        Keyboard.Listen(Key.Up, ButtonState.Down, Movement, null, new Vector(3000, 0));
71        Keyboard.Listen(Key.Left, ButtonState.Down, ChangeAngle, null, 1.0);
72        Keyboard.Listen(Key.Right, ButtonState.Down, ChangeAngle, null, -1.0);
[8096]73        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli");
74    }
[8137]75    void Movement(Vector movement)
[8115]76    {
[8186]77        if(GetObjectAt(bikePhysicsObject.Position - new Vector(0, bike.Height / 2) * 0.9, 0.1) != null)
78        {
79            bike.Push(movement);
80        }
[8115]81    }
[8145]82    void ChangeAngle(double ammount)
[8115]83    {
[8155]84        bike.AngularVelocity = ammount;
[8115]85    }
86    IntMeter pointCounter;
[8137]87    void Points()
[8115]88    {
89        pointCounter = new IntMeter(0);
90        Label pointLabel = new Label();
91        pointLabel.X = Screen.Left + 100;
92        pointLabel.Y = Screen.Top - 100;
93        pointLabel.TextColor = Color.Black;
94        pointLabel.Color = Color.White;
95        pointLabel.BindTo(pointCounter);
96        Add(pointLabel);
97    }
[8163]98
[8096]99}
Note: See TracBrowser for help on using the repository browser.