home *** CD-ROM | disk | FTP | other *** search
AMOS Source Code | 1992-02-26 | 3.5 KB | 130 lines |
- 'Program: I put a question to the Amoszine #2 (Lee Bamber), his
- ' answere is in that issue.
- ' Bloke: Paul Overy
- '
- ' By the way Lee, are you sure about saying:-
- ' "If you can't use floating point number systems, you
- ' can rule out the use of the Amos commands that will do
- ' this in an instant."
- ' =============
- '
- ' Floats are painfully slow, I only use them when intialising a program,
- ' even then I save them to disk so I only have to do it once.
- ' There also the new binary integer arithmetic routines for fast trig.
- '
- ' This is my own answer to my own question, is hungry on memory but
- ' its very fast! (yes its a look up table)
- '
- ' By the way... This is my engine for my future coming game Bolt Thrower.
- '
- Dim PX(72),PY(72)
- Global PX(),PY(),_MOUSE_X,_MOUSE_Y,CX,CY,MX,MY,FRAME,X,Y,_START10
- '
- 'Look of data store in Bank 10
- Proc _TO_BE_DELETED
- Proc _SET_UP
- '
- _START10=Start(10) : X=100*512 : Y=100*512
- '
- Do
- _MOUSE_X=X Screen(X Mouse)
- _MOUSE_Y=Y Screen(Y Mouse)
- Sprite 2,X Hard(CX),Y Hard(CY),FRAME
- Proc _TEST_MOUSE
- Proc _CALC_POSITION
- Wait Vbl
- Loop
- '
- Procedure _TEST_MOUSE
- If Mouse Key
- Add MX,PX(FRAME) : Add MY,PY(FRAME)
- End If
- End Proc
- Procedure _CALC_POSITION
- Proc _FIND_ANGLE[_MOUSE_X,_MOUSE_Y,CX,CY]
- TURN=FRAME-Param
- 'find & turn in the quickest direction.
- If Abs(TURN)>36
- Add FRAME,Sgn(TURN),1 To 72
- Else
- Add FRAME,-Sgn(TURN),1 To 72
- End If
- CX=X/512 : CY=Y/512
- ' Make some false gravity
- If Abs(MX)>32 or Abs(MY)>32
- LX=MX/32
- LY=MY/32
- Else
- LX=MX
- LY=MY
- If Abs(MX)>1 or Abs(MY)>1
- LX=0 : MX=0
- LY=0 : MY=0
- End If
- End If
- 'move
- Add X,MX : Add Y,MY
- 'slow step speed
- Add MX,-LX : Add MY,-LY
- End Proc
- Procedure _FIND_ANGLE[X1,Y1,X2,Y2]
- '
- X3=X1-X2 : Y3=Y2-Y1
- ' Re-scale ships off screen to fit look up data
- While Abs(X3)>320 or Abs(Y3)>224
- X3=X3/2 : Y3=Y3/2
- Wend
- 'Flip data to fit correct axis.
- If X3>0
- If Y3>=0
- ANG=Peek(Y3*320+X3+_START10)
- Else
- ANG=37-Peek(-Y3*320+X3+_START10)
- End If
- Else
- If Y3>=0
- ANG=73-Peek(Y3*320-X3+_START10)
- Else
- ANG=35+Peek(-Y3*320-X3+_START10)
- End If
- End If
- Centre Str$(ANG)
- End Proc[ANG]
- Procedure _SET_UP
- Screen Open 0,320,200,4,Lowres : Flash Off : Curs Off : Cls 0
- Change Mouse 2
- K=19
- For N#=0.0 To 2.0*Pi# Step Pi#/36.0
- PX(K)=Cos(N#)*64 : PY(K)=Sin(N#)*64
- Draw PX(K)/4+100,PY(K)/4+100 To -PX(K)/4+100,-PY(K)/4+100
- Bar PX(K)/4+98,PY(K)/4+98 To PX(K)/4+102,PY(K)/4+102
- Get Bob K,80,80 To 80+48,80+48 : Cls 0
- Hot Spot K,24,24
- Exit If K=18
- Add K,1,1 To 72
- Next N#
- For K=16 To 31 : Colour K,$FFF : Next K
- End Proc
- '
- Procedure _TO_BE_DELETED
- ' For GENERATING LOOK UP Data For FINDING ANGLES
- Text 0,100,"This only needs to be done once."
- Degree
- Erase 10 : Reserve As Data 10,320*200
- ADR=Start(10)
- For Y=0 To 199
- Text 0,Text Base,"Wait..."+Str$(199-Y)+" "
- For X=0 To 319
- X#=X : Y#=Y
- If Y<>0 : Rem check for devide by 0.
- PRE_ANG=Atan(X#/Y#)
- Else
- PRE_ANG=90
- End If
- ANG=PRE_ANG/5 : Rem needs word storage,cut down to 1-72 byte size
- Add ANG,1,1 To 72 : Rem Bob frame can't start at zero.
- Poke ADR,ANG : Inc ADR
- Next X
- Next Y
- Radian
- End Proc