2 Replies - 3822 Views - Last Post: 11 October 2011 - 05:58 PM

#1 ChrisWofford  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 10-October 11

Getting Hopper to Score.

Posted 10 October 2011 - 04:47 PM

Hello life savors. We are working on a project making a little kids game using AS 3.0 Here is the problem, I have read a lot on the using a Dynamics Text field for basic things, this is obviously a little more complicated. Since every time Hoppers tongue collides with the bug is when we want the score to go up. Some collision code is there, and some basic scoring code has been implemented, the qustion is how do I get it to display dynamically on the screen, as hopper eats the bugs? and then transition the level number inside another dynamics text field. Once Hopper has scored enough points?
Any help would be appreciated most of the code is inside the main .fla which is below, other code is inside the bug.as, tongue.as e.t.c. e.t.c. So if you want to look at the other .as just let me know otherwise here is the main. Thanks Again.

The array is handling the collision detection, and determining the outcome, and scoring is after that.


//import information
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.events.KeyboardEvent;
import flash.events.Event;
import flash.utils.Timer;
import flash.ui.Keyboard;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.media.SoundTransform;
import flash.media.SoundMixer;

//create level and score variables
var level:int = 0;
var score:int = 0;




//instantiate background graphic
var bground:Background = new Background();
addChild(bground);

var scoreStaticText:ScoreStaticText = new ScoreStaticText();
scoreStaticText.x = 82.50;
scoreStaticText.y = 555.50;
addChild(scoreStaticText);

var scoreDynText:ScoreDynText = new ScoreDynText();
scoreDynText.x = 206.00;
scoreDynText.y = 555.50;

addChild(scoreDynText);

//begin playing level theme, set it to loop, and lower the volume to a level that isn't deafening
var levelTheme:LevelTheme;
var levelThemeChannel:SoundChannel;
levelTheme = new LevelTheme();
levelThemeChannel = levelTheme.play(0, int.MAX_VALUE);
var themeTransform:SoundTransform = new SoundTransform();
themeTransform.volume = 0.03;
levelThemeChannel.soundTransform=themeTransform;

//instantiate Hopper's body
var hopperBody:HopperBody = new HopperBody();
addChild(hopperBody);

//function to keep the head oriented toward the mouse
stage.addEventListener(MouseEvent.MOUSE_MOVE, lookAtMouse);

function lookAtMouse(event:MouseEvent):void {
	//find out mouse coordinates to find out the angle
	var cy:Number = mouseY - hopperBody.y; 
	var cx:Number = mouseX - hopperBody.x;
	
	//find out the angle
	var Radians:Number = Math.atan2(cy,cx);
	
	//convert to degrees to rotate
	var Degrees:Number = Radians * 180 / Math.PI;
	
	//rotate
	if (mouseY<251){
		hopperBody.rotation = Degrees+90;		
		}
	
}

//initialize variables for the bug class
var bugType:int = 0;
var bugRand:int;
var bugTimer:Timer;
var bugArray:Array =[];

//timer to send bugs across the screen
bugTimer = new Timer(2000);
bugTimer.addEventListener("timer", sendBug);
bugTimer.start();

var j:int = 0;

function sendBug(e:Event){
	
	if (level <= 4){
		bugArray[j] = new Bug();
		bugRand = Math.random()*4+1;
	
		if (bugRand ==1){
			j++;
			bugArray[j] = new Bug();
			stage.addChild(bugArray[j]);
			bugType = bugRand;		
		}
	
		if (bugRand == 2){
			j++;
			bugArray[j] = new Bug2();
			stage.addChild(bugArray[j]);
			bugType = bugRand;		
		}
	
		if (bugRand == 3){
			j++;		
			bugArray[j] = new Bug3();
			stage.addChild(bugArray[j]);
			bugType = bugRand;		
		}
	
		if (bugRand == 4){
			j++;
			bugArray[j] = new Bug4();
			stage.addChild(bugArray[j]);
			bugType = bugRand;		
		}
	}
}

var _isStageClicked:Boolean;

addEventListener(Event.ENTER_FRAME, onEnter);
stage.addEventListener(MouseEvent.CLICK, onclick);

