Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > General > Gaming and Game Development

Reply
 
Thread Tools Rate Thread Display Modes
Old 05-29-2012, 12:35 PM   #1
vash229
Registered User
 
Join Date: Sep 2011
Posts: 10
Default [AS3] help with a flash game

I am quite new to AS3, and this is my project, which is due in 2 days. Due to the lovely idea of cramming 30 students into my class, I didn't get much quality consultation time with my teacher.

My problems are:

1) Hit detection- my character won't get hit, despite putting all the code in from a very general video tutorial and tweaking it to match my game.

2) I need my character to collect gold as you press left. And I need that gold to stay with him and update the scoreboard once he reaches back up the top.

2.5) Once the character reaches the top, I want him to do a “success” animation, which I have put into the character movie clip. I do not however, know how to activate it.

I've done most of the code and the graphic design but I’m really stuck and I hope someone can help me out.

Thanks guys.

Last edited by vash229; 05-29-2012 at 03:34 PM.
vash229 is offline   Reply With Quote
Old 05-29-2012, 03:11 PM   #2
Scearezt
Satisfied User
 
Scearezt's Avatar
 
Join Date: Jun 2010
Location: C:\\System32\Hungary
Posts: 426
Lightbulb

So, you want a full game from us? Because then nothing important is done in your application so far.
Scearezt is offline   Reply With Quote
Old 05-29-2012, 03:25 PM   #3
vash229
Registered User
 
Join Date: Sep 2011
Posts: 10
Default

I'm getting the impression you think I'm some lazy prick.

I don't want a full game from anyone. I am making newbie mistakes and I need someone to have a look at my file so they can point out mistakes, missing pieces etc.

If you have looked at my file, you can see a lot of the code is done, 95% of the graphic design is done, but it's not working the way it should. Thus, I politely and respectfully need someone with excellent AS3 skills to spare some of their time to help me.

Any help is greatly appreciated.

It's not like I'm trying to find someone to do my work while I play games.
vash229 is offline   Reply With Quote
Old 05-29-2012, 03:29 PM   #4
Scearezt
Satisfied User
 
Scearezt's Avatar
 
Join Date: Jun 2010
Location: C:\\System32\Hungary
Posts: 426
Lightbulb

If you done the 95% of your code and the graphics, then DO NOT post the FLA on the internet because anyone can stole your game idea.. etc.. so post some piece of your code. Most of the developers here won't take a look at the FLAs.
Scearezt is offline   Reply With Quote
Old 05-29-2012, 03:41 PM   #5
vash229
Registered User
 
Join Date: Sep 2011
Posts: 10
Default

It will be quite difficult to imagine the game if you're just looking at the code itself. I'll clean up the code and post it.
vash229 is offline   Reply With Quote
Old 05-30-2012, 02:10 AM   #6
vash229
Registered User
 
Join Date: Sep 2011
Posts: 10
Default

The biggest problem right now is that my char is not getting hit, it's not losing a life, pausing, reset and resuming.

The character needs to collect something from the other side of the screen while an enemy continues to spit fire at him. 4 fires are randomly shot at him.


Hope someone can help me out.

Code:
import flash.display.MovieClip;


var gameSpeed:int;
var isCollecting: Boolean;

var fireOneClips:Array;
var fireTwoClips:Array;
var fireThreeClips:Array;
var fireFourClips:Array;

var fireThrowerID:int;
var fireMoverID:int;

var lives:int;

var score:int;

var deathFlashTimer:Timer;




function init():void 
{
	gameSpeed = 500; // in ms
	stage.addEventListener(KeyboardEvent.KEY_UP,onKeyReleased);


	fireOneClips=new Array();
	fireTwoClips=new Array();
	fireThreeClips=new Array();
	fireFourClips=new Array();
	fireThrowerID=setInterval(throwFire,gameSpeed*2);
	fireMoverID=setInterval(moveAllFires,gameSpeed*2);
	
	deathFlashTimer=new Timer(gameSpeed,6);
	deathFlashTimer.addEventListener(TimerEvent.TIMER,flashChar);
	deathFlashTimer.addEventListener(TimerEvent.TIMER_COMPLETE,loseLife);
	lives=3;
	lives_mc.gotoAndStop(lives+1);
	
	score=0;
	updateScore(0);
	isCollecting=false;

}

