Click here to Skip to main content
15,878,814 members
Articles / Programming Languages / C#

Roller Coaster

Rate me:
Please Sign up or sign in to vote.
4.98/5 (31 votes)
31 Mar 2014CPOL4 min read 56.6K   30   28
Build and ride roller coasters on Windows 8. Use your Ultrabook to play the game using touch.

This article is an entry in our AppInnovation Contest. Articles in this sub-section are not required to be full articles so care should be taken when voting.

  • App Up Store Closed

    Roller Coaster did fairly well in the free section of the AppUp Store, ranking in the top 10 at times. It was a great run, and I appreciate being invoked in the contest from Intel And CodeProject. But Times are a changing and its time to look forward. I have decided to rebuild the back end and open source it (This is a work in progress). Although I enjoyed the style i coded it, it was way too complex, and hard to debug (More on this later If I create another post). So the new focus is simple straight forward minimum dependency's. I have Created a WebGL Version for testing, but keep in mind the new backed isn't done, but it will in the end have the same functionality.

    I plan to build a front end in Unity at some point, to push out to several devices. As This is really branching off from this post, I may create another post focused on its new focus and purpose at some point. Everything In Introduction on this page and below ill leave as is.

    Open Source: https://rollercoastermaker.codeplex.com/

    RCWebGL: http://rollercoaster.dickinsonbros.com/index.aspx (This is running the game server side and displaying it in webgl)

    Flow charts: https://www.lucidchart.com/documents/view/47a0-9e54-52e81405-b926-70b30a0080fd

    I Built this along with the AppUp Project, and it shares the same code base the AppUp Version has.

    Windows Phone: http://www.windowsphone.com/en-us/store/app/roller-coaster/139a20f7-31c2-40b9-8deb-de763c3c3032

Introduction

Roller Coaster. Build and ride roller coasters with ease. Designed to be able to learn to play in seconds with touch. Use of gyroscope while riding to get coins for high scores.

Its designed to be able to play it in varying time spans. Its a game you could pull out at lunch and build a coaster in 2-3 min and show a friend. Also one that you could spend much more time building the perfect coaster.

The game is written in C#, and is using XNA as a front end (a Windows 8 "Desktop App").

Background

My name is Mark Dickinson I am a student at ASU, and am a CS major. I have been working with roller coaster design since I made my first mod on Warcraft 3 with triggers. I learned a huge amount from watching players struggle to learn the game quickly. I stopped adding features and spent over a year on and off making the features that existed very easy to use and straight forward. I have since spent most of my time in c#, sliverlight, and xna.

Key Features

  • Fully playable with keyboard, mouse, and touch.
  • Building coasters, with a large amount of flex-ability yet designed to take only seconds to learn.
  • Ride coasters, from in the cart or from a third person perspective.
  • Ability to lean in your cart left or right in your cart to get coins while riding.

Screenshots

Riding (Cart View)

Riding (Third Person View)

The code

Backend

The back end of the game is built in c# in a library called "RCLIB" .

Here is a function I have in "RCLIB".

Build Track

  • Is coaster finished
  • Where would the track be built
  • Check for flipped on bools, (e.g., iqnoreOutOfBounds)
  • If its on, make sure it can fix the issue, or return zero tracks built.

Note: When it attempts to fix the issue, it allows the game to build additional tracks, or back up a small amount.

