Wednesday, July 4, 2012

[Action Script] [AS3] game development help July,2012

Hi I need help with my game project. This game is very simple but since I am new to OOP I am not able to proceed further.The game is of a character running left or right avoiding falling objects and collecting some objects in the way.
I am using random number to add these objects to the stage. The problem is I want these objects to appear only once.
Also I need to check for collision with the hero which has a different custom class Hero attached to it.

Please help.

--------------------------------------------
This is the custom class file for new objects to be collected:
-----------------------------------------------
package {
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.events.MouseEvent;
import flash.ui.Keyboard;
import flash.ui.Mouse;
import flash.text.TextField;
import flash.events.TimerEvent;
import flash.utils.Timer;
import BaseObject;
import Hero;

public class Collectibles extends MovieClip{

private var collectiblesTimer:Timer = new Timer(5000);
private var object1:Object1 = new Object1;
public var gameFinished:GameFinishedScreen = new GameFinishedScreen;
public var newObject:MovieClip;
public function Collectibles() {
// constructor code
collectiblesTimer.addEventListener(TimerEvent.TIME R,addRandomObjects);
collectiblesTimer.start();

//initialise the game finished screen
//gameFinished.nextLevel.buttonMode = true;
//gameFinished.nextLevel.addEventListenerMouseEvent. CLICK,onGameFinished);
}

public function addRandomObjects(evt:TimerEvent): void {
//create an instance of a random object
var randomNumber:Number = Math.random();
var objectCount:int = 0;

// 0 .... 1
if (randomNumber >= 0 && randomNumber <= 0.2) {
newObject = new Object1();
objectCount += 1;
trace(objectCount);
newObject.amountPointsWorth = 20;
}
if (randomNumber >= 0.2 && randomNumber <= 0.4) {
newObject = new Object2();
objectCount += 1;
trace(objectCount);
newObject.amountPointsWorth = 30;
}
if (randomNumber >= 0.4 && randomNumber <= 0.6) {
newObject = new Object3();
objectCount += 1;
trace(objectCount);
newObject.amountPointsWorth = 100;
}
if (randomNumber >= 0.6 && randomNumber <= 0.8) {
newObject = new Object4();
objectCount += 1;
trace(objectCount);
newObject.amountPointsWorth = 100;
}
if (randomNumber >= 0.8 && randomNumber <= 1) {
newObject = new Object5();
objectCount += 1;
trace(objectCount);
newObject.amountPointsWorth = 50;
}
if(objectCount == 5) {
trace("objectCount" + objectCount);
}
// limit the objects
newObject.x = Math.random() * stage.stageWidth;
newObject.y = Math.random() * (stage.stageHeight - 150);

// limit the boundaries for the new Object
if(newObject.x > stage.stageWidth){
newObject.x = stage.stageWidth - newObject.width;
}
if(newObject.y <= 200){
newObject.y = 200 + newObject.width/2;
}
if(newObject.y >= 300){
newObject.y = 300 - newObject.width/2;
}

addChild(newObject);
/*if(newObject.hitTestObject(hero)){
testCollisionObjects();
}*/
}
public function testCollisionObjects() {
trace("this will work");
// check for collision of new object with the hero
/*if(newObject.hitTestObject(hero)){
trace("new object hits hero");
}*/

}
}

}
--------------------------------------
[AS3] game development help

Related Post



0 comments: