05-29-2012, 12:35 PM
|
#1
|
|
Registered User
Join Date: Sep 2011
Posts: 10
|
[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.
|
|
|
05-29-2012, 03:11 PM
|
#2
|
|
Satisfied User
Join Date: Jun 2010
Location: C:\\System32\Hungary
Posts: 426
|
So, you want a full game from us? Because then nothing important is done in your application so far.
|
|
|
05-29-2012, 03:25 PM
|
#3
|
|
Registered User
Join Date: Sep 2011
Posts: 10
|
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.
|
|
|
05-29-2012, 03:29 PM
|
#4
|
|
Satisfied User
Join Date: Jun 2010
Location: C:\\System32\Hungary
Posts: 426
|
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.
|
|
|
05-29-2012, 03:41 PM
|
#5
|
|
Registered User
Join Date: Sep 2011
Posts: 10
|
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.
|
|
|
05-30-2012, 02:10 AM
|
#6
|
|
Registered User
Join Date: Sep 2011
Posts: 10
|
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.
|
|
|
05-30-2012, 11:46 AM
|
#7
|
|
Satisfied User
Join Date: Jun 2010
Location: C:\\System32\Hungary
Posts: 426
|
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.
|
|
|
05-31-2012, 06:53 AM
|
#8
|
|
Registered User
Join Date: Sep 2011
Posts: 10
|
Scearezt,
I appreciate the help. Thanks.
Last edited by vash229; 05-31-2012 at 03:48 PM.
|
|
|
06-01-2012, 02:51 PM
|
#9
|
|
Registered User
Join Date: Sep 2011
Posts: 10
|
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.
|
|
|
| Thread Tools |
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT. The time now is 08:29 AM.
///
|
|