cb-hackers / cbEnchanted

A new runtime for CoolBasic
13 stars 3 forks source link

Laatikko-laatikko törmäys bugaa, kun objektit ovat erikokoisia #126

Closed valscion closed 12 years ago

valscion commented 12 years ago
FrameLimit 40

'load player 
guy=LoadObject("Media\guy.bmp",72)
PositionObject guy,0, -40

car=LoadObject("Media\car.bmp",72)
PositionObject car, -100, -40

'setup a box-box sliding collision to the car 
SetupCollision guy,car,1,1,2

w1 = ObjectSizeX(guy)
h1 = ObjectSizeY(guy)

w2 = ObjectSizeX(car)
h2 = ObjectSizeY(car)

DrawToWorld ON
Repeat

    'Controls
    If LeftKey() Then TurnObject guy,5
    If RightKey() Then TurnObject guy, -5
    If UpKey() Then MoveObject guy,3
    If DownKey() Then MoveObject guy, -3

    'camera follow
    UpdateGame
    CloneCameraPosition guy

    DrawGame

    Box ObjectX(guy) - w1 / 2, ObjectY(guy) + h1 / 2, w1, h1, OFF
    Box ObjectX(car) - w2 / 2, ObjectY(car) + h2 / 2, w2, h2, OFF

    DrawScreen

Until EscapeKey()

Mielenkiintoista huomata, ettei tuo toimi CB:lläkään oikein.

aXu-AP commented 12 years ago

Kesti hieman aikaa tajuta mitä tuossa esimerkissä tapahtui, katsoin että ukko pysyy paikoillaan ja auto liikkuu ennen kuin tajusin kameran seuraavan ukkoa :D Aika erikoinen bugi tosiaan.

Tässä jännä havainto, joka voi olla hyödyksi: kaksi erikokoista laatikkoa törmäävät toisiinsa samalla tavoin kuin kaksi laatikkoa, joiden leveys ja korkeus ovat edellisten laatikoiden keskiarvot. Havainnollistus sekavaan selitykseen:

alku:
w1 = Rand(30, 200)
h1 = Rand(30, 200)
w2 = Rand(30, 200)
h2 = Rand(30, 200)
ws = (w1 + w2) / 2
hs = (h1 + h2) / 2
Repeat
    Color 255, 128, 0
    Box 200 - w1/2, 150 - h1/2, w1, h1, 1
    Color 255, 255, 0
    Box MouseX() - w2/2, MouseY() - h2/2, w2, h2, 1

    If BoxOverlap(200 - ws/2, 150 - hs/2, ws, hs, MouseX() - ws/2, MouseY() - hs/2, ws, hs) Then
        Color 192, 0, 0
    Else
        Color 128, 128, 128
    EndIf
    Box 200 - ws/2, 150 - hs/2, ws, hs, 0
    Box MouseX() - ws/2, MouseY() - hs/2, ws, hs, 0

    DrawScreen
    If KeyHit(cbkeyspace) Then Goto alku
Forever

EDIT: Tuo esimerkkikin toimii oikein kun lisää:

ObjectRange guy, (88 + 32) / 2, (48 + 32) / 2
ObjectRange car, (88 + 32) / 2, (48 + 32) / 2

Tietenkin tuo sekoittaisi törmäykset kaikkiin muihin objekteihin, mutta käsittänet idean.