init();

function onKeyReleased(e:KeyboardEvent):void
{



	switch (e.keyCode)
	{
		case Keyboard.LEFT :
			char_mc.gotoAndStop(char_mc.leftFrame);
			break;
			if (checkCharMoveHit("left")) {
						//die
						charDied();
					} else {
						char_mc.gotoAndStop(char_mc.leftFrame);
					}

		case Keyboard.RIGHT :
			char_mc.gotoAndStop(char_mc.rightFrame);
			break;
			if (checkCharMoveHit("right")) {
						//die
						charDied();
					} else {
						char_mc.gotoAndStop(char_mc.rightFrame);
					}


	}

}

	
	function updateScore(amount:int):void{
		score+=amount;
		score_txt.text="SCORE: "+score;
		
	}
	
function playClip(clip:MovieClip):void {
	if (clip.currentFrame==clip.totalFrames) {
		clip.gotoAndStop(1);
	} else {
		clip.gotoAndStop(clip.currentFrame+1);
	}
}

	
function resetGame(e:TimerEvent=null):void {
	char_mc.gotoAndStop(1);
	
	deathFlashTimer.reset();
	var i:int;
	var b:MovieClip;
	for (i=fireOneClips.length-1; i>=0; i--) {
		b=fireOneClips[i];
		removeChild(b);
		fireOneClips.splice(i,1);
	}
	
	for (i=fireTwoClips.length-1; i>=0; i--) {
		b=fireTwoClips[i];
		removeChild(b);
		fireTwoClips.splice(i,1);
	}
	for (i=fireThreeClips.length-1; i>=0; i--) {
		b=fireThreeClips[i];
		removeChild(b);
		fireTwoClips.splice(i,1);
	}
	for (i=fireFourClips.length-1; i>=0; i--) {
		b=fireFourClips[i];
		removeChild(b);
		fireTwoClips.splice(i,1);
	}

	resumeGame();
}

function pauseGame():void {
	stage.removeEventListener(KeyboardEvent.KEY_UP,onKeyReleased);
	
	clearInterval(fireThrowerID);
	clearInterval(fireMoverID);
}

function resumeGame():void {
	stage.addEventListener(KeyboardEvent.KEY_UP,onKeyReleased);
	
	fireThrowerID=setInterval(throwFire,gameSpeed*4);
	fireMoverID=setInterval(moveAllFires,gameSpeed);
}


function charDied():void {
	pauseGame();
	deathFlashTimer.start();
	//trace('char died');
	

}


function flashChar(e:TimerEvent):void {
	char_mc.visible=! char_mc.visible;


}

function loseLife(e:TimerEvent):void {
	trace('life lost');
	lives--;
	lives_mc.gotoAndStop(lives+1);
	if (lives>0) {
		resetGame();

	}
	
}

