All pastes #96148 Raw Edit

Unnamed

public text v1 · immutable
#96148 ·published 2006-07-22 17:40 UTC
rendered paste body
#include "SDL.h"

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



int gameover;
int speedplayer1 = 1;


int world_camerax = 0;
int world_cameray = 0;


/* source and destination rectangles */
SDL_Rect rcSrc, rcSprite;



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}, } ;


void draw_tiles(SDL_Surface *screen){
SDL_Surface *tile[2];
   int x, y;
     int scroll_x, scroll_y;   // (NEW) 
  int offset_x, offset_y;   // (NEW) 


SDL_Rect rect; 

   SDL_Rect srcRect;

   for (y = 0; y < SCREEN_SIZEY; y++) 
  {
    for (x = 0; x < SCREEN_SIZEX; x++) 
    {
             scroll_x = (world_camerax / TILE_SIZE);  
      scroll_y = (world_cameray / TILE_SIZE);
      // (NEW)
      offset_x = scroll_x & (TILE_SIZE - 1);
      offset_y = scroll_y & (TILE_SIZE - 1);
         
          tile[map[WORLD_SIZEY][WORLD_SIZEX]];
          
          tile[1]   = SDL_LoadBMP("data//graphic//tile1.bmp");
          tile[2]   = SDL_LoadBMP("data//graphic//tile2.bmp");

          
      rect.x = x * TILE_SIZE; 
      rect.y = y * TILE_SIZE;
      rect.w = rect.h = TILE_SIZE;

SDL_BlitSurface( tile[2], &srcRect, screen, &rect ); 
}
   }
}