Hi I was just wondering how(and where) I would write the code to make the usermode cursor (now called TP) make the character teleport to mouse position;
function on_mouse_click(==eModeTP) {
character[EGO].Animate(8, 0, eOnce, eBlock,eForwards);
Ã, Ã, Ã, character[EGO].ChangeRoom(1, mouse.x, mouse.y+25);
Ã, Ã, Ã, character[EGO].Animate(8, 0, eOnce, eBlock, eBackwards);
}
You're thinking along the right lines with on_mouse_click, but it needs to be more like:
function on_mouse_click(MouseButton button) {
// called when a mouse button is clicked. button is either LEFT or RIGHT
if (IsGamePaused() == 1) {
// Game is paused, so do nothing (ie. don't allow mouse click)
}
else if (button == eMouseLeft) {
if (mouse.Mode == eModeTP) {
cEgo.Animate(8, 0, eOnce, eBlock,eForwards);
cEgo.ChangeRoom(cEgo.Room, mouse.x, mouse.y+25);
// Of course, if you only HAVE one room, the 'cEgo.Room' bit isn't needed
cEgo.Animate(8, 0, eOnce, eBlock, eBackwards);
}
else ProcessClick(mouse.x, mouse.y, mouse.Mode );
}
else { // right-click, so cycle cursor
mouse.SelectNextMode();
}
}
I'd guess that after the animaton, EGO is 'invisible' (until it reverses), so you could possibly even directly change his coords, instead of using cEgo.NewRoom(..):
cEgo.x - mouse.x;
cEgo.y = mouse.y + 25;
Also, you could use player instead of character[EGO] or cEgo, i.e.:
player.ChangeRoom(player.Room, mouse.x, mouse.y+25);
And, if you have a scrolling room, you'll need to adjust the coordinates to compensate, by adding GetViewportX/Y, i.e.:
mouse.x + GetViewportX(), (mouse.y + 25) + GetViewportY()
I think originally you had something in your post about walkable areas - would you want teleport to only work if EGO could walk at the new location, or wouldn't that matter?
can you tell me? I mean if I dont have him teleporting to a walkable area wont he not be able to move?
No, he wouldn't - but since he could just teleport off again, I wasn't sure if it's be a proble. However, I suppose you could have him teleporting halfway up a wall, which would be a problem. Just add a check to on_mouse_click, using GetWalkableAreaAt(..) (http://www.adventuregamestudio.co.uk/manual/GetWalkableAreaAt.htm), e.g.:
else if (button == eMouseLeft) {
if (mouse.Mode == eModeTP && GetWalkableAreaAt(mouse.x, mouse.y+25) != 0) {
// Etc....