• 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

Object lists? Tlist ?

oddchild

New member
Joined
Jul 18, 2017
Messages
24
Hi Everyone,

I haven't been programming in a few years. I used to use Blitzmax, but was wanting to do something with Cerberus...

In Blitz there was a kind of a list called Tlist I could load my objects up into it, then call the list later and draw the images that way. I could also sort that list.

Code:
Global EntityList:TList = New TList
Global sorter:TList = New TList


Type dudes
    Field x:Float
    Field y:Float
    Field kind            ' is he a cop or a normal guy
    Field img                            'load up the dudes
    Field direction    'which way is he going
    Field speed    'how fast
    Field frame            'frame of animation
    Field hp
Method New()
    EntityList.AddLast(Self) 
    totaldudes = totaldudes + 1
End Method
 
End Type

This would add the guys to the list when ever the dudes type was made. I understand that Type in Monkey / CErberus is Class. But even with changing that I cannot figure out.

In Blitz I could just run this, and make 40 sprites easy.

Code:
For Local number = 0 To 40

    guys:dudes = New dudes
    guys.kind = Rand (1,6)

....

but if I try that same kind of code it isnt working.

Code:
For guys:dudes = EachIn Entitylist
DrawImage guys.img, guys.x  + mapx ,guys.y + mapy,guys.frame

Next

What kind of list do I need to use for objects???


Thanks!!!
 
Last edited by a moderator:
It is possible, but you need to create a list for dudes objects.

Code:
Global dudeList:List<dudes>

dudeList = New List<dudes>

If I find some time I can write a working example for that. It's something that seems to be missing in the docs.
 
Thanks for the help, I will try this out. I was looking for hours and couldnt figure it out on my own.
 
For guys = EachIn dudeList



DrawImage guys.img ,guys.x ,guys.y,0,2,2,guys.frame







DrawText guys.direction, guys.x, guys.y



Next





Still not showing up... :( seems like it is closer to working though.
 
I got it to work.



For guys = EachIn dudeList



If guys.x < 575 And guys.y < 420 Then DrawImage guys.img ,guys.x ,guys.y,0,2,2,guys.frame


Next

I ended up having to write this clause in to make it run faster?

Anywho, thanks again!
 
Here is a basic example for something like this. Just in case someone else has this problem.
BTW I move this post into the beginners section, if you don't mind.

Code:
Strict
 
Import mojo


Global dudeList:List<Dude>


Function Main:Int()
    New Game()
    Return 0
End


Class Game Extends App

    Method OnCreate:Int()
    
        dudeList = New List<Dude>
        
        For Local i:Int=0 Until 40
            Local d:Dude = New Dude()
            d.x = Rnd(100, 300)
            d.y = Rnd(100, 300)
        Next
        
        Return 0
    End
    
    
    Method OnUpdate:Int()
        
        'Get them moving somehow.
        For Local d:Dude = Eachin dudeList
            d.x += -1 + Rnd(2)
            d.y += -1 + Rnd(2)
        Next
    
        
        
        Return 0
    End
    
    
    Method OnRender:Int()
        
        Cls()
        
        For Local d:Dude = Eachin dudeList
            DrawCircle(d.x, d.y, 10)
        Next
        
        Return 0
    End
    
End


Class Dude

    Field x:Float
    Field y:Float


    Method New()
        dudeList.AddLast(Self)
    End

End
 
Unlike BlitzMax's New method. The New method in Cerberus can take parameters and be overloaded.
 
Back
Top Bottom