Monday, 1 February 2010

The beginnings of my flash game

So onto the beginning of my flash game. First of all I had to draw what I was going to need which would be a track and definitely a car. I also drew some obstacles that I would code later on aswell as a dynamic text box to become my timer. All of these were given their own layer. E.g. obstacles, timer, car, track etc.



Now that it was all drawn I could begin coding so I created my Actionscript layer. I decided that first I would code my car, however it wouldn't be easy as I wanted it to move exactly like a car rather then a dot along a road.
This proved to be incredibly tricky needing lots of vars and functions howwever I finally got it to work with gradual acceleration, stearing and reversing. This is my proudest achievement in actionscript to date. Below are all the vars I used for this part of my code:
var speed = 0;
var acceleration = 0.2;
var maxSpeed = 10;
var maxReverse = -5
var carRotation
var leftPressed
var rightPressed
var upPressed
var downPressed
var friction = 0.85
var rotationSpeed = 12


I decided it would be easier to create vars stating that a button is pressed and then creating a function using that var then to just simply have the key code scripting. Below is an example of what I did:

if ( event.keyCode == 37){
leftPressed = true;
}

if (leftPressed){
mc_car.rotation -= carRotation;
}


Thats all for now my next post will be about me conquering collision detection.

No comments:

Post a Comment