Auto-moving reticle logic [Solved]

Started by LLamaBoy, Thu 07/08/2008 20:26:37

Previous topic - Next topic

LLamaBoy

So I've been using AGS for about a week now, after being roped into a project with some friends.

Today I had an idea on making a kind of minigame which would basically be a darts/archery type aiming game where you would have a reticle moving and you'd stop it by hitting space. First it would move left-right, then up-down, and after the second space, it stops and tells you what you hit.

I took some time to search the forums to see if anything similar had been discussed, but came up empty, so I started on my own.

Unfortunately, I got a little stuck with the logic of making the aiming reticle move back and forth while allowing input.
I tried a couple of different approches:

First, I tried to use an Overlay sprite and move it one unit per iteration in a while loop, but that just caused the game to hang as it blocked any input.

After that, I thought of using a Character with the reticle sprite and making it .Walk() back and forth on the X or Y axis, calling .StopWalking() when the space bar is pressed. This works better, as it allows input, but I'm still having a little trouble with it:
When I call .Walk() on the cReticle, it becomes invisible and it doesn't walk, but the Moving property remains 1. The entire room is walkable and I use eAnywhere in the function call.

Can someone let me know if my logic for this problem is OK? Also, if anyone can identify and solve the vanishing character problem as well, that would be a major help.

Thanks a lot.

Makeout Patrol

Making it a character should work, although I'd personally just make it an overlay or something like that and just make it move using a non-blocking script in the repeatedly execute function.

The reason it's disappearing when it's 'walking' is because it's playing the character's 'walk' view, which must have blank frames in it. Open the 'Views' menu and open up the view of your crosshair. You're going to need to have at least four loops in there (one for when the crosshair is moving left, one for right, one each for up and down). I haven't tested it myself, but you might need to put in a second frame in each of these loops, as the first frame in a 'walk' view is the 'stand' frame, and every frame after it is the 'walk' animation; it might just stick with the first frame if you don't provide any others, however.

Khris

I've used an object:

Code: ags
// room script file

function room_AfterFadeIn() {
  mouse.Visible = false;
}


int state;
int x = 160;  // center
int y = 120;
int xa = -9;  // offsets object handle - center
int ya = 10;
int m = 3; // movement speed

function room_RepExec() {
  if (state == 0) {
    x += m;
    if (x>220 || x<100) m = -m;
  }
  if (state == 1) {
    y += m;
    if (y>180 || y<60) m = -m;
  }
  if (state < 2) Crosshair.SetPosition(x+xa, y+ya);
}

function on_key_press(int k) {
  if (k == ' ') state++;
  if (state == 2) {
    Display("You aimed at %d, %d.", x-160, y-120);
    state = 0;
    y = 120;
  }
}

LLamaBoy

Quote from: Makeout Patrol on Thu 07/08/2008 21:44:08
Making it a character should work, although I'd personally just make it an overlay or something like that and just make it move using a non-blocking script in the repeatedly execute function.

That's the vital part I was missing, I completely forgot that rooms can have their own rep-ex function, It all works perfectly now, and I ended up going back to the overlay after all, much less hassle.

Quote from: Makeout Patrol on Thu 07/08/2008 21:44:08
The reason it's disappearing when it's 'walking' is because it's playing the character's 'walk' view, which must have blank frames in it.

That explains why it was vanishing, and I fixed that before going back to the overlay method, but it still wouldn't move anywhere after calling .Walk() on it; it would just stay on its starting point. Any idea why? As I said before, the entire room was made walkable and I used the eAnywhere parameter as well. Just asking out of academic curiosity now, as the problem is solved.

Thanks again.

Makeout Patrol

Quote from: Makeout Patrol on Thu 07/08/2008 21:44:08
The reason it's disappearing when it's 'walking' is because it's playing the character's 'walk' view, which must have blank frames in it.

That explains why it was vanishing, and I fixed that before going back to the overlay method, but it still wouldn't move anywhere after calling .Walk() on it; it would just stay on its starting point. Any idea why? As I said before, the entire room was made walkable and I used the eAnywhere parameter as well. Just asking out of academic curiosity now, as the problem is solved.

Thanks again.
[/quote]

I can't think of any reason that wouldn't work, I'd have to take a look at the code. It might be the placement of the Walk() method; again, I think you'd need to use the repeatedly execute function and have it wait for the reticule to reach a certain point before calling a new Walk() method to move in the opposite direction, although if you'd put it somewhere else I would assume it would make it to the first set of coordinates you'd sent it to and then stop.

SMF spam blocked by CleanTalk