function throwFire():void{
	var chance:int = Math.floor(Math.random() * 2) + 1;
	//trace('throw fire');
	
	
	if (chance==1)
	{
		// Pick a number 1 -> 4
		var which:int = Math.floor(Math.random() * 4) + 1;
		
		var newFire:MovieClip;
		
		if (which == 1)
		{
			newFire=new Fire1();
			fireOneClips.push(newFire);
			newFire.x = 490.55;
			newFire.y = 266.20;

		}else if (which == 2){
			
			newFire=new Fire2();
			fireTwoClips.push(newFire);
			newFire.x = 463.10;
			newFire.y = 293.15;
			
		}else if (which == 3){
			
			newFire=new Fire3();
			fireThreeClips.push(newFire);
			newFire.x = 404.80;
			newFire.y = 315.60;
			
		}else if (which == 4){
			
			newFire=new Fire4();
			fireFourClips.push(newFire);
			newFire.x = 335.85;
			newFire.y = 350.55; 
			
		}
		
		addChild(newFire);

	}

}
function moveAllFires():void
{
		var i:int;
		var b:MovieClip;
		for (i=fireOneClips.length-1;i>=0;i--){
			b=fireOneClips[i];
			b.gotoAndStop(b.currentFrame+1);
			if(b.currentFrame==b.totalFrames){
				removeChild(b);
				fireOneClips.splice(i,1);//makes flames stuck
			}
		}
		
		for (i=fireTwoClips.length-1;i>=0;i--){
			b=fireTwoClips[i];
			b.gotoAndStop(b.currentFrame+1);
			if(b.currentFrame==b.totalFrames){
				removeChild(b);
				fireTwoClips.splice(i,1);//makes flames stuck
			}
		}
		
		for (i=fireThreeClips.length-1;i>=0;i--){
			b=fireThreeClips[i];
			b.gotoAndStop(b.currentFrame+1);
			if(b.currentFrame==b.totalFrames){
				removeChild(b);
				fireThreeClips.splice(i,1);
			}
		}
		
		for (i=fireFourClips.length-1;i>=0;i--){
			b=fireFourClips[i];
			b.gotoAndStop(b.currentFrame+1);
			if(b.currentFrame==b.totalFrames){
				removeChild(b);
				fireFourClips.splice(i,1);
			}
		}

//HIT at case 2,3,4,(5,6, 7)
function checkFireMoveHit():Boolean{
	var i:int;
		var b:MovieClip;
		for (i=fireOneClips.length-1;i>=0;i--){
			b=fireOneClips[i];
			switch(char_mc.currentFrame){
				case 2: 
				if(b.currentFrame==11) {
					return true;
					trace(char_mc.currentFrame);
					
				}
				break;
			
			
			}
		
		}
		
		for (i=fireTwoClips.length-1; i>=0; i--) {
		b=fireTwoClips[i];
		switch (char_mc.currentFrame) {
			case 3 :
				if (b.currentFrame==11) {
					return true;

				}
				break;
		}
		}
		
		for (i=fireThreeClips.length-1; i>=0; i--) {
		b=fireThreeClips[i];
		switch (char_mc.currentFrame) {
			case 4 :
				if (b.currentFrame==10) {
					return true;

				}
				break;
		}
		}
		for (i=fireFourClips.length-1; i>=0; i--) {
		b=fireFourClips[i];
		switch (char_mc.currentFrame) {
			case 5 :
				if (b.currentFrame==9) {
					return true;
					}
				break;
				
			case 6 :
				if (b.currentFrame==9) {
					return true;
					}
				break;
				
			case 7 :
				if (b.currentFrame==9) {
					return true;
					}
				break;
				
		}
		}
				
	return false;
	}
}

