Ultimate Amiga

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: How to get the Mouse X and Y coordinate on the board?  (Read 2922 times)

0 Members and 1 Guest are viewing this topic.

xboxisfinished

  • A600
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 205
  • Generic Amiga User
    • gamemakermagazine.com
How to get the Mouse X and Y coordinate on the board?
« on: September 26, 2013, 04:57:08 AM »

OK I am attempting to make a very simple game to get my hands dirty on AROS programming language.  I have made a grid of dots one starting at coordinate X=16, Y=16 and then it continues the distance between connecting one dot to the other is by 8 steps, when it reaches to the second dot it is 16+8 which would give you 24 and then the second one between 24 and the other dot is by 8 which is 32 and then the other one is by 8 which is 40 and the other one by 8 which is 48 and so on. As you can see on the picture below.



Uploaded with ImageShack.us

I stored these coordinates in an array as well. Now the problem I have is getting the coorect X and Y coordinate of the mouse to match on the dots on the board. What I want is when the mouse is hovering over the first dot it would say X 16 and Y 16 and when I move the mouse on the second dot it would say X 24 and Y 16 but if I hover the mouse on the black spot between the first dot and second dot I want it to say nothing...I am using the Text X,Y, string$ function to display the X and Y mouse coordinate and I am using the X mouse and Y mouse function to get the current X and Y mouse coordinate.

If I get them raw the top left would say X 144 and if I divide it by 9 it would turn to 16 but if I move the mouse on the second dot it would remain 16 and if i move the mouse almost to the end of the board then it would say 17 and 18...so there is something wrong here when I put new X mouse coordinate in the Text function.

SO what I want is to get the right math calculation so that it displays 16 on the first dot (using the text function) then 24 on the second one and 32 on the third one and so on.
Logged

SamuraiCrow

  • compile-time wierdo
  • Forum Mod
  • A1200
  • *****
  • Karma: 5
  • Offline Offline
  • Gender: Male
  • Posts: 946
  • Compile-time wierdo
Re: How to get the Mouse X and Y coordinate on the board?
« Reply #1 on: September 26, 2013, 02:29:22 PM »

Keep in mind that the X Mouse and Y Mouse commands give their results in sprite coordinates.  The sprite coordinate system allows sprites to move right off the sides of the screen.  I think these are referred to as Hardware coordinates in the AmosPro manual so the X Hard and Y Hard functions are the ones you need to look up.  It will convert them either to or from screen coordinates.  From there the characters on the screen are 8x8 pixels usually so dividing the results by 8 will give you the character position.

:Edit:
It is the X Screen and Y Screen functions rather than X Hard and Y Hard.  Sorry about that.
« Last Edit: September 26, 2013, 02:42:41 PM by SamuraiCrow »
Logged

xboxisfinished

  • A600
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 205
  • Generic Amiga User
    • gamemakermagazine.com
Re: How to get the Mouse X and Y coordinate on the board?
« Reply #2 on: September 26, 2013, 04:29:34 PM »

Thank you so much but I believe I solved it yesterday using this method,

HX=(((X Mouse-16)/18)-16)*8
HY=(Y Mouse -66)

I get now the accurate results I need. Now in the if statement I use

if HX+16=BOARD(HX,0) and HY+16=BOARD(0,HY) and I get accurate result of each pixel dot on the board the way I wanted it :)
Logged

bruceuncle

  • AMOS Dev
  • A500
  • *****
  • Karma: 6
  • Offline Offline
  • Gender: Male
  • Posts: 425
  • WINUAE Amiga User
Re: How to get the Mouse X and Y coordinate on the board?
« Reply #3 on: September 26, 2013, 11:17:14 PM »

I'd recommend getting used to the Hardware-to-Screen and Screen-to-Hardware conversions functions as SamuraiCrow suggests.  They will be much faster than doing it yourself in code.  And this situation crops up all the time in AMOS programs.

The Screen coordinates start at 0,0 top left down to 319,255 bottom right (assuming a Lowres PAL display).  The Hardware coordinates to match that 0,0 Screen position are defaulted to 129, 50 when AMOS Pro starts up.  Bobs and most drawing instructions use Screen coordinates.  Sprites and hardware (Mouse, Joystick) use Hardware coordinates.  So you end up converting between them quite often.  Better to get used to using the conversion functions now rather than later.  Saves a lot of headaches  ;)
Logged
Repeat after me ...  "The AMOS Pro architecture is complex but it is not complicated."
Pages: [1]   Go Up
 

TinyPortal 2.2.2 © 2005-2022