[A83] Re: Angles


[Prev][Next][Index][Thread]

[A83] Re: Angles





----------------------------------------------
Original Message
From: "Sebastiaan Roodenburg"<sebastiaan@rimsystems.nl>
Subject: [A83] Re: Angles
Date: Thu, 20 Sep 2001 15:19:42 +0200
It doesn't have to be that accurate, really.  I don't wanna have to mess
with all that trig stuff =)  Or lookup tables, or anything of the sort. 
I'd rather stick to bit-level math.  

here is the source to the angle routine in pheonix:

fire_big_bullet:
        inc     hl
        inc     hl
        ld      a,(player_y)
        sub     (hl)                   ;I'm guessing this is the enemy Y
        ret     c
        srl     a
        srl     a
        ld      b,a                     ; B = (PY - EY)
        srl     a
        add     a,b
        ret     z
        ld      b,a                     ; B = (3/8) * (PY - EY)
        dec     hl
        dec     hl
        ld      a,(player_x)
        sub     (hl)                    ; A = PX - EX
        inc     hl
        inc     hl
        jr      c,fire_big_left
        call    get_angle
        ld      a,c
        
deploy_big:
        ld      bc,(which_shot)
        bit     7,c
        jr      nz,deploy_huge
        add     a,27
        ld      de,big_ebullet_data
        ld      (de),a
        jr      fire_enemy_bullet

get_angle:
        ld      c,0
        sub     b
        ret     c                       ; DX < (3/8) DY -> straight down
        inc     c
        sub     b
        ret     c                       ; DX < (3/4) DY -> slight angle
        inc     c
        sub     b
        ret     c                       ; DX < (3/2) DY -> 45 deg angle
        sub     b
        ret     c
        inc     c                       ; DX > (3/2) DY -> high angle
        ret


can anyone, maybe even patrick davidson himself, explain this to me?

>
>i think the most simple way to do it would be like this:
>
> l = distense between the two points ( ==  sqrt( (enemy_x-player_x)^2 +
>(enemy_y-player_y)^2) ), devided by the speed ( == 3 for 3 pixels per
>frame )
> dx = (enemy_x-player_x) / l
> dy = (enemy_y-player_y) / l
>
>then when you want to let your bullet travel, let is start at (player_x,
>player_y), and add (dx,dy) to that point every frame...
>
>you could use some fixed-point values to speed up a bit... i'm not sure if
>it is posible to use a look-up-table for the SRQT thing...
>
>---
>
>an other way to do it, would be to use sin/cos/tan calculations...
>
>angle = arctan( (y2-y1)/(x2-x1) )
>dx = 3 * sin(angle)
>dy = 3 * cos(angle)
>
>the sin and cos can be calculated with a single lookuptable ( cos(a) ==
>sin(a + .5 Pi) ), using fixed-point values..
>
>> -----Oorspronkelijk bericht-----
>> Van: assembly-83-bounce@lists.ticalc.org
>> [mailto:assembly-83-bounce@lists.ticalc.org]Namens Joe Pemberton
>> Verzonden: Thursday, September 20, 2001 14:55
>> Aan: assembly-83@lists.ticalc.org
>> Onderwerp: [A83] Angles
>>
>>
>>
>> How would I determine the angle needed for an enemy bullet fired from
>> (enemy_x), (enemy_y) so it would hit the player (player_x),
>> (player_y) at a
>> constant speed of 3 pixels per frame?  I saw the routine in Pheonix that
>> did this but I can't understand it.  help?..
>>
>> _____________________________________________
>> Free email with personality! Over 200 domains!
>> http://www.MyOwnEmail.com
>>
>>
>>
>
>
>
>

_____________________________________________
Free email with personality! Over 200 domains!
http://www.MyOwnEmail.com