I've been following Wave's Beginners guide to BlitzMax - mainly on using types, functions and methods as I've always had problems getting my head round those and I've not done any programming for a long while now.
Anyway, I put this together as I fancied creating a little gambling game with dog racing, betting, odds and so on and wanted to see something moving so I could get an idea on simulating the actual races. It works ok but I'm after some of you experts to have a look over it and see if I'm doing anything sloppy specifically with the way the random number is used to increase a dogs speed of movement.
I don't think I've really got my head around types totally yet although doing this has helped massively so I'd appreciate any suggestions or advice.
Thanks.
Anyway, I put this together as I fancied creating a little gambling game with dog racing, betting, odds and so on and wanted to see something moving so I could get an idea on simulating the actual races. It works ok but I'm after some of you experts to have a look over it and see if I'm doing anything sloppy specifically with the way the random number is used to increase a dogs speed of movement.
I don't think I've really got my head around types totally yet although doing this has helped massively so I'd appreciate any suggestions or advice.
Thanks.
' ** Dog racing by Tony Black - 29/6/08 ' ** Created as an example to learn the use of functions, types and methods. ' Strict Global YPos:Int Global N:Int Global List:TList ' Keeps the dogs inside Dogtype Global Finished:Byte = False Global Winner:String Type DogType Field X:Int Field Y:Int Field Speed:Int Field Name:String Field Colour:Int Method Draw() ' Display the dog on screen. DrawOval (X , Y ,50 , 25) End Method Method Move() ' Move dog according to Speed along its X axis Speed=Rand(1,5) X:+ Speed 'DrawText Name+" "+Colour+" "+X+" "+Y+" "+Speed,0,30 If X > 760 Finished = True Winner=Name EndIf End Method Method Reset() ' Reset the dogs starting positions for new race Speed = 1 X = 100 End Method Function Create() Local NewDog:DogType ' declares a variable to store our Dogs type. NewDog = New DogType ' puts the address of the new Dog into the variable NewDog NewDog.X = 100 ; NewDog.Y = YPos ' Sets the start position of the Dog on screen. ' YPos is global so it can have the dogs on different start positions down the screen ' by incrementing 20 each time a dog is created or they'd all be in the same spot on screen. ' Let's name the puppies. I couldn't work out how to run through a the type and ammend the ' type.name field so had to name them on creation of each dog using the following method which ' is a bit scrappy. N is the counter for/next loop calling the creation function for each dog. If N = 1 NewDog.Name = "Patch" NewDog.Colour = 20 EndIf If N = 2 NewDog.Name = "Fido" NewDog.Colour = 40 EndIf If N = 3 NewDog.Name = "Sparky" NewDog.Colour = 60 EndIf If N = 4 NewDog.Name = "Rex" NewDog.Colour = 80 EndIf If N = 5 NewDog.Name = "Blue" NewDog.Colour = 100 EndIf If N = 6 NewDog.Name = "Buddy" NewDog.Colour=150 EndIf If N = 7 NewDog.Name = "Lassie" NewDog.Colour = 200 EndIf If N = 8 NewDog.Name = "Mutley" NewDog.Colour = 250 EndIf If Not List Then List = CreateList() List.AddLast (NewDog) ' Puts the new dog into our dogs list. End Function End Type Graphics 800 , 600 Global DogList:TList = CreateList() ' Create a list to store all Dogs ' Create the dogs. For N = 1 To 8 ' Fixed number of dogs as they are all named. YPos=100+N*40 DogType.Create() Next While Not KeyHit(Key_Escape) Flip ; Cls DrawText "Press Esc to Exit...." , 0 , 0 YPos=140 For Local Dog:DogType = EachIn List Dog.Draw() Dog.Move() SetColor 255,100,Dog.Colour DrawText Dog.Name , 0 , YPos YPos:+ 40 Next If Finished=True SetColor 255,255,200 DrawText "The Winner: "+Winner+" ... Press Space to Restart.",0,500 Flip Repeat Until KeyHit(Key_Space) Finished = False For Local Dog:DogType = EachIn List Dog.Reset() Next EndIf Wend