Author
|
Topic: Movement on mouseclick (long)
|
Tamtur |
posted 01-18- 03:45 PM CT (US)
Ok, for the past couple days I've been trying to make it so that when the mouse is on and I click on a sprit, dink moves to it (I've made all my sprites without hardboxes for now so I don't have to worry about that yet.) Also, I am hoping to switch from mouse to non mouse movement. I have been decently successful, but there are a few bugs I can't figure out. FYI - &dinktry is a global variable, it is the sprite that is dink when the mouse is controlled, and the other variables are always int-ed in the main( ) procedure.The only problem I have switching is that the sprite I use for dink doesn't do the "idle" sequence - how do I put that in the code? Here is the code for the dink sprite: &dinktry = create_sprite(&xloc,&yloc,1,12,1); sp_base_walk(&dinktry, 70); sp_base_attack(&dinktry, 100); sp_speed(&dinktry, 2); sp_timing(&dinktry, 33); Now for the movement. I have tried two ways. Here is the code for the first way: void click ( void ) { &xgoal = sp_x(¤t_sprite,-1); &ygoal = sp_y(¤t_sprite,-1); &xstart = sp_x(&dinktry,-1); &ystart = sp_y(&dinktry,-1); debug("x goal - &xgoal, y - &ygoal. x start - &xstart, y start - &ystart"); &xgoal -= &xstart; &ygoal -= &ystart; debug("x goal is now &xgoal, y is &ygoal - starts: &xstart, &ystart"); sp_my(&dinktry,&ystart); sp_mx(&dinktry,&ystart); wait(2000); } This one doesn't work at all. I thought I might be using sp_mx and my wrong (since in dinkc.txt it says speed, not movement), but when I added the debug lines I realized that it wasn't even getting that far. The second debug line shows no change from the first even though I've subtracted them. I have no clue why. The second way I tried is much more complicated. I figured out the problem I was having with it (I was figuring up to but positive, but y is greater going down), but it is so much more complicated. The last problem I'm having is that whenI go back to Dink from the mouse, &dinktry stays where he is (unless I don't freeze him, then he follows Dink around). I tried using sp_kill(); - this must just strip the script, though. Is there a way to get rid of the sprite? Otherwise there will be a lot of sprites running around. And I would rather not use visions for this case. Right now, the script reads: void click ( void ) { sp_base_walk(1, 70); sp_base_attack(1, 100); sp_dir(1, 8); sp_brain(1, 1); sp_que(1, 0); sp_noclip(1, 0); &xloc = sp_x(&dinktry,-1); &yloc = sp_y(&dinktry,-1); sp_x(1, &xloc); sp_y(1, &yloc); sp_kil(&dinktry); } Thank you for helping me Tamtur
|
someone2
|
posted 01-19- 12:18 AM CT (US)
You can set the idle with base_idle(), and kill the sprite with sp_active().I don't know why your substracting operations don't work though. |
Tamtur
|
posted 01-19- 01:23 PM CT (US)
Thanks someone,I tried both, and the sp_active worked but the base_idle didn't start working right off, only after I'd moved dink once. And it had the strange side effect of turning dink into a burning tree on some corners (I used the base idle of twelve, which is him facing direction 2 - it must have been the wrong one) Do I need to use sp_seq to start him in his idle pose right off? I tried it once and it didn't seem to work. And if you know the right idle number for dink offhand (it's not in start-1) that would be nice, otherwise I'll figure it out. Thanks Tamtur |
Beuc
|
posted 01-19- 03:28 PM CT (US)
For the substract: you may have not declared the variables.For the idle sequence: check dink.ini. I don't know if it's what you want... :) |
someone2
|
posted 01-20- 02:46 AM CT (US)
The base_idle must have a factor of ten. You will (probably) need to set it to 10 (is that Dink's idle sequences?) and not 12.You can get the sequence numbers from DinkEdit, in the frame selection screen. |
Tamtur
|
posted 01-21- 03:59 PM CT (US)
For the subtracting operation: The 'int &xstart' etc. are all in the main () procedure. Is that what you're referring to when you say 'declaring the variables'? Or is there something else I need to do?For the record, the debug file doesn't say anything between the two 'debug' lines while it is subtracting. Do you know if I am using the sp_mx and sp_my right? |
Beuc
|
posted 01-22- 10:58 AM CT (US)
You're right, sp_mx() is to set how many pixels the sprite moves each time. It's NOT the location of the sprite. To understand this, check the dinkc.txt in your develop dir... And tell me if I'm right or not :) |
Tamtur
|
posted 01-22- 03:33 PM CT (US)
What the dinkc.txt file says is:int sp_mx(int sprite, int value (-1 to not change)); X movement. If you don't want to deal with directions, or need some kind of weird movement, this lets you specify in pixels how fast the sprite is going. -5 would move left. 5 would move right. I wasn't completely sure what it meant when it said "This lets you specify... how fast the sprite is going.", but I figured with the pixels references that it is used the way I did. Now, question: if I actually get this script to work, will dink walk to where he is going, or will the sprite just jump over there? If it jumps, I can just change it to a loop so he's walking over. I think. Have a great day. |
Beuc
|
posted 01-23- 05:25 AM CT (US)
If you use sp_x(), the sprite will "jump". Use move() or move_stop() (I don't know, check dinkc.txt), and for the sprite parameter, use 1, i.e. Dink (Dink is sprite #1).Great day also :) |
Tamtur
|
posted 01-23- 12:57 PM CT (US)
The second way that I've been trying is using move_stop. The problem with move_stop is that you need a direction, and if it isn't exactly that direction, you need to have him change direction at some point. This one is complex, and I have written it out, but I don't know if there is an easier way. It also has some bugs in it but it works most of the time. Here is the script: (All the variables were declared in the main () procedure. &dinktry is the dink sprite.)void click ( void ) { &xgoal = sp_x(¤t_sprite,-1); &ygoal = sp_y(¤t_sprite,-1); &xstart = sp_x(&dinktry,-1); &ystart = sp_y(&dinktry,-1); if (&xgoal == &xstart) { if (&ygoal == &ystart) { say(&dinktry, "You are there already."); } else { if (&ygoal < &ystart) move_stop(&dinktry, 8, &ygoal, 0); if (&ygoal > &ystart) move_stop(&dinktry, 2, &ygoal, 0); debug("move left or right"); } } if (&xstart < &xgoal) { if (&ygoal == &ystart) move_stop(&dinktry, 6, &xgoal, 0); if (&ystart > &ygoal) { move_stop(&dinktry, 9, &ygoal, 0); move_stop(&dinktry, 6, &xgoal, 0); debug("move down and right"); } if (&ystart < &ygoal) { move_stop(&dinktry, 3, &ygoal, 0); move_stop(&dinktry, 6, &xgoal, 0); debug("move up and right"); } } if (&xstart > &xgoal) { if (&ygoal == &ystart) move_stop(&dinktry, 4, &xgoal, 0); if (&ystart > &ygoal) { move_stop(&dinktry, 7, &ygoal, 0); move_stop(&dinktry, 4, &xgoal, 0); debug("move down and left"); } if (&ystart < &ygoal) { move_stop(&dinktry, 1, &ygoal, 0); move_stop(&dinktry, 4, &xgoal, 0); debug("move up and left"); } } } |
Beuc
|
posted 01-24- 04:05 AM CT (US)
You may rip off a script from "Birth of an Empire" or "Quest for Dorinthia 2", where goblins follows Dink.Or use the enemy system where the enemy follows the guy who hit him. (e.g. check in en-pill1.c). You'll just have to create a sprite and tell the Dink sprite to follow it. But it'll work well in an area with no hardness, because you saw it: the enemies who follows you, are quite stupid when they hit a rock. |