Go Back   CodingForums.com > :: Client side development > Flash & ActionScript

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-25-2012, 03:05 PM   PM User | #1
fightapilotdean
New Coder

 
Join Date: Mar 2012
Location: Leicester
Posts: 18
Thanks: 2
Thanked 0 Times in 0 Posts
fightapilotdean is an unknown quantity at this point
Question Adobe Flash CS3 Join Games?

Hi all.
Currently at college we are doing games development unit. We have to make a game in flash to demonstrate we can do it.
Now i have created the first game with ease which is basically a game where you just click on box's and you either win or lose. but i am curious because the other game is a basic version of space invaders. this has a scoring system and it changes and displays your final score when you die, i am just wondering if there would be a way to put this score system into the first game. just wondering if anyone could point me in the right direction really. the codes are below :d

Treasure game - no scores


Code:
var intRandom:int = 0;
var bolNewGame:Boolean = false;
reSet();

function reSet():void
{
	mcpwin1.visible = false;
	mcpwin2.visible = false;
	mcpwin3.visible = false;
//this hides the "win" symbols

	mcplose1.visible = false;
	mcplose2.visible = false;
	mcplose3.visible = false;
//this hides the "lose" symbols

	btnbutton1.visible = true;
	btnbutton2.visible = true;
	btnbutton3.visible = true;
//this shows the three buttons

	bolNewGame = false;
}

function Random3(event:MouseEvent):void
{
	
	intRandom = Math.floor(Math.random()*3);
	reSet();
	txtmessage.text = "This is a new game, Click a box and see if you can find the missing money";
}

// what happens if button1 is pressed
function button1(event:MouseEvent):void
{
	if (bolNewGame == false)
	{
		if (intRandom == 0)
		{
			txtmessage.text = "WAAAAHAYYYY, You found it :D Click the button to have another go!";
			btnbutton1.visible = false;
			mcpwin1.visible = true;
		}
		else
		{
			txtmessage.text = ":( Damn where could it be, Click the button to have another go";
			btnbutton1.visible = false;
			mcplose1.visible = true;
		}
	}
	bolNewGame=true;
	
}

// what happens if button2 is pressed
function button2(event:MouseEvent):void
{
	if (bolNewGame == false)
	{
		if (intRandom == 0)
		{
			txtmessage.text = "WAAAAHAYYYY, You found it :D Click the button to have another go!";
			btnbutton2.visible = false;
			mcpwin2.visible = true;
		}
		else
		{
			txtmessage.text = ":( Damn where could it be, Click the button to have another go";
			btnbutton2.visible = false;
			mcplose2.visible = true;
		}
	}
	bolNewGame=true;
}

// what happens if button3 is pressed
function button3(event:MouseEvent):void
{
	if (bolNewGame == false)
	{
		if (intRandom == 0)
		{
			txtmessage.text = "WAAAAHAYYYY, You found it :D Click the button to have another go!";
			btnbutton3.visible = false;
			mcpwin3.visible = true;
		}
		else
		{
			txtmessage.text = ":( Damn where could it be, Click the button to have another go";
			btnbutton3.visible = false;
			mcplose3.visible = true;
		}
	}
	bolNewGame=true;
}

btnreset.addEventListener(MouseEvent.CLICK, Random3);
btnbutton1.addEventListener(MouseEvent.CLICK, button1);
btnbutton2.addEventListener(MouseEvent.CLICK, button2);
btnbutton3.addEventListener(MouseEvent.CLICK, button3);



Space Invader game - scoring 



// Invaders Game code
// DO NOT CHANGE


var intLazerX:int = 30;
var intScore:int = 0;
var intPlaneX:int = 2;
var intPlaneY:int = 1;
var intHit:int = 0;

var intSpeed:int = 4;
var intGunPos:int = 0;
var intLazerY:int = 20;
var intLazerSpeed:int = 20;


var bolEndGame:Boolean = false;
var bolBullet:Boolean = false;
var bolBomb:Boolean = false;
var bolBomb2:Boolean = false;
var bolShotDown:Boolean = false;
var bolShotDown2:Boolean = false;

