• Dear Cerberus X User!

    As we prepare to transition the forum ownership from Mike to Phil (TripleHead GmbH), we need your explicit consent to transfer your user data in accordance with our amended Terms and Rules in order to be compliant with data protection laws.

    Important: If you accept the amended Terms and Rules, you agree to the transfer of your user data to the future forum owner!

    Please read the new Terms and Rules below, check the box to agree, and click "Accept" to continue enjoying your Cerberus X Forum experience. The deadline for consent is April 5, 2024.

    Do not accept the amended Terms and Rules if you do not wish your personal data to be transferred to the future forum owner!

    Accepting ensures:

    - Continued access to your account with a short break for the actual transfer.

    - Retention of your data under the same terms.

    Without consent:

    - You don't have further access to your forum user account.

    - Your account and personal data will be deleted after April 5, 2024.

    - Public posts remain, but usernames indicating real identity will be anonymized. If you disagree with a fictitious name you have the option to contact us so we can find a name that is acceptable to you.

    We hope to keep you in our community and see you on the forum soon!

    All the best

    Your Cerberus X Team

DevLog Testing: Path finding module by Rich

mag

Active member
3rd Party Module Dev
3rd Party Tool Dev
Joined
Mar 5, 2018
Messages
261
I'm testing path finding module by @Rich

649


This is a good module and fast. The module post is here : https://www.cerberus-x.com/community/threads/path-finding-class.787/#post-6214

The code for the above testing game is here:
Code:
Import mojo
Import paths
Function Main:Int();New myClass;Return 0;End
Class myClass Extends App
    Field p:Path
    Field map:Int[]
    Const gameGridX:Int=50
    Const gameGridY:Int=50
    Field hero:Int
    Field enermy:Int[]
    Const enermyAmount:Int=10
    Field target:Int=-1
    Field moveTimer:Int
    Const MOVE_SPEED:Int=100
    Method OnCreate:Int()
        p = New Path()
        'resize map
        map = map.Resize(gameGridX*gameGridY)
        'put item into map
        For Local x:Int=0 Until gameGridX
            For Local y:Int=0 Until gameGridY
                If Rnd(10)<8
                    map[x+(y*gameGridX)]=0 '0=nothing
                Else
                    map[x+(y*gameGridX)]=1 '1=tree
                endif
            Next
        next
        'put hero on map
        Local newPlace:Int
        Repeat
            newPlace=Int(Rnd(gameGridX*gameGridY))
        Until map[newPlace]=0
         hero=newPlace
        'put enermy on map
        enermy=enermy.Resize(enermyAmount)
        For Local k:Int=0 Until enermyAmount
            Local newPlace:Int
            Repeat
                newPlace=Int(Rnd(gameGridX*gameGridY))
            Until map[newPlace]=0
            enermy[k]=newPlace
        next
        'reset moving timer
        moveTimer=Millisecs()
       Return 0
    End
    Method OnUpdate:Int()
        If MouseHit(0)
            target=Int(Int(MouseX()/8)+(Int(MouseY()/6)*gameGridX))
            If map[target]<>0 Then
                target=-1 'cannot go
            Else
                p.GetRoute(hero,target,map,gameGridX,gameGridY, 0, true)
            endif
        endif
        If Millisecs()-moveTimer>MOVE_SPEED
            moveTimer=Millisecs()
            'move the hero
            If target<>-1   
                p.GetRoute(hero,target,map,gameGridX,gameGridY, 0, true)
                If p.Route.Length()>1 Then
                    hero=p.Route[p.Route.Length()-2]
                endif
            endif
            'move the enermy
            For Local k:Int=0 Until enermyAmount
                If Rnd(10)<4 'make less effective
                    p.GetRoute(enermy[k],hero,map,gameGridX,gameGridY, 0, true)
                    If p.Route.Length()>1 Then
                        enermy[k]=p.Route[p.Route.Length()-2]
                    endif
                endif
            Next
        endif
        Return 0
    End
    
    Method OnRender:Int()
        Cls 0,0,0
        'render the map
        For Local x:Int=0 Until gameGridX
            For Local y:Int=0 Until gameGridY
                Select map[x+(y*gameGridX)]
                Case 0
                    'nothing
                    SetColor(0,255,125)
                    DrawPoint((x*8)+4,(y*6)+3)
                Case 1
                    'tree
                    SetColor(0,255,0)
                    DrawCircle((x*8)+4,(y*6)+3,4)
                end
            Next
        next
        'render hero
        SetColor(255,255,255)
        Local x:Int=hero Mod gameGridX
        Local y:Int=hero / gameGridX
        DrawCircle((x*8)+4,(y*6)+3,4)
        DrawText("hero",(x*8)+10,(y*6)+10)
        'render target
        If target<>-1
            SetColor(255,255,255)
            Local x:Int=target Mod gameGridX
            Local y:Int=target / gameGridX
            DrawRect((x*8)+4,(y*6)-3,1,12)
            DrawRect((x*8)-4,(y*6)+3,16,1)
        endif
        'render enermy
        For Local k:Int=0 Until enermyAmount
            SetColor(255,0,0)
            Local x:Int=enermy[k] Mod gameGridX
            Local y:Int=enermy[k] / gameGridX
            DrawCircle((x*8)+4,(y*6)+3,4)
        next
        'general info
        SetColor(255,255,255)
        DrawText("Click to move a hero",0,0)
        Return 0
    End
End
 
I really like that test / example
 
Hello,
I have executed the example that was shared. My doubt, this is how it should be seen? The example does not stretch and occupies the entire screen. Maybe it's my system's error?
Thanks for sharing!
R.-

PS: If I set the hero outside the grid, the example stops with an error.

650
 
Last edited:
Nothing wrong with your system.

Actually, the test code didn't factor that issue :p (because there is no one screen size in CerberusX :cool: )

The solution; Probably try increase the grid to 100x100.

gameGridX=100
gameGridY=100
 
Haa! Okay, I just wanted to be sure. Thanks for the example.
I hope to have some time to study CerberusX soon.
All the examples that I find will help me a lot.
R.-
 
Back
Top Bottom