# Create a flash draw game like Line Rider or others – A different approach – Part 3

Maybe some of you did not notice it, but there was a real pearl in a comment of Create a flash draw game blike Line Rider or others – A different approach – Part 2 post.

Jesuson studied all the source codes and came up with this comment:

—————-

I have been testing it and it chash a lot of times. I would change next things:
1. For the collision response, to calculate the out velocity I would use

vx1=-cosa*w.vx sina*w.vy;
vy1=(-cosa*w.vy-sina*w.vx)*bounce;

w.vx = -cosa*vx1-sina*vy1; //ball X velocity
w.vy = -cosa*vy1 sina*vx1; //ball Y velocity

Now it has got aceleration and velocity wonâ€™t be infinite.

2. There is some problems when you test the perimeter of the ball for collisions. The first is you donâ€™t do it in order. For do it in order change
by

The second is, what happend if there are diferent points of collisions? for expample if ball collide with floor and wall, you donâ€™t must take it like a single collision, becouse the response wonâ€™t be good.
For fix it I take all the collisions points what are together (For detect than itÂ´s together you have to detect them in order like I said)and put it in a collision group array, and then I calculate diferents responses with diferent arrays.

Here you can see what Iâ€™m speaking about:
Good method â€“> http://denvish.net/ulf/130607/55602_collisions5.fla

Look what happend in two cases when the ball hit the wall.
note: use up/down to acelerate/brake.

—————-

This is the actionscript with some comments from the author

```gravity = .2;
bounce = 0;
precision = 360;
w1.vx = 0;
w1.vy = 0;
w1.vAngle = 0;
w1.col = false;
w1.cArray = [];
onEnterFrame = function () {
w1.vy += gravity;
checkWL1(w1, level);
checkWL2(w1, level);
control(w1);
w1._x += w1.vx;
w1._y += w1.vy;
w1._rotation += w1.vAngle;
scrollWorld();
};
////////////////// Colisiones /////////////////////////////
function checkWL1(w, level) {
w.sumX = 0;
w.sumY = 0;
w.collisions = 0;
for (i=1; i0) {
checkArray(w);
//collisionResponse(w);
}
w.cArray = [];
}
function checkWL2(w, level) {
w.col = false;
for (i=1; i0) {
w.col = true;
}
}
function checkDL(px, py, w, l) {
if (l.hitTest(px, py, true)) {
w.sumX += px;
w.sumY += py;
w.collisions++;
w.col2 = true;
} else {
w.col2 = false;
}
}
function collisionResponse(w) {
w.hitX = w1.sumX/w.collisions;
w.hitY = w.sumY/w.collisions;
dx = w._x-w.hitX;
dy = w._y-w.hitY;
d = Math.sqrt((dx*dx)+(dy*dy));
angle = Math.atan(dx/dy);
if (dy>0) {
cosa = Math.cos(angle);
sina = Math.sin(angle);
} else {
cosa = -Math.cos(angle);
sina = -Math.sin(angle);
}
w.sina = sina;
w.cosa = cosa;
w._x += d2*sina*2;
w._y += d2*cosa*2;
v = Math.sqrt((w.vx*w.vx)+(w.vy*w.vy));
vx1 = -cosa*w.vx+sina*w.vy;
vy1 = (-cosa*w.vy-sina*w.vx)*bounce;
w.vx = -cosa*vx1-sina*vy1;
w.vy = -cosa*vy1+sina*vx1;
}
function checkArray(w) {
cont = 20;
w.sumX = 0;
w.sumY = 0;
w.collisions = 0;
for (i=0; i0) {
if (cont == 0) {
collisionResponse(w);
w.collisions = 0;
w.sumX = 0;
w.sumY = 0;
cont = 20;
} else {
cont--;
}
}
}
}
}
///////////////////// Control ///////////////////////////////
function control(w1) {
if (Key.isDown(38) && w1.col && w1.vx<10) {
w1.vx += .3;
}
if (Key.isDown(40) && w1.col && w1.vx>-3) {
w1.vx -= .1;
}
}
///////////////////// Camera  ////////////////////////////
function scrollWorld() {
if (w1._x>350 && w1.vx>0) {
level._x -= w1.vx;
w1._x -= w1.vx;
}
if (w1._x<200 && w1.vx<0) {
level._x -= w1.vx;
w1._x -= w1.vx;
}
}```

And this is the result (up and down arrows to move the ball)

Now I am going to study more in depth this work because I find it really interesting, so expect a tutorial based on this code during next days.

And this is the source code hosted on my site, just in case some day the link provied by Jesuson should disappear.

215 GAME PROTOTYPES EXPLAINED WITH SOURCE CODE
// 1+2=3
// 10000000
// 2 Cars
// 2048
// Avoider
// Ballz
// Block it
// Blockage
// Bloons
// Boids
// Bombuzal
// Breakout
// Bricks
// Columns
// CubesOut
// Dots
// DROP'd
// Dudeski
// Eskiv
// Filler
// Fling
// Globe
// HookPod
// Hundreds
// InkTd
// Iromeku
// Lumines
// Magick
// MagOrMin
// Maze
// Memdot
// Nano War
// Nodes
// o:anquan
// Ononmin
// Pacco
// Phyballs
// Platform
// Poker
// Pool
// Poux
// Pudi
// qomp
// Racing
// Renju
// SameGame
// Security
// Sling
// Slingy
// Sokoban
// Splitter
// Sproing
// Stack
// Stairs
// Stringy
// Sudoku
// Tetris
// Threes
// Toony
// Turn
// TwinSpin
// vvvvvv
// Wordle
// Worms
// Yanga
// Zhed
// zNumbers