Code:
@name Langtons Ant - [TalkingGoose]
@persist N Direction X Y MultX PNum Printed
@persist [Yellow,Black,Red,Green,Blue]:vector [Grid,AllProps]:array
interval(100)
if(first())
{
###INITIALIZATION###
print("Langtons Ant - Made by TalkingGoose")
print("Langtons Ant will Take 35 seconds to load.")
print("Please wait...")
#Create grid and posistions
for(X=1,10)
{
for(Y=1,10)
{
N++
Grid[N,vector2]=vec2(X,Y)
}
}
#Setup colors
Yellow = vec(255,255,0)
Black = vec(0,0,0)
Red = vec(255,0,0)
Green = vec(0,255,0)
Blue = vec(0,0,255)
#Stop spawn effect
propSpawnEffect(0)
#Set starting position and direction
X = 5
Y = 5
Direction=1
#Create 'Ant'
holoCreate(0)
holoScaleUnits(0,vec(1,1,5))
holoColor(0,Black)
#Setup ready for prop spawning
timer("NextProp",350)
N=0
Printed=0
runOnLast(1)
####################
}
###PROP DELETION###
if(last())
{
for(N=1,100)
{
AllProps[N,entity]:propDelete()
}
}
###################
###PROP SPAWNING###
#Check if timer allows prop to spawn
if(clk("NextProp"))
{
#Time until next execution
timer("NextProp",350)
#Continue until all props have spawned
if(N!=100)
{
N++
#Set attributes of prop and add to array
Prop = propSpawn("models/hunter/plates/plate.mdl",entity():pos()+vec(0,0,30)+(vec(Grid[N,vector2])*3),ang(0,0,0),1)
Prop:setColor(Blue)
AllProps:pushEntity(Prop)
}
elseif(!Printed)
{
print("All "+AllProps:count()+" now spawned. Continuing with main code.")
Printed=1
}
}
###################
###Don't execute main code unless all props are spawned###
if(AllProps:count()==100)
{
###BOUNDRIES###
if(X>=11)
{
X = 1
}
if(X<=0)
{
X = 10
}
if(Y>=11)
{
Y = 1
}
if(Y<=0)
{
Y = 10
}
###############
###MOVE DIRECTION###
if(AllProps[PNum,entity]:getColor()==Blue)
{
#Color current prop
AllProps[PNum,entity]:setColor(Green)
#Move to next prop depending on direction
if(Direction==1)
{
X+=1
}
if(Direction==2)
{
Y-=1
}
if(Direction==3)
{
X-=1
}
if(Direction==4)
{
Y+=1
}
Direction+=1
}
elseif(AllProps[PNum,entity]:getColor()==Green)
{
#Color current prop
AllProps[PNum,entity]:setColor(Blue)
#Move to next prop depending on direction
if(Direction==1)
{
X-=1
}
if(Direction==2)
{
Y+=1
}
if(Direction==3)
{
X+=1
}
if(Direction==4)
{
Y-=1
}
Direction-=1
}
#Correct Direction
if(Direction>4)
{
Direction = 1
}
elseif(Direction<1)
{
Direction = 4
}
####################
###CORRECT PLACEMENT###
#Get where the ant should go on the X axis
AntX=Grid[X*10,vector2]:x()
#Get where the ant should go on the Y axis
AntY=Grid[Y,vector2]:y()
#Translate information to props
CX = ((AntX*10)+1)-10
PNum = (CX+(AntY-1))
#Move ant
holoPos(0,AllProps[PNum,entity]:massCenter())
#######################
####DEBUG###
#print("Pos: "+AntX+","+AntY)
#print("Correct X: "+CX)
#print("Prop: "+PNum)
#print("Direction: "+Direction)
#print("X: "+X)
#print("Y: "+Y)
#print("\n")
#print("\n")
############
} This code requires prop core to be enabled so make sure you have it.
Bookmarks