Here are some button images you can download. We have buttons for
fans, and buttons for developers that have been featured on the site.
|
|
|  |
Now it’s time to make bricks disappear if they group in a 2×2 square.
Read part 1 and 2 if you did not already.
It’s not difficult to check if bricks form a 2×2 square… and it’s not difficult to remove them from the stage.
The tricky part is making bricks fill the empty spaces left by disappeared bricks and managing combos (fallen bricks can make another 2×2 square, generating more falling bricks, and so on).
I preferred not to have an onEnterFrame on every brick to check if it’s over an empty space and eventually move it, so I created another array called bricks_in_field saving the depth of the brick in that position, so when I remove some bricks I just have to put in the moveable_bricks the depth found in the bricks_in_field array and the “engine” does the rest.
Here it is the actionscript:
ACTIONSCRIPT:
-
// declaring some setup variables
-
// number of horizontal cells
-
grid_width = 16;
-
// number of vertical cells
-
grid_height = 10;
-
// size of the cell
-
tile_size = 30;
-
// offset in pixels fron the left side of the stage
-
x_offset = 10;
-
// offset in pixels from the top side of the stage
-
y_offset = 10;
-
// number of different colors that can be displayed in a brick
-
different_colors = 3;
-
// boolean values saying if I should wait for the left (or right, up…) key to be released
-
// this is used to make the player move bricks tapping arrow keys instead of just pressing them
-
wait_left = false;
-
wait_right = false;
-
wait_up = false;
-
wait_down = false;
-
// flag indicating if blocks are falling
-
falling = false;
-
// array containing the game field data
-
field = new Array();
-
// array containing bricks position
-
bricks_in_field = new Array();
-
// array containing the bricks I can move
-
moveable_bricks = new Array();
-
// initializing and drawing the play field and the bricks position fields
-
for (x=0; x<grid_width; x++) {
-
field[x] = new Array();
-
bricks_in_field[x] = new Array();
-
for (y=0; y<grid_height; y++) {
-
field[x][y] = 0;
-
bricks_in_field[x][y] = 0;
-
// look how I det ermine cells position according to tile size and offsets
-
cell = _root.attachMovie(“brick”, “brick_”+_root.getNextHighestDepth(), _root.getNextHighestDepth(), {_x:x*tile_size+x_offset, _y:(y+2)*tile_size+y_offset});
-
// first frame = empty cell
-
cell.gotoAndStop(1);
-
}
-
}
-
// calling the function that will place four bricks on the stage
-
place_bricks();
-
// main function, to be executed at every frame
-
_root.onEnterFrame = function() {
-
// if blocks aren’t falling
-
if (!falling) {
-
// checking if a block is the upper left one of a four block square
-
for (x=0; x<grid_width; x++) {
-
for (y=0; y<grid_height; y++) {
-
if (field[x][y] != 0 and field[x][y] == field[x+1][y] and field[x][y] == field[x+1][y+1] and field[x][y] == field[x][y+1]) {
-
// physically removing the bricks
-
_root[“brick_”+bricks_in_field[x][y+1]].removeMovieClip();
-
_root[“brick_”+bricks_in_field[x][y+2]].removeMovieClip();
-
_root[“brick_”+bricks_in_field[x+1][y+1]].removeMovieClip();
-
_root[“brick_”+bricks_in_field[x+1][y+2]].removeMovieClip();
-
// updating field array
-
field[x][y] = 0;
-
field[x][y+1] = 0;
-
field[x+1][y+1] = 0;
-
field[x+1][y] = 0;
-
// checking upper bricks to make them fall
-
start_y = y-1;
-
while (field[x][start_y]>0) {
-
moveable_bricks.push(bricks_in_field[x][start_y+1]);
-
start_y–;
-
}
-
start_y = y-1;
-
while (field[x+1][start_y]>0) {
-
moveable_bricks.push(bricks_in_field[x+1][start_y+1]);
-
start_y–;
-
}
-
falling = true;
-
}
-
}
-
}
-
// place new bricks only if no bricks are falling
-
if (!falling and moveable_bricks.length == 0) {
-
place_bricks();
-
}
-
// this is how I detect if a key was tapped:
-
// when it’s pressed, I wait for it to be released (in this case: not pressed)
-
// thanks to the wait_<direction> variable
-
if (Key.isDown(Key.LEFT)) {
-
wait_left = true;
-
} else {
-
if (wait_left) {
-
// if the left key has been tapped, move the four bricks on the left
-
for (x=0; x<4; x++) {
-
// this "if" is used to determine if the bricks are still inside the game field
-
if ((_root[“brick_”+moveable_bricks[x]]._x-x_offset)/tile_size-_root[“brick_”+moveable_bricks[x]].pos%2>0) {
-
_root[“brick_”+moveable_bricks[x]]._x -= tile_size;
-
}
-
}
-
// reset variable, now I must wait again for a key to be pressed
-
wait_left = false;
-
}
-
}
-
// same routine for the right key
-
if (Key.isDown(Key.RIGHT)) {
-
wait_right = true;
-
} else {
-
if (wait_right) {
-
for (x=0; x<4; x++) {
-
if ((_root[“brick_”+moveable_bricks[x]]._x-x_offset)/tile_size-_root[“brick_”+moveable_bricks[x]].pos%2<14) {
-
_root[“brick_”+moveable_bricks[x]]._x += tile_size;
-
}
-
}
-
wait_right = false;
-
}
-
}
-
// when the DOWN arrow is pressed, I must rotate the bricks clockwise
-
// block 0: moves to the right and becomes block 1
-
// block 1: moves down and becomes block 3
-
// block 2: moves up and becomes block 0
-
// block 3: moves to the left and becomes block 2
-
if (Key.isDown(Key.DOWN)) {
-
wait_down = true;
-
} else {
-
if (wait_down) {
-
for (x=0; x<4; x++) {
-
switch (_root[“brick_”+moveable_bricks[x]].pos) {
-
case 0 :
-
_root[“brick_”+moveable_bricks[x]].pos = 1;
-
_root[“brick_”+moveable_bricks[x]]._x += tile_size;
-
break;
-
case 1 :
-
_root[“brick_”+moveable_bricks[x]].pos = 3;
-
_root[“brick_”+moveable_bricks[x]]._y += tile_size;
-
break;
-
case 2 :
-
_root[“brick_”+moveable_bricks[x]].pos = 0;
-
_root[“brick_”+moveable_bricks[x]]._y -= tile_size;
-
break;
-
case 3 :
-
_root[“brick_”+moveable_bricks[x]].pos = 2;
-
_root[“brick_”+moveable_bricks[x]]._x -= tile_size;
-
break;
-
}
-
}
-
wait_down = false;
-
}
-
}
-
// when the UP arrow is pressed, I must rotate the bricks counter-clockwise
-
// block 0: moves down the right and becomes block 2
-
// block 1: moves to the left and becomes block 0
-
// block 2: moves to the right and becomes block 3
-
// block 3: moves up and becomes block 1
-
if (Key.isDown(Key.UP)) {
-
wait_up = true;
-
} else {
-
if (wait_up) {
-
for (x=0; x<4; x++) {
-
switch (_root[“brick_”+moveable_bricks[x]].pos) {
-
case 0 :
-
_root[“brick_”+moveable_bricks[x]].pos = 2;
-
_root[“brick_”+moveable_bricks[x]]._y += tile_size;
-
break;
-
case 1 :
-
_root[“brick_”+moveable_bricks[x]].pos = 0;
-
_root[“brick_”+moveable_bricks[x]]._x -= tile_size;
-
break;
-
case 2 :
-
_root[“brick_”+moveable_bricks[x]].pos = 3;
-
_root[“brick_”+moveable_bricks[x]]._x += tile_size;
-
break;
-
case 3 :
-
_root[“brick_”+moveable_bricks[x]].pos = 1;
-
_root[“brick_”+moveable_bricks[x]]._y -= tile_size;
-
break;
-
}
-
}
-
wait_up = false;
-
}
-
}
-
// when SPACE key is pressed, I don’t wait for its release but I detect the key at once
-
if (Key.isDown(Key.SPACE)) {
-
// letìs made bricks fall…
-
falling = true;
-
}
-
} else {
-
//if the blocks are falling
-
// blocks_landed variable will count the number of bricks that already touched the ground
-
// or that cannot fall anymore because they are over other bricks
-
blocks_landed = 0;
-
for (x=0; x<moveable_bricks.length; x++) {
-
// calculating x and y position of the brick in the array
-
x_pos = (_root[“brick_”+moveable_bricks[x]]._x-x_offset)/tile_size;
-
y_pos = (_root[“brick_”+moveable_bricks[x]]._y-y_offset)/tile_size-1;
-
// determining if the block can fall. There are two conditions:
-
// 1: its position is less than zero. It means the block is outside the grid, in its starting position
-
// 2: its position is lower than the grid height and the tile under the block is empty
-
if ((y_pos<0) or ((y_pos<grid_height) and (field[x_pos][y_pos] == 0))) {
-
// updating field array
-
field[x_pos][y_pos] = _root[“brick_”+moveable_bricks[x]]._currentframe;
-
field[x_pos][y_pos-1] = 0;
-
// physically moving the brick
-
_root[“brick_”+moveable_bricks[x]]._y += tile_size;
-
} else {
-
// if the brick cannot move down, increase the number of blocks landed
-
blocks_landed++;
-
}
-
}
-
// if all four bricks landed successfully…
-
if (blocks_landed == moveable_bricks.length) {
-
for (x=0; x<moveable_bricks.length; x++) {
-
x_pos = (_root[“brick_”+moveable_bricks[x]]._x-x_offset)/tile_size;
-
y_pos = (_root[“brick_”+moveable_bricks[x]]._y-y_offset)/tile_size-1;
-
// saving in the brick array the name of the brick landed on (x_pos,y_pos)
-
bricks_in_field[x_pos][y_pos] = moveable_bricks[x];
-
}
-
// reset variable to false
-
falling = false;
-
// reset moveable_bricks array
-
moveable_bricks = new Array();
-
}
-
}
-
};
-
// function to place four bricks on the stage
-
function place_bricks() {
-
// placing the four bricks
-
for (x=0; x<4; x++) {
-
// again, look how I determine bricks position according to tile size and offsets
-
brk = _root.attachMovie(“brick”, “brick_”+_root.getNextHighestDepth(), _root.getNextHighestDepth(), {_x:(grid_width/2+(x%2))*tile_size+x_offset, _y:y_offset+tile_size*Math.floor(x/2)});
-
// setting a random color for the brick (frames 2 to different_colors+1)
-
brk.gotoAndStop(Math.floor(Math.random()*different_colors)+2);
-
// saving brick position
-
// 0: up left
-
// 1: up right
-
// 2: bottom left
-
// 3: bottom right
-
brk.pos = x;
-
// saving the depth of the brick into the moveable_bricks array
-
// if you look how did I assign brick names, you’ll see that I can determine a brick name
-
// starting from its depth. It’s simply "brick_"+<the_depth>
-
moveable_bricks[x] = brk.getDepth();
-
}
-
}
And this is the result:
Now wait for the next step to handle timing events.
Download the source.
Bookmark this page on Digg, Kinja, FURL, Redit & other sites
Today WordPress.org team released version 2.6 with these notes:
I’m happy to announce that version 2.6 of WordPress.org is now available, almost a month ahead schedule. Version 2.6 “Tyner,” named for jazz pianist McCoy Tyner, contains a number of new features that make WordPress a more powerful CMS: you can now track changes to every post and page and easily post from wherever you are on the web, plus there are dozens of incremental improvements to the features introduced in version 2.5.
If you are the kind of blogger that waits for others to install latest releases before upgrading his own blog… well, I installed it and everything is working great.
You can check new features in this video:
I am finding really useful theme previews, because I am going to revamp the theme and keep new look secret until it’s finished.
Have no fear and install it.
Bookmark this page on Digg, Kinja, FURL, Redit & other sites
|
|  |
In the 1st part I showed you how to make a deflection engine starting from an old tutorial, now it’s time to let the player draw walls.
The idea comes from Srdjan Susnic, a reader who runs the blog Ask For Game Task.
The main task Srdjan accomplished was to add a mouse control so a player can draw lines from which the ball will bounce.
After collision between the ball and a line drawn by mouse, that line must be removed
The code is clear and well commented, but it seems to suffer a bug if the player just clicks the mouse without drawing.
It’s just a minor issue I fixed in a moment, and if you already read the original post, I just added the control if the player drew a line when he releases the mouse button with player_drew variable.
Anyway, this is the actionscript:
ACTIONSCRIPT:
-
// create game object
-
game = {gravity:0, dragging:false, clip:_root.game_mc, stageW:500, stageH:400, maxV:20};
-
// create object
-
// point p0 is its starting point in the coordinates x/y
-
_root.attachMovie(“ball”, “ball”, 1);
-
game.myOb = {clip:ball, airf:1, b:1, f:1, r:20, lastTime:getTimer()};
-
game.myOb.p0 = {x:150, y:80};
-
// vectors x/y components
-
game.myOb.vx = 8;
-
game.myOb.vy = 12;
-
// create first vector
-
// point p0 is its starting point in the coordinates x/y
-
// point p1 is its end point in the coordinates x/y
-
game.v = new Array();
-
game.v[0] = {p0:{x:50, y:40}, p1:{x:450, y:40}, b:1, f:1};
-
game.v[1] = {p0:{x:50, y:40}, p1:{x:50, y:360}, b:1, f:1};
-
game.v[2] = {p0:{x:50, y:360}, p1:{x:450, y:360}, b:1, f:1};
-
game.v[3] = {p0:{x:100, y:80}, p1:{x:400, y:320}, b:1, f:1};
-
_root.createEmptyMovieClip(“lines”, 2);
-
lines.lineStyle(1, 0xff0000);
-
// draw and calculate all parameters for the wall vectors
-
for (x=0; x<game.v.length; x++) {
-
lines.moveTo(game.v[x].p0.x, game.v[x].p0.y);
-
lines.lineTo(game.v[x].p1.x, game.v[x].p1.y);
-
updateVector(game.v[x], true);
-
}
-
_root.onEnterFrame = function() {
-
_root.runMe();
-
};
-
// function to draw the points, lines and show text
-
function drawAll(v) {
-
// place ob mc
-
v.clip._x = v.p1.x;
-
v.clip._y = v.p1.y;
-
}
-
// main function
-
function runMe() {
-
// start to calculate movement
-
var ob = game.myOb;
-
// add air resistance
-
ob.vx *= ob.airf;
-
ob.vy *= ob.airf;
-
// dont let it go over max speed
-
if (ob.vx>game.maxV) {
-
ob.vx = game.maxV;
-
} else if (ob.vx<-game.maxV) {
-
ob.vx = -game.maxV;
-
}
-
if (ob.vy>game.maxV) {
-
ob.vy = game.maxV;
-
} else if (ob.vy<-game.maxV) {
-
ob.vy = -game.maxV;
-
}
-
// update the vector parameters
-
updateObject(ob);
-
// check the walls for collisions
-
for (x=0; x<game.v.length; x++) {
-
var w = game.v[x];
-
var v = findIntersection(ob, w);
-
v = updateVector(v, false);
-
var pen = ob.r-v.len;
-
// if we have hit the wall
-
if (pen>=0) {
-
// move object away from the wall
-
ob.p1.x += v.dx*pen;
-
ob.p1.y += v.dy*pen;
-
// change movement, bounce off from the normal of v
-
var vbounce = {dx:v.lx, dy:v.ly, lx:v.dx, ly:v.dy, b:1, f:1};
-
var vb = bounce(ob, vbounce);
-
ob.vx = vb.vx;
-
ob.vy = vb.vy;
-
}
-
}
-
/********************************************************************/
-
// CODE ADDED BY SRDJAN SUSNIC
-
// check the lines created by mouse for collisions
-
x = 0;
-
while (x<game.mouseV.length) {
-
var w = game.mouseV[x];
-
var v = findIntersection(ob, w);
-
v = updateVector(v, false);
-
var pen = ob.r-v.len;
-
// if we have hit the wall
-
if (pen>=0) {
-
// move object away from the wall
-
ob.p1.x += v.dx*pen;
-
ob.p1.y += v.dy*pen;
-
// change movement, bounce off from the normal of v
-
var vbounce = {dx:v.lx, dy:v.ly, lx:v.dx, ly:v.dy, b:1, f:1};
-
var vb = bounce(ob, vbounce);
-
ob.vx = vb.vx;
-
ob.vy = vb.vy;
-
// remove the clip and vector array of the collided line
-
game.mouseV[x].lineClip.removeMovieClip();
-
game.mouseV.splice(x, 1);
-
} else {
-
x++;
-
}
-
}
-
// END OF CODE ADDED BY SRDJAN SUSNIC
-
/********************************************************************/
-
// reset object to other side if gone out of stage
-
if (ob.p1.x>game.stageW+ob.r) {
-
ob.p1.x = -ob.r;
-
} else if (ob.p1.x<-ob.r) {
-
ob.p1.x = game.stageW+ob.r;
-
}
-
if (ob.p1.y>game.stageH+ob.r) {
-
ob.p1.y = -ob.r;
-
} else if (ob.p1.y<-ob.r) {
-
ob.p1.y = game.stageH+ob.r;
-
}
-
// draw it
-
drawAll(ob);
-
// make end point equal to starting point for next cycle
-
ob.p0 = ob.p1;
-
// save the movement without time
-
ob.vx = ob.vx/ob.timeFrame;
-
ob.vy = ob.vy/ob.timeFrame;
-
}
-
// function to find all parameters for the vector
-
function updateVector(v, frompoints) {
-
// x and y components
-
if (frompoints) {
-
v.vx = v.p1.x-v.p0.x;
-
v.vy = v.p1.y-v.p0.y;
-
} else {
-
v.p1.x = v.p0.x+v.vx;
-
v.p1.y = v.p0.y+v.vy;
-
}
-
// length of vector
-
v.len = Math.sqrt(v.vx*v.vx+v.vy*v.vy);
-
// normalized unti-sized components
-
if (v.len>0) {
-
v.dx = v.vx/v.len;
-
v.dy = v.vy/v.len;
-
} else {
-
v.dx = 0;
-
v.dy = 0;
-
}
-
// right hand normal
-
v.rx = -v.dy;
-
v.ry = v.dx;
-
// left hand normal
-
v.lx = v.dy;
-
v.ly = -v.dx;
-
return v;
-
}
-
function updateObject(v) {
-
// find time passed from last update
-
var thisTime = getTimer();
-
var time = (thisTime-v.lastTime)/100;
-
// we use time, not frames to move so multiply movement vector with time passed
-
v.vx *= time;
-
v.vy *= time;
-
// add gravity, also based on time
-
v.vy = v.vy+time*game.gravity;
-
v.p1 = {};
-
// find end point coordinates
-
v.p1.x = v.p0.x+v.vx;
-
v.p1.y = v.p0.y+v.vy;
-
// length of vector
-
v.len = Math.sqrt(v.vx*v.vx+v.vy*v.vy);
-
// normalized unti-sized components
-
v.dx = v.vx/v.len;
-
v.dy = v.vy/v.len;
-
// right hand normal
-
v.rx = -v.vy;
-
v.ry = v.vx;
-
// left hand normal
-
v.lx = v.vy;
-
v.ly = -v.vx;
-
// save the current time
-
v.lastTime = thisTime;
-
// save time passed
-
v.timeFrame = time;
-
}
-
// find intersection point of 2 vectors
-
function findIntersection(v1, v2) {
-
// vector between center of ball and starting point of wall
-
var v3 = {};
-
v3.vx = v1.p1.x-v2.p0.x;
-
v3.vy = v1.p1.y-v2.p0.y;
-
// check if we have hit starting point
-
var dp = v3.vx*v2.dx+v3.vy*v2.dy;
-
if (dp<0) {
-
// hits starting point
-
var v = v3;
-
} else {
-
var v4 = {};
-
v4.vx = v1.p1.x-v2.p1.x;
-
v4.vy = v1.p1.y-v2.p1.y;
-
// check if we have hit side or endpoint
-
var dp = v4.vx*v2.dx+v4.vy*v2.dy;
-
if (dp>0) {
-
// hits ending point
-
var v = v4;
-
} else {
-
// it hits the wall
-
// project this vector on the normal of the wall
-
var v = projectVector(v3, v2.lx, v2.ly);
-
}
-
}
-
return v;
-
}
-
// find new vector bouncing from v2
-
function bounce(v1, v2) {
-
// projection of v1 on v2
-
var proj1 = projectVector(v1, v2.dx, v2.dy);
-
// projection of v1 on v2 normal
-
var proj2 = projectVector(v1, v2.lx, v2.ly);
-
var proj = {};
-
// reverse projection on v2 normal
-
proj2.len = Math.sqrt(proj2.vx*proj2.vx+proj2.vy*proj2.vy);
-
proj2.vx = v2.lx*proj2.len;
-
proj2.vy = v2.ly*proj2.len;
-
// add the projections
-
proj.vx = v1.f*v2.f*proj1.vx+v1.b*v2.b*proj2.vx;
-
proj.vy = v1.f*v2.f*proj1.vy+v1.b*v2.b*proj2.vy;
-
return proj;
-
}
-
// project vector v1 on unit-sized vector dx/dy
-
function projectVector(v1, dx, dy) {
-
// find dot product
-
var dp = v1.vx*dx+v1.vy*dy;
-
var proj = {};
-
// projection components
-
proj.vx = dp*dx;
-
proj.vy = dp*dy;
-
return proj;
-
}
-
/********************************************************************/
-
// CODE ADDED BY SRDJAN SUSNIC
-
// declare starting point of the current drawing line
-
var lineX1, lineY1;
-
// declare ending point of the current drawing line
-
var lineX2, lineY2;
-
// flag that states if we can draw line or not
-
can_draw = false;
-
// flag that states if the player drew a line
-
player_drew = false;
-
// next movie depth for the current drawing line
-
nextLineDepth = 0;
-
// create array for vectors of lines drawn by mouse
-
game.mouseV = new Array();
-
// create a movie which represents a line drawn by mouse
-
_root.createEmptyMovieClip(“mouseLine”, 3);
-
// when we click…
-
onMouseDown = function () {
-
// get starting point of line according to current mouse position
-
lineX1 = _root._xmouse;
-
lineY1 = _root._ymouse;
-
// set drawing flag so we can draw a line when mouse is moved
-
can_draw = true;
-
};
-
// when we move mouse…
-
onMouseMove = function () {
-
if (can_draw) {
-
// the player is drawing!
-
player_drew = true;
-
// get ending point of line according to current mouse position
-
lineX2 = _root._xmouse;
-
lineY2 = _root._ymouse;
-
// clear the previous line drawn by mouse
-
mouseLine.clear();
-
// set the drawing style
-
mouseLine.lineStyle(2, 0×00dd00);
-
// move the pen to the starting position
-
mouseLine.moveTo(lineX1, lineY1);
-
// draw the line to the ending position
-
mouseLine.lineTo(lineX2, lineY2);
-
}
-
};
-
// when we release…
-
onMouseUp = function () {
-
if (player_drew) {
-
// clear the line drawn by mouse
-
mouseLine.clear();
-
// create a new movie clip which contains the line previously drawn by mouse
-
var tmp = createEmptyMovieClip(“newLine”, 10+nextLineDepth);
-
tmp.lineStyle(5, 0×0000ff);
-
tmp.moveTo(lineX1, lineY1);
-
tmp.lineTo(lineX2, lineY2);
-
// increase movie depth for the next line
-
nextLineDepth++;
-
// add the parameters of previously created line to the end of line vectors array
-
// lineClip parameter is used to store previously created line movie clip
-
// so we can remove it when ball bounces from it
-
index = game.mouseV.length;
-
game.mouseV[index] = {p0:{x:lineX1, y:lineY1}, p1:{x:lineX2, y:lineY2}, b:1, f:1, lineClip:tmp};
-
// calculate all parameters for the created line vector
-
updateVector(game.mouseV[index], true);
-
// set drawing flag so we can’t draw a line when mouse is moved
-
player_drew = false;
-
}
-
can_draw = false;
-
};
-
// END OF CODE ADDED BY SRDJAN SUSNIC
-
/********************************************************************/
And this is the result:
Now you can draw lines with the mouse and the only thing we need in order to have a complete game engine is handling the exit.
Any idea?
Download the source code and play.
Bookmark this page on Digg, Kinja, FURL, Redit & other sites
|
|  |
You know Flash content is invisible to search engines. In order to have your Flash page (or game) indexed, you have to create an HTML page with some keywords, and pray.
Until yesterday.
Today, something is changing in Search Engines Optimization (SEO) techniques.
Look what Google and Adobe have to say
From Adobe
Adobe is providing optimized Adobe Flash Player technology to Google and Yahoo! to enhance search engine indexing of the Flash file format (SWF) and uncover information that is currently undiscoverable by search engines. This will provide more relevant automatic search rankings of the millions of dynamic content that run in Adobe Flash Player.
Without additional changes to content, developers can continue to provide experiences that are possible only with Adobe Flash technology without the trade-off of a loss in search indexing.
It will also positively affect the Search Engine Optimization community, which will develop best practices for building content utilizing Adobe Flash technologies, and enhance the ability to find and monetize SWF content.
Source: SWF searchability FAQ
From Google
Q: What do I need to do to get Google to index the text in my Flash files?
Basically, you don’t need to do anything. The improvements that we have made do not require any special action on the part of web designers or webmasters. If you have Flash content on your website, we will automatically begin to index it, up to the limits of our current technical ability.
That said, you should be aware that Google is now able to see the text that appears to visitors of your website. If you prefer Google to ignore your less informative content, such as a “copyright” or “loading” message, consider replacing the text within an image, which will make it effectively invisible to us.
Source: Improved Flash indexing
How can I get benefits from that?
If a successful SWF file will link to some external sites, maybe this will affect PageRank or at least help sites ranking.
A link to a sponsor in a successful game probably will get more valuable, and maybe people that look for your game will be able to find it in the official page and not in one portal with better ranking than your one.
Just rambling of course, but I am very very interested in it…
Bookmark this page on Digg, Kinja, FURL, Redit & other sites
|
|  |
In the 1st part I showed you how to make a deflection engine starting from an old tutorial, now it’s time to let the player draw walls.
The idea comes from Srdjan Susnic, a reader who runs the blog Ask For Game Task.
The main task Srdjan accomplished was to add a mouse control so a player can draw lines from which the ball will bounce.
After collision between the ball and a line drawn by mouse, that line must be removed
The code is clear and well commented, but it seems to suffer a bug if the player just clicks the mouse without drawing.
It’s just a minor issue I fixed in a moment, and if you already read the original post, I just added the control if the player drew a line when he releases the mouse button with player_drew variable.
Anyway, this is the actionscript:
ACTIONSCRIPT:
-
// create game object
-
game = {gravity:0, dragging:false, clip:_root.game_mc, stageW:500, stageH:400, maxV:20};
-
// create object
-
// point p0 is its starting point in the coordinates x/y
-
_root.attachMovie(“ball”, “ball”, 1);
-
game.myOb = {clip:ball, airf:1, b:1, f:1, r:20, lastTime:getTimer()};
-
game.myOb.p0 = {x:150, y:80};
-
// vectors x/y components
-
game.myOb.vx = 8;
-
game.myOb.vy = 12;
-
// create first vector
-
// point p0 is its starting point in the coordinates x/y
-
// point p1 is its end point in the coordinates x/y
-
game.v = new Array();
-
game.v[0] = {p0:{x:50, y:40}, p1:{x:450, y:40}, b:1, f:1};
-
game.v[1] = {p0:{x:50, y:40}, p1:{x:50, y:360}, b:1, f:1};
-
game.v[2] = {p0:{x:50, y:360}, p1:{x:450, y:360}, b:1, f:1};
-
game.v[3] = {p0:{x:100, y:80}, p1:{x:400, y:320}, b:1, f:1};
-
_root.createEmptyMovieClip(“lines”, 2);
-
lines.lineStyle(1, 0xff0000);
-
// draw and calculate all parameters for the wall vectors
-
for (x=0; x<game.v.length; x++) {
-
lines.moveTo(game.v[x].p0.x, game.v[x].p0.y);
-
lines.lineTo(game.v[x].p1.x, game.v[x].p1.y);
-
updateVector(game.v[x], true);
-
}
-
_root.onEnterFrame = function() {
-
_root.runMe();
-
};
-
// function to draw the points, lines and show text
-
function drawAll(v) {
-
// place ob mc
-
v.clip._x = v.p1.x;
-
v.clip._y = v.p1.y;
-
}
-
// main function
-
function runMe() {
-
// start to calculate movement
-
var ob = game.myOb;
-
// add air resistance
-
ob.vx *= ob.airf;
-
ob.vy *= ob.airf;
-
// dont let it go over max speed
-
if (ob.vx>game.maxV) {
-
ob.vx = game.maxV;
-
} else if (ob.vx<-game.maxV) {
-
ob.vx = -game.maxV;
-
}
-
if (ob.vy>game.maxV) {
-
ob.vy = game.maxV;
-
} else if (ob.vy<-game.maxV) {
-
ob.vy = -game.maxV;
-
}
-
// update the vector parameters
-
updateObject(ob);
-
// check the walls for collisions
-
for (x=0; x<game.v.length; x++) {
-
var w = game.v[x];
-
var v = findIntersection(ob, w);
-
v = updateVector(v, false);
-
var pen = ob.r-v.len;
-
// if we have hit the wall
-
if (pen>=0) {
-
// move object away from the wall
-
ob.p1.x += v.dx*pen;
-
ob.p1.y += v.dy*pen;
-
// change movement, bounce off from the normal of v
-
var vbounce = {dx:v.lx, dy:v.ly, lx:v.dx, ly:v.dy, b:1, f:1};
-
var vb = bounce(ob, vbounce);
-
ob.vx = vb.vx;
-
ob.vy = vb.vy;
-
}
-
}
-
/********************************************************************/
-
// CODE ADDED BY SRDJAN SUSNIC
-
// check the lines created by mouse for collisions
-
x = 0;
-
while (x<game.mouseV.length) {
-
var w = game.mouseV[x];
-
var v = findIntersection(ob, w);
-
v = updateVector(v, false);
-
var pen = ob.r-v.len;
-
// if we have hit the wall
-
if (pen>=0) {
-
// move object away from the wall
-
ob.p1.x += v.dx*pen;
-
ob.p1.y += v.dy*pen;
-
// change movement, bounce off from the normal of v
-
var vbounce = {dx:v.lx, dy:v.ly, lx:v.dx, ly:v.dy, b:1, f:1};
-
var vb = bounce(ob, vbounce);
-
ob.vx = vb.vx;
-
ob.vy = vb.vy;
-
// remove the clip and vector array of the collided line
-
game.mouseV[x].lineClip.removeMovieClip();
-
game.mouseV.splice(x, 1);
-
} else {
-
x++;
-
}
-
}
-
// END OF CODE ADDED BY SRDJAN SUSNIC
-
/********************************************************************/
-
// reset object to other side if gone out of stage
-
if (ob.p1.x>game.stageW+ob.r) {
-
ob.p1.x = -ob.r;
-
} else if (ob.p1.x<-ob.r) {
-
ob.p1.x = game.stageW+ob.r;
-
}
-
if (ob.p1.y>game.stageH+ob.r) {
-
ob.p1.y = -ob.r;
-
} else if (ob.p1.y<-ob.r) {
-
ob.p1.y = game.stageH+ob.r;
-
}
-
// draw it
-
drawAll(ob);
-
// make end point equal to starting point for next cycle
-
ob.p0 = ob.p1;
-
// save the movement without time
-
ob.vx = ob.vx/ob.timeFrame;
-
ob.vy = ob.vy/ob.timeFrame;
-
}
-
// function to find all parameters for the vector
-
function updateVector(v, frompoints) {
-
// x and y components
-
if (frompoints) {
-
v.vx = v.p1.x-v.p0.x;
-
v.vy = v.p1.y-v.p0.y;
-
} else {
-
v.p1.x = v.p0.x+v.vx;
-
v.p1.y = v.p0.y+v.vy;
-
}
-
// length of vector
-
v.len = Math.sqrt(v.vx*v.vx+v.vy*v.vy);
-
// normalized unti-sized components
-
if (v.len>0) {
-
v.dx = v.vx/v.len;
-
v.dy = v.vy/v.len;
-
} else {
-
v.dx = 0;
-
v.dy = 0;
-
}
-
// right hand normal
-
v.rx = -v.dy;
-
v.ry = v.dx;
-
// left hand normal
-
v.lx = v.dy;
-
v.ly = -v.dx;
-
return v;
-
}
-
function updateObject(v) {
-
// find time passed from last update
-
var thisTime = getTimer();
-
var time = (thisTime-v.lastTime)/100;
-
// we use time, not frames to move so multiply movement vector with time passed
-
v.vx *= time;
-
v.vy *= time;
-
// add gravity, also based on time
-
v.vy = v.vy+time*game.gravity;
-
v.p1 = {};
-
// find end point coordinates
-
v.p1.x = v.p0.x+v.vx;
-
v.p1.y = v.p0.y+v.vy;
-
// length of vector
-
v.len = Math.sqrt(v.vx*v.vx+v.vy*v.vy);
-
// normalized unti-sized components
-
v.dx = v.vx/v.len;
-
v.dy = v.vy/v.len;
-
// right hand normal
-
v.rx = -v.vy;
-
v.ry = v.vx;
-
// left hand normal
-
v.lx = v.vy;
-
v.ly = -v.vx;
-
// save the current time
-
v.lastTime = thisTime;
-
// save time passed
-
v.timeFrame = time;
-
}
-
// find intersection point of 2 vectors
-
function findIntersection(v1, v2) {
-
// vector between center of ball and starting point of wall
-
var v3 = {};
-
v3.vx = v1.p1.x-v2.p0.x;
-
v3.vy = v1.p1.y-v2.p0.y;
-
// check if we have hit starting point
-
var dp = v3.vx*v2.dx+v3.vy*v2.dy;
-
if (dp<0) {
-
// hits starting point
-
var v = v3;
-
} else {
-
var v4 = {};
-
v4.vx = v1.p1.x-v2.p1.x;
-
v4.vy = v1.p1.y-v2.p1.y;
-
// check if we have hit side or endpoint
-
var dp = v4.vx*v2.dx+v4.vy*v2.dy;
-
if (dp>0) {
-
// hits ending point
-
var v = v4;
-
} else {
-
// it hits the wall
-
// project this vector on the normal of the wall
-
var v = projectVector(v3, v2.lx, v2.ly);
-
}
-
}
-
return v;
-
}
-
// find new vector bouncing from v2
-
function bounce(v1, v2) {
-
// projection of v1 on v2
-
var proj1 = projectVector(v1, v2.dx, v2.dy);
-
// projection of v1 on v2 normal
-
var proj2 = projectVector(v1, v2.lx, v2.ly);
-
var proj = {};
-
// reverse projection on v2 normal
-
proj2.len = Math.sqrt(proj2.vx*proj2.vx+proj2.vy*proj2.vy);
-
proj2.vx = v2.lx*proj2.len;
-
proj2.vy = v2.ly*proj2.len;
-
// add the projections
-
proj.vx = v1.f*v2.f*proj1.vx+v1.b*v2.b*proj2.vx;
-
proj.vy = v1.f*v2.f*proj1.vy+v1.b*v2.b*proj2.vy;
-
return proj;
-
}
-
// project vector v1 on unit-sized vector dx/dy
-
function projectVector(v1, dx, dy) {
-
// find dot product
-
var dp = v1.vx*dx+v1.vy*dy;
-
var proj = {};
-
// projection components
-
proj.vx = dp*dx;
-
proj.vy = dp*dy;
-
return proj;
-
}
-
/********************************************************************/
-
// CODE ADDED BY SRDJAN SUSNIC
-
// declare starting point of the current drawing line
-
var lineX1, lineY1;
-
// declare ending point of the current drawing line
-
var lineX2, lineY2;
-
// flag that states if we can draw line or not
-
can_draw = false;
-
// flag that states if the player drew a line
-
player_drew = false;
-
// next movie depth for the current drawing line
-
nextLineDepth = 0;
-
// create array for vectors of lines drawn by mouse
-
game.mouseV = new Array();
-
// create a movie which represents a line drawn by mouse
-
_root.createEmptyMovieClip(“mouseLine”, 3);
-
// when we click…
-
onMouseDown = function () {
-
// get starting point of line according to current mouse position |