Dharmit
February 4th, 2005, 04:59 AM
Hello,
I am facing problem with a game that i am developing.
This game is simple, Hunter hunts for ghosts which are there in swamp.
The hunter rotates as per the mouse movement (and thats the problem). When I click he (the Hunter) goes to the place where i clicked and stops. When you press the space bar, it takes out its sword and hunts the ghost. pretty simple, huh, but the problem is with the rotation of the hunter.
The problem is that whenever the hunter is taking the angle of 90 or 270, the swf starts to disfunction and generates error.
Can anyone look into the code and please tell me what the problem is. I am looking to the code since last 2 and a half hours.
Thankyou in advance.
I am attaching the fla file and the swf file too.
eiefai
February 4th, 2005, 02:54 PM
i can't view the fla file
"Unexpected File Format" Error
Dharmit
February 4th, 2005, 07:07 PM
the code that is in the file will be explained here:
there is only 1 frame on main time line and the code on it is as follows:
stop();
var rotAng = 0; //for angle of rotation
ArrSine=[0.000,.0175,.0349,.0523,.0698,.0872,.1045,.1219,.1 392,.1564,.1736,.1908,.2079,.2250,.2419,.2588,.275 6,.2924,.3090,.3256,.3420,.3584,.3746,.3907,.4067, .4226,.4384,.4540,.4695,.4848,.5000,.5150,.5299,.5 446,.5592,.5736,.5878,.6018,.6157,.6428,.6561,.669 1,.6820,.6947,.7071,.7193,.7314,.7431,.7547,.7660, .7771,.7880,.7986,.8090,.8192,.8290,.8387,.8480,.8 572,.8660,.8746,.8829,.8910,.8988,.9063,.9135,.920 5,.9272,.9336,.9397,.9455,.9511,.9563,.9613,.9659, .9703,.9744,.9781,.9816,.9848,.9877,.9903,.9925,.9 945,.9962,.9976,.9986,.9994,.9998,1.000]; //for different values of angle for sin
var endX = 0; //for value of x between hunter and click
var endY = 0; //for value of y between hunter and click
var dx = 0; //for value of x between hunter and click
var dy = 0; //for value of y between hunter and click
var Jump = 0; //To check if he is in jump position or standing position
var HSpeed = 10; //Setting speed of hunter
Mouse.hide(); //Hiding the mouse
startDrag("Light",true); //Dragging movieclip light
the Hunter instance is having code as follows:
onClipEvent (load) {
this._x = 300;
this._y = 250;
_root.Jump = 0;
}
onClipEvent (mouseDown) {
_root.endX = Math.floor(_root._xmouse);
_root.endY = Math.floor(_root._ymouse);
_root.Jump = 1;
}
onClipEvent (enterFrame) {
_root.Hx = this._x;
_root.Hy = this._y;
if (Key.isDown(Key.SPACE)) {
_root.Weapon.gotoAndPlay("Sword");
}
if (Math.ceil(this._x) == _root.endX && Math.ceil(this._y) == _root.endY) {
_root.Jump = 0;
}
if (_root.Jump == 1) {
this._x += ((_root.endX-this._x)/_root.HSpeed);
this._y += ((_root.endY-this._y)/_root.HSpeed);
}
}
the code inside the Hunter movieclip is having THREE actions and TWO frame labels named "stand" and "jump"
the code is as follows:
Action on frame 1:
This is the code in which i m having the problem.
countx = Math.abs(this._x-_root.Light._x);
county = Math.abs(this._y-_root.Light._y);
countH = Math.sqrt((countx*countx)+(county*county));
sinAng = county/countH;
found = 0;
i = 0;
while (found == 0) {
if (_root.ArrSine[i]<=sinAng) {
_root.rotAng = i;
} else {
found = 1;
}
i++;
}
if (this._y>_root.Light._y && this._x<_root.Light._x) {
_root.rotAng = -_root.rotAng;
}
if (this._y>_root.Light._y && this._x>_root.Light._x) {
_root.rotAng = -(180-_root.rotAng);
}
if (this._y<_root.Light._y && this._x>_root.Light._x) {
_root.rotAng = 180-_root.rotAng;
}
if (this._y<_root.Light._y && this._x<_root.Light._x) {
_root.rotAng = _root.rotAng;
}
this._rotation = _root.rotAng;
Action on frame 2:
gotoAndPlay(1);
Action on frame 3:
stop();
I am finding problem in the frame 1 code.
Please help.
Leet
February 4th, 2005, 10:35 PM
I'm not sure what you want but if you want the character to rotate based on the location of the mouse then you want this code.
_root.onMouseMove = function() {
var xdiff = _root._xmouse-_root.character._x;
var ydiff = _root._ymouse-_root.character._y;
var angle:Number = Math.atan2(ydiff, xdiff);
angle = angle*180/Math.PI;
_root.character._rotation = angle;
};
Dharmit
February 5th, 2005, 02:09 AM
Thanks Leet,
I think that i was doing an easy thing in a difficult way.
Thanks a lot.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.