Angle Collisions
#7
It's a problem with your numbers exceeding type limits. The variable bang never gets lowered, it only goes higher until it errors out.

For fun, I reset the variable to zero, to make a race track simulation...

Code: (Select All)
DIM bv AS _INTEGER64
'caveball
ms& = _NEWIMAGE(800, 600, 32)
border& = _NEWIMAGE(800, 600, 32)
RANDOMIZE TIMER
DIM c1 AS LONG
DIM klr AS _UNSIGNED LONG
DIM empty AS _UNSIGNED LONG
SCREEN border&
c1 = _RGB(255, 255, 255)
x1 = 50
y1 = 50
flag = 0
WHILE flag = 0
    x2 = (RND * 80) + 80 + x1
    IF x2 > 750 THEN
        x2 = 750
        flag = 1
    END IF
    y2 = RND * 60 + 20
    fatline x1, y1, x2, y2, 2, c1
    x1 = x2
    y1 = y2
WEND

flag = 0
WHILE flag = 0
    y2 = (RND * 80) + 80 + y1
    IF y2 > 550 THEN
        y2 = 550
        flag = 1
    END IF
    x2 = 750 - (RND * 60 + 20)
    fatline x1, y1, x2, y2, 2, c1
    x1 = x2
    y1 = y2
WEND

flag = 0
WHILE flag = 0
    x2 = x1 - ((RND * 80) + 80)
    IF x2 < 50 THEN
        x2 = 50
        flag = 1
    END IF
    y2 = 550 - (RND * 60 + 20)
    fatline x1, y1, x2, y2, 2, c1
    x1 = x2
    y1 = y2
WEND

flag = 0
WHILE flag = 0
    y2 = y1 - ((RND * 80) + 80)
    IF y2 < 50 THEN
        y2 = 50
        flag = 1
    END IF
    x2 = RND * 60 + 20
    IF flag = 1 THEN x2 = 50
    fatline x1, y1, x2, y2, 2, c1
    x1 = x2
    y1 = y2
WEND
bx = 400
by = 400
speed = 2
SCREEN ms&

bang = 11
DO
    _LIMIT 60
    CLS
    LOCATE 1, 1: PRINT bx; by; bv; "    ";
    _PUTIMAGE , border&, ms&
    bang = bang + bm
    bx = bx + speed * COS(0.01745329 * bang)
    by = by + speed * SIN(0.01745329 * bang)
    bm = 0
    FOR bv = bang - 120 TO bang + 120 STEP 10
        checkx = bx + (12 * bang / bv) * COS(0.01745329 * bv)
        checky = by + (12 * bang / bv) * SIN(0.01745329 * bv)
        klr = POINT(checkx, checky)

        IF klr = c1 AND bm = 0 THEN
            bm = bm + bv
        END IF
    NEXT
    bang = 0 ' JUST FOR FUR RACE TRACK EFFECT...

    CIRCLE (bx, by), 10, c1
    _DISPLAY
    kk$ = INKEY$

LOOP UNTIL kk$ = CHR$(27)


SUB circleBF (cx AS LONG, cy AS LONG, r AS LONG, klr AS _UNSIGNED LONG)
    rsqrd = r * r
    y = -r
    WHILE y <= r
        x = SQR(rsqrd - y * y)
        LINE (cx - x, cy + y)-(cx + x, cy + y), klr, BF
        y = y + 1
    WEND
END SUB

SUB fatline (x0, y0, x1, y1, r, klr AS _UNSIGNED LONG)
    IF ABS(y1 - y0) < ABS(x1 - x0) THEN
        IF x0 > x1 THEN
            lineLow x1, y1, x0, y0, r, klr

        ELSE
            lineLow x0, y0, x1, y1, r, klr
        END IF
    ELSE
        IF y0 > y1 THEN
            lineHigh x1, y1, x0, y0, r, klr
        ELSE
            lineHigh x0, y0, x1, y1, r, klr
        END IF
    END IF
END SUB
SUB lineLow (x0, y0, x1, y1, r, klr AS _UNSIGNED LONG)
    dx = x1 - x0
    dy = y1 - y0
    yi = 1
    IF dy < 0 THEN
        yi = -1
        dy = -dy
    END IF
    'D = (2 * dy) - dx
    d = (dy + dy) - dx
    y = y0
    FOR x = x0 TO x1
        circleBF x, y, r, klr

        IF d > 0 THEN
            y = y + yi
            ' D = D + (2 * (dy - dx))
            d = d + ((dy - dx) + (dy - dx))
        ELSE
            ' D = D + 2 * dy
            d = d + dy + dy
        END IF
    NEXT x
