grid?

Blitz3D Forums/Blitz3D Programming/grid?

Guy Fawkes(Posted 2009) [#1]
hi all. im having a small problem w/ the rpg maker im writing. i need it to draw a grid using lines inside of the rectangle, but its not working right. what is going on?

code:



Thanks for the help!

Rez


Midimaster(Posted 2009) [#2]
It is difficult, to understand what exactly you want to have...

So if you want to have a grid in the left field, it must be constructed with
2 sorts of lines:

	For x1=1 To GraphicsWidth()/4 Step 32
		For y1=1 To GraphicsHeight()-1 Step 32

			linex = rectx+x1
			liney = recty+y1
			;linewidth = rectx+x1+32
			;lineheight = recty+y1+32

			blahx = linex
			blahy = liney
			;blahwidth = linewidth
			;blahheight= lineheight

			Line 1, liney, GraphicsWidth()/4, liney
			Line linex, 1, linex, GraphicsHeight()-1

		Next
	Next



please write more about the aim of the code


Guy Fawkes(Posted 2009) [#3]
i want to take 2 lines, make them 32x32 width / height, and put the grid inside of the rectangle


Guy Fawkes(Posted 2009) [#4]
here's what i have so far. although i would like to use the rectangle, and delete any extra lines from the grid.

code:



and also, the grid should stay in the rectangle no matter what screen resolution i set it to use


Midimaster(Posted 2009) [#5]
is it this?

While Not KeyHit(1)

Cls

Color 255, 255, 255

	rectx = 2
	recty = 2
	Width=Int(GraphicsWidth()/4/32)*32
	Height=Int(GraphicsHeight()/32)*32

	Rect rectx, recty, Width+3, Height+3, 0

	For x1=0 To width Step 32
		linex = rectx+x1
		Line linex+1, RectY, linex+1, RectY+Height
	Next
	
	For y1=0 To height Step 32
		liney = recty+y1
		Line RectX, liney+1, RectX + Width, liney+1
	Next 

    Text 10, 10, "x: "+blahx
    Text 10, 30, "y: "+blahy
    Text 10, 50, "width: "+blahwidth
    Text 10, 70, "height: "+blahheight

    Flip
Wend



Guy Fawkes(Posted 2009) [#6]
yes. except for 1 thing. i need the rectangle and grid to stay the same size and in the same position no matter what resolution other than that, it's perfect!

thanks!

Rez


Midimaster(Posted 2009) [#7]
how should this work?

do you need grids which have each a size of 32x32 or do you need a exact number of grids in x-axis and y-axis? you cannot have both, or?

two possibilities:

1.
Make 3D-Graphic with Camera View from the top to the floor. The 3D will take care about, that the whole world is visible, independet from resolution.

2.
Scaling down the size of the grids, so that it fits:
for examle, if 6 fields are necessary:
        ....
	rectx = 2
	recty = 2
        GridSize=int(GraphicsWidth()/4/6)
	Width=Int(GraphicsWidth()/4/GridSize)*GridSize
	Height=Int(GraphicsHeight()/GridSize)*GridSize

	Rect rectx, recty, Width+3, Height+3, 0

	For x1=0 To width Step GridSize
        .....                  ^^^^



Guy Fawkes(Posted 2009) [#8]
i need grids with a size of 32x32 that fit ONLY in the rectangle

and im not doing 3d. im making a 2d rpg maker.

that is what this grid is for. to place tiles in at any screen resolution


Midimaster(Posted 2009) [#9]
and the number of grid can vary depending on the resolution and size of the grid? it does not matter, how many they will be? OK

At the moment the code works like this, or? Did you test some other resolutions? Tell me more about a certain resolution and what problems you can see (if you see some....)


Guy Fawkes(Posted 2009) [#10]
well. the higher the width and height of the resolution, the bigger the size of the grid becomes. which i dont want to happen. theres a way to keep it the same size, but im not sure what to use to do this.

the # of grids should fill the rectangle with a grid, and thats it. nothing more. the # of the grids is w/e fits in the rectangle.


Guy Fawkes(Posted 2009) [#11]
SO. here's how it would work:

here's the rectangle w/ the lines in it located in the same place and same size for ALL screen resolutions:

____________
|++++++++++|
|++++++++++|
|++++++++++|
|++++++++++|
|++++++++++|
|++++++++++|
|++++++++++|
|++++++++++|

+ stands for both horizontal and vertical lines at the same time


Midimaster(Posted 2009) [#12]
so, if I understand you right, the number of grids is not fix in general, but it should be fixed by the size of the rect, which you will change.


the two parameters already allow you to control the size of the rectangle and this way also the number of grids:

Width=Int(GraphicsWidth()/4/32)*32
Height=Int(GraphicsHeight()/32)*32

change this to

Width=10*32
Height=10*32

...and you will get a grid of 10x10 elements

or

Width=600
Height=600

...and you will get a filled grid of that size


But what should happen, if the size of the rect you want is bigger than the resolution allows?



GRID OF CROSSES?

I see your picture and now I am not sure, that you want to have grid of rectangles or grid of crosses?

; grid of crosses
....
	For x1=16 To width Step 32
		For y1=16 To height Step 32
			linex = rectx+x1
			liney = recty+y1
			Line linex+1-11, liney+1, linex+1+11, liney+1
			Line linex+1, liney+1-11, linex+1, liney+1+11
		Next
	Next
....



Guy Fawkes(Posted 2009) [#13]
i want a grid w/ rectangles (aka squares :P), using line to draw them. im testing your code now.


Guy Fawkes(Posted 2009) [#14]
instead of making boxes using the line, i want the lines to create something that looks like this: + so the lines create plus's instead of boxes

that way, the rectangle will make them look like boxes ^^
_______
|+++++|
|+++++|
|+++++|
|+++++|
|+++++|


Guy Fawkes(Posted 2009) [#15]
a better illustration:

________
|-|-|-|-|
|-|-|-|-|
|-|-|-|-|
|-|-|-|-|
|-|-|-|-|
|-|-|-|-|


Midimaster(Posted 2009) [#16]
but that exactly, what my last cod is doing...

experiments:

try to change the values "11" to numbers from 11 to 16

Line linex+1-15, liney+1, linex+1+15, liney+1
Line linex+1, liney+1-15, linex+1, liney+1+15


try to change only the second "11":

Line linex+1-0, liney+1, linex+1+30, liney+1
Line linex+1, liney+1-0, linex+1, liney+1+30


Guy Fawkes(Posted 2009) [#17]
no it doesnt quite do what i want it to. instead of making just pluses inside the rectangle, it makes whole boxes.


Midimaster(Posted 2009) [#18]
I spoke about the code "grid og crosses"

	For x1=16 To width Step 32
		For y1=16 To height Step 32
			linex = rectx+x1
			liney = recty+y1
			Line linex+1-11, liney+1, linex+1+11, liney+1
			Line linex+1, liney+1-11, linex+1, liney+1+11
		Next
	Next



I see crosses !!!

and if you gamble with the values "11" you will learn to move the lines in every position you want.


Guy Fawkes(Posted 2009) [#19]
ok. now i see crosses. but now is there anyway u can connected those pluses so they look like boxes, but arent actually boxes?



thanks!

Rez


Guy Fawkes(Posted 2009) [#20]
i tried messing w/ it, and it just didnt make the cross turn into a box..


Guy Fawkes(Posted 2009) [#21]
what number would i have to change to connect the crosses to the rectangle?


Midimaster(Posted 2009) [#22]
...u can connected those pluses so they look like boxes, but arent actually boxes?...

what is the difference between boxes and crosses, which looks like boxes? lines are much more comfortable. What will be the advantage of the crosses?



...and it just didnt make the cross turn into a box..

with a number of 16 the line get connected. Your cross distance is the 32, the distance to the rect is the 16.
Each line is paintet 11 to the left and 100 to the right of this center point. So remains a hole of 5 pixels. (16-11). If you change the values to 15 it remain only 1 pixel, if you use 16 they are connected

Graphics3D 800,600,24,2
width=320
Height=320
Color 222,222,222
Rect rectx, recty, Width+3, Height+3, 0

	For x1=16 To width Step 32
		For y1=16 To height Step 32
			linex = rectx+x1
			liney = recty+y1
			Line linex+1-15, liney+1, linex+1+15, liney+1
			Line linex+1, liney+1-15, linex+1, liney+1+15
		Next
	Next
	
Flip
WaitKey()


or test this changes:

Graphics3D 800,600,24,2
width=320
Height=320
rectX=10
rectY=10
Color 222,222,222
Rect rectx, recty, Width+3, Height+3, 0

	For x1=0 To width-1 Step 32
		For y1=0 To height-1 Step 32
			linex = rectx+x1
			liney = recty+y1
			Line linex+1-0, liney+1, linex+1+30, liney+1
			Line linex+1, liney+1-0, linex+1, liney+1+30
		Next
	Next
	
Flip
WaitKey()



Guy Fawkes(Posted 2009) [#23]
the advantage of boxes is that i want to place tilemaps in them. that is the whole idea.

but to do that, i need the lines to be crosses that are interconnected. thus forming a shape like this:
_______
|#####|
|#####|
|#####|
|#####|


Guy Fawkes(Posted 2009) [#24]
this is as close as i could get it. i need that plus in the middle of the box then i need to be able to make it STAY in the middle of the box and stay the same size no matter what screen resolution it is, and what position it is

code:



thanks!


Midimaster(Posted 2009) [#25]
Rez,

that is really difficult to talk about...

I am not 100% sure, that I understood, what you want!

Please tell me what is correct:
1.
There is a free to move Rect, the Width and the Height is free
2.
Inside the rect there will be tiles, the size is always 32x32 pix
The number depents on Width and Heght of the Rect.
3.
There are lines looking like crosses in each Tile "area".
4.
The have to look like crosses, but have to be changed to boxes. Why


Some qustions:
if you plan to draw tiles in that rect, why do you need the lines? are the lines behind or in front of the tiles?

what should the lines demonstrate to the user at the end?

what is the difference between crosses that touch each other, and my lines in the end. Both looks the same for the user, or?

What is your plan to do with this feature?

Is it for finding out the positions of the tiles? is it for finding out where the mouse is?

in which way can these lines move or interact during the program?

your last picture was not very helpful. because this # is made of four lines, not 2!

perhaps you can paint something and it to me in a email info@...?


Guy Fawkes(Posted 2009) [#26]
1-4 is also correct. BUT ill email u a pic. again, what i plan to do is make a 2d rpg drag and drop editor.


Guy Fawkes(Posted 2009) [#27]
check ur email ;)


Midimaster(Posted 2009) [#28]
got your email, thank you.

but if i see the picture now, there is no reason for construct the lines as cross. What is the reason for want it like that? What would be the advantage?

This could be done with lines much better, Do you need also thick lines?

And if you plan to add single tiles, why not paint a black filles rect with a number of white filled boxes on it?






please aswer the other questions form the last post too.


Guy Fawkes(Posted 2009) [#29]
Please tell me what is correct:
1.
There is a free to move Rect, the Width and the Height is free

yes, u need to be able to move the rect at any x or y position and still have the grid in the middle. and yes u also need to be able to stretch the rectangle to any width or height, and the grid will remain the same size inside the rectangle.

2.
Inside the rect there will be tiles, the size is always 32x32 pix
The number depents on Width and Heght of the Rect.

basically, yes.

3.
There are lines looking like crosses in each Tile "area".

sorta. there are crosses that MAKE boxes.

4.
The have to look like crosses, but have to be changed to boxes. Why

they have to be crosses that connect to each other in order to form a box.

Some qustions:
if you plan to draw tiles in that rect, why do you need the lines? are the lines behind or in front of the tiles?

they should be drawn to the front, as im going to use this grid system to create a drag drop type gui

what should the lines demonstrate to the user at the end?

the lines should demonstrate to the use a rectangle w/ boxes in it made of 2 lines horizontal and vertical.

what is the difference between crosses that touch each other, and my lines in the end. Both looks the same for the user, or?

the difference is i cant use a rectangle without the lines overlapping it.

What is your plan to do with this feature?

my plan is to make a 2d rpg drag drop editor (obviously).

Is it for finding out the positions of the tiles? is it for finding out where the mouse is?

im proally gonna need a little help w/ figuring out how to drag drop the tiles from the boxes in the grid.

in which way can these lines move or interact during the program?

no matter what, the grid should ALWAYS stay in the middle of the rectangle. and the rectangle should be able to move to any x or y coordinate.

your last picture was not very helpful. because this # is made of four lines, not 2!

i know its not helpful, so i sent u an email :P


it would be cool if there was a variable that specified a # of border thickness. but it doesnt have to


Guy Fawkes(Posted 2009) [#30]
here's a fix. the prob is the grid inside the rectangle doesnt stay the same size or stay in the middle for everytime i use a different screen resolution or height and width of the rectangle.




Guy Fawkes(Posted 2009) [#31]
o b4 i fgt. heres the code to my rpg drag and drop editor.



notice how the 1st graphic is in the 1st box?

i need to be able to control how many sets of graphics go into how many sets of boxes.

so if i have 4 boxes, and only wanted 2 different graphics in all 4 boxes, like i would have a barrel tile, and a tree tile, and a sand tile, and a water tile, if i wanted to draw all 4, in rows of 2 or 3 or 4, i could simply change a variable to do that.


Guy Fawkes(Posted 2009) [#32]
here's a pic of my rpg maker to show u what i want to do w/ this grid code that i need help w/

http://www.mediafire.com/imageview.php?quickkey=0zmzzj2vggm&thumb=4


Midimaster(Posted 2009) [#33]
the function we at the moment talk about will be able...

1. to edit a single tile?

2. to construct a landscape with given tiles?



I think, you should not start your project with so many open things to do. At first I would try to write a "ShowLandscape"-Function with given Tiles and given Map. If this works you can add a Move-Lanscape-Feature and so on...

At the moment to have to many components that are not working but depent on each other. and it is missing a structure.

try this:
Graphics3D 800,600

Global Layer0=CreateImage(32,32,10)

Dim Map%(100,100)


LoadLayer

LoadMap

Repeat
	PaintLandscape 8,4
	;EditSomething	
Until KeyHit(1)



Function PaintLandscape(Colums%,Rows%)
	Local TileTyp%

		; draw the tiles
		For y=0 To Rows-1
			For x=0 To Colums-1
				TileTyp=Map(x,y)
				DrawImage Layer0,x*32,y*32,TileTyp
			Next
		Next

		;draw the grid
		Color 255,255,255
		For i=0 To Colums
			Line i*32,0,i*32,Rows*32
		Next
		For i=0 To Rows
		 	Line 0,i*32,Colums*32,i*32
		Next 
		Flip
End Function



Function LoadLayer()
	; a simulation only produces colored rectangles
	Local i%
		For I=1 To 4
			SetBuffer ImageBuffer(Layer0,i)
			Color Rand(255),Rand(255),Rand(255) 
			Rect 0,0,32,32,1
		Next
		SetBuffer BackBuffer()
End Function



Function LoadMap()
	; a simulation only produces a random map
	For y=0 To 99	  
		For X=0 To 99
		  Map(x,y)=Rand(1,4)
		Next
	Next
End Function




Midimaster(Posted 2009) [#34]
in a second step you now can change only one thing at one time f.e the free position of the landscape:

Function PaintLandscape(Colums%,Rows%,Xoff%,YOff%)
	Local TileTyp%

		; draw the tiles
		For y=0 To Rows-1
			For x=0 To Colums-1
				TileTyp=Map(x,y)
				DrawImage Layer0,Xoff+x*32,YOff+y*32,TileTyp
			Next
		Next

		;draw the grid
		Color 255,255,255
		For i=0 To Colums
			Line Xoff+i*32,YOff+0,Xoff+i*32,YOff+Rows*32
		Next
		For i=0 To Rows
		 	Line Xoff+0,YOff+i*32,Xoff+Colums*32,YOff+i*32
		Next 
		Flip
End Function


test it and only if it is working add a new feature, f.e free starting position of map:


Function PaintLandscape(Colums%,Rows%,Xoff%,Yoff%,MapX%,MapY%)
	Local TileTyp%

		; draw the tiles
		For y=0 To Rows-1
			For x=0 To Colums-1
				TileTyp=Map(MapX+x,MapY+y)
				DrawImage Layer0,Xoff+x*32,Yoff+y*32,TileTyp
				; only for demonstration map numbers:
				Text Xoff+x*32,YOff+y*32+10,(MapX+x)+"/"+(MapY+y)
			Next
		Next

		;draw the grid
		Color 255,255,255
		For i=0 To Colums
			Line Xoff+i*32,YOff+0,Xoff+i*32,Yoff+Rows*32
		Next
		For i=0 To Rows
		 	Line Xoff+0,YOff+i*32,Xoff+Colums*32,Yoff+i*32
		Next 
		Flip
End Function



Guy Fawkes(Posted 2009) [#35]
its PERFECT. now. how do i replace those tiles w/ an animimage and make it so i can control how many go in what squares at once?

like if i wanted to load the animimage. and i had 8 tiles in the image. but only wanted to load them in rows of 2.


Midimaster(Posted 2009) [#36]
I think it is better to chat now...
please try to come into german blitz chat now. im waiting for you,

use nickname riz please


Midimaster(Posted 2009) [#37]
no message


Midimaster(Posted 2009) [#38]
ok, rez

here is the plan what to do next:

add to new functions to the main loop
-MoveMouseTile
-SelectMouseTile

write a function MoveMouseTile which moves one icon together with the mouse
-draw at mouse position Layer(MouseTileNumber)


write another function SelectMouseTile, which interact on mouseactions:
-find out which rectangle was entered
-find out wich box was entered
decide is it drag or drop
- drag: store TileNumber in a variable MouseTileNumber
- drop : store MouseTileNumber in Map(x,y)

but do not change old (running) functions therefore

keep your structure


Guy Fawkes(Posted 2009) [#39]
i see. meet me in the chat


Guy Fawkes(Posted 2009) [#40]
can someone please help me make it so that i can drag an icon of choice in my rpg drag drop maker to a tile of choice in the map grid? i have included the media along w/ an exe. i know the graphics are horrible but please bare w/ me.

media:

http://www.mediafire.com/download.php?nmmytzyr12j

code:




Midimaster(Posted 2009) [#41]
chat?


Guy Fawkes(Posted 2009) [#42]
feel free to anyone else who wants to help


Guy Fawkes(Posted 2009) [#43]
midimaster, where are you? i haven't seen you in the chat for over 3 days now.....


Gabriel(Posted 2009) [#44]
You know, if you're going to go back to the old habits of harrassing people who try to help you, there was no point in changing your name from DarkShadowWing in the first place.


Ked(Posted 2009) [#45]
midimaster, where are you? i haven't seen you in the chat for over 3 days now.....

Not everyone's life consists of getting on here every day. He might be busy...

...or have H1N1. :P


Guy Fawkes(Posted 2009) [#46]
and you know gabriel, i wasn't harrassing anybody. so there was no point in that post. i was talking to him and him alone. not you, not ked. but him..


Guy Fawkes(Posted 2009) [#47]
PS. i didnt change my name because of this. i changed my name because i wanted to.


WERDNA(Posted 2009) [#48]
There is always the chat room at www.blitzmonkeys.com :)


Guy Fawkes(Posted 2009) [#49]
why thank you, werdna ^^ at least SOMEONE is kind around here


Ked(Posted 2009) [#50]
Good for Werdna!


Guy Fawkes(Posted 2009) [#51]
yea. ur right :) Good for werdna. now ive had enough of u ked, so im not responding to this post anymore.