Advertisement

Help on my basic tile engine

Started by December 12, 2000 08:29 PM
2 comments, last by jim bob 24 years ago
Hello again. I read the tuts on Tiling in DirectX. Well, I still need a bit more help on DirectX and Windows with that. So any help is greatly appreciated. This is just copy and pasted from the tutorial. I am using VC++ compiler, C++ language, and I have included ddraw.lib and winmm.lib. I also have included windows.h, windowsx.h, and ddraw.h to my project.
  

//-----INCLUDES-----//

#include <ddraw.h>
#include <windows.h>
#include <windowsx.h>

//-----DEFINES-----//

#define TILE_SIZE       32
#define WORLD_SIZEX     20
#define WORLD_SIZEY     20
#define SCREEN_SIZEX    12
#define SCREEN_SIZEY    12
#define WINDOWS_LEAN_AND_MEAN

//-----GLOBALS-----//

int world_camerax = 0;
int world_cameray = 0;

//-----MAP-----//

char map[WORLD_SIZEY][WORLD_SIZEX] = {
     {2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2},
     {2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2},
     {2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2},
     {2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2},
     {2, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 2},
     {2, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 2},
     {2, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 2},
     {2, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 2},
     {2, 1, 1, 2, 2, 2, 2, 2, 2, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 2},
     {2, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2},
     {2, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2},
     {2, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 2},
     {2, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 2},
     {2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2},
     {2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2},
     {2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2},
     {2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2},
     {2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2},
     {2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2},
     {2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2}, };

//-----DRAWING-----//

void draw_tiles(void)
{
  int tile;
  int x, y;
  int scroll_x, scroll_y;   // (NEW) 

  int offset_x, offset_y;   // (NEW) 



  RECT tile_src;

for (y = 0; y < SCREEN_SIZEY; y++) 
  {
    for (x = 0; x < SCREEN_SIZEX; x++) 
    { 
      // (NEW)

      scroll_x = x + (world_camerax / TILE_SIZE);  
      scroll_y = y + (world_cameray / TILE_SIZE);

      // (NEW)

      offset_x = world_camerax & (TILE_SIZE - 1);
      offset_y = world_cameray & (TILE_SIZE - 1);

      tile = map[scroll_y][scroll_x];

tile_src.left    =  (tile - 1) * TILE_SIZE;
      tile_src.top     =  0;
      tile_src.right   =  tile * TILE_SIZE;
      tile_src.bottom  =  TILE_SIZE;

// (MODIFIED)

      BltFast((x * TILE_SIZE) - offset_x, (y * TILE_SIZE) - offset_y, lpddsoffscreen, &tile_src, NULL);	

    }
  }
}

//-----ADD STUFF HERE????-----//


  
Thanks to Martin Estevao for that code. Is that code correct in how I put it together? If not, what is wrong? Also, the main thing I need to know is how to set up my Game_Main() with Windows and DirectX to draw my map. Can someone show me what code I need to add/change to just make a basic engine that will display 2 different tile in whatever pattern I want onto the main window? I thank you very much. I am not worthy of a sig!
I am not worthy of a sig! ;)
Oooohhhh, Ok, I get it. Thanks a lot guys, the help was really appreciated.

I am not worthy of a sig!
I am not worthy of a sig! ;)
Advertisement
quote: Original post by jim bob


Thanks to Martin Estevao for that code. Is that code correct in how I put it together? If not, what is wrong?


That is a question that only you can answer properly. Try compiling it and running it and see what happens! If it doesn't work then let us know what went wrong. It looks ok to a general glance but I think that you need a surface to do BltFast(). ie
 destSurface->BltFast(...) 


quote:
Also, the main thing I need to know is how to set up my Game_Main() with Windows and DirectX to draw my map.


You place you Game_Main() inside the windows loop that looks at the messages. Take a look at an article here on GameDev for an example.


quote:
Can someone show me what code I need to add/change to just make a basic engine that will display 2 different tile in whatever pattern I want onto the main window? I thank you very much.


Not sure what you mean here. You can change your map array to have any pattern that you want.

Try looking at CDX's map class. It shows how to do smooth scrolling and stuff.









-------
Andrew

Edited by - acraig on December 13, 2000 4:33:09 PM
Ahhh, yes, ok. I will check that out. Thank you very much Andy.

I am not worthy of a sig!
I am not worthy of a sig! ;)

This topic is closed to new replies.

Advertisement