Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/20/24 20:05
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (VoroneTZ, 7th_zorro), 1,332 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Question #278965
07/16/09 09:57
07/16/09 09:57
Joined: Jul 2009
Posts: 19
Poland
V
Varen Offline OP
Newbie
Varen  Offline OP
Newbie
V

Joined: Jul 2009
Posts: 19
Poland
Hey, im amatour-programist and i still have lots of problem with programming. Pls dont tell me to "hide under the stone coz u r noob" :P

My game is supposed to be 2d game, the player will control his character by clicking on the map . I hope the image explains all. I want the red spot(which is the character) to go slowly to the point clicked by player. How should i do it?

THX in advance

Re: Question [Re: Varen] #279022
07/16/09 12:23
07/16/09 12:23
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Go hide under a KEYBOARD coz u r a geek noob! grin

Serious, thats a hard question without knowing what youve done so far,
how you maps are handled, ... the list goes on.

All the same, in a general way, to do what you want, you need to...
1> Check if mouse was clicked, if so store the target location of the click.
2> Calculate the angle between the 'current" position and the target position.
3> Rotate the player-object to face the target.
4> Move the player-object "forward" by a fixed amount(of your choice).
5> Check if youve arrived at the target, if NOT, go back to step 1.


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Question [Re: EvilSOB] #279043
07/16/09 13:30
07/16/09 13:30
Joined: Jul 2009
Posts: 19
Poland
V
Varen Offline OP
Newbie
Varen  Offline OP
Newbie
V

Joined: Jul 2009
Posts: 19
Poland
Actually, this game is going to look as the picture shows. The player controls his character that looks like the spot on 2d map, so i dont have to think about rotating him.
Could u give me an example code pls :P If u dnt wanna waste the time for it,
ill understand...

Re: Question [Re: Varen] #279046
07/16/09 13:35
07/16/09 13:35
Joined: Feb 2009
Posts: 3,207
Germany, Magdeburg
Rei_Ayanami Offline
Expert
Rei_Ayanami  Offline
Expert

Joined: Feb 2009
Posts: 3,207
Germany, Magdeburg
here:
vec_set(temp,player.x);
vec_sub(temp,your_clicked_position.x);
vec_to_angle(player.pan,temp);

PLease
Rei_ayanami!

Re: Question [Re: Rei_Ayanami] #279076
07/16/09 14:25
07/16/09 14:25
Joined: Jun 2006
Posts: 2,640
Earth
Germanunkol Offline
Expert
Germanunkol  Offline
Expert

Joined: Jun 2006
Posts: 2,640
Earth
Code:
VECTOR newPos;
var newPosSet = OFF;

PANEL* theSpot = {
	bmap = "stone.tga";
	layer = 2;
	flags = SHOW;
}

void set_new_pos()
{
	newPos.x = mouse_pos.x;		//store the current mouse position.
	newPos.y = mouse_pos.y;
	
	newPos.x -= bmap_width(theSpot.bmap)/2;		//make sure the center of the player reaches the position, not the corner of the player
	newPos.y -= bmap_height(theSpot.bmap)/2;
	
	newPosSet = ON;
}

VECTOR temp;
var theSpotSpeed = 10;			//play with this value

void move_to_mouse_pos()
{
	
	VECTOR myVelocity;
	vec_set(myVelocity,nullvector);			//make player not move at beginning
	
	while(1)
	{
		//if there's a new position: calculate the direction from my position to the new position.
		if(newPosSet == ON)
		{
			vec_diff(myVelocity,newPos,vector(theSpot.pos_x,theSpot.pos_y,0));
			newPosSet = OFF;
		}
		
		vec_set(temp,myVelocity);
		vec_normalize(temp,time_step*theSpotSpeed);		//pointing in the direction that I should move in, correct length
		//speed*time = distance to be covered
		
		theSpot.pos_x += temp.x;			//add the  to the position
		theSpot.pos_y += temp.y;
		
		if(vec_dist(vector(theSpot.pos_x,theSpot.pos_y,0),newPos) < theSpotSpeed*time_step) vec_set(myVelocity,nullvector);
		
		wait(1);
	}
}


void main()
{
	//put these lines in your main function:
	mouse_mode = 4;
	vec_set(newPos,vector(-1,-1,0));			//new position.
	
	on_mouse_left = set_new_pos;
	move_to_mouse_pos();
	
	
}




hope this is what you're looking for.
Note: there's no acceleration/breaking in there... wouldn't be hard to add though.


~"I never let school interfere with my education"~
-Mark Twain
Re: Question [Re: Germanunkol] #279080
07/16/09 14:32
07/16/09 14:32
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
"EvilSOB returns to OVERWATCH position" grin


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Question [Re: EvilSOB] #279097
07/16/09 14:55
07/16/09 14:55
Joined: Jul 2009
Posts: 19
Poland
V
Varen Offline OP
Newbie
Varen  Offline OP
Newbie
V

Joined: Jul 2009
Posts: 19
Poland
Thank u very much! I hope itll work smile

Re: Question [Re: Varen] #279140
07/16/09 18:17
07/16/09 18:17
Joined: Jun 2006
Posts: 2,640
Earth
Germanunkol Offline
Expert
Germanunkol  Offline
Expert

Joined: Jun 2006
Posts: 2,640
Earth
If not ask EvilSob... I don't want him to get boring while overwatching laugh


~"I never let school interfere with my education"~
-Mark Twain

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1