View Full Version : point and click
chevron8653
06-13-2007, 08:14 AM
Hi there.
well ive looked for tutorials on games like this but havnt found ne at all.
What im wondering how to do is make a classic point and click adventure game with a story line of course, inventory, and when the use clicks the mouse around the screen the character i have animated plays their walking aniamtion and walks to the mouse clicked position not just appears their.
well ne help on how to make games like that would be great thanks in advanced
I don't think you're going to find many tutorials on making a game like that, because it is based mainly on simple actionscripting principles, rather then anything specific to gaming. (Like a tile based platformer for instance.)
You would just store the coordinates of the mouse on press, and then increment the characters position till it gets there.
Inventory would just be a series of boolean variables.
When the character hitTests with a certain object or coordinate, that item is flagged as true and added to thier inventory.
chevron8653
06-14-2007, 03:39 AM
hi thakns for replying.
yeah i tried methods like storing the mouses x and y coordinates into an array each time the mouse is clicked which all that part worked, but how would i get the character to move on its own in a line either left or right to the clicked mouse coordiates ive tried moveTo but i think thats just for api.
This is just a platform like click and point not a birds eye view RPG.
thanks in advanced.
edit:
here is the code i used to store the moues x and y coordinates in an array.
//links movement array//
var linkmove:Array = [];
//links mouse controls//
onMouseDown = function () {
trace(linkmove);
linkmove[0] = _xmouse;
linkmove[1] = _ymouse;
_root.link_mc.moveTo(linkmove);
};
Yeah, moveTo is used for dynamic drawing; you just need to move the coordinates of your player object incrementally till it reaches its goal.
I don't think you really need an array for that, unless you want to be able to set up like waypoints where you click on a few different positions and the characters moves through them in succession.
Especially if you only need to move left/right, I would just store it in a single variable.
Check this out, I just threw it together now from an old file I had, so I'm not promising its the single best way to do it, but this should at least get you started:
var mouseX:Number;
var moveSpeed = 5;
//On Mouse Down, get the coordinates of the mouse
this.onMouseDown = function() {
mouseX = _root._xmouse;
//Run the player move function
playerMove();
};
function playerMove() {
//Run this every frame until it is deleted
this.onEnterFrame = function() {
//Hold players position
var thisX:Number = this.player1._x;
//Is the player is near to where the mouse was clicked, end this function
if ((Math.round(thisX) == Math.round(mouseX))) {
delete this.onEnterFrame;
//ELSE move the player
} else {
//if the player is to the right of the mouseClick:
if (thisX>mouseX) {
//Flip to face the mouseClick
this.player1._xscale = -100;
//
//If it is within range of movespeed, use a smaller number to move it
//I do this in case the player ends up on say x=20, and the mouse is x=21.
//This will make sure he doesn't skip over 21.
if (thisX-mouseX<moveSpeed) {
this.player1._x -= 1;
} else {
//Else, move it left using the moveSpeed
this.player1._x -= moveSpeed;
}
//else if the player is to the left of the mouseClick:
} else if (thisX<mouseX) {
//Flip to face the mouseClick
this.player1._xscale = 100;
if (mouseX-thisX<moveSpeed) {
this.player1._x += 1;
} else {
this.player1._x += moveSpeed;
}
}
}
//If the player hits the hat, "give it to him"
if (!hatHit) {
if (this.player1.hitTest(this.hatMc)) {
this.player1.gotoAndStop("_hat");
this.hatMc.swapDepths(1975);
this.hatMc.removeMovieClip();
var hatHit:Boolean = true;
}
}
};
}
If I were going to actually build this, I would probably use a setInterval over an onEnterFrame, and I would probably use the tween class to move the player, it would give a smoother transition.
Good Luck!
chevron8653
06-15-2007, 09:07 AM
hi there thanks for the help with that it works a treat.
all though ive had to make some minor modifications to the code so it works with the character i animated probly here is my edit and after the edit ill exsplain a couple things that im trying to figure out.
var mouseX:Number;
var moveSpeed = 5;
var actions:Array = [];
//On Mouse Down, get the coordinates of the mouse//
this.onMouseDown = function() {
if (_ymouse<350.5) {
mouseX = _root._xmouse;
//Run the player move function
playerMove();
}
};
function playerMove() {
//Run this every frame until it is deleted
this.onEnterFrame = function() {
//Hold players position
var thisX:Number = this.link_mc._x;
//Is the player is near to where the mouse was clicked, end this function
if ((Math.round(thisX) == Math.round(mouseX))) {
checkdirectionstop();
delete this.onEnterFrame;
//ELSE move the player
} else {
//if the player is to the right of the mouseClick:
if (thisX>mouseX) {
//Flip to face the mouseClick
checkageleft();
//
//If it is within range of movespeed, use a smaller number to move it
//I do this in case the player ends up on say x=20, and the mouse is x=21.
//This will make sure he doesn't skip over 21.
if (thisX-mouseX<moveSpeed) {
this.link_mc._x -= 1;
} else {
//Else, move it left using the moveSpeed
this.link_mc._x -= moveSpeed;
}
//else if the player is to the left of the mouseClick:
} else if (thisX<mouseX) {
//Flip to face the mouseClick
checkageright();
if (mouseX-thisX<moveSpeed) {
this.link_mc._x += 1;
} else {
this.link_mc._x += moveSpeed;
}
}
}
//If the player hits the hat, "give it to him"
if (!hatHit) {
if (this.link_mc.hitTest(this.hatMc)) {
this.link_mc.gotoAndStop("_hat");
this.hatMc.swapDepths(1975);
this.hatMc.removeMovieClip();
var hatHit:Boolean = true;
}
}
};
}
//the functions below check to see if link is an adult or child and does actions accordingly//
//check for walking right//
function checkageright() {
if (_global.Islink<16) {
_root.link_mc.gotoAndPlay("_walkright");
} else if (_global.Islink>16) {
_root.link_mc.gotoAndPlay("_kidrunright");
}
}
//checks for walking left//
function checkageleft() {
if (_global.Islink<16) {
_root.link_mc.gotoAndPlay("_walkleft");
} else if (_global.Islink>16) {
_root.link_mc.gotoAndPlay("_kidrunleft");
}
}
//function below checks the stopping part//
function checkdirectionstop() {
if (_global.Islink == 2) {
gotoAndPlay("_stopedright");
} else if (_global.Islink == 3) {
gotoAndPlay("_stopedleft");
}
}
well everything works perfectly its just the stuff in the checkdirectionstop() function im trying to get working and ive tried putting em in a few different places in the code but nothing works.
coz with the character it has double of each animation one for each direction left and right, so if his left walking animation is playing when he reaches the mouse pointer destination im wanting him to gotoAndplay his left stoped animation and same thing just with right side.
Also another thing when his moving he starts his walking animation but freezes on the first frame of it until he reaches the point of where u clicked then he starts his walk animation, is there any way to make it that he loops his walking animation untill he reaches the point of where u clicked?
thanks again for helping its most appreciated.
Ok, there are a few things you're doing here that you don't need to.
It looks like you have all different frames created for the character walking left/right. All you're doing there is adding to the file size.
As long as the animation is the same walking in both directions, you just flip the character using a negative xscale. Same with your stopedright/stopedleft frames. That is all I did above to flip my pacman dude.
It simplifies the code, and produces a smaller file. Both are usually a good idea when making a game, especially if you intend to put it online.
Also, I see you evaluating _global.Islink.
I assume this is a variable you are setting in link_mc to tell you what age he is at?
If so, that is not exactly how I would handle it. First, if you're going to declare it globally, do it here and give it the value somewhere else. You wouldn't really need to make this global though. If this is a variable being set in link_mc, you could just call it using this.link_mc.Islink.
But beyond that, it looks to me like you might be storing what frame he is on in that variable? If so, you don't need to do that, you can just evaluate his currentframe from this timeline using this.link_mc._currentframe.
But, in the code I'm pasting below I'm removing that evaluation all together.
I'm setting the global variable to be _global.ageNum = 0;
Then I'm calling different frames in the walk function based on that variable:
this.gotoAndPlay("_walk"+ageNum);
So, your player frames in this scenario would just be named accordingly:
_walk0 and _walk1
Then you just set that ageNum variable in whatever event changes your characters age.
It is just one less thing you have to evaluate in the onEnterFrame, which again, will speed up the code. Look how much smaller the code I'm pasting below is in comparison.
See if you adapt this to suit your game, otherwise, you should post your file here so I can better help you.
Also, as far as your walk cycle not looping properly...
I didn't have a cycle on my guy, so it wasn't coded in.
I had the onEnterFrame repeatedly sending him to the first frame of the cycle. Now it toggles back and forth, so it should work for you.
Just make sure in your link_mc that you have a command on the last frame of each cycle to send it back to the first frame of each cycle.
Like:
this.gotoAndPlay("_walk0") at the end ot he walk0 cycle, etc...
var mouseX:Number;
var moveSpeed = 5;
var actions:Array = [];
_global.ageNum = 0;
var isStopped:Boolean = true;
this.onMouseDown = function() {
if (_root._ymouse<350.5) {
mouseX = _root._xmouse;
playerMove();
}
};
function playerMove() {
this.link_mc.onEnterFrame = function() {
//Is the player is near to where the mouse was clicked, end this function
if ((Math.round(this._x) == Math.round(mouseX))) {
this.gotoAndStop("_stop"+ageNum);
isStopped = true;
delete this.onEnterFrame;
} else {
if (isStopped) {
trace(isStopped);
this.gotoAndPlay("_walk"+ageNum);
isStopped = false;
}
//if the player is to the right of the mouseClick:
if (this._x>mouseX) {
//Flip to face the mouseClick
this._xscale = -100;
//If it is within range of movespeed, use a smaller number to move it
if (this._x-mouseX<moveSpeed) {
this._x -= 1;
} else {
//Else, move it left using the moveSpeed
this._x -= moveSpeed;
}
//else if the player is to the left of the mouseClick:
} else if (this._x<mouseX) {
//Flip to face the mouseClick
this._xscale = 100;
if (mouseX-this._x<moveSpeed) {
this._x += 1;
} else {
this._x += moveSpeed;
}
}
}
};
}
chevron8653
06-16-2007, 05:28 AM
i guess i shouldev exsplained how ive got it setup better lol.
if i could would u send me your email address so i can send u the fla to look at how ive got the character setup? id post it here but i dont want it where neone can get it and i dont know ne private file hosting forums.
Also the _global.Islink is the global variable i have setup in the link movie clip that tells u what section of his animation is playing like _global.Islink = 0 is on the frame of _stopedright and so on there are 22 sections of him with all different animations and theres different ones for left and right side thats why the flipping with coding dosent really suit this which is why im trying to set it so he plays the animation according to the direction of the mouse.
Well let me know if u would like me to email u the fla it would help u understand better im also on WLM as chevron8653[at]hotmail.com replace the [at] with @.
thanks for helping hope its not to annoying for yah.
edit: just noticed ur emails in ur profile so ill send u the fla now and u can take a look at it when ever u have spare time, thanks again.
edit two: oh and as u will see when u test the fla by the walk cycle not looping i ment that it freezes on the first frame of the loop cycle while the character is moving then whenit stops it continuesly loops the walk cycle.
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.