Need some help (AS2).
Posted: Wed Mar 06, 2013 5:55 pm
Hello!
To begin with, I'm new user, but i have been following this forum log time before great Corta's had "left" us. I'm also sorry for my poor english grama .
SO ! The thing is that i decided to begin my adventure with MacromediaFlash (currently 8 but i can get it upgraded, of course in legal way ) and i need some help in few things. I just started to "write" basic things wchich aren't that basic as you think I'm able to write .
I'm still trying to understand how arrays and objects works and use them as i would like. To add i'm IT student (first year) and my programmer skills will improve in time.
Howewer i'm easy learner, so with a little help i'd be able to create some nice stuff.
Just a curio of my game:
Inspired with CoC and other girls-morph games i'd make player pet "upgradeable" with transforming various body parts, adding new by using items, participating events, submiting, denying, fighting etc. It'll be shown as perks affecting stats, giving additionall passive/active skills/event solutions. Yea right. I know what you think. Soooo basic. Another dumb guy with dumb ideas BUT!
As a Rp fanatic i can't see the point of cow-morph girl equiped with sub-machine gun or using great arcane power. I thought "why don't give player pet AI that various morphs will affect his/her behaviour in the way it should? ". I'd like to leave some control like grabbing loot or pointining special event items that will occur from time to time.
To make it clear. Player at start will have to choose hispersonality. Something like Devil/Succuba/Palladin etc. Player would be kind of his pet patron, so his personality will affect basic pet stats, probability of various(I love this word <3) events. Then player will be moved to specific lair (according to his personality) and presented with "pets" he can choose. I'm also thinking about other way of choosing it. Something like instead of lair he'll be moved to random map with 1 lvl enemies and with last call of his GOD power affect choosen one wchich then will be moved to lair.
There player will be able to set some options(like map for next exploring), feed his pet, equip it, etc. Of course i'd like to make some events here to happens too. For example "Puff, she's giving a birth ! Puff, it's a "smthing"!" Then player would be presented with option to use offspring instead of mother.
Ok, ok. Move on .
After choosing map, eq, etc. player pet will be moved where player chossed and we can watch how she/he explores map with random number of enemies/spawns and events. To complete the map, player have to wait for portal that will appear after some time. If his pet died before, everything it earned is lost and we're back in the lair.
It's just part of what i would like to have in game. I skipped a lot of ideas to not overload this thread. If youd like it i'll make right one in right place .
To the point:
I tried compare 2 codes that aren't mine so don't flame ;d. In first one enemy is treaten as object, in second only added to array (or i'm blind and stupid).
Enemies should follow player and the closest one should be stucked in frame(2) ;p.
Just if you could point where i make mistakes. It'll make me learn it faster ;d. Just don't laugh if i messed all. Please :d
To begin with, I'm new user, but i have been following this forum log time before great Corta's had "left" us. I'm also sorry for my poor english grama .
SO ! The thing is that i decided to begin my adventure with MacromediaFlash (currently 8 but i can get it upgraded, of course in legal way ) and i need some help in few things. I just started to "write" basic things wchich aren't that basic as you think I'm able to write .
I'm still trying to understand how arrays and objects works and use them as i would like. To add i'm IT student (first year) and my programmer skills will improve in time.
Howewer i'm easy learner, so with a little help i'd be able to create some nice stuff.
Just a curio of my game:
Inspired with CoC and other girls-morph games i'd make player pet "upgradeable" with transforming various body parts, adding new by using items, participating events, submiting, denying, fighting etc. It'll be shown as perks affecting stats, giving additionall passive/active skills/event solutions. Yea right. I know what you think. Soooo basic. Another dumb guy with dumb ideas BUT!
As a Rp fanatic i can't see the point of cow-morph girl equiped with sub-machine gun or using great arcane power. I thought "why don't give player pet AI that various morphs will affect his/her behaviour in the way it should? ". I'd like to leave some control like grabbing loot or pointining special event items that will occur from time to time.
To make it clear. Player at start will have to choose hispersonality. Something like Devil/Succuba/Palladin etc. Player would be kind of his pet patron, so his personality will affect basic pet stats, probability of various(I love this word <3) events. Then player will be moved to specific lair (according to his personality) and presented with "pets" he can choose. I'm also thinking about other way of choosing it. Something like instead of lair he'll be moved to random map with 1 lvl enemies and with last call of his GOD power affect choosen one wchich then will be moved to lair.
There player will be able to set some options(like map for next exploring), feed his pet, equip it, etc. Of course i'd like to make some events here to happens too. For example "Puff, she's giving a birth ! Puff, it's a "smthing"!" Then player would be presented with option to use offspring instead of mother.
Ok, ok. Move on .
After choosing map, eq, etc. player pet will be moved where player chossed and we can watch how she/he explores map with random number of enemies/spawns and events. To complete the map, player have to wait for portal that will appear after some time. If his pet died before, everything it earned is lost and we're back in the lair.
It's just part of what i would like to have in game. I skipped a lot of ideas to not overload this thread. If youd like it i'll make right one in right place .
To the point:
I tried compare 2 codes that aren't mine so don't flame ;d. In first one enemy is treaten as object, in second only added to array (or i'm blind and stupid).
Enemies should follow player and the closest one should be stucked in frame(2) ;p.
Just if you could point where i make mistakes. It'll make me learn it faster ;d. Just don't laugh if i messed all. Please :d
- Code: Select All Code
var health:Number = 100;
var radians:Number = 180/Math.PI;
healthbar_mc.onEnterFrame = function()
{
healthbar_mc._xscale=_root.health*1;
if(_root.health<=0){
health=0;
}
if(_root.health>=100){
health=100;
}
}
button_btn.onRelease = function(koma)
{
_root.health = _root.health - 10;
if(_root.health!=0)
{
trace(_root.health);
removeMovieClip(button_btn);
};
}
///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
var enemyObjectsArray:Array = [];
/**
* Create Enemy
* ---------------
* This Method is used to create new enemy objects,
* attach movieClips to them and set the enemyObject's properties like position
*/
function createEnemy(numberOfEnemies:Number, enemyBehavior:String, enemyLibraryClip:String):Void
{
//run a for loop to create numberOfEnemies
for(var i = 0; i < numberOfEnemies; i++)
{
//attach a new enemy movieclip from the library
var tempEnemy_mc:MovieClip = _root.attachMovie(enemyLibraryClip, enemyLibraryClip+_root.getNextHighestDepth(), _root.getNextHighestDepth());
//set new enemy position
tempEnemy_mc._x = random(Stage.width);
tempEnemy_mc._y = random(Stage.height);
//
//set enemy behavior
if(enemyBehavior == "typeA")
{
//define enemy characteristics
tempEnemy_mc.speed = 1
tempEnemy_mc.turnRate = .05
tempEnemy_mc.agroRange = 200;
tempEnemy_mc.mode = "follow"
}
else if(enemyBehavior == "typeB")
{
//define enemy characteristics
tempEnemy_obj.speed = 4
tempEnemy_obj.turnRate = .5
tempEnemy_obj.agroRange = 200;
tempEnemy_obj.mode = "follow"
}
else if(enemyBehavior == "typeC")
{
//define enemy characteristics
tempEnemy_obj.speed = 1
tempEnemy_obj.turnRate = .2
tempEnemy_obj.agroRange = 100;
tempEnemy_obj.mode = "run"
}
//save object properties such as a reference to our movieClip on root, distance total, etc
tempEnemy_obj = {myMc:tempEnemy_mc, distanceTotal:0, distanceY:0, distanceY:0, moveDistanceX:0, moveDistanceY:0, moveX:0, moveY:0, totalmove:0}
//add the enemy object to array
enemyObjectsArray.push(tempEnemy_obj);
}
}
/**
* Update Enemy
* ---------------
* This Method is used to calculate distance between objects in enemyObjectsArray
* and sort the array based on distanceTotal using the "sortOn" function
*/
function updateEnemies():Void
{
//run a for loop on our array and update every enemy object in there
for(var i = 0; i < enemyObjectsArray.length; i++)
{
//set temporary variables that we'll use to reference the enemy/target
//enemy is an object
var enemy:Object = enemyObjectsArray[i];
//player_mc is a movieclip
var target:MovieClip = player_mc;
//To use movieClip method like gotoAndStop, gotoAndPlay, etc,
//we use the "myMc" parameter of our enemy object that we saved earlier.
//The mc parameter is basically a "link" to the enemy movieClip on stage
//tell movieclip to go to first frame
enemy.myMc.gotoAndStop(1);
//calculate distance between enemyObject's movieClip and target
enemy.distanceX = target._x - enemy.myMc._x;
enemy.distanceY = target._y - enemy.myMc._y;
//get total distance as one number
enemy.distanceTotal = Math.sqrt(enemy.distanceX * enemy.distanceX + enemy.distanceY * enemy.distanceY);
//sort the array based on the enemy object's "distanceTotal" parameter
enemyObjectsArray.sortOn("distanceTotal", Array.NUMERIC);
//the first item in our array (enemyObjectsArray[0])
//has the lowest distanceTotal value hense its the closest
//tell the closest enemy movieClip to go to frame 2 to visually show that it's closest
enemyObjectsArray[0].myMc.gotoAndStop(2);
updatePosition(tempEnemy_mc, player_mc);
}
}
//
// updatePosition(follower, target)
// use ex: updatePosition(myEnemyMovieClip, playerMovieClip)
//
function updatePosition(follower:MovieClip, target:MovieClip) {
//calculate distance between follower and target
follower.distanceX = target._x-follower._x;
follower.distanceY = target._y-follower._y;
//get total distance as one number
follower.distanceTotal = Math.sqrt(follower.distanceX * follower.distanceX + follower.distanceY * follower.distanceY);
//check if target is within agro range
if(follower.distanceTotal <= follower.agroRange){
//calculate how much to move
follower.moveDistanceX = follower.turnRate * follower.distanceX / follower.distanceTotal;
follower.moveDistanceY = follower.turnRate * follower.distanceY / follower.distanceTotal;
//increase current speed
follower.moveX += follower.moveDistanceX;
follower.moveY += follower.moveDistanceY;
//get total move distance
follower.totalmove = Math.sqrt(follower.moveX * follower.moveX + follower.moveY * follower.moveY);
//apply easing
follower.moveX = follower.speed * follower.moveX / follower.totalmove;
follower.moveY = follower.speed * follower.moveY / follower.totalmove;
//move & rotate follower
if(follower.mode == "follow")
{
follower._x += follower.moveX;
follower._y += follower.moveY;
follower._rotation = Math.atan2(follower.moveY, follower.moveX) * radians;
}
else if(follower.mode == "run")
{
follower._x -= follower.moveX;
follower._y -= follower.moveY;
follower._rotation = (Math.atan2(follower.moveY, follower.moveX) * radians)+180;
}
}
}
///////////////////////////////////////////////////////////////////////////////////
//add an onEnterFrame to repeat our updateEnemies function every frame
_root.onEnterFrame = function():Void
{
updateEnemies();
}
//create some enemies
createEnemy(random(10+1), "typeA", "enemy1_mc");
createEnemy(random(10+1), "typeC", "enemy2_mc");
//start/stop drag for player_mc
player_mc.onPress = function(){
startDrag(this);
}
player_mc.onRelease = function(){
stopDrag();
}
////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////