Here's the first part of a tutorial on how to program a Shining-Force-Battle-like engine.This first part deals with the ground setup : how to definate the tile type, the X position and the Y position, and the defense coefficient : this is the easiest part.The other part will deal with movements and attacks.
First, you must choose your battleground dimensions : let's take 7*10 as an example It gives us :
DIM Ground(7,10) \*\then we must fill the 'ground' array with values representing the tiles : - 1 => Herb
DATA 1,1,1,1,1,1,1,1,1,1 DATA 1,2,1,1,3,1,1,2,2,1 DATA 1,2,1,3,3,3,3,2,1,1 DATA 1,2,1,3,3,3,1,1,1,1 DATA 1,2,1,1,3,3,1,1,2,2 DATA 1,2,1,1,1,3,1,1,1,2 DATA 1,2,2,1,1,1,1,1,2,2Then we read the values :
FOR i=1 to 7 FOR j=1 TO 10 READ Ground(i,j) NEXT j,i(This is not obligated to use DATA's : you can set a separate file like battle1.grd )
Now that the whole ground is saved in memory in the 'ground' array, we must use this one to draw the ground :
FOR i=1 TO 7 FOR j=1 TO 10 IF Ground(i,j)=1 THEN LOCATE i,j : COLOR 10 : PRINT "H" IF Ground(i,j)=2 THEN LOCATE i,j : COLOR 8: PRINT "S" IF Ground(i,j)=3 THEN LOCATE i,j : COLOR 2: PRINT "T" NEXT i,jI think you understood that H, S and T means Herb, Stone and Tree. The colors are light green (10), dark grey (8) and dark green (2).
Now, the ground is drawn on the screen, but we don't have our position
and tiles proprties.
So, at the beginning of the program, insert:
XPOS=1 : YPOS=1and betweenIF Ground(i,j)=3 .... PRINT "T" and NEXT i,j , insert those three lines so that we can see our position without hiding the ground :
IF Ground(i,j)=1 AND i=xpos AND j=ypos THEN LOCATE i,j : COLOR 4 : print "H" IF Ground(i,j)=2 AND i=xpos AND j=ypos THEN LOCATE i,j : COLOR 4 : print "S" IF Ground(i,j)=3 AND i=xpos AND j=ypos THEN LOCATE i,j : COLOR 4 : print "T"Note : COLOR 4 is red
K$=INKEY$ : K$=RIGHT$(K$,1) IF k$="H" AND xpos > 1THEN xpos = xpos - 1 IF k$="P" AND xpos < 7THEN xpos = xpos + 1 IF k$="K" AND ypos > 1THEN ypos = ypos - 1 IF k$="M" AND ypos < 10 THEN ypos = ypos + 1 IF k$=";" THEN END LOCATE 1,60 : PRINT "X=";xpos LOCATE 2,60 : PRINT "Y=";yposThen let's show tiles status :
LOCATE 3,60 : PRINT "Ground=" LOCATE 4,60 : PRINT "Coefficient=" LOCATE 4,75 : print "%" IF Ground(xpos,ypos)=1 THEN LOCATE 3,67 : PRINT "Herb " : LOCATE 4,73 : PRINT "15" IF Ground(xpos,ypos)=2 THEN LOCATE 3,67 : PRINT "Stone" : LOCATE 4,73 : PRINT " 0" IF Ground(xpos,ypos)=3 THEN LOCATE 3,67 : PRINT "Tree " : LOCATE 4,73 : PRINT "30"Thought this is an example, you can change tiles name and defense coefficient. Now ,this is just a text program but you can create a tile file, with graphics. If you want to see this complete tutorial, click here. The keys are Up, Down, Left, Right and F1 to quit.
Click here to download the graphic version of the engine.