Author Topic: Grid display  (Read 1414 times)

Rob

  • Guest
Grid display
« on: March 06, 2014, 03:35:04 pm »
Hi, I am new to the DFSDK community and was wondering, how do you display a map as a grid like in plants vs zombies or in any turn based game? Also, how would you set 'items' in an individual square?

expleo

  • Jr. Member
  • **
  • Posts: 57
  • Karma: +0/-0
    • View Profile
Re: Grid display
« Reply #1 on: March 07, 2014, 02:50:35 am »
Hi, you need 2 'layers'. One as a matrix that is your grid, with individual views (read up on viewadd, imageadd and arrays to do this). then you should have a seccond 'layer' to place the items in.

Not a complete 'solution' for you this, but the question is not very spesific, so I suggest you try experiment with a 2x2 grid to get the hang of it, then ask an specific questions you might have

Rob

  • Guest
Re: Grid display
« Reply #2 on: March 08, 2014, 10:00:37 am »
Ok, so I have a 9X5 grid using a for loop

//columns 15 and rows 10.
int main()
{
int grid[10][15];
for(int i = 0;i < 10;i++) //row by 9.
{
for(int j =0;j < 15;j++) //columns by 5.
{
grid[j]='W';
}
}
return 0;
}

how can I use this to show the grid in the game?

expleo

  • Jr. Member
  • **
  • Posts: 57
  • Karma: +0/-0
    • View Profile
Re: Grid display
« Reply #3 on: March 09, 2014, 07:49:01 am »
Ho, Your code wont work as you try to put a char (W) into Your array defined as 'INT'. I have no idea what you are trying to accomplish, but the following code will do what you want, listing W's in a grid 9x15  (or reduce to 5, if the comment of 5 is correct as opposed to the code of 15: (Also please note the syntax for dragonfire SDK main sub)

//====================================================
// App.cpp
//====================================================
#include "DragonFireSDK.h"

int Font;


void DrawGrid(){ // NB B! Never Call this sub more than one time, as it contains textadd. If you need to do this many times, split the functions
   int locX=20;
   int lockY=20;

for(int j =0;j < 15;j++){ //columns by 5.
   for(int i = 0;i < 10;i++){ //row by 9.
      TextAdd(locX,lockY,"W",Font);
      locX+=10;
   }
   lockY+=10;
   locX=20;
}
}

void AppMain()
{
Font=FontAdd("Georgia","Regular",10,0x0000FF);
DrawGrid();
}

void AppExit()
{

}

void OnTimer()
{
    // Main loop code goes here.  OnTimer() is called 30 times per second.
}