public override void Update(cObject o) { o.handled = true; bool iscontrollable = true; if (disablecontrol > 0) { disablecontrol--; iscontrollable = false; } //Velocity momentum handle double resistance = o.velocityMomentum <= 1 ? 1 : o.velocityMomentum; if (game._cKeyboard.IsKeyPressed(controls.forward) && iscontrollable && !freezecontrols) { if (o.velocityMomentum < maxVelocity) o.velocityMomentum += 5 / resistance; if (fuel < 2000) { double ok = (fuel / 2000); o.velocityMomentum *= ok; } } else if (game._cKeyboard.IsKeyPressed(controls.backward) && iscontrollable && !freezecontrols) { if (o.velocityMomentum >= 0) o.velocityMomentum -= 0.5; else o.velocityMomentum -= o.velocityMomentum < -5 ? 0 : 1; } else if (o.velocityMomentum > 0) { double factor = 0.2; if (game._cKeyboard.IsKeyPressed(controls.brake)) factor = 1; o.velocityMomentum -= factor; if (o.velocityMomentum < 0) o.velocityMomentum = 0; } else if (o.velocityMomentum < 0) { double factor = 0.2; if (game._cKeyboard.IsKeyPressed(controls.brake)) factor = 1; o.velocityMomentum += factor; if (o.velocityMomentum > 0) o.velocityMomentum = 0; } //Velocity angle handle if (o.velocityMomentum > 0.5) { if (game._cKeyboard.IsKeyPressed(controls.right) && iscontrollable && !freezecontrols) o.rotation -= o.velocityMomentum / (5 * (o.velocityMomentum / maxVelocity)); if (game._cKeyboard.IsKeyPressed(controls.left) && iscontrollable && !freezecontrols) o.rotation += o.velocityMomentum / (5 * (o.velocityMomentum / maxVelocity)); } else if (o.velocityMomentum < -0.5) { if (game._cKeyboard.IsKeyPressed(controls.right) && iscontrollable && !freezecontrols) o.rotation += o.velocityMomentum / (5 * (o.velocityMomentum / maxVelocity)); if (game._cKeyboard.IsKeyPressed(controls.left) && iscontrollable && !freezecontrols) o.rotation -= o.velocityMomentum / (5 * (o.velocityMomentum / maxVelocity)); } if (game._cKeyboard.IsKeyPressed(controls.forward) && game._cKeyboard.IsKeyPressed(controls.right) && iscontrollable && !freezecontrols) { if (game._cKeyboard.IsKeyPressed(32)) driftright += driftright < 45 ? 2 : 0; else driftright += driftright < 30 ? 0.5 : 0; o.velocityAngle = new Angle(o.rotation + driftright, Angle.Degrees); } else if (game._cKeyboard.IsKeyPressed(controls.forward) && game._cKeyboard.IsKeyPressed(controls.left) && iscontrollable && !freezecontrols) { if (game._cKeyboard.IsKeyPressed(32)) driftleft += driftleft < 45 ? 2 : 0; else driftleft += driftleft < 30 ? 0.5 : 0; o.velocityAngle = new Angle(o.rotation - driftleft, Angle.Degrees); } else { driftright = 0; driftleft = 0; o.velocityAngle = new Angle(o.rotation + driftleft - driftright, Angle.Degrees); } double vx = 0.0, vy = 0.0; o.GetVelocity(ref vx, ref vy); o.posX += vx; o.posY += vy; if (driftright > 5 || driftleft > 5) { double ox = 0, oy = 0; o.GetPosition(ref ox, ref oy); double ptx = 10, pty = -5; ptx += ox; pty += oy; cMath.RotatePointAroundOrigin(new Angle(o.rotation, Angle.Degrees), ox + (o.Image.Width / 2), oy - (o.Image.Height / 2), ref ptx, ref pty); double ptx2 = 10, pty2 = -25; ptx2 += ox; pty2 += oy; cMath.RotatePointAroundOrigin(new Angle(o.rotation, Angle.Degrees), ox + (o.Image.Width / 2), oy - (o.Image.Height / 2), ref ptx2, ref pty2); double skidrotation = o.rotation; game.skidmarks[game.skidcounter % game.skidmarks.Length].SetImage(Properties.Resources.skidmark); game.skidmarks[game.skidcounter % game.skidmarks.Length].SetRotation(new Angle(skidrotation, Angle.Degrees)); game.skidmarks[game.skidcounter++ % game.skidmarks.Length].SetPosition(ptx, pty); game.skidmarks[game.skidcounter % game.skidmarks.Length].SetImage(Properties.Resources.skidmark); game.skidmarks[game.skidcounter % game.skidmarks.Length].SetRotation(new Angle(skidrotation, Angle.Degrees)); game.skidmarks[game.skidcounter++ % game.skidmarks.Length].SetPosition(ptx2, pty2); } double dec = o.velocityMomentum == 0 ? 2.5 : o.velocityMomentum; if (fuel - Math.Abs(dec * 2) < 0) fuel = 0; else fuel -= Math.Abs(dec * 2); if (o.velocityMomentum <= 2) { if (playIdle == true) { playFirst = playEnd = true; playIdle = false; if (o.velocityMomentum > 0) { OnceSounds.controls.stop(); } TriggerLoop("idle.wav"); } } else if (o.velocityMomentum > 2 && o.velocityMomentum < maxVelocity) { if (game._cKeyboard.IsKeyPressed(controls.forward) && iscontrollable) { if (playFirst == true) { sound_triggered = ticker; LoopSounds.controls.stop(); if (current_acc_pos > 0) { TriggerOnce("acc.wav", current_acc_pos); } else { TriggerOnce("acc.wav", 0); } playRelease = playEnd = playIdle = true; playFirst = false; } } else { if (playRelease == true) { playFirst = playEnd = playIdle = true; playRelease = false; LoopSounds.controls.stop(); TriggerOnce("release.wav", 0); } } current_acc_pos = (o.velocityMomentum / maxVelocity) * 5; } else if (o.velocityMomentum >= maxVelocity - 5) { if (playEnd == true) { playIdle = playFirst = playRelease = true; playEnd = false; TriggerLoop("end.wav"); } } }
public abstract void Update(cObject o);
public void SetStartObject(cObject o) { startpointobj = o; }
public bool CarCollision(PointF point, cObject o) { players[0].car.collisionHandled = true; switch (o.collisionType) { case (int)CollisionType.Bounce: players[0].car.SetPosition(players[0].car.posXOld, players[0].car.posYOld); players[0].car.rotation = players[0].car.rotationOld; if (players[0].car.velocityMomentum < 10) players[0].car.velocityMomentum = 0; players[0].car.customModule.Event(Car.Events.Collision, (int)players[0].car.velocityMomentum / 2); players[0].car.velocityMomentum = (players[0].car.velocityMomentum / 4) * -1; break; case (int)CollisionType.Car: players[0].car.SetPosition(players[0].car.posXOld, players[0].car.posYOld); players[0].car.rotation = players[0].car.rotationOld; players[0].car.customModule.Event(Car.Events.Collision, (int)players[0].car.velocityMomentum / 2); players[0].car.velocityMomentum /= 2; break; case (int)CollisionType.Grass: players[0].car.velocityMomentum *= 0.95; break; case (int)CollisionType.Checkpoint: if (players[0].cp == o) { races[activeRace].OnPlayerEnterCheckpoint(0); return true; } else if (players[1].cp == o) break; break; } return true; }
public void SetPlayerCheckpoint(int playerid, cObject o) { racers[playerid].checkpointobj = o; }
public void LinkObjectToPlayer(int playerid, cObject o) { racers[playerid].racer = o; }
public bool IsCameraFollowingObject(cObject o, int camid) { return cameras[camid].followingObject == o.objectId; }
public void FollowObject(cObject o, int camid) { cameras[camid].followingObject = o.objectId; }
public cObject CreateObject() { cObject o = new cObject(objects.Count); objects.Add(o); return o; }