Move sprite to X,Y (as LINE) in assembly

Page 1/4
| 2 | 3 | 4

By DanySoft

Champion (452)

DanySoft's picture

05-09-2013, 22:30

Hello,
Possible that no one read my post on : Problem calcul in BASIC

See these two links: Missile Command and Battle Ship Clapton II.

This second game, he used the direction of the missile fired by the enemy toward our ship.

How is it possible to calculate the exact assembly in the routine of 0-360 °, and the position of the spacecraft (X, Y)?
Thanks for your cooperation.

I shall await your comments.

thanks
DanySoft :D :D

Login or register to post comments

By Marq

Champion (387)

Marq's picture

06-09-2013, 08:27

It's a bit hard to follow your explanation... Do you want to linearly interpolate the place of a missile from (x0,y0) to (x1,y1) in assembly or what? Or get the direction for the missile from the ship's current location (which is pretty much the same anyway)?

By DanySoft

Champion (452)

DanySoft's picture

06-09-2013, 20:57

I understand your answer ...
I've just found a solution from a file aredbook.txt: -> Generic MSX programming information resources
- How to build a LINE from BASIC.
I have already studied the variables of the program, and we can convert at the meeting, with the hope of being able to use this routine for games in ROM!
But....
We thank them for their cooperation even if it is minimal!

Thanks! :P
DanySoft

By DanySoft

Champion (452)

DanySoft's picture

06-09-2013, 22:15

Hey, this page is empty for adding comment ?
DanySoft

By DanySoft

Champion (452)

DanySoft's picture

06-09-2013, 22:17

This BASIC is WRONG!!

[b][code]
10 SCREEN 0
20 INPUT"START X,Y";X1,Y1
30 INPUT"END X,Y",X2,Y2
40 SCREEN 2
50 X=X1:Y=Y1:L=X2-X1:S=Y2-Y1:CTR=L/2
60 PSET(X,Y)
70 CTR=CTR+S:IF CTR

By umaiboux

Resident (43)

umaiboux's picture

07-09-2013, 14:26

If the following conditions are satisfied, the sample code of aredbook is correct.

Y2 >= Y1
X2 >= X1
ABS(X2-X1) >= ABS(Y2-Y1)

Therefore, depending on the above three conditions,
- Write eight subroutines
or
- Branch process in detail
(swap X1 and X2, etc.)

Or, I modified the sample code. However, non-integer values are used.

10 SCREEN 0
20 INPUT"START X,Y";X1,Y1
30 INPUT"END X,Y";X2,Y2
40 SCREEN 2
50 X=X1:Y=Y1:LX=ABS(X2-X1):LY=ABS(Y2-Y1)
60 IF LX>LY THEN L=LX ELSE L=LY
65 ' "L=SQR(LX*LX+LY*LY)" is the better for MISSILE ???
70 DX=(X2-X1)/L:DY=(Y2-Y1)/L
80 PSET(X+0.5,Y+0.5)
90 X=X+DX:Y=Y+DY:IF ABS(X-X1)<=LX AND ABS(Y-Y1)<=LY THEN 80
100 LINE(X1,Y1+5)-(X2,Y2+5)
110 GOTO 110

By DanySoft

Champion (452)

DanySoft's picture

07-09-2013, 21:18

Use this for sprite ?

And necessary the assembleer to example:

two code :

	ld A,2
	ld b,4
	SRL A	;divide to 2

and ...

DX= (X2-X1)/L
DY= (Y2-Y1)/L

	ld A,X1
	ld b,Y1
	SBC A,B

;  / L  ?????

This is not calcul fix to ASM, please help!
DanySoft

By umaiboux

Resident (43)

umaiboux's picture

08-09-2013, 14:23

DX or DY maybe not integer. (example: 0.7, -0.1, 0.333333... , etc.)
Therefore, DX or DY cannot be in one register.
Two (or more) registers are used for DX or DY. It is complicated.

