PDA

View Full Version : [AS3] Game help


Kloucek888
12-07-2008, 04:43 PM
Sorry for the misleading title, but i got three questions, and didn't really wanted to describe them all in one bug title.
+ i'm a total rookie, so the su subject fits ;)

First

I want to make a game similar to: http://www.kontraband.com/games/14242/1-Out-Of-24/

I'm stuck on putting the tiles on the stage. So i want to make a grid of 24 tiles (6 by 4) with one them being different from other.
Putting tiles on a stage is easy:
package {
import flash.display.*;



public class odd_game extends MovieClip {

public function odd_game():void {

var tiles:Array = new Array();


for (var i:uint=1 ; i<=24 ; i++){
for (var x:uint=0 ; x <6 ; x++ ){
for (var y:uint=0 ; y<4 ; y++){
tiles.push(i);
var c:Tile1 = new Tile1();
c.stop();
c.x = x*63;
c.y = y*63;


addChild(c);


}
}
}
}
}
}
It makes a nice grid of multiplied movie clip showng the first frame. I want one (random) of those clips show the second frame of the mc. And of course add a different listener to it. No idea how :/

Second
More of a teoretical question. What is the best way to add timer to the game? I mean i added a most basic one with a bar animation but it doesn't count the time perfectly. If the computer is becoming slow the time is being counted erraticly (what i can see on the animation).

Can i just make a tween (showing the disappearing progress bar) lasting for 720 frames (one minute with 12fps) and just add a stop() at the end of it? Or is there a better (proper) way of doing it?

third
My application will consist of 4 minigames. There will be scoring involved, some data bases (to compare scores) etc. What, according to You guys is the most efficient way of putting this kind of application together (it's a group project)? Making a different .swf file for every part, or putting it all in one file?

That's it (so far, i'm sure i'll be here more often before the deadline). It's a school project, and my first pretty big one with flash/as3. Please tutor me;)

rrh
12-08-2008, 06:16 AM
Some questions, to better understand where you're going with this:
What is the purpose of the 'tiles' array?
When you have those three nested for loops, how many tiles does that create?

Second:
There's also a Timer class, which you could consider for your timer.

Third:
I usually avoid multiple .swf where it isn't necessary, and have worked on group projects by dividing it into classes.

Kloucek888
12-08-2008, 06:40 AM
It's for a simple "1 out of 24" game. So one of the 24 tiles plays the second frame. The user is to find which one is it.
So far i got here:
package {
import flash.display.*;


public class odd_game extends MovieClip {


public function odd_game():void {
var gridArray:Array;
gridArray = new Array();


for (var i:uint=1 ; i<=24 ; i++){
for (var x:uint=0 ; x <6 ; x++ ){
for (var y:uint=0 ; y<4 ; y++){
var c:Tile = new Tile();
c.x = x*63;
c.y = y*63;
addChild(c);

gridArray.push(c);
}
}
}
var r:uint = Math.floor(Math.random()*24);
gridArray[r].gotoAndStop(2);
trace (gridArray);

}
}
}
so this is what it does:
http://bartosz.dk/game.png

And what it outputs from the trace():
http://bartosz.dk/trace.png



P.S. Ok, i got rid of the line
for (var i:uint=1 ; i<=24 ; i++){


And it worked
I seem to understand what the problem was. It made the array with 24*24 elements, since the loop was running this much.

You helped me with thinking mate, thanks for that :)