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.
Ooo thanks!
Would something like this be a good idea?
| 1 | if (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 | } |
| 1 | //You give mouse coordinates, you get Item/Enemy ID |
| 2 | WhatHappened = 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.
http://agdn.netfirms.com/main/html/tut_4.htm
the best.
lots of other goodies on there too.
Thanks everyone!!