Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Character movement via mouse.

This thread is locked; no one can reply to it. rss feed Print
Character movement via mouse.
julian_boolean
Member #8,201
January 2007

Is there any relatively clean code laying around for this sorta thing? I'm talking about being able to move the player's character/hero by point and click, rather then the arrow keys.

Neil Walker
Member #210
April 2000
avatar

julian_boolean
Member #8,201
January 2007

Ooo thanks!

Would something like this be a good idea?

1if (mouse_b &1)
2{
3 if (target_is_collidable)
4 {
5 // don't move
6 }
7 
8 else if (target_is_enemy)
9 {
10 // move to location and engage enemy
11 }
12 
13 else if (target_is_item)
14 {
15 // move to location and pick up item
16 }
17 
18 else
19 // move to location
20}

Paul whoknows
Member #5,081
September 2004
avatar

1//You give mouse coordinates, you get Item/Enemy ID
2WhatHappened = player.CheckCollision(mouse.x, mouse.y, ItemID, EnemyID);
3
4 switch(WhatHappened)
5 {
6 //target_is_collidable, as you call it
7 case 1:
8 player.say("I can't go there, uga uga");
9 break;
10
11 // move to location and stay there
12 case 2:
13 player.MoveTo(mouse.x, mouse.y);
14 break;
15
16 // move to location and pick up item
17 case 3:
18 player.MoveTo(mouse.x, mouse.y);
19 player.AddItem(ItemID); //Adds the item located at x,y to the player's inventory
20 break;
21
22 // move to location and engage enemy
23 case 4:
24 player.MoveTo(mouse.x, mouse.y);
25 player.AttackEnemy(EnemyID) //Player attacks the enemy located at x,y
26 break;
27 }

Untested pseudo code, use it at your own risk.

____

"The unlimited potential has been replaced by the concrete reality of what I programmed today." - Jordan Mechner.

piccolo
Member #3,163
January 2003
avatar

http://agdn.netfirms.com/main/html/tut_4.htm
the best.
lots of other goodies on there too.

wow
-------------------------------
i am who you are not am i

julian_boolean
Member #8,201
January 2007

Thanks everyone!!

Go to: