Object lists? Tlist ?

oddchild

New member
Joined
Jul 18, 2017
Messages
14
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:

Phil7

Administrator
CX Code Contributor
3rd Party Tool Dev
Joined
Jun 26, 2017
Messages
557
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.
 

oddchild

New member
Joined
Jul 18, 2017
Messages
14
Thanks for the help, I will try this out. I was looking for hours and couldnt figure it out on my own.
 

oddchild

New member
Joined
Jul 18, 2017
Messages
14
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.
 

oddchild

New member
Joined
Jul 18, 2017
Messages
14
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!
 

Phil7

Administrator
CX Code Contributor
3rd Party Tool Dev
Joined
Jun 26, 2017
Messages
557
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
 

dawlane

Well-known member
CX Code Contributor
Joined
Jun 21, 2017
Messages
806
Unlike BlitzMax's New method. The New method in Cerberus can take parameters and be overloaded.
 
Top Bottom