PART 1 :: field.
a ground in db, easy, you tell me.
MAKE MATRIX Matrix
So if the map is made 1000 units wide by 1000 high it makes 2000000 triangle just for the field!
We risk ending up with a fast turn play as a quarter image by second.
But do not worry I propose in this chapter to solve this problem as a point of support for all the rest.
Please note this will definitely be the hardest chapter but you warned.
A / Storage and loading of the ground.
In order to manage the land and these interractions with the game (eg a bump where objects are elevated)
it is essential to store all the informations about it.
For now we will only interest to:
The height of the matrix in these different items
The texture assigned to each point of the matrix (the tiles)
I therefore propose to create two tables that contain these data:
dim height# (map_width, map_height)
dim tiles (map_width, map_height)
map_width and map_height matches the number of the top of your field in height and width.
Then you can load a field from an external file in our tables.
Unfortunately, how to load a data file if you do not own this file.
I therefore propose to create the data file from your two empty tables.
We can store the data as follows:
a word that contains the width of the map ( in tiles )
a word containing the height of the map ( in tiles )
then for each tiles of your land,
a word corresponding to the tiles associated
a float containing the height of the matrix at this point
I propose a code to help you
open to write 1,"map"
write word 1,map_width
write word 1,map_height
for t=0 to map_width
for s=0 to map_height
write word 1,tiles(t,s)
write float 1,height#(t,s)
next s
next t
Then you can load your file "flat texture map" using the same code as previously but replacing
the write by read, it makes sense, right? ^^
B / Display the field and camera
Okay now, we'll create the matrix !!
make matrix 1,18,12,18,12
That's done...
This is not an error, the matrix is not at all the dimensions of the land contained in the table.
And that's fine because the maps strategy games tend to be very large.
In fact it is just enough that the created matrix fills the visual space of the camera, which is very small when the view is plunging and not too
far from the ground.
A small diagram:
So you will understand that it is difficult (not impossible) to make a camera that moves away from the map or that lifts the view because the dimensions of the matrix must then change.
The dimensions of the matrix that I have given are for a position and an angle precise for the camera that I will give but nothing prevents you choose your own dimensions.
Before continuing I explain the illusion principle of a matrix of the size of the map during a displacement of the camera
In fact the view of the camera shows the entire matrix least one row and one colone.
In this manner during a displacement of the camera, it moves in the space of that line and colone
and when the view moves out the matrix, the camera is repositioned on the opposite edge of the matrix
and all the plots of the matrix are offset (as shown by the small one in the diagram)
Thus the illusion of giant ground is perfect and you can make a map
of any size.
How to code this? You can try to do it, I suggest a small code that you can improve.
Make sure that the camera view can't leave the size of the map.
move_camerax#=0
move_cameray#=0
if leftkey() and camerax#<map_width-12 then move_camerax#=0.5
if rightkey() and camerax#>0 then move_camerax#=-0.5
if upkey() and cameray#>0 then move_cameray#=-0.5
if downkey() and cameray#<map_height-18 then move_cameray#=0.5
inc camerax#,move_camerax# rem camera position on the map
inc cameray#,move_cameray#
inc offset_camerax#,move_camerax# rem camera position cropped
inc offset_cameray#,move_cameray#
if offset_camerax#<0 then inc offset_camerax#,1 : update=1
if offset_cameray#<0 then inc offset_cameray#,1 : update=1
if offset_camerax#>1 then dec offset_camerax#,1 : update=1
if offset_cameray#>1 then dec offset_cameray#,1 : update=1
position camera 8.5+offset_camerax#,10,8+offset_cameray#
point camera 8.5+offset_camerax#,2,7.27+offset_cameray#
if update rem if the camera was out of the matrix, we update the matrix based
update=0 : vux=camerax# : vuy=cameray#
for t=0 to 18
for s=0 to 12
SET MATRIX HEIGHT 1,t,s,height#(vux+t,vuy+s)
next s
next t
for t=0 to 17 rem because on a matrix of 18 by 12, there are only 17 by 11 plots texture
for s=0 to 11
SET MATRIX TILE 1,t,s,tiles(vux+t,vuy+s)
next s
next t
UPDATE MATRIX 1
endif
That is pretty daunting. It is crucial to understand this code before continuing.
Before closing chapter, I note, as we have data for only the matrix height peaks and tiles but there may be
many other chart data as the fog of war that can be simulated by the normal matrix.
By being more or less directed towards the camera they can partially or totally obscure portions of the matrices.