root/object.c

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

DEFINITIONS

This source file includes following definitions.
  1. newobject
  2. deleteobject
  3. putobject

   1 /* object.c */
   2 #include<string.h>
   3 #include<stdlib.h>
   4 #include<screen.h>
   5 #include<object.h>
   6 
   7 object* newobject(int w, int h, char* shape){
   8   int i;
   9   char* tmp;
  10   object* ret = (object*)malloc(sizeof(object));
  11   ret->size.x = w;
  12   ret->size.y = h;
  13   ret->shape = (char*)malloc(sizeof(char)*w*h);
  14   strncpy(ret->shape, shape, w*h);
  15   return ret;
  16 }
  17 
  18 void deleteobject(object* obj){
  19   free(obj->shape);
  20   free(obj);
  21 }
  22 
  23 void putobject(object* obj, int id, int x, int y){
  24   int i,j;
  25   int w = obj->size.x;
  26   int h = obj->size.y;
  27   for(i=0;i<h;i++){
  28     for(j=0;j<w;j++){
  29       if(obj->shape[i*w+j] != ' '){ 
  30         putdata(x+j, y+i, obj->shape[i*w+j],(unsigned char)id);
  31       }
  32     }
  33   }
  34 }

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