Mutant Turmite Attack
BlitzMax Forums/BlitzMax Beginners Area/Mutant Turmite Attack
| ||
| I decided to use Turmites to learn a bit about Bmax, have Bmax since the beginning but have never realy got down to using it. So Turmites seemed a good idea to understand the basics. TURMITES: A simple Two-State infinite Turing Machine. Rules are very simple, it checks the pixel it's on and if painted it turns right and advances; if not painted it turns left and advances; it also changes the pixel when leaving. You can find more information about Turmites in the Web. WORLD: a 640x480 wrapped_around world CODING: No real problems here once I sorted out the "nasty" syntax ( a better manual would be nice) But scavenging samples and these great forums I sorted myself out. The lack of being able to read a pixel from the screen buffer made me use an array, no real problem here but I would realy like a command to this effect(please Mark). Overall it has been a pleasant experience. Next couple of days I have off-work I'll try and code some simple game. Here is the code for those that might like to have a look at Turmites, feel free to modify what you like. And excuse my non-standard style.
SetGraphicsDriver GLMax2DDriver()
Global number_of_turmites=20
Global map[640,480]
Global largo=Rand(10,120)
Global tictac
Global info
'**********************************************************************
'Here I define the basic turmite
'**********************************************************************
Type mite
Field x,y
Field rojo,verde,azul
Field dir,stat
Global lista:TList
Method actua()
If map[x,y] = 1
SetColor(0,0,0)
Plot(x,y)
map[x,y]=0
dir=dir+1
If dir>3
dir=0
EndIf
Else
SetColor(rojo,verde,azul)
Plot(x,y)
map[x,y]=1
dir=dir-1
If dir<0
dir=3
EndIf
EndIf
Select dir
Case 0
y=y-1
If y<0
y=479
EndIf
Case 1
x=x+1
If x>639
x=0
EndIf
Case 2
y=y+1
If y>479
y=0
EndIf
Case 3
x=x-1
If x<0
x=639
EndIf
End Select
End Method
Function create()
If lista = Null lista = CreateList()
socas:mite = New mite
socas.x = Rand(0,639) ; socas.y = Rand(0,479)
socas.rojo = Rand(50,255) ; socas.verde = Rand(50,255) ; socas.azul = Rand(50,255)
socas.dir=Rand(0,3)
lista.addlast(socas)
'socas.link=dadas.AddLast(socas)
'unomas=unomas+1
End Function
End Type
For n=1 To number_of_turmites
mite.create()
Next
Graphics 640,480,32
HideMouse()
timer=CreateTimer(1)
Repeat
'Cls
For n= 1 To 100
For t:mite = EachIn mite.lista
t.actua()
Next
Next
If info=1
SetColor(0,0,0)
DrawRect(20,20,40,40)
SetColor(255,255,0)
DrawText largo,23,22
DrawText tictac,23,42
EndIf
Flip
If KeyHit(key_space)
For mapy=0 To 479
For mapx=0 To 639
map[mapx,mapy]=0
Next
Next
ClearList(mite.lista)
number_of_turmites=Rand(2,20)
For n=1 To number_of_turmites
mite.create()
Next
Cls
StopTimer(timer)
timer=CreateTimer(1)
largo=Rand(10,120)
EndIf
tictac=TimerTicks(timer)
If tictac > largo
For mapy=0 To 479
For mapx=0 To 639
map[mapx,mapy]=0
Next
Next
ClearList(mite.lista)
number_of_turmites=Rand(2,20)
For n=1 To number_of_turmites
mite.create()
Next
Cls
StopTimer(timer)
timer=CreateTimer(1)
largo=Rand(10,120)
EndIf
If KeyHit(key_f1)
Select info
Case 0
info=1
Case 1
info=0
End Select
EndIf
Until KeyHit(key_escape) Or AppTerminate()
|