External Exam Download Resources Web Applications Games Recycle Bin

race track | gml

 TypeDesc
viewportpropertyallows us to set up our 'camera' to focus or view a segmented portion of the room in the game window. great for large maps or areas etc.
image_anglevariablecurrent angle at which the image will be drawn.
SpriteImages
sprCar
sprTrack3072x2304

Place origin between the front wheels for FWD steering / handling (feel free to try back wheels to simulate RWD):




Finally, set race track collision mask to precise (slow). This is not an ideal long-term solution, but will do while we are learning GML:




ObjectSpriteProperties
objCarsprCarVisible
objTracksprTrack3072x2304Visible

objCar Step

//on-road max speed:
var max_speed = 20;

//check if on or off-road:
if not(place_meeting(x, y, objTrack)){
  //car is off-road, so cap max speed:
  max_speed = 5;
  //if we go on ro off-road, speed will be too high...
  if (speed > max_speed){
    //... so decay speed gradually each step:
    speed = speed * 0.95;  
  }
}

//steering:
if (keyboard_check(vk_left)){
  image_angle = image_angle + 3;
  direction = direction + 3;
}

if (keyboard_check(vk_right)){
  image_angle = image_angle - 3;
  direction = direction - 3;
}

//accelerate:
if (keyboard_check(vk_up)){
  if (speed < max_speed){
    speed = speed + 0.5;
  }
}

Challenges

  1. Add an emergency / hand brake
  2. Add a boost / NOS button