Code archives/3D Graphics - Misc/Random buildings

This code has been declared by its author to be Public Domain code.

Download source code

Random buildings by Ben(t)
(Posted 19 years ago)
this code is designed to create random buildings in the square area that you specify
Type tower
	Field entity
	Field scale#
	Field x#,z#
	Field growth#
	Field shrink#
	Field time#
	Field timeout#
	Field move#
	Field reach#
	Field xsc#
	Field zsc#
End Type

Global tower=CreateCube()
EntityType tower,walls
EntityPickMode tower,2
HideEntity tower


TG#=TG#+1

If TG# > 15 Then

t.tower=New tower
	t\entity=CopyEntity (tower)
			t\x#=Rnd(-500,500)
			t\z#=Rnd(-500,500)
			t\xsc#=Rnd(25)
			t\zsc#=Rnd(25)
		t\growth#=Rnd(1)
		t\shrink#=Rnd(1)
		t\reach#=Rnd(1,200)
		t\timeout#=Rnd(250)
	TG#=0
EndIf


For t.tower=Each tower
	If t\time# < t\timeout# Then
	t\scale#=t\scale#+t\growth#
	Else
	t\scale#=t\scale#-t\shrink#
	EndIf
	
ScaleEntity t\entity,t\xsc#,t\scale#,t\zsc#
	PositionEntity t\entity,t\x#,t\scale#,t\z
	
	If t\scale# >= t\reach# Then t\time#=t\time#+1
	If t\scale# < 0 Then FreeEntity t\entity:Delete t
	
Next

Comments

chwaga
(Posted 19 years ago)
I'm lazy, could you put it in an example?

Ben(t)
(Posted 19 years ago)
here it is


Graphics3D 640,480,32,2
SeedRnd(MilliSecs())

units=1
walls=2

camera=CreateCamera()
EntityType camera,units
EntityRadius camera,2,2


Type tower
Field entity
Field scale#
Field x#,z#
Field growth#
Field shrink#
Field time#
Field timeout#
Field move#
Field reach#
Field xsc#
Field zsc#
End Type

light=CreateLight()
TurnEntity light,90,0,0

Global tower=CreateCube()
EntityColor tower,255,0,0
EntityType tower,walls
HideEntity tower

ground=CreatePlane()
EntityType ground,walls

Collisions units,walls,2,3
Collisions walls,units,2,3

While Not KeyHit(1)

;Mouse movement
Local x_speed#,y_speed#
x_speed=(MouseXSpeed()-x_speed)/5+x_speed
y_speed=(MouseYSpeed()-y_speed)/5+y_speed
MoveMouse GraphicsWidth()/2,GraphicsHeight()/2
TurnEntity camera,(y_speed/6),0,0
TurnEntity camera,0,(-x_speed/6),0
RotateEntity camera,EntityPitch(camera),EntityYaw(camera),0


If KeyDown(17) Then MoveEntity camera,0,0,1
If KeyDown(31) Then MoveEntity camera,0,0,-1
If KeyDown(30) Then MoveEntity camera,-1,0,0
If KeyDown(32) Then MoveEntity camera,1,0,0
If KeyDown(57) Then TranslateEntity camera,0,1,0
If KeyDown(46) Then TranslateEntity camera,0,-1,0


TG#=TG#+1

If TG# > 15 Then

t.tower=New tower
t\entity=CopyEntity (tower)
t\x#=Rnd(-500,500)
t\z#=Rnd(-500,500)
t\xsc#=Rnd(25)
t\zsc#=Rnd(25)
t\growth#=Rnd(1)
t\shrink#=Rnd(1)
t\reach#=Rnd(1,200)
t\timeout#=Rnd(250)
TG#=0
EndIf


For t.tower=Each tower
If t\time# < t\timeout# Then
t\scale#=t\scale#+t\growth#
Else
t\scale#=t\scale#-t\shrink#
EndIf

ScaleEntity t\entity,t\xsc#,t\scale#,t\zsc#
PositionEntity t\entity,t\x#,t\scale#,t\z

If t\scale# >= t\reach# Then t\time#=t\time#+1
If t\scale# < 0 Then FreeEntity t\entity:Delete t

Next

UpdateWorld
RenderWorld
Text 0,0,"w,a,s,d to move, c and spacebar to float up and down"
Flip
Wend
End


enjoy

Code Archives Forum