function checkCharMoveHit(dir:String):Boolean {
	var i:int;
	var b:MovieClip;
	if (dir=="left") {
		
		
		for (i=fireOneClips.length-1; i>=0; i--) {
			b=fireOneClips[i];
			switch (char_mc.currentFrame) {
				case 2 :
					if (b.currentFrame==11) {
						return true;

						}
					break;
				

			}

		}
		
		
		for (i=fireTwoClips.length-1; i>=0; i--) {
			b=fireTwoClips[i];
			switch (char_mc.currentFrame) {
				case 3 :
					if (b.currentFrame==11) {
						return true;

					}
					break;

			}

		}
		
				for (i=fireThreeClips.length-1; i>=0; i--) {
			b=fireThreeClips[i];
			switch (char_mc.currentFrame) {
				case 4 :
					if (b.currentFrame==10) {
						return true;

						}
					break;
				

			}

		}
		
		
		for (i=fireFourClips.length-1; i>=0; i--) {
			b=fireFourClips[i];
			switch (char_mc.currentFrame) {
				case 5 :
					if (b.currentFrame==9) {
						return true;

					}
					break;

			}

		}
		for (i=fireFourClips.length-1; i>=0; i--) {
			b=fireFourClips[i];
			switch (char_mc.currentFrame) {
				case 6 :
					if (b.currentFrame==9) {
						return true;

					}
					break;

			}

		}
		for (i=fireFourClips.length-1; i>=0; i--) {
			b=fireFourClips[i];
			switch (char_mc.currentFrame) {
				case 7 :
					if (b.currentFrame==9) {
						return true;

					}
					break;

			}

		}
	} else {
		//right
for (i=fireOneClips.length-1; i>=0; i--) {
			b=fireOneClips[i];
			switch (char_mc.currentFrame) {
				case 2 :
					if (b.currentFrame==11) {
						return true;

					}
					break;
//				
//
			}

		}
//		
//		//barrel 2 going right
		for (i=fireTwoClips.length-1; i>=0; i--) {
			b=fireTwoClips[i];
			switch (char_mc.currentFrame) {
				case 3 :
					if (b.currentFrame==11) {
						return true;

					}
					break;

			}

		}
		
		for (i=fireThreeClips.length-1; i>=0; i--) {
			b=fireThreeClips[i];
			switch (char_mc.currentFrame) {
				case 4 :
					if (b.currentFrame==10) {
						return true;

					}
					break;

			}
		for (i=fireFourClips.length-1; i>=0; i--) {
			b=fireFourClips[i];
			switch (char_mc.currentFrame) {
				case 5 :
					if (b.currentFrame==9) {
						return true;

					}
					break;

			}

		}

	for (i=fireFourClips.length-1; i>=0; i--) {
			b=fireFourClips[i];
			switch (char_mc.currentFrame) {
				case 6 :
					if (b.currentFrame==9) {
						return true;

					}
					break;

			}

		}
	for (i=fireFourClips.length-1; i>=0; i--) {
			b=fireFourClips[i];
			switch (char_mc.currentFrame) {
				case 7 :
					if (b.currentFrame==9) {
						return true;

					}
					break;

			}

		}

		}	

	}
return false;
}

Last edited by vash229; 05-30-2012 at 02:14 AM.
vash229 is offline   Reply With Quote
Old 05-30-2012, 11:46 AM   #7
Scearezt
Satisfied User
 
Scearezt's Avatar
 
Join Date: Jun 2010
Location: C:\\System32\Hungary
Posts: 426
Lightbulb

Using arrays is not always the best way to check collision. You should seperate things like character, enemy, enemy fire, coins into classes. So you no longer need to keep that many arrays.
ActionScript Code:
package #PACKAGE# {     import flash.display.MovieClip;     import flash.events.Event;     public class EnemyFire extends MovieClip     {         private var PLAYER = #STATIC REFERENCE OF THE PLAYER#;         public function EnemyFire(xPosition:Number,yPosition:Number) {             x = xPosition;             y = yPosition;             addEventListener(Event.ADDED_TO_STAGE, init);         }         private function init(e:Event){             removeEventListener(Event.ADDED_TO_STAGE, init);             addEventListener(Event.REMOVED_FROM_STAGE, removed);             addEventListener(Event.ENTER_FRAME, updateDisplay);         }         private function updateDisplay(e:Event) {             //..more..             if (hitTestObject(PLAYER)) {                 //do something..             }             //..more..         }         private function removed(e:Event) {             removeEventListener(Event.REMOVED_FROM_STAGE, removed);             removeEventListener(Event.ENTER_FRAME, updateDisplay);         }     } }
Just a fast example.
Scearezt is offline   Reply With Quote
Old 05-31-2012, 06:53 AM   #8
vash229
Registered User
 
Join Date: Sep 2011
Posts: 10
Default

Scearezt,

I appreciate the help. Thanks.

Last edited by vash229; 05-31-2012 at 03:48 PM.
vash229 is offline   Reply With Quote
Old 06-01-2012, 02:51 PM   #9
vash229
Registered User
 
Join Date: Sep 2011
Posts: 10
Default

Hi salma98210, I've already figured out how the hit detection works for the character. The code has changed a bit since the time I posted this.
vash229 is offline   Reply With Quote
Reply


Thread Tools
Display Modes 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. The time now is 04:32 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.