Stack Flash game prototype

Read all posts about "" game

During the last days I received a lot of prototypes from different readers.

One I want to mention is something called “a new idea in AS2” by Shival Gupta

That’s how he got in contact with me:

Hi Emanuele.

A few days before you published some info on Box2d library in AS3 and one of the examples that it produced was of stacking boxes.

Eventually I developed this weak prototype on stacking in AS2 but it was really messy as each box had its own onEnterFrame function.

But anyways I think that the stacking concept has really great potential in making a game. If you are interested, shall I email that “poor” proto to you?

If you like that concept will you please publish a tutorial on it.
Understand, its a really cool concept and has great potential. I even has some ideas on making a stacking box game.

Please reply to this mail with your reply and suggestions.

Best regards
Shiv

Coding a stacking prototype in AS2 is not that easy, and as you will see later in this post, Shival asked me to publish his prototype because “it would be an honour to me to get my work published in emanueleferonato.com” and because the code has some bugs Shival is not able to fix at the moment, so he is asking for help to everybody.

The game concept is simple: you have something like a fan and have to shoot air to some falling colored crates in order to make them stop each one in the colored spot that matches the color of the crate.

The code is split through 5 frames, but the main engine is:

// HERES THE STACK! PROTOTYPE// 
stop();
Mouse.hide();
// loading values//
gravity = 2;
fired = 0;
shot = 10;
xspeed = 0;
yspeed = 0;
xspeed2 = 0;
yspeed2 = 0;
xspeed3 = 0;
yspeed3 = 0;
wind = 0.6;
score = 0;
// generating items//
generate_items();
// attaching mouse//
attachMovie("crosshair", "crosshair", 1);
// telling flash how to generate items//
// and what properties should the generated items have//
function generate_items() {
	//generating boxes//
	junk = _root.attachMovie("rock", "rock"+_root.getNextHighestDepth(), _root.getNextHighestDepth(), {_x:75, _y:25});
	punk = _root.attachMovie("rock", "rock2"+_root.getNextHighestDepth(), _root.getNextHighestDepth(), {_x:75, _y:0});
	lunk = _root.attachMovie("rock", "rock3"+_root.getNextHighestDepth(), _root.getNextHighestDepth(), {_x:75, _y:-25});
	//initializing the colours of the boxes//
	junk.gotoAndStop(1);
	punk.gotoAndStop(2);
	lunk.gotoAndStop(3);
	// inscribing properties//
	junk.onEnterFrame = function() {
		this._y += gravity;
		this._y += yspeed;
		this._x += xspeed;
		this._x += wind;
		xspeed *= 0.8;
		while (_root.terrain.hitTest(this._x, this._y+this._height/2, true)) {
			this._y--;
		}
		while (_root.punk.hitTest(this._x, this._y+this._height/2, true)) {
			this._y--;
		}
		while (_root.punk.hitTest(this._x-this._width/2, this._y, true)) {
			this._x++;
		}
		while (_root.punk.hitTest(this._x+this._width/2, this._y, true)) {
			this._x--;
		}
		while (_root.lunk.hitTest(this._x, this._y+this._height/2, true)) {
			this._y--;
		}
		while (_root.lunk.hitTest(this._x-this._width/2, this._y, true)) {
			this._x++;
		}
		while (_root.lunk.hitTest(this._x+this._width/2, this._y, true)) {
			this._x--;
		}
		if (_root.redmat.hitTest(this)) {
			this._alpha -= 1.5;
			this._rotation -= 5;
			this._y -= gravity*2;
		}
		if (this._alpha<10) {
			this.removeMovieClip();
			score += 50;
		}
		if (_root.terrain.conveyer.hitTest(this)) {
			xspeed++;
		}
	};
	punk.onEnterFrame = function() {
		this._y += gravity*2;
		this._y += yspeed2;
		this._x += xspeed2;
		this._x += wind;
		xspeed2 *= 0.8;
		while (_root.terrain.hitTest(this._x, this._y+this._height/2, true)) {
			this._y--;
		}
		while (_root.junk.hitTest(this._x, this._y+this._height/2, true)) {
			this._y--;
		}
		while (_root.junk.hitTest(this._x-this._width/2, this._y, true)) {
			this._x++;
		}
		while (_root.junk.hitTest(this._x+this._width/2, this._y, true)) {
			this._x--;
		}
		while (_root.lunk.hitTest(this._x, this._y+this._height/2, true)) {
			this._y--;
		}
		while (_root.lunk.hitTest(this._x-this._width/2, this._y, true)) {
			this._x++;
		}
		while (_root.lunk.hitTest(this._x+this._width/2, this._y, true)) {
			this._x--;
		}
		if (_root.blumat.hitTest(this)) {
			this._alpha -= 1.5;
			this._rotation -= 5;
			this._y -= gravity*2;
		}
		if (this._alpha<10) {
			this.removeMovieClip();
			score += 50;
		}
		if (_root.terrain.conveyer.hitTest(this)) {
			xspeed2++;
		}
	};
	lunk.onEnterFrame = function() {
		this._y += gravity*2;
		this._y += yspeed3;
		this._x += xspeed3;
		this._x += wind;
		xspeed3 *= 0.8;
		while (_root.terrain.hitTest(this._x, this._y+this._height/2, true)) {
			this._y--;
		}
		while (_root.junk.hitTest(this._x, this._y+this._height/2, true)) {
			this._y--;
		}
		while (_root.junk.hitTest(this._x-this._width/2, this._y, true)) {
			this._x++;
		}
		while (_root.junk.hitTest(this._x+this._width/2, this._y, true)) {
			this._x--;
		}
		while (_root.punk.hitTest(this._x, this._y+this._height/2, true)) {
			this._y--;
		}
		while (_root.punk.hitTest(this._x-this._width/2, this._y, true)) {
			this._x++;
		}
		while (_root.punk.hitTest(this._x+this._width/2, this._y, true)) {
			this._x--;
		}
		if (_root.gremat.hitTest(this)) {
			this._alpha -= 1.5;
			this._rotation -= 5;
			this._y -= gravity*2;
		}
		if (this._alpha<10) {
			this.removeMovieClip();
			score += 50;
		}
		if (_root.terrain.conveyer.hitTest(this)) {
			xspeed3++;
		}
	};
}
// mouse movements//
crosshair.onEnterFrame = function() {
	this._x = _xmouse;
	this._y = _ymouse;
};
//movement of the windmachine//
tank.onEnterFrame = function() {
	mousex = _xmouse-this._x;
	mousey = (_ymouse-this._y)*-1;
	angle = Math.atan(mousey/mousex)/(Math.PI/180);
	if (mousex<0) {
		angle += 180;
	}
	if (mousex>=0 && mousey<0) {
		angle += 360;
	}
	firepower = Math.sqrt(mousex*mousex+mousey*mousey);
	if (firepower>400) {
		firepower = 400;
	}
	this.cannon._rotation = angle*-1;
};
function onMouseDown() {
	shot--;
	if (shot<0) {
		shot = 0;
	}
	angle = tank.cannon._rotation-1;
	start_ball_x = tank._x+48*Math.cos(angle*Math.PI/180);
	start_ball_y = tank._y+48*Math.sin(angle*Math.PI/180);
	cannonball_fired = attachMovie("cannonball", "cannonball_"+_root.getNextHighestDepth(), _root.getNextHighestDepth(), {_x:start_ball_x, _y:start_ball_y});
	cannonball_fired.dirx = Math.cos(angle*Math.PI/180)*firepower;
	cannonball_fired.diry = Math.sin(angle*Math.PI/180)*firepower;
	cannonball_fired.onEnterFrame = function() {
		this._x += this.dirx/30;
		this._y += this.diry/30;
		// interaction between wind and boxes//
		if (lunk.hitTest(this._x, this._y, true)) {
			this.removeMovieClip();
			xspeed3 += firepower/15;
			lunk._rotation += firepower;
		}
		if (junk.hitTest(this._x, this._y, true)) {
			this.removeMovieClip();
			xspeed += firepower/15;
			junk._rotation += firepower;
		}
		if (punk.hitTest(this._x, this._y, true)) {
			this.removeMovieClip();
			xspeed2 += firepower/15;
			punk._rotation += firepower;
		}
		// a useful reset or respawn function//   
		if (respawn.hitTest(this._x, this._y, true)) {
			this.removeMovieClip();
			junk.removeMovieClip();
			punk.removeMovieClip();
			lunk.removeMovieClip();
			score = 0;
			generate_items();
		}
		// scoring//   
		_root.txt.text = "Score: "+score;
		if (_root.score>149) {
			_root.gotoAndPlay(3);
		}
	};
}
// a useless reset function. Just a stupid backup//
function reset() {
	junk._x = 200;
	junk._y = 26;
	punk._x = 200;
	punk._y = 0;
	lunk._x = 200;
	lunk._y = -50;
	junk._rotation = 0;
	punk._rotation = 0;
	lunk._rotation = 0;
	junk._height = 50;
	punk._width = 50;
	junk._width = 50;
	punk._height = 50;
	lunk._width = 50;
	lunk._height = 50;
	junk._alpha = 100;
	punk._alpha = 100;
	lunk._alpha = 100;
}

