root/screen.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. initscreen
  2. putdata
  3. checkcollision

   1 /* screen.c */
   2 
   3 #include<stdlib.h>
   4 #include<screen.h>
   5 #include<vector2.h>
   6 #include<object.h>
   7 
   8 const unsigned char NONOBJ = 255;
   9 const unsigned char WALL = 254;
  10 const unsigned char BORDER = 253;
  11 
  12 unsigned char* dispbuffer; 
  13 unsigned char* checkbuffer;
  14 
  15 void initscreen(void){
  16   dispbuffer = (unsigned char*)malloc(sizeof(unsigned char)*
  17                              SCREENWIDTH*SCREENHEIGHT);
  18   checkbuffer = (unsigned char*)malloc(sizeof(unsigned char)*
  19                                        SCREENWIDTH*SCREENHEIGHT);
  20   
  21 }
  22 
  23 void putdata(int x, int y, unsigned char d, unsigned char c){
  24   if(0<=x&&x<SCREENWIDTH && 0<=y && y<SCREENHEIGHT){ 
  25     dispbuffer[SCREENWIDTH*y+x]=d;
  26     checkbuffer[SCREENWIDTH*y+x]=c;
  27   }
  28 }
  29 
  30 unsigned char checkcollision(vector2 pos, object* obj){
  31   int x,y;
  32   unsigned char id;
  33   for(y=0;y<obj->size.y;y++){
  34     for(x=0;x<obj->size.x;x++){
  35       if(obj->shape[(int)(obj->size.x)*y+x] !=' '){
  36         id = checkbuffer[SCREENWIDTH*((int)(pos.y)+y)+(int)(pos.x)+x];
  37         if(id !=NONOBJ){
  38           return id;
  39         }
  40       }
  41     }
  42   }
  43   return NONOBJ;
  44 }

/* [<][>][^][v][top][bottom][index][help] */