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-20-2012, 10:34 PM   #1
ElGamble
Registered User
 
Join Date: Jan 2012
Posts: 11
Default [AS3] Collision detection - dying when coming into contact with enemies

Hi guys,
I'm still slightly new to the actionscripting world, and for a project at college we have to recreate an existing game that has been made in game maker in actionscript.

So the tiling and movement etc are correct to some extent, but I have no idea how to start with the collision detection.
When the koala touches a TNT, the koala is meant to die and a movie clip is supposed to play and the koala falls off of the screen. I have some idea of how to do this using simpler methods, but not with classes and arrays etc.
Could anyone please give me some pointers or tips on where to start with this?
Here's a selection of the code so far:


import flash.events.Event;

const MAP_WIDTH = 16
const MAP_HEIGHT = 11
const TILE_WIDTH = 40
//-------


//Level 01 Setup
//0 is Blank, 1 is Walls, 5 is Koalas
//2 is Dynamite, 4 is Exit, 3 is Detonator

var origMap:Array = [
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 5, 2, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 2, 0, 1],
[1, 0, 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1],
[1, 0, 1, 0, 1, 4, 0, 0, 0, 2, 0, 1, 0, 1, 0, 1],
[1, 5, 1, 0, 1, 2, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1],
[1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1],
[1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1],
[1, 5, 1, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1],
[1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
]

var map:Array; // used in the game play...
var displayMap:Array;
var koalas:Array = new Array(
var dynamites:Array = new Array();
var detonators:Array = new Array();
var exits:Array = new Array();


* TILE_WIDTH;
tile.visible = false;
addChild(tile);
tile.gotoAndStop(1);
switch (map[row][col]){
case 1: tile.gotoAndStop(2);
break;
case 2:
var myDynamite_mcynamite = new Dynamite();
myDynamite_mc.x = TILE_WIDTH / 2 + (col) * TILE_WIDTH;
myDynamite_mc.y = TILE_WIDTH / 2 + (row + 1) * TILE_WIDTH;
myDynamite_mc.visible = false;
myDynamite_mc.row = row;
myDynamite_mc.col = col;
addChild(myDynamite_mc);
dynamites.push(myDynamite_mc);
break;
case 3:
var myDetonator_mcetonator = new Detonator();
myDetonator_mc.x = TILE_WIDTH / 2 + (col) * TILE_WIDTH;
myDetonator_mc.y = TILE_WIDTH / 2 + (row + 1) * TILE_WIDTH;
myDetonator_mc.visible = false;
myDetonator_mc.row = row;
myDetonator_mc.col = col;
addChild(myDetonator_mc);
detonators.push(myDetonator_mc);
break;
case 4:
var myExit_mc:Exit = new Exit();
myExit_mc.x = TILE_WIDTH / 2 + (col) * TILE_WIDTH;
myExit_mc.y = TILE_WIDTH / 2 + (row + 1) * TILE_WIDTH;
myExit_mc.visible = false;
myExit_mc.row = row;
myExit_mc.col = col;
addChild(myExit_mc);
exits.push(myExit_mc);
break;
case 5:
var myKoala_mc:Koala = new Koala();
myKoala_mc.addEventListener(Event.ENTER_FRAME, moveKoala);
myKoala_mc.x = TILE_WIDTH / 2 + (col) * TILE_WIDTH;
myKoala_mc.y = TILE_WIDTH / 2 + (row + 1) * TILE_WIDTH;
myKoala_mc.visible = false;
myKoala_mc.row = row;
myKoala_mc.col = col;
addChild(myKoala_mc);
koalas.push(myKoala_mc);




break;
}
}
}
}

function copyArray(copy:Array, original:Array){
/* copies the contents of original array into copy. Both arrays assumed to be 2D */
for (var row = 0; row < original.length; row++){
copy[row] = new Array()
for (var col = 0; col < original[row].length; col++){
copy[row][col] = original[row][col]
}
}
}

// other listeners==================
restart_btn.visible = false;
rescue_mc.visible = false;
splash_mc.start_btn.addEventListener(MouseEvent.CL ICK, startGame);
restart_btn.addEventListener(MouseEvent.CLICK, reStartGame);
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
stage.addEventListener(KeyboardEvent.KEY_UP, keyUpHandler);

// Event Handlers===================
function startGame(m:MouseEvent){
DoOver();

splash_mc.visible = false;
for (var row = 0; row < MAP_HEIGHT; row++){
for (var col = 0; col < MAP_WIDTH; col++){
displayMap[row][col].visible = true;
}
}
for each (var bear in koalas){
bear.visible = true;
setChildIndex(bear, numChildren - 1);
}
for each (var TNT in dynamites){
TNT.visible = true;
setChildIndex(TNT, numChildren - 1);
}
for each (var DET in detonators){
DET.visible = true;
setChildIndex(DET, numChildren - 1);
}
for each (var EXIT in exits){
EXIT.visible = true;
setChildIndex(EXIT, numChildren - 1);
}
restart_btn.visible = true;
rescue_mc.visible = true;
}
ElGamble 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 11:15 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2013, 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.