Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
0 registered members (), 905 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Tactical RPG Grid setup #355027
01/24/11 10:19
01/24/11 10:19
Joined: Jan 2004
Posts: 3,023
The Netherlands
Helghast Offline OP
Expert
Helghast  Offline OP
Expert

Joined: Jan 2004
Posts: 3,023
The Netherlands
Roxas had asked previously how to calculate grid movement for a tactical game (link to thread: Tactical RPG Grid Calculation ) . I took an hour to write a pretty dynamic system for that, and thought people could make use of it.
it's just a multi-dimensional array that calculates distance cost from any grid cell based on a given diameter, but it's a good start for any tactics game.

the code clamps around the edges properly.
you can use the mouse position to set a position to calculate from, and use the scrollwheel to increase/decrease the movement radius.

Code:
#include <acknex.h>
#include <default.c>

#define GRID_size 10
#define GRID_cellsize 32

var GridMoveSquares = 3; // stores size of movement diameter
var GridArray[GRID_size][GRID_size]; // stores size of grid

// visual debug representation variables
var current_row = 3;
var current_col = 1;

// function that resets every GRID value
function resetGrid() {
	var X_index = 0;
	var Y_index = 0;
	
	for(X_index=0; X_index<GRID_size; X_index++) {
		for(Y_index=0; Y_index<GRID_size; Y_index++) {
			GridArray[X_index][Y_index] = 0;
		}
	}
}

// function that visually represents the GRID data
function drawGridData() {
	var column_index = 0;
	var row_index = 0;
	
	for(column_index=0; column_index<GRID_size; column_index++) {
		for(row_index=0; row_index<GRID_size; row_index++) {
			if(GridArray[column_index][row_index] == 0) {
				draw_text(str_for_num(NULL, GridArray[column_index][row_index]), GRID_cellsize*column_index, GRID_cellsize*row_index, vector(255,255,255));
			} else {
				draw_text(str_for_num(NULL, GridArray[column_index][row_index]), GRID_cellsize*column_index, GRID_cellsize*row_index, vector(0,0,255));
			}
		}
	}
}

// actually calculate the cells that can be moved on
function setMoveGrid(var row, var col) {
	var column_index = 0;
	var row_index = 0;
	var clampedIndex;
	
	resetGrid(); // reset
	
	for(column_index=GridMoveSquares; column_index>=0; column_index--) {
		// fill right hand side of column
		clampedIndex = clamp(col+column_index, 0, GRID_size-1);
		GridArray[row][clampedIndex] = column_index;
		for(row_index=GridMoveSquares; row_index>=column_index; row_index--) {
			GridArray[clamp(row+(row_index-column_index), 0, GRID_size-1)][clampedIndex] = row_index;
			GridArray[clamp(row-(row_index-column_index), 0, GRID_size-1)][clampedIndex] = row_index;
		}
		
		// fill left hand side of column
		clampedIndex = clamp(col-column_index, 0, GRID_size-1);
		GridArray[row][clampedIndex] = column_index;
		for(row_index=GridMoveSquares; row_index>=column_index; row_index--) {
			GridArray[clamp(row+(row_index-column_index), 0, GRID_size-1)][clampedIndex] = row_index;
			GridArray[clamp(row-(row_index-column_index), 0, GRID_size-1)][clampedIndex] = row_index;
		}
	}
}

function getMouseInput() {
	current_row = clamp(integer(abs(mouse_pos.x) / GRID_cellsize), 0, GRID_size-1);
	current_col = clamp(integer(abs(mouse_pos.y) / GRID_cellsize), 0, GRID_size-1);
	GridMoveSquares += (mickey.z/120); GridMoveSquares = clamp(GridMoveSquares, 0, GRID_size);
}

function main() {
	mouse_mode = 4;
	resetGrid(); // reset GRID
	
	while(1) {
		getMouseInput();
		setMoveGrid(current_row,current_col); // calculate new GRID data
		
		drawGridData(); // debug draw grid
		wait(1);
	}
}



I hope someone can make use of it, or atleast learn from it laugh

regards,


Formerly known as dennis_fantasy
Portfolio - http://www.designorhea.com/
Project - http://randomchance.cherrygames.org/
Re: Tactical RPG Grid setup [Re: Helghast] #355115
01/24/11 18:25
01/24/11 18:25
Joined: Jun 2006
Posts: 2,640
Earth
Germanunkol Offline
Expert
Germanunkol  Offline
Expert

Joined: Jun 2006
Posts: 2,640
Earth
There's no diagonal movement currently, correct?
Only right/left/up/down...?


~"I never let school interfere with my education"~
-Mark Twain
Re: Tactical RPG Grid setup [Re: Germanunkol] #355190
01/25/11 08:48
01/25/11 08:48
Joined: Jan 2004
Posts: 3,023
The Netherlands
Helghast Offline OP
Expert
Helghast  Offline OP
Expert

Joined: Jan 2004
Posts: 3,023
The Netherlands
you should see something similar to:


(Uploaded with ImageShack.us)

which, as you can see, does also take into account diagonal movement (it's just an immediate cost of 2).
Also, this is extremely bare-bones ofcourse, it only is a visual representation of how to calculate and clamp movement cost within a certain range, there is no movement, visuals or game at all present. Just something to get someone with the idea started.

regards,


Formerly known as dennis_fantasy
Portfolio - http://www.designorhea.com/
Project - http://randomchance.cherrygames.org/

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1