END SUB
SUB lineHigh (x0, y0, x1, y1, r, klr AS _UNSIGNED LONG)
    dx = x1 - x0
    dy = y1 - y0
    xi = 1
    IF dx < 0 THEN
        xi = -1
        dx = -dx
    END IF
    ' D = (2 * dx) - dy
    D = (dx + dx) - dy
    x = x0
    FOR y = y0 TO y1
        circleBF x, y, r, klr

        IF D > 0 THEN
            x = x + xi
            ' D = D + (2 * (dx - dy))
            D = D + ((dx - dy) + (dx - dy))
        ELSE
            ' D = D + 2 * dx
            D = D + dx + dx
        END IF
    NEXT y
END SUB

Jut get rid of my bang = 0 ' JUST FOR FUR RACE TRACK EFFECT... and watch the counter I put in. When it errors, it displays a bogus scientific number notation, and the ball freezes.

I hope that is of some help.

Pete
If eggs are brain food, Biden takes his scrambled.
Reply


Messages In This Thread
Angle Collisions - by james2464 - 10-15-2022, 01:39 AM
RE: Angle Collisions - by bplus - 10-15-2022, 02:16 AM
RE: Angle Collisions - by james2464 - 10-15-2022, 04:01 AM
RE: Angle Collisions - by James D Jarvis - 10-15-2022, 10:39 PM
RE: Angle Collisions - by Pete - 10-15-2022, 10:46 PM
RE: Angle Collisions - by James D Jarvis - 10-15-2022, 11:24 PM
RE: Angle Collisions - by james2464 - 10-16-2022, 12:17 AM
RE: Angle Collisions - by OldMoses - 10-16-2022, 01:14 PM
RE: Angle Collisions - by james2464 - 10-16-2022, 07:11 PM
RE: Angle Collisions - by OldMoses - 10-18-2022, 08:20 PM
RE: Angle Collisions - by james2464 - 10-18-2022, 10:47 PM
RE: Angle Collisions - by OldMoses - 10-19-2022, 12:23 AM
RE: Angle Collisions - by Pete - 10-16-2022, 12:13 AM
RE: Angle Collisions - by Pete - 10-16-2022, 12:50 AM
RE: Angle Collisions - by bplus - 10-16-2022, 01:01 PM
RE: Angle Collisions - by bplus - 10-16-2022, 01:27 PM
RE: Angle Collisions - by OldMoses - 10-16-2022, 04:02 PM
RE: Angle Collisions - by bplus - 10-16-2022, 06:46 PM
RE: Angle Collisions - by bplus - 10-16-2022, 07:45 PM
RE: Angle Collisions - by james2464 - 10-16-2022, 08:04 PM
RE: Angle Collisions - by James D Jarvis - 10-16-2022, 08:07 PM
RE: Angle Collisions - by bplus - 10-16-2022, 08:47 PM
RE: Angle Collisions - by James D Jarvis - 10-16-2022, 08:55 PM
RE: Angle Collisions - by bplus - 10-17-2022, 10:07 AM
RE: Angle Collisions - by bplus - 10-17-2022, 12:26 PM
RE: Angle Collisions - by OldMoses - 10-17-2022, 12:58 PM
RE: Angle Collisions - by bplus - 10-17-2022, 01:11 PM
RE: Angle Collisions - by james2464 - 10-17-2022, 01:57 PM
RE: Angle Collisions - by OldMoses - 10-17-2022, 02:19 PM
RE: Angle Collisions - by bplus - 10-17-2022, 02:49 PM
RE: Angle Collisions - by james2464 - 10-17-2022, 03:46 PM
RE: Angle Collisions - by bplus - 10-17-2022, 04:53 PM
RE: Angle Collisions - by james2464 - 10-17-2022, 05:27 PM
RE: Angle Collisions - by Dav - 10-18-2022, 02:22 AM
RE: Angle Collisions - by james2464 - 10-18-2022, 03:25 AM
RE: Angle Collisions - by Pete - 10-17-2022, 04:10 PM
RE: Angle Collisions - by bplus - 10-17-2022, 04:55 PM
RE: Angle Collisions - by james2464 - 10-17-2022, 05:23 PM
RE: Angle Collisions - by james2464 - 10-18-2022, 02:00 AM
RE: Angle Collisions - by Pete - 10-18-2022, 02:10 AM
RE: Angle Collisions - by Pete - 10-18-2022, 03:20 AM
RE: Angle Collisions - by james2464 - 10-18-2022, 03:57 AM
RE: Angle Collisions - by bplus - 10-18-2022, 03:27 PM
RE: Angle Collisions - by james2464 - 10-18-2022, 04:11 PM
RE: Angle Collisions - by bplus - 10-18-2022, 08:27 PM
RE: Angle Collisions - by Pete - 10-18-2022, 08:44 PM
RE: Angle Collisions - by bplus - 10-18-2022, 10:10 PM
RE: Angle Collisions - by Pete - 10-18-2022, 10:19 PM
RE: Angle Collisions - by james2464 - 10-20-2022, 12:30 AM
RE: Angle Collisions - by bplus - 10-20-2022, 02:36 AM
RE: Angle Collisions - by james2464 - 10-20-2022, 01:51 PM
RE: Angle Collisions - by Pete - 10-20-2022, 03:48 AM
RE: Angle Collisions - by bplus - 10-20-2022, 02:52 PM
RE: Angle Collisions - by james2464 - 10-20-2022, 04:21 PM
RE: Angle Collisions - by bplus - 10-20-2022, 04:37 PM
RE: Angle Collisions - by james2464 - 10-21-2022, 07:10 PM
RE: Angle Collisions - by Pete - 10-21-2022, 07:20 PM
RE: Angle Collisions - by bplus - 10-21-2022, 09:05 PM
RE: Angle Collisions - by OldMoses - 10-22-2022, 12:09 AM
RE: Angle Collisions - by james2464 - 10-22-2022, 10:29 PM
RE: Angle Collisions - by bplus - 10-22-2022, 10:59 PM
RE: Angle Collisions - by justsomeguy - 10-22-2022, 11:45 PM
RE: Angle Collisions - by Pete - 10-23-2022, 12:37 AM
RE: Angle Collisions - by OldMoses - 10-23-2022, 12:46 AM
RE: Angle Collisions - by james2464 - 10-24-2022, 04:57 PM
RE: Angle Collisions - by james2464 - 10-24-2022, 11:14 PM
RE: Angle Collisions - by bplus - 10-25-2022, 12:37 AM
RE: Angle Collisions - by james2464 - 10-25-2022, 03:25 AM
RE: Angle Collisions - by OldMoses - 10-25-2022, 10:47 PM
RE: Angle Collisions - by james2464 - 10-25-2022, 10:52 PM
RE: Angle Collisions - by OldMoses - 10-26-2022, 03:39 AM
RE: Angle Collisions - by james2464 - 10-26-2022, 03:51 PM
RE: Angle Collisions - by OldMoses - 10-26-2022, 04:18 PM
RE: Angle Collisions - by james2464 - 10-26-2022, 08:41 PM
RE: Angle Collisions - by OldMoses - 10-27-2022, 12:33 AM
RE: Angle Collisions - by james2464 - 10-27-2022, 03:36 PM
RE: Angle Collisions - by OldMoses - 10-29-2022, 12:05 AM
RE: Angle Collisions - by james2464 - 10-29-2022, 01:45 AM
RE: Angle Collisions - by james2464 - 10-30-2022, 04:41 PM
RE: Angle Collisions - by bplus - 10-30-2022, 06:16 PM
RE: Angle Collisions - by james2464 - 10-30-2022, 06:25 PM
RE: Angle Collisions - by bplus - 10-30-2022, 06:31 PM
RE: Angle Collisions - by james2464 - 10-30-2022, 06:37 PM
RE: Angle Collisions - by bplus - 10-30-2022, 06:45 PM
RE: Angle Collisions - by james2464 - 10-31-2022, 01:27 AM
RE: Angle Collisions - by bplus - 10-31-2022, 01:52 AM
RE: Angle Collisions - by TempodiBasic - 11-01-2022, 02:38 AM
RE: Angle Collisions - by bplus - 11-01-2022, 11:31 AM
RE: Angle Collisions - by james2464 - 11-01-2022, 04:15 PM
RE: Angle Collisions - by triggered - 11-01-2022, 03:03 AM
RE: Angle Collisions - by james2464 - 11-03-2022, 06:53 PM
RE: Angle Collisions - by OldMoses - 11-04-2022, 12:56 AM



Users browsing this thread: 16 Guest(s)