Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

How to tell if the mouse circles 'x'?

Couldn't think of a better place to put this.

Basically, for a small project I'm working on (will be released as a script, don't worry) I'm setting up more advanced mouse interactions. All was going well, until I stumbled upon one algorithm that just hates me, and I've been staring at a blank canvas since.

I need to detect if the mouse has drawn a circle around an event. I already determine a single pixel to be the event's checking point, to allow moderate crudeness in regards to bounding box sizes. I had an idea, at some point and time, but it escaped me, and I cannot seem to get it back. I provided a couple of the supporting methods so at least my blank canvas can be understood.

def update_mouse_buffer
if @counter == 3
@m_buff_array_x << @mouse.x
@m_buff_array_y << @mouse.y
@counter = 0
endif
@counter += 1
end

def update_mouse_commands
check_mouse_click
check_mouse_rclick
check_mouse_hover
check_mouse_hold
check_mouse_slash
check_mouse_circle
clear_mouse_buffer if @clear_buffer
end

def check_mouse_circle
(logic, not syntactically correct!)
for event in $game_map.events[]
for count in @m_buff_array_y.size
mouse_x = @m_buff_array_x[count]
mouse_y = @m_buff_array_y[count]
check_event_centers(event)
target_y = @event_center_y
target_x = @event_center_x
##What to do next??
end
end
end

If someone helps my scrambled brain, I'll give credit of course! And thanks! That's right, both!

lol Thanks guys.
 
It looks like you're loading the x and y, but not checking them. You have to check to see that the mouse goes on every side of the event, and going back to the origin. So, I recommend using four flags, one for each tile-based direction off of the mouse. Then, make sure that the flags can only be turned on in a specific order (so you can't go from the flag for "above" the event directly to the flag for "below" the event) When you check the position, you activate the flag if it hasn't been activated, and keep track of the current flag, so you know if you're backtracking. (So you go from the current flag to another that's already been activated) Also, I recommend that instead of using a one pixel checkpoint, you make a small gray area, to make it a bit easier to tie it in at the end.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top