And Shival is asking for help in this way

Mouse is the only control for this game.

I have the scheme and concept of “STACK!” but due to my rookieness in flash, I cannot code a function. The function is to produce multiple boxes having the same property. But I made it really “unproper”.
For instance, if I have 5 boxes, I need 5 movieclip attachments, and 5*5 = 25 collisions.

Yes, A game can be made with all this fuss. 10 boxes and managing 10 x 10 = 100 collisions :(
But I know that there is also an easier way of making this game.

Also, can you fix the terrain collision code?
I tried my best but nothing better happened.

So pls download the attachment “Stack!.fla” ,” Stack!.swf”
and pls help me out.

I hope you like my idea (a game in future).

Download the source code and give him feedback

Get the most popular Phaser 3 book

Through 202 pages, 32 source code examples and an Android Studio project you will learn how to build cross platform HTML5 games and create a complete game along the way.

Get the book

214 GAME PROTOTYPES EXPLAINED WITH SOURCE CODE
// 1+2=3
// 100 rounds
// 10000000
// 2 Cars
// 2048
// A Blocky Christmas
// A Jumping Block
// A Life of Logic
// Angry Birds
// Angry Birds Space
// Artillery
// Astro-PANIC!
// Avoider
// Back to Square One
// Ball Game
// Ball vs Ball
// Ball: Revamped
// Balloon Invasion
// BallPusher
// Ballz
// Bar Balance
// Bejeweled
// Biggification
// Block it
// Blockage
// Bloons
// Boids
// Bombuzal
// Boom Dots
// Bouncing Ball
// Bouncing Ball 2
// Bouncy Light
// BoxHead
// Breakout
// Bricks
// Bubble Chaos
// Bubbles 2
// Card Game
// Castle Ramble
// Chronotron
// Circle Chain
// Circle Path
// Circle Race
// Circular endless runner
// Cirplosion
// CLOCKS - The Game
// Color Hit
// Color Jump
// ColorFill
// Columns
// Concentration
// Crossy Road
// Crush the Castle
// Cube Jump
// CubesOut
// Dash N Blast
// Dashy Panda
// Deflection
// Diamond Digger Saga
// Don't touch the spikes
// Dots
// Down The Mountain
// Drag and Match
// Draw Game
// Drop Wizard
// DROP'd
// Dudeski
// Dungeon Raid
// Educational Game
// Elasticity
// Endless Runner
// Erase Box
// Eskiv
// Farm Heroes Saga
// Filler
// Flappy Bird
// Fling
// Flipping Legend
// Floaty Light
// Fuse Ballz
// GearTaker
// Gem Sweeper
// Globe
// Goat Rider
// Gold Miner
// Grindstone
// GuessNext
// Helicopter
// Hero Emblems
// Hero Slide
// Hexagonal Tiles
// HookPod
// Hop Hop Hop Underwater
// Horizontal Endless Runner
// Hundreds
// Hungry Hero
// Hurry it's Christmas
// InkTd
// Iromeku
// Jet Set Willy
// Jigsaw Game
// Knife Hit
// Knightfall
// Legends of Runeterra
// Lep's World
// Line Rider
// Lumines
// Magick
// MagOrMin
// Mass Attack
// Math Game
// Maze
// Meeblings
// Memdot
// Metro Siberia Underground
// Mike Dangers
// Mikey Hooks
// Nano War
// Nodes
// o:anquan
// One Button Game
// One Tap RPG
// Ononmin
// Pacco
// Perfect Square!
// Perfectionism
// Phyballs
// Pixel Purge
// PixelField
// Planet Revenge
// Plants Vs Zombies
// Platform
// Platform game
// Plus+Plus
// Pocket Snap
// Poker
// Pool
// Pop the Lock
// Pop to Save
// Poux
// Pudi
// Pumpkin Story
// Puppet Bird
// Pyramids of Ra
// qomp
// Quick Switch
// Racing
// Radical
// Rebuild Chile
// Renju
// Rise Above
// Risky Road
// Roguelike
// Roly Poly
// Run Around
// Rush Hour
// SameGame
// SamePhysics
// Save the Totem
// Security
// Serious Scramblers
// Shrink it
// Sling
// Slingy
// Snowflakes
// Sokoban
// Space Checkers
// Space is Key
// Spellfall
// Spinny Gun
// Splitter
// Spring Ninja
// Sproing
// Stabilize!
// Stack
// Stick Hero
// String Avoider
// Stringy
// Sudoku
// Super Mario Bros
// Surfingers
// Survival Horror
// Talesworth Adventure
// Tetris
// The Impossible Line
// The Moops - Combos of Joy
// The Next Arrow
// Threes
// Tic Tac Toe
// Timberman
// Tiny Wings
// Tipsy Tower
// Toony
// Totem Destroyer
// Tower Defense
// Trick Shot
// Tunnelball
// Turn
// Turnellio
// TwinSpin
// vvvvvv
// Warp Shift
// Way of an Idea
// Whack a Creep
// Wheel of Fortune
// Where's my Water
// Wish Upon a Star
// Word Game
// Wordle
// Worms
// Yanga
// Yeah Bunny
// Zhed
// zNumbers