C#
static public int BuildTrack(Direction direction, 
          List<Object3D> myTracks, ref List<Direction> directions)
{
    //No Building Tracks IF Coaster is finshed, this is a fail safe.
    if (CoasterFinshed)
    {
        return 0;
    }


    Object3D track = new Object3D();
    Vector3 newOrientation = new Vector3();
    Vector3 newLocation = new Vector3();
    Vector3 LastOrientation = new Vector3();

    //Find Where Next Track would be
    if (myTracks.Count > 0)
    {
        LastOrientation = new Vector3(myTracks.Last<Object3D>().Orientation.X, 
          myTracks.Last<Object3D>().Orientation.Y, myTracks.Last<Object3D>().Orientation.Z);
        newOrientation = new Vector3(myTracks.Last<Object3D>().Orientation.X, 
          myTracks.Last<Object3D>().Orientation.Y, myTracks.Last<Object3D>().Orientation.Z);
        newLocation = new Vector3(myTracks.Last<Object3D>().Location.X, 
          myTracks.Last<Object3D>().Location.Y, myTracks.Last<Object3D>().Location.Z);
    }
    else
    {
        LastOrientation = new Vector3();
        newOrientation = new Vector3(0, 270, 0);
        newLocation = new Vector3(0, 0, -40);
    }
    newOrientation = GetNewOrientation(newOrientation, direction);
    newLocation = GetNewLocation(newOrientation, newLocation, LastOrientation);

    track.Location = newLocation;
    track.Orientation = newOrientation;
    track.Scale = new Vector3(Constants.TRACK_SCALE, Constants.TRACK_SCALE, Constants.TRACK_SCALE);

    //
    if (iqnoreAllButStandard)
    {
        //Build The Track Standard
        directions.Add(direction);
        myTracks.Add(track);
        return 1;
    }

    else if (iqnoreFinshArea == false && InFinshArea(newLocation))
    {
        directions.Add(direction);
        myTracks.Add(track);
        FinshCoaster(myTracks, ref directions, 1);
        return 0;
    }

    else if (iqnoreAutoLoop == false && AutoLoop(myTracks, ref directions))
    {
        return 0;
    }

    else if (iqnoreCollision == false && CollisionDetected(newLocation, myTracks))
    {
        return 0;
    }

    else if (iqnoreFlaten == false && Flaten(myTracks, direction, track, 
             newOrientation, newLocation, LastOrientation, ref directions))
    {
        return 0;
    }

    if (iqnoreTracksToLow == false && TrackToLow(newLocation, newOrientation))
    {
        return 0;
    }

    else if (iqnoreBounceOffWall == false && BounceOffWall(newLocation, direction, myTracks, ref directions))
    {
        return 0;
    }

    else if (iqnoreOutOfBounds == false && OutOfBounds(newLocation))
    {
        return 0;
    }

    else
    {
        //Build The Track Standard
        directions.Add(direction);
        myTracks.Add(track);
        return 1;
    }

The point of showing this is that the game attempts to fix rules broken by the user, so to lower the learning curve in such a way that they can keep building, with out having to deal with rules most of the time.

Frontend

The front end is using standard XNA, to for user Inputs, loading content, and showing visuals.

Due to not wanting my back end to have any ties to my front end I had to rebuild parts that existed in xna.

Here is my draw method, showing a downside of my choice of making them completely separate instead of sharing some of the xna code base. But overall it makes for a much more flexible code base.

Draw loop

C#
protected override void Draw(GameTime gameTime)
{

    GraphicsDevice.DepthStencilState = DepthStencilState.Default;
    GraphicsDevice.BlendState = BlendState.Opaque;
    GraphicsDevice.Clear(Color.CornflowerBlue);

    //Layout
    drawManager.DrawModel(layoutModel, new Microsoft.Xna.Framework.Vector3(0, 0, 0), 
      new Microsoft.Xna.Framework.Vector3(0, 0, 0), new Microsoft.Xna.Framework.Vector3(.25f, .25f, .25f));

    //Tracks
    for (int i = 0; i < core.Tracks.Count; i++)
    {
        drawManager.DrawModel(trackModel, 
          new Microsoft.Xna.Framework.Vector3(core.Tracks[i].Location.X, 
              core.Tracks[i].Location.Y, core.Tracks[i].Location.Z),
          new Microsoft.Xna.Framework.Vector3(core.Tracks[i].Orientation.X, 
              core.Tracks[i].Orientation.Y, core.Tracks[i].Orientation.Z),
          new Microsoft.Xna.Framework.Vector3(RollerCoaster.Constants.TRACK_SCALE, 
              RollerCoaster.Constants.TRACK_SCALE, RollerCoaster.Constants.TRACK_SCALE));
    }

    //Cart
    drawManager.DrawModel(cartModel, 
       new Microsoft.Xna.Framework.Vector3(core.Cart.Location.X, 
           core.Cart.Location.Y, core.Cart.Location.Z),
       new Microsoft.Xna.Framework.Vector3(core.Cart.Orientation.X, 
           core.Cart.Orientation.Y, core.Cart.Orientation.Z),
       new Microsoft.Xna.Framework.Vector3(RollerCoaster.Constants.CART_SCALE, 
           RollerCoaster.Constants.CART_SCALE, RollerCoaster.Constants.CART_SCALE));


    spriteBatch.Begin();
    //Menu
    DrawMenu();

    //Draw Mouse
    MouseState currentMouseState = Mouse.GetState();
    float mouseX = (1980.0f / GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width) * currentMouseState.X;
    float mouseY = (1080.0f / GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height) * currentMouseState.Y;

    Microsoft.Xna.Framework.Vector2 posMouse = new Microsoft.Xna.Framework.Vector2(mouseX, mouseY);
    spriteBatch.Draw(pointer, posMouse, Color.White);

    spriteBatch.End();

    //Clean Up
    GraphicsDevice.DepthStencilState = DepthStencilState.Default;

    base.Draw(gameTime);
}

Final Note

Building a game project that makes sense for the Ultrabook has been sort of like building a project built for computer and a tablet at the same time. Finding the fine line from additional features/ Options and keep simplicity has been a interesting struggle.

In the end roller coaster is a perfect fit for causal play on an Ultrabook in nearly any setting.

Download

http://www.appup.com/app-details/roller-coaster-maker

Change Log

10/8/2012 - Uploaded Roller Beta Version (1.0)

10/27/2012 - Uploaded Roller Coaster Version (1.14), Fixed Menus (ride menu still needs finished), added coin mode, fixed several issues and bugs. Next version will be on the app-up Store.

11/21/2012 - Finished Game, Cleaned out bugs, streamlined UI. Submitted App to AppUp Store, Awaiting approval.

11/21/2012 - Approved in the Appup Store. Removed old Versions from this post.

3/31/2014 - Appup Store has been shutdown. Added Section At top with a open source links and more information about the future of roller coaster.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Student
United States United States
Student at ASU, CS Major.

Comments and Discussions

 
GeneralMy vote of 4 Pin
Member 106163912-Apr-14 22:01
Member 106163912-Apr-14 22:01 
SuggestionDownload Link Pin
Gamenew0930-Mar-14 16:02
Gamenew0930-Mar-14 16:02 
GeneralRe: Download Link Pin
Rover2341 - Mark Dickinson30-Mar-14 16:22
Rover2341 - Mark Dickinson30-Mar-14 16:22 
Generalwow Pin
Paulo Augusto Kunzel29-Oct-13 14:34
professionalPaulo Augusto Kunzel29-Oct-13 14:34 
GeneralMy vote of 5 Pin
Member 94311087-Jan-13 10:55
Member 94311087-Jan-13 10:55 
GeneralMy vote of 5 Pin
Manoj Kumar Choubey15-Nov-12 19:48
professionalManoj Kumar Choubey15-Nov-12 19:48 
GeneralMy vote of 5 Pin
Savalia Manoj M6-Nov-12 17:19
Savalia Manoj M6-Nov-12 17:19 
GeneralMy vote of 5 Pin
Wendelius27-Oct-12 9:24
mentorWendelius27-Oct-12 9:24 
GeneralMy vote of 5 Pin
Hari Tantry24-Oct-12 11:57
Hari Tantry24-Oct-12 11:57 
GeneralMy vote of 3 Pin
Hari Tantry23-Oct-12 7:32
Hari Tantry23-Oct-12 7:32 
GeneralRe: My vote of 3 Pin
Rover2341 - Mark Dickinson23-Oct-12 8:10
Rover2341 - Mark Dickinson23-Oct-12 8:10 
GeneralMy vote 5 Pin
Nitin S22-Oct-12 20:23
professionalNitin S22-Oct-12 20:23 
GeneralMy vote of 5 Pin
Andrew Aylett20-Oct-12 12:06
Andrew Aylett20-Oct-12 12:06 
GeneralMy vote of 5 Pin
Yvan Rodrigues19-Oct-12 13:26
professionalYvan Rodrigues19-Oct-12 13:26 
QuestionMy Vote of 5 Pin
Ratish Philip16-Oct-12 18:02
Ratish Philip16-Oct-12 18:02 
GeneralMy vote of 5 Pin
Paul Daniel Dickinson12-Oct-12 3:42
Paul Daniel Dickinson12-Oct-12 3:42 
GeneralMy vote of 5 Pin
Chris Maunder9-Oct-12 14:45
cofounderChris Maunder9-Oct-12 14:45 
SuggestionRegarding Downloads Pin
Ranjan.D8-Oct-12 1:26
professionalRanjan.D8-Oct-12 1:26 
GeneralRe: Regarding Downloads Pin
Rover2341 - Mark Dickinson8-Oct-12 6:11
Rover2341 - Mark Dickinson8-Oct-12 6:11 
GeneralRe: Regarding Downloads Pin
Ranjan.D8-Oct-12 6:55
professionalRanjan.D8-Oct-12 6:55 
GeneralMy vote of 5 Pin
IInjac7-Oct-12 11:48
IInjac7-Oct-12 11:48 
GeneralMy vote of 5 Pin
lukeadickinson7-Oct-12 8:52
lukeadickinson7-Oct-12 8:52 
GeneralMy vote of 5 Pin
Ranjan.D7-Oct-12 8:25
professionalRanjan.D7-Oct-12 8:25 
GeneralMy vote of 5 Pin
ojanacek7-Oct-12 3:58
ojanacek7-Oct-12 3:58 
GeneralRe: My vote of 5 Pin
Rover2341 - Mark Dickinson7-Oct-12 5:25
Rover2341 - Mark Dickinson7-Oct-12 5:25 
For this post, I have it running in native xna. And I figured for this contest it would make more sense that way as Ill be moving it to the app up store with Intel.

So yes, this is full screen xna. What do you think my project so far?


But...

"Metro" Apps officially dont support XNA. But I have recently ported a version of this to metro (awaiting approval) using moho.

Moho works on "Metro", and it reads in a full XNA project. There is a little bit of work to make it work with moho, but it can be done in a day.

About Moho's Site. (http://monogame.codeplex.com/)
The Guide I used online( http://blogs.msdn.com/b/bobfamiliar/archive/2012/08/01/windows-8-xna-and-monogame-part-1-overview.aspx[^]))

All of these steps are in the guide above, I strongly suggest you use the guide over what i am typing here, as this is off the top of my head.

Steps:
1. Download Moho (a bit of pain you have to use github or something like it)
2. Get Moho Update
3. In Visual studio 2012 Put in the WindowsMetroTemplate
4. Create a new project in visual studio 2012 using the moho project type
5. Add your XNA Project to the Solution, or use the one thats in the template (its already hooked up to mono)
6. Add the monoGame.Framework to your references on your xna project
Note: (I couldn't get this part to work right from the guide above, so i mannuly found added, all of the SharpDX references, from MonoGame Folder That you download in step 1)
7. In visual studio 2010, you have to build all your content in xna (content manger), grab them from your debug folder, and add them to your xna project. Put them in a folder called "Content".
8. Run game.
9. I found that one of the references was making it fail the windows cert test, but i wasnt using it so i removed it. (dont remember what one but the test tells you)

Here is a sample, I made that you requested. Its a Simple XNA Game, that uses moho to run on windows 8 "Metro". It has a texture, and a model.

https://docs.google.com/open?id=0B_i7Pi4RW6VNWTZ6Z0FBWHBjOFE

Updated Sample* The old sample with missing a project file.

Open Folder MohoSample, Then MohoSample, then MohoSample.csproj. Then it will come up correctly.

modified 7-Oct-12 14:21pm.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.