A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: CS3 AS2 Flash game help!

  1. #1
    Junior Member
    Join Date
    Sep 2012
    Posts
    2

    CS3 AS2 Flash game help!

    Hi guys,
    I am new to this forum and wanted to ask a question about creating a game! I am quite good at as2, but don't know how to do this! any help will be appreciated
    Basically, I am trying to make a 2d game where you drive a train-it will have 3 speeds and 2 braking speeds. It will go round a circuit with the camera moving around with it! In fact, it is just like this: http://www.youtube.com/watch?v=DtPzo8R0Y30
    If any of you can tell me how to create a game like in the video, I will be so happy!
    Thanks guys!
    Samuel

  2. #2
    Senior Member
    Join Date
    Mar 2010
    Posts
    157
    I think I can help you with this. But to keep things basic, I'm not going to code the wagons for you.
    I'm not testing the code, so it might have some bugs. But I trust you will be able to take care of them if you're motivated.

    First off, let's create a clip that looks like the first wagon and create an instance of that object on the stage. Let's give it the instance name 'train_mc' (do so in the properties panel).
    Then create an new object that looks like, say, a circle. We'll call it 'checkpoint'. Create a few instances of 'checkpoint' and call them i1_mc, i2_mc, i3_mc etc. Let's just stick with four of them for now. Arrange them in a square or a similar shape.

    On a layer on _root, enter this code:


    var nrOfStops:Number = 4 //the four instances of 'checkpoint'
    var currentStop:Number = 1;
    var speed:Number = 0;
    var maxspeed:Number = 30;
    var minspeed:Number = 0;
    var acceleration:Number = 4;
    updateTangent();

    function updateTangent():Void{
    _root.dy = _root['i'+ (currentStop + i > nrOfStops? 1 : currentStop + 1) +'_mc' ]._y - _root['i' + currentStop +'_mc']._y;
    _root.dx = _root['i'+ (currentStop + i > nrOfStops? 1 : currentStop + 1) +'_mc']._x - _root['i' + currentStop +'_mc']._x;
    _root.tangent = dy/dx;
    }

    onEnterFrame = game;

    function game():Void{
    input();
    move();
    checkpoint();
    }

    function input():Void{

    if(Key.isDown(Key.UP)){
    speed += acceleration;
    }else if (Key.isDown(Key.DOWN)){
    speed -= acceleration;
    }
    if(speed > maxspeed){
    speed = maxspeed;
    }else if(speed < minspeed){
    speed =minspeed;
    }

    }

    function move():Void{
    train_mc._y += speed * tangent;
    train_mc._x += speed / tangent;
    }

    function checkpoint():Void{
    if(train_mc.hitTest(_root['i'+(currentStop+1) + '_mc'])){
    currentStop ++;
    }
    if(train_mc.hitTest(_root['i'+(1 + '_mc'])){
    currentStop = 1;
    }
    }
    Let me know if it works! If it doesn't, I hope you can use it to guide you none the less!

  3. #3
    Senior Member
    Join Date
    Mar 2010
    Posts
    157
    Could you mention if this code has been useful to you?

  4. #4
    Junior Member
    Join Date
    Sep 2012
    Posts
    2
    Hi, thanks a lot! It did help me :-) Sorry for not replying sooner-a levels ;-)

  5. #5
    Senior Member
    Join Date
    Mar 2010
    Posts
    157
    Glad to hear Good luck with your game

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center