including a variable

Blitz3D Forums/Blitz3D Beginners Area/including a variable

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

here's the entire file, butcher it. I can't think of anything :(

Graphics3D 1024, 768, 32, 2
SetBuffer BackBuffer()
AutoMidHandle 1
Global size#=2
Global black = ReadPixelFast (1, 1)

Type bricks
	Field x
	Field y
	Field id
	Field w
	Field h
	Field cr
	Field cg
	Field cb
End Type

Type BombBrick
	Field x
	Field y
	Field w
	Field h
	Field id
	Field r
	Field cr
	Field cg
	Field cb
End Type

Type metalbrick
	Field x
	Field y
	Field id
	Field w
	Field h
End Type

Type superbrick 
	Field x
	Field y
	Field w
	Field h
	Field id
	Field phase
	Field cr
	Field cg
	Field cb
End Type

Type powerbrick
	Field x
	Field y
	Field w
	Field h
	Field cr
	Field cg
	Field cb
	Field id
	Field kind 
End Type

Type powerup
	Field x
	Field y
	Field kind
End Type

Global ColorR = 255
Global ColorG
Global ColorB
Global BrickType$ = "normal"
Global bomb = LoadImage("images\bomb.bmp")
MaskImage bomb, 255, 255, 255

Color 255, 255, 255
Repeat
Text 0, 0, "WELCOME TO THE LEVEL CREATOR"
Text 0, 14, "TO PROCEED, PRESS THE SPACEBAR"
Until KeyHit(57)
Cls 
load("testingfile")
Repeat
	RenderWorld()
	
	If MouseDown(1) And (Round(MouseY(), (size*10)+1))+((size*10)/2) < 600 Then
		For b.bricks = Each bricks
			If b\x = Round(MouseX(), (size*30)+1) And b\y = Round(MouseY(), (size*10)+1) Then 
				Delete b
				Exit
			EndIf  
			
		Next
		
		For bb.BombBrick = Each BombBrick
			If bb\x = Round(MouseX(), (size*30)+1) And bb\y = Round(MouseY(), (size*10)+1) Then 
				Delete bb
				Exit
			EndIf  			
		Next
		
		For mb.metalbrick = Each metalbrick
			If mb\x = Round(MouseX(), (size*30)+1) And mb\y = Round(MouseY(), (size*10)+1) Then 
				Delete mb
				Exit
			EndIf  
			
		Next
		
		For sb.superbrick = Each superbrick
			If sb\x = Round(MouseX(), (size*30)+1) And sb\y = Round(MouseY(), (size*10)+1) Then 
				Delete sb
				Exit
			EndIf  
		Next
		
		For pb.powerbrick = Each powerbrick
			If pb\x = Round(MouseX(), (size*30)+1) And pb\y = Round(MouseY(), (size*10)+1) Then 
				Delete pb
				Exit
			EndIf  
		Next
		If Instr (BrickType, "normal") Then CreateBrick(Round(MouseX(), (size*30)+1), Round(MouseY(), (size*10)+1), size, ColorR, ColorG, ColorB)
		If Instr (BrickType, "metal") Then CreateMetalBrick(Round(MouseX(), (size*30)+1), Round(MouseY(), (size*10)+1), size)
		If Instr(BrickType, "ghost") Then CreateGhostBrick(Round(MouseX(), (size*30)+1), Round(MouseY(), (size*10)+1), size)
		If Instr(BrickType, "bomb") Then 
			BrickType$ = Replace$ (BrickType$, "bomb ", "")
			CreateBombBrick(Round(MouseX(), (size*30)+1), Round(MouseY(), (size*10)+1), size, ColorR, ColorG, ColorB, Int BrickType)
			BrickType$ = "bomb " + BrickType$
		EndIf 
		If Instr(BrickType, "super ") Then 
			BrickType$ = Replace$ (BrickType$, "super ", "")
			CreateSuperBrick(Round(MouseX(), (size*30)+1), Round(MouseY(), (size*10)+1), size, Int BrickType, ColorR, ColorG, ColorB)
			BrickType$ = "super " + BrickType$
		EndIf
	EndIf
	
	If MouseDown(2) Then 
		For b.bricks = Each bricks
			If b\x = Round(MouseX(), (size*30)+1) And b\y = Round(MouseY(), (size*10)+1) Then 
				Delete b
				Exit
			EndIf  			
		Next
		
		For bb.BombBrick = Each BombBrick
			If bb\x = Round(MouseX(), (size*30)+1) And bb\y = Round(MouseY(), (size*10)+1) Then 
				Delete bb
				Exit
			EndIf  			
		Next
		
		For mb.metalbrick = Each metalbrick
			If mb\x = Round(MouseX(), (size*30)+1) And mb\y = Round(MouseY(), (size*10)+1) Then 
				Delete mb
				Exit
			EndIf  
			
		Next
		
		For sb.superbrick = Each superbrick
			If sb\x = Round(MouseX(), (size*30)+1) And sb\y = Round(MouseY(), (size*10)+1) Then 
				Delete sb
				Exit
			EndIf  
		Next
		
		For pb.powerbrick = Each powerbrick
			If pb\x = Round(MouseX(), (size*30)+1) And pb\y = Round(MouseY(), (size*10)+1) Then 
				Delete pb
				Exit
			EndIf  
		Next
	EndIf 
	
	If KeyHit(46) Then
		FlushKeys()
		Print "Input the color (RGB) values"
		ColorR = Input$("RED : ")
		ColorG = Input$("GREEN : ")
		ColorB = Input$("BLUE : ")
		Cls 
	EndIf
	
	If KeyHit(31) Then
		FlushKeys()
		Print "Input the brick size, current size is " + size + "."
		Print "SUGGESTION : do not make size under 0.2 or over 4"
		Print "as the size is how many times the orginal dimensions (30 x 10)"
		size# = Float Input$("SIZE : ")
		Cls 
	EndIf
	
	
	If KeyHit(20) Or (Instr(BrickType$, "normal") = False And Instr(BrickType$, "metal") = False And Instr(BrickType$, "ghost") = False And Instr(BrickType$, "super") = False And Instr(BrickType$, "bomb") = False) Then
		
		FlushKeys()
		Print "Enter the new kind of brick"
		Print "'normal' for regular bricks"
		Print "'metal' for metal bricks"
		Print "'ghost' for ghost bricks"
		Print "for bomb bricks, type 'bomb ' (with the space) then the explosion radius"
		Print "for super bricks, type 'super ' (with the space) then the number of phases"
		BrickType$ = Input$("Brick Type : ")
		BrickType$ = Lower$(BrickType$)
		Cls 
		FlushKeys()
	EndIf
	
	drawbricks()
	Color 255, 255, 255
	
	Text 512 - (StringWidth("PRESS T TO CHANGE BRICK TYPE")/2), 640, "PRESS T TO CHANGE BRICK TYPE"
	Text 512 - (StringWidth("PRESS S TO CHANGE SIZE")/2), 660, "PRESS S TO CHANGE SIZE"
	Text 512 - (StringWidth("PRESS C TO CHANGE COLOR")/2), 680, "PRESS C TO CHANGE COLOR"
	Text 512 - (StringWidth("PRESS ESCAPE TO SAVE AND QUIT")/2), 700, "PRESS ESCAPE TO SAVE AND QUIT"
	Line 0, 600, 1024, 600
	Flip
	Cls 
	
Until KeyHit(1)

name$ = Input$("Filename (enter nothing to not save)  :  ")
If name <> "" Then Save(name$)

End 

Function Round( Number , N )

   If ( Number Mod N ) >= ( N *.5 )
        Number  = ( Ceil( Number / N ) + 1 ) * N
   Else
        Number = Floor( Number / N ) * N
   EndIf

   Return Number

End Function

Function CreateSuperBrick(x, y, s#, phases, cr, cg, cb)
	SB.superbrick = New superbrick
	sb\x = x
	sb\y = y
	sb\w = s*30
	sb\h = s*10
	sb\cr = cr
	sb\cg = cg
	sb\cb = cb
	sb\phase = phases
	If sb\phase > 5 Then sb\phase = 5
	sb\id = CreateImage(sb\w, sb\h)
	SetBuffer ImageBuffer(sb\id)
		Color cr, cg, cb
		Rect 0, 0, sb\w, sb\h
	SetBuffer BackBuffer()
End Function

Function CreateBrick(x, y, s#, cr, cg, cb)
	b.bricks = New bricks
	b\x = x
	b\y = y
	b\w = s*30
	b\h = s*10
	b\cr = cr
	b\cg = cg
	b\cb = cb
	b\id = CreateImage(b\w, b\h)
	SetBuffer ImageBuffer(b\id)
		Color cr, cg, cb
		Rect 0, 0, b\w, b\h
	SetBuffer BackBuffer()
End Function 

Function CreateGhostBrick(x, y, s)
	b.bricks = New bricks
	b\x = x
	b\y = y
	b\w = s*30
	b\h = s*10
	b\cr = 4
	b\cg = 4
	b\cb = 4
	b\id = CreateImage(b\w, b\h)
	SetBuffer ImageBuffer(b\id)
		Color 4, 4, 4
		Rect 0, 0, b\w, b\h
		Color 200, 200, 200
		Rect 0, 0, b\w, b\h, 0
	SetBuffer BackBuffer()
End Function

Function CreatePowerBrick(x, y, s#, cr, cg, cb, kind=0)
If kind = 0 Then

	pb.bricks = New bricks
	pb\x = x
	pb\y = y
	pb\w = s*30
	pb\h = s*10
	pb\id = CreateImage(pb\w, pb\h)
	SetBuffer ImageBuffer(pb\id)
		Color cr, cg, cb
		Rect 0, 0, pb\w, pb\h
		If cr < 255 And cg < 255 And cb < 255 Then
			Color 255, 255, 255
		Else
			Color 0, 0, 0
		EndIf 
		Text 2, 2, "SUPERBALL"
		
	SetBuffer BackBuffer()
	
EndIf 

Color 255, 255, 255
End Function 

Function CreateMetalBrick(x, y, s#)
	mb.metalbrick = New metalbrick
	mb\x = x
	mb\y = y
	mb\w = s*30
	mb\h = s*10
	mb\id = CreateImage(mb\w, mb\h)
	SetBuffer ImageBuffer(mb\id)
		Color 100,100,100
		Rect 0, 0, mb\w, mb\h
	SetBuffer BackBuffer()
End Function

Function CreateBombBrick(x, y, s, cr, cg, cb, r)
	bb.BombBrick = New BombBrick
	bb\x = x
	bb\y = y
	bb\w = s*30
	bb\h = s*10
	bb\r = r
	bb\cr = cr
	bb\cg = cg
	bb\cb = cb
	ResizeImage bomb, bb\w, bb\h
	bb\id = CreateImage(bb\w, bb\h)
	SetBuffer ImageBuffer(bb\id)
		Color cr, cg, cb
		Rect 0, 0, bb\w, bb\h
		DrawImage bomb, bb\w / 2, bb\h / 2
	SetBuffer BackBuffer()
End Function

Function DrawBricks()
	For b.bricks = Each bricks
		DrawImage b\id, b\x, b\y
	Next
	
	For mb.metalbrick = Each metalbrick
		DrawImage mb\id, mb\x, mb\y
	Next
	
	For sb.superbrick = Each superbrick
		DrawImage sb\id, sb\x, sb\y
	Next
	
	For bb.bombbrick = Each bombbrick
		DrawImage bb\id, bb\x, bb\y
	Next
	For pb.powerbrick = Each powerbrick
		DrawImage pb\id, pb\x, pb\y
	Next
End Function

Function Load(filename$)

	
	file = OpenFile("maps\testingfile.bb")
	
			brickcount = Int ReadLine(file)
			If brickcount > 0 Then 
			For n = 0 To brickcount
				Local x = Int ReadLine(file)
				Local y = Int ReadLine(file)
				Local s# = Float ReadLine(file)
				Local cr = Int ReadLine(file)
				Local cg = Int ReadLine(file)
				Local cb = Int ReadLine(file)
				CreateBrick(x, y, s, cr, cg, cb)
			Next
			EndIf 
			brickcount = Int ReadLine(file)
			If brickcount > 0 Then 
			For n = 0 To brickcount - 1
				x = Int ReadLine(file)
				y = Int ReadLine(file)
				s# = Float ReadLine(file)
				Local phase = Int ReadLine(file)
				cr = Int ReadLine(file)
				cg = Int ReadLine(file)
				cb = Int ReadLine(file)
				If s > 0.0 Then CreateSuperBrick(x, y, s, phase, cr, cg, cb)
			Next
			EndIf 
			
		
	CloseFile file

End Function

Function countbricks()
	For b.bricks = Each bricks
		count = count + 1
	Next
	Return count 
End Function



Function Save(filename$)

	file = WriteFile("maps"+filename$+".bb")
	file = OpenFile("maps"+filename$+".bb")
	
		WriteLine file, countbricks()
		For b.bricks = Each bricks
			WriteLine file, b\x
			WriteLine file, b\y
			WriteLine file, b\w / 30
			WriteLine file, b\cr
			WriteLine file, b\cg
			WriteLine file, b\cb
		Next
		
		For sb.superbrick = Each superbrick
		count = count + 1
		Next
		WriteLine file, count 
		For sb.superbrick = Each superbrick
			WriteInt file, sb\x
			WriteInt file, sb\y
			WriteFloat file, sb\w / 30
			WriteInt file, sb\phase
			WriteInt file, sb\cr
			WriteInt file, sb\cg
			WriteInt file, sb\cb
		Next
	;	WriteLine file, "METALBRICKS"
		For mb.metalbrick = Each metalbrick
			WriteLine file, mb\x
			WriteLine file, mb\y
			WriteLine file, mb\w / 30
		Next
	;	WriteLine file, "POWERBRICKS"
		For pb.powerbrick = Each powerbrick
			WriteLine file, pb\x
			WriteLine file, pb\y
			WriteLine file, pb\w / 30
			WriteLine file, pb\cr
			WriteLine file, pb\cg
			WriteLine file, pb\cb
			WriteLine file, pb\kind
		Next
	;	WriteLine file, "BOMBBRICKS"
		For bb.BombBrick = Each BombBrick
			WriteLine file, bb\x
			WriteLine file, bb\y
			WriteLine file, bb\w / 30
			WriteLine file, bb\cr
			WriteLine file, bb\cg
			WriteLine file, bb\cb
			WriteLine file, bb\r
		Next 
	
	CloseFile file 
End Function