30 August 2018, 21:35 | #1 | |
Puttymoon inhabitant
|
AMAL animation string
My program starts like this:
Setting up the screen and then: Code:
Channel 3 to Bob 3 Shared A,B,C,D,E,F A=Rnd(200): B=Rnd(100) Set Bob 1,,, Set Bob 2,,, Set Bob 3,,, Bob 1,A,B,1 . . . . Then I have some condition inside the loop for a procedure, that is called when LMB is pressed Code:
Do If Mouse Key=1 Then MOVEMENT Loop . . Now the program jumps to execute a procedure. Procedure looks like this: Code:
Procedure MOVEMENT C=X Mouse-128 D=Y Mouse-42 E=C-A F=B-D Bob 3, A, B, 2 Code:
A$="S: Move E,F,100; Jump S" Amal 3, A$ Amal On 3 End Proc Quote:
|
|
30 August 2018, 21:54 | #2 |
Users Awaiting Email Confirmation
Join Date: Aug 2018
Location: Country
Posts: 38
|
It doesn't work that way, you can't use AMOS variable with AMAL just like that. In order to use it in AMAL you have to use Amreg command to 'pass' it there (or read from). Please read in the doc or look for an exaple code because it's not that simply as BASIC syntax.
Update: Alright, I wasn't going to do it because I'm moving to a new apartment and I don't have much time now but... it was a challenge I often take up ;-). Firstly, your solution simply can not work because you mistake X and Y coordinates with how many pixels command Move should move a Bob. What's more, Move will not move a Bob to a position you think, it will move it by X and Y pixels adding to its actual position. For example if a Bob is on X=300, Y=100 and you send to AMAL "Move X=(your X Mouse coordinates), Y=(your Y Mouse coordinates) it will add to 300 the value of your X Mouse and will do the same with Y. Simply your Bob will fly out of the screen in opposite to your desire direction. Here is the working code (you may adapt it to your needs): Code:
Curs Off Channel 3 To Bob 3 X=160 : Y=100 Bob 3,X,Y,2 Amreg(Asc("X")-65)=X : Rem // Pass the starting coordinate X to the Register X Amreg(Asc("Y")-65)=Y : Rem // Pass the starting coordinate Y to the Register Y Do If Mouse Key=1 Then MOVEMENT Loop Procedure MOVEMENT DESTX=X Mouse-128 : Rem // Read the value where the mouse X clicked DESTY=Y Mouse-50 : Rem // Read the value where the mouse Y clicked ACTX=Amreg(Asc("X")-65) : Rem // Read the actual Bob position X ACTY=Amreg(Asc("Y")-65) : Rem // Read the actual Bob position Y XDIST=DESTX-ACTX : Rem // Take the X distance between actual Bob coordinates and the destination YDIST=DESTY-ACTY : Rem // Take the Y distance between actual Bob coordinates and the destination R#=Sqr(XDIST^2+YDIST^2) : Rem // Callculate stright line For I=1 To R# '// You have to handle division by 0 in RX/RY by your own RX=ACTX+(I/R#)*(XDIST) : Rem // Calculate next step X RY=ACTY+(I/R#)*(YDIST) : Rem // Calculate next step Y Amreg(Asc("X")-65)=RX : Rem // Pass it to the Register X Amreg(Asc("Y")-65)=RY : Rem // Pass it to the Register Y A$="Let X=RX; Let Y=RY" Amal 3,A$ Amal On 3 X=Amreg(Asc("X")-65) Y=Amreg(Asc("Y")-65) Locate 0,1 : Print " " Locate 0,1 : Print X,Y Wait Vbl Next I '// Because we operate on decimals the final coordinates are not always.. '// ..the same as of the mouse click (DESTX, DESTY). In order to make.. '// ..sure we get the Bob on its right position we send only once the.. '// ..final coordinates (Rem those lines and click a destination and.. '// ..do NOT move the mouse pointer to see what I mean) Amreg(Asc("X")-65)=DESTX : Rem // Pass the original mouse X value to the Register X Amreg(Asc("Y")-65)=DESTY : Rem // Pass the original mouse X value to the Register Y A$="Let X=RX; Let Y=RY" Amal 3,A$ Amal On 3 End Proc Last edited by Epo; 01 September 2018 at 20:34. |
30 August 2018, 22:48 | #3 |
Puttymoon inhabitant
|
No, I can't get it. There is an example for Amreg in AMOS Help, but it uses that for maintenance the speed of the game. I just want to read mouse coords to a variable and use it as a target point for a bob to move to. A routine where bob follows the clicked point on the screen. Seems AmReg is somehow able to gather the coords and store them in RA-RZ (R0-R25) register (variable)?
Like Code:
Amreg(RA)=XM EDIT: A partial success. I adjusted my procedure to look as this: Code:
Procedure MOVEMENT Amreg(RB)=Y Mouse-42-B Amreg(RA)=X Mouse-128-A Bob 3,A,B,3 A$="S: Move RA,RB,100; Pause;" Amal 3, A$ Amal On 3 End Proc Last edited by Predseda; 31 August 2018 at 09:42. |
31 August 2018, 15:27 | #4 |
Banned
Join Date: May 2011
Location: Spain
Posts: 519
|
Hi predseda , insert the Mouse Coordinates in the main Loop then you get what you are looking for the Amreg's need to be looped(udpdate) inside ThE Amal or outside but update al the time if you want to get the right coordinates of the mouse
Last edited by Amiten; 31 August 2018 at 15:40. |
31 August 2018, 16:37 | #5 |
Banned
Join Date: May 2011
Location: Spain
Posts: 519
|
but I dont understand really what you want to do ... but here the way you need to use the Amal to make a object position are in the X & Y of the mouse when we press key and maybe is not what you are looking for, if you explain me better your Idea may I can help you , regards
Get Sprite Palette Cls 0 Global A,B A=Rnd(200) : B=Rnd(100) Bob 1,A,B,1 Procedure MOVEMENT Amreg(0)=X Mouse-128 Amreg(1)=Y Mouse-42 A$="A:Move RA,RB,100;Pause;" Bob 3,Amreg(0),Amreg(1),2 Amal 3,A$ Amal On 3 End Proc Do If Mouse Key=1 Then MOVEMENT Loop this example red square are bob 1 and white bob 3 https://drive.google.com/open?id=1NJ...dcTMh2IXpdc-CY Example source code: https://drive.google.com/open?id=19f...JKqcDJTzxGkWsZ Last edited by Amiten; 31 August 2018 at 16:43. |
01 September 2018, 20:11 | #6 |
Users Awaiting Email Confirmation
Join Date: Aug 2018
Location: Country
Posts: 38
|
Look at post #2. I provided a solution.
|
02 September 2018, 22:34 | #7 |
Puttymoon inhabitant
|
Thank you guys. I am just examining your examples. It still doesnt do exactly what I want, but I am sure I will learn something from you and finally get into it. I will let you know.
EDIT: GOT IT! I altered my original procedure from what you both suggested and now it looks like this: Code:
Procedure MOVEMENT Amreg(0)=X Mouse-128-A Amreg(1)=Y Mouse-42-B Bob 3,A,B,3 A$="S: RA, RB, 100; Pause;" Amal 3,A$ Amal On 3 End Proc Last edited by Predseda; 02 September 2018 at 22:58. |
04 September 2018, 22:34 | #8 |
Registered User
Join Date: Mar 2015
Location: Sheffield UK
Posts: 360
|
Of course ..
If you are defining an animation string from basic at each turn, you could do ... a$="Move "+str$(xmoves)+","+str$(ymoves)+","+str$(totalsteps)+"anything else" where xmoves,ymoves & totalsteps are standard basic variables at runtime Not ideal but it's easier to grasp (a bit like a virtual compiler) Also, if you are using AMAL registers take a look at AMREG (channel,register) in the manual as these variables are local to the routine rather than the whole AMAL system. In short, treat each AMAL channel as a self contained mini program UNLESS you need to share information between channels, only then use the global registers One other thing.... In the examples above, what would happen if the mouse button was clicked again before the Move instruction had completed? I assume it would re-calculate all the co-ordinates and try again, which would seem very slow (unless that is the idea) Otherwise I'd suggest looking at the AU (AUtotest) function in AMAL Last edited by volvo_0ne; 04 September 2018 at 23:30. |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
AMAL as primary code... | volvo_0ne | Coders. AMOS | 14 | 13 April 2018 01:59 |
AMAL channel n to object n limit?? | volvo_0ne | Coders. AMOS | 1 | 07 October 2017 21:18 |
Amal animation & HREV with joystick commands | Brick Nash | Coders. AMOS | 8 | 02 June 2016 18:32 |
Animating explosion without amal | aszu | Coders. AMOS | 13 | 17 March 2016 23:33 |
More AMAL headaches.... | volvo_0ne | Coders. AMOS | 0 | 23 February 2016 00:17 |
|
|