function onEnter(event:Event):void{
	if (mouseY<335){
		if (_isStageClicked){
			addTongue();
		}
	}
}
function onclick(event:Event):void{
	_isStageClicked = true;
}

function addTongue():void{
	_isStageClicked = false;
	var tongue:Tongue = new Tongue();
	addChild(tongue);

	for (var i:int = 0; i < bugArray.length; i++){
		if (tongue.hitTestObject(bugArray[i])){
			var whipHit:WhipHit;
			var whipHitChannel:SoundChannel;
			whipHit = new WhipHit();
			whipHitChannel = whipHit.play();
			var whipHitTransform:SoundTransform = new SoundTransform();
			whipHitTransform.volume = 0.08;
			whipHitChannel.soundTransform=whipHitTransform;
		
			if (bugType == 1){				
				score = score + 150;
				stage.removeChild(bugArray[i]);
			}
			else if (bugType == 2){				
				score = score + 100;
				stage.removeChild(bugArray[i]);
			}
			else if (bugType == 3){				
				score = score + 50;
				stage.removeChild(bugArray[i]);
			}
			else if (bugType == 4){				
				score = score - 100;
				stage.removeChild(bugArray[i]);
			}
		}
		else if (bugArray.x>=900){
			stage.removeChild(bugArray[i]);
		}
	}
}

addEventListener(Event.ENTER_FRAME, level2Change);

function level2Change(event:Event):void {
	if ((score >= 100)&&(score < 200)){
		level = 2;
		trace("level" + level);
		removeEventListener(Event.ENTER_FRAME, level2Change);
	}
}

addEventListener(Event.ENTER_FRAME, level3Change);

function level3Change(event:Event):void {
	if ((score >= 200)&&(score < 400)){
		level = 3;
		trace("level" + level);
		removeEventListener(Event.ENTER_FRAME, level3Change);
	}
}
	
addEventListener(Event.ENTER_FRAME, level4Change);

function level4Change(event:Event):void {
	if ((score >= 400)&&(score < 800)){
		level = 4;
		trace("level" + level);
		removeEventListener(Event.ENTER_FRAME, level4Change);
	}
}

addEventListener(Event.ENTER_FRAME, level5Change);

function level5Change(event:Event):void {
	if (score >= 800){
		level = 5;		
		SoundMixer.stopAll();
		var levelFiveLoader:Loader = new Loader();
		var levelFiveRequest:URLRequest = new URLRequest("LevelFive.swf");
		levelFiveLoader.load(levelFiveRequest);
		addChild(levelFiveLoader);
		removeEventListener(Event.ENTER_FRAME, level5Change);
	}
}
	
	
	

/* Move with Keyboard Arrows
Allows the specified symbol instance to be moved with the keyboard arrows. */



//stage.addEventListener(KeyboardEvent.KEY_DOWN, fl_PressKeyToMove);

//function fl_PressKeyToMove(event:KeyboardEvent):void
//{
	//var speed = 10;

	//switch (event.keyCode)
	//{
		//case Keyboard.LEFT:
		//{
			//hopperBody.x -= speed;
			//break;
		//}
		//case Keyboard.RIGHT:
		//{
			//hopperBody.x += speed;
			//break;
		//}
	//}
//limitPadBorderWidth(hopperBody);

//}

//function limitPadBorderWidth(object:MovieClip) {
	
	//var objectHalfWidth:uint=object.width/2;
	
	//if (object.x+objectHalfWidth>600){
		//object.x=600-objectHalfWidth;
	//}
	//else if (object.x-objectHalfWidth<232) {
		//object.x=232+objectHalfWidth;
	//}
//}





Is This A Good Question/Topic? 0
  • +

Replies To: Getting Hopper to Score.

#2 ChrisWofford  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 10-October 11

Re: Getting Hopper to Score.

Posted 11 October 2011 - 04:11 PM

:-( No love for the flash huh?
Was This Post Helpful? 0
  • +
  • -

#3 ChrisWofford  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 10-October 11

Re: Getting Hopper to Score.

Posted 11 October 2011 - 05:58 PM

NVM Got it People thanks!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1