piątek, 6 marca 2015

#Stencyl: Ghost Car
Difficulty: (4/10)

What is a ghost car?
Think of racing games. In almost all if not all racing games you will have a time attack mode where your aim is to get the best time on a track. You can compete against ghost car which represents „you” in your best run.

Racing game with ghost car on the left

Original request:


Link to video of the game:

Follow the link to get to the game with implemented ghost car:
Ghost Car algorithm:
The problem was solved for top view racing game.
 


















Example of top view racing game

What we want is:
  • Record player's position(x,y) as the game goes on
  • Make Ghost car object(actor) which repeats the last „run” based on recorded positions sequence

Ghost Car solution:
I made a Stencyl game to show how to record positions and use them for ghost car. The idea of the game is that you move green square(using arrow keys) and collect 3 yellow squares. Once you collect all 3 timer stops and you may press R to try another run. On "not first run" there will be a ghost car in form of red square. Ghost car will always show the run with the best time.

Yellow squares could be used as checkpoints for player in racing games.

The thing we need to watch out for while implementing ghost car is first run. On first run we cant load ghost car because there is no path for it to follow. Another thing we need to consider is that ghost car always shows the best run. 

When created event in <scene behavior>

  • Count – number of yellow squares already taken
  • time – time of the timer
  • temp list – list containing as list[i] – x and as list[i+1] – y coordinate of a player in current run
  • better time – answer if current run is better than so far the best
  • do every <0.01> – counting time of current run. Counting ends if all yellow squares are taken.
  • Helper_1 – keeps index [i] of currently checked temp_list[i] it is increased by 2 (not as usually by 1) because of how temp list is organized
  • do every <0.05>:
  • if run not finished (not all yellows taken)
  • record position of player
  • if it isn't your first run
  • update position of ghost car (if possible == if there are elements for that)
  • Create player and yellow squares
  • If it isn't your first run create ghost car
When player touches yellow square <colision behavior>
  • Kill touched yellow square – so it wouldn't be touched again
  • Increase count (variable of already touched yellow squares)
  • Trigger event <collision> in scene behavior
Event triggered by when player touches yellow square <scene behavior>
  • If all yellow eaten (this pretty much marks the end of run)
  • If it's end of first run – change it to first run finished, make current time the best time
  • If current time is better than best run time:
    • mark that there is new better time (used in drawing event)
    • set new best time to current time
    • set new best list of position to the list of positions of current run

Tags:
Stencyl, Racing, Ghost, Car,

Brak komentarzy:

Prześlij komentarz