mcpBullet.visible = false;
mcpExplosion1.visible = false;
mcpExplosion2.visible = false;
mcpExplosion3.visible = false;
mcpBomb.visible = false;
mcpBomb2.visible = false;


function reSet():void
{
	mcpAAgun.visible = true;
	mcpBomb.visible = false;
	mcpBomb2.visible = false;
	bolBullet = false;
    bolBomb = false;
	bolBomb2 = false;
	bolEndGame = false;
	bolShotDown = false;
	bolShotDown2 = false;
	
	mcpExplosion1.visible = false;
	mcpExplosion2.visible = false;
	mcpExplosion3.visible = false;
	mcpBullet.visible = false;
	mcpPlane1.visible = true;
	mcpPlane2.visible = true;
	mcpPlane1.x = 0;
	mcpPlane2.x = 800;
	mcpBomb.y = 150;
	mcpBomb2.y = 225;
	mcpBullet.y=255;
	intScore = 0;
	txtScore.text = intScore.toString();
	
}
	

function randomBomb():void
{
	var intRandom:int = 0;
	intRandom = Math.floor(Math.random()*80);
	if(intRandom == 1)
	{
		bolBomb = true;
		mcpBomb.x = mcpPlane1.x;
	}
}

function randomBomb2():void
{
	var intRandom:int = 0;
	intRandom = Math.floor(Math.random()*100);
	if(intRandom == 1)
	{
		bolBomb2 = true;
		mcpBomb2.x = mcpPlane2.x;
	}
}

function shotDown():void
{
	if(mcpPlane1.hitTestPoint(mcpBullet.x + mcpBullet.width,mcpBullet.y + mcpBullet.height,true))
	{
		intScore = intScore + 1;
		bolShotDown = true;
		mcpExplosion1.x = mcpPlane1.x;
		mcpExplosion1.visible = true;
		mcpPlane1.visible = false;
		mcpBullet.visible = false;
		mcpBomb.visible = false;
		mcpPlane1.x = 0; 
		
		txtScore.text = intScore.toString();
	}
}

function shotDown2():void
{
	if(mcpPlane2.hitTestPoint(mcpBullet.x + mcpBullet.width,mcpBullet.y + mcpBullet.height,true))
	{
		intScore = intScore + 1;
		bolShotDown2 = true;
		mcpExplosion3.x = mcpPlane2.x;
		mcpExplosion3.visible = true;
		mcpPlane2.visible = false;
		mcpBullet.visible = false;
		mcpBomb2.visible = false;
		mcpPlane2.x = 800; 
		
		txtScore.text = intScore.toString();
	}
}

function bombed():void
{
	if(mcpAAgun.hitTestPoint(mcpBomb.x + mcpBomb.width,mcpBomb.y + mcpBomb.height,true))
	{
		mcpExplosion2.x = mcpAAgun.x;
		mcpExplosion2.visible = true;
		mcpAAgun.visible = false;
		mcpBomb.visible = false;
		txtOutput.text = "GAME OVER";
		bolEndGame = true;
	}
}

function bombed2():void
{
	if(mcpAAgun.hitTestPoint(mcpBomb2.x + mcpBomb2.width,mcpBomb2.y + mcpBomb2.height,true))
	{
		mcpExplosion2.x = mcpAAgun.x;
		mcpExplosion2.visible = true;
		mcpAAgun.visible = false;
		mcpBomb2.visible = false;
		txtOutput.text = "GAME OVER";
		bolEndGame = true;
	}
}