You can use the other way. " Write eight subroutines"

10 SCREEN 0
20 INPUT"START X,Y";X1,Y1
30 INPUT"END X,Y";X2,Y2
40 SCREEN 2
50 FLAG=0
60 IF Y2 >= Y1 THEN FLAG=FLAG+1
70 IF X2 >= X1 THEN FLAG=FLAG+2
80 IF ABS(X2-X1) >= ABS(Y2-Y1) THEN FLAG=FLAG+4
90 ON FLAG+1 GOSUB 200,300,400,500,600,700,800,900
100 LINE(X1,Y1+5)-(X2,Y2+5)
110 GOTO 110
200 ' Y2 < Y1 , X2 < X1 , ABS(X2-X1) < ABS(Y2-Y1)
210 X=X1:Y=Y1:L=Y1-Y2:S=X1-X2:CTR=L/2
220 PSET(X,Y)
230 CTR=CTR+S:IF CTR < L THEN 250
240 CTR=CTR-L:X=X-1
250 Y=Y-1:IF Y>=Y2 THEN 220
260 RETURN
300 GOSUB 1000 : RETURN
400 GOSUB 1000 : RETURN
500 ' Y2 >= Y1 , X2 >= X1 , ABS(X2-X1) < ABS(Y2-Y1)
510 X=X1:Y=Y1:L=Y2-Y1:S=X2-X1:CTR=L/2
520 PSET(X,Y)
530 CTR=CTR+S:IF CTR < L THEN 550
540 CTR=CTR-L:X=X+1
550 Y=Y+1:IF Y<=Y2 THEN 520
560 RETURN
600 GOSUB 1000 : RETURN
700 GOSUB 1000 : RETURN
800 GOSUB 1000 : RETURN
900 ' Y2 >= Y1 , X2 >= X1 , ABS(X2-X1) >= ABS(Y2-Y1)
910 X=X1:Y=Y1:L=X2-X1:S=Y2-Y1:CTR=L/2
920 PSET(X,Y)
930 CTR=CTR+S:IF CTR < L THEN 950
940 CTR=CTR-L:Y=Y+1
950 X=X+1:IF X<=X2 THEN 920
960 RETURN
1000 SCREEN 0
1010 PRINT"under construction..."
1020 STOP
1030 END

By DanySoft

Champion (452)

DanySoft's picture

08-09-2013, 21:34

yeah!
But to ASM ?????
The game of Battle Clapton2 have use the small ball from enemy to Shuttle.

Else.... make ASM o no?

Sad
DanySoft

By DanySoft

Champion (452)

DanySoft's picture

08-09-2013, 23:01

And....
i'm use the formul of ASM of use angle to °360:
use this for my game as "TANK"....

You see "M-Tanks" : this game is creating by autor:"Assembler" !
Make sprite from tank to tank is great !

The sorcery is necessary for three part:

1. Check Location of X,Y on TANK:
2. calculation position and long from two tank
3. fire the ball from tank to tank (example: 30° is position X,Y on TANK)

This sorcery is necessary for future GAME !! But This BASIC is slow....... and use XBASIC for FAST SPEED on GAME,
and single GAME are 16K from ROM o RAM!!!!!

and then my game is different from his own:
is installed cannons and machine guns from the ground, and rotate 360 ° was easy!

DanySoft

By umaiboux

Resident (43)

umaiboux's picture

09-09-2013, 13:50

Writing a program for ASM : try by yourself Wink ( or wait for the other user...)

---

If you want to get the angle from (X1,Y1)-(X2,Y2), you can use arctangent.
http://en.wikipedia.org/wiki/Inverse_trigonometric_functions
http://en.wikipedia.org/wiki/Trigonometric_functions
It is ATN(n) in MSX-BASIC.
Of course, It cannot be handled within the range of integers. complicated in ASM.

However, I wonder if the angle is necessary or not.

Page 1/4
| 2 | 3 | 4