function EnterFrame(event:Event):void
{
	if(bolEndGame == false)
	{
		mcpPlane1.x = mcpPlane1.x+3;
		mcpPlane1.y = 100;
		mcpPlane2.x = mcpPlane2.x - 5;
		mcpPlane2.y = 200;
	
		if(bolShotDown == false)
		{
			randomBomb();
		}
		
		if(bolShotDown2 == false)
		{
			randomBomb2();
		}
		
		if(mcpPlane1.x >750)
		{
			mcpPlane1.x = 0;
			mcpExplosion1.visible = false;
			mcpExplosion2.visible = false;
			mcpPlane1.visible = true;
			bolShotDown = false;
		}
		
		if(mcpPlane2.x < 0)
		{
			mcpPlane2.x = 750;
			mcpExplosion1.visible = false;
			mcpExplosion3.visible = false;
			mcpPlane2.visible = true;
			bolShotDown2 = false;
		}
	
		if(bolBullet == true)
		{
			mcpBullet.visible = true;
			mcpBullet.y = mcpBullet.y - 8;
			shotDown();
			shotDown2();
			if(mcpBullet.y < 10)
			{
				mcpBullet.y = 363;
				mcpBullet.visible = false;
				bolBullet = false;
			}
		}
	
		if(bolBomb == true)
		{
			mcpBomb.visible = true;
			mcpBomb.y = mcpBomb.y + 6;
			bombed();
		
			if(mcpBomb.y > 450)
			{
				mcpBomb.y = 160;
				mcpBomb.visible = false;
				bolBomb = false;
			}
		}
		
		if(bolBomb2 == true)
		{
			mcpBomb2.visible = true;
			mcpBomb2.y = mcpBomb2.y + 6;
			bombed2();
		
			if(mcpBomb2.y > 450)
			{
				mcpBomb2.y = 160;
				mcpBomb2.visible = false;
				bolBomb2 = false;
			}
		}
	}
}


function handleKeyDown(event:KeyboardEvent) :void
{
	if (event.keyCode == Keyboard.SHIFT) 
	{
		txtOutput.text = "Key SHIFT";
	}
	
	if (event.keyCode == Keyboard.CONTROL) 
	{
		txtOutput.text = "Key Ctrl NEW GAME";
		reSet();
	}
	
	if (event.keyCode == Keyboard.SPACE) 
	{
		txtOutput.text = "FIRE!";
		mcpBullet.x = mcpAAgun.x;
		bolBullet = true;
		
	}
	
	if (event.keyCode == Keyboard.LEFT) 
	{
		//txtOutput.text = "Move Left";
		mcpAAgun.x = mcpAAgun.x - 4;
		if(mcpAAgun.x < 70)
		{
			mcpAAgun.x = 70;
		}
	}
	
	if (event.keyCode == Keyboard.RIGHT) 
	{
		//txtOutput.text = "Move Right";
		mcpAAgun.x = mcpAAgun.x + 4;
		if(mcpAAgun.x > 650)
		{
			mcpAAgun.x = 650;
		}
	}
	
}

stage.addEventListener(KeyboardEvent.KEY_DOWN,handleKeyDown);
addEventListener(Event.ENTER_FRAME, EnterFrame);
any help will be greatly appreciated, i dont want to know how it should be i just really need a point in the right direction :)
p.s we are using Adobe Flash Pro CS3 - Actionscript 3 :d

Last edited by WA; 05-25-2012 at 05:26 PM..
fightapilotdean is offline   Reply With Quote
Old 05-25-2012, 03:35 PM   PM User | #2
djpaul1963
New Coder

 
djpaul1963's Avatar
 
Join Date: Apr 2012
Location: Athens GR
Posts: 65
Thanks: 0
Thanked 8 Times in 8 Posts
djpaul1963 is an unknown quantity at this point
The scoring variable of the space invaders is the var intScore:int = 0; on top of the code, where all variables are assigned. This variable gets increased in shotDown and shotDown2 functions where a collision between your shot and the alien has been detected.

Moving now to your treasure game, it's very easy to insert that variable increase below the lines you say "WAAAAHAYYYY, You found it".
Of course you must still define the variable on top of your program in a global position (I believe you know already about variable scope and when variables are visible only inside a function or not).

Happy coding!
djpaul1963 is offline   Reply With Quote
Users who have thanked djpaul1963 for this post:
fightapilotdean (05-31-2012)
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:25 PM.


Advertisement
Log in to turn off these ads.