// function that draws the screen void Draw_Map(int map_x_location, char map_array[12][MAP_SIZE], POSITION pos, POSITION laserPos, int laser, POSITION missilePos, int missile) { int x = map_x_location; int y = 0; // clear both planes SetPlane (LIGHT_PLANE); ClrScr(); SetPlane (DARK_PLANE); ClrScr(); // draw ship, and missiles and cannons if they exist drawShip(pos, map_x_location); if (laser) drawLaser(laserPos, map_x_location); if (missile == 1) drawMissile(missilePos, map_x_location); if (missile == -1) drawUpMissile(missilePos, map_x_location); // Well.. the map_x_location will keep track of where we are on the X-plane on the map array // This way we mask out the stuff in the array that we use.. So we will only read 20x12 elements of the // array (instead of MAP_SIZEx12 which it is at the moment.. ) while (x < (map_x_location + 20)) {// Again, we can't view more than 20 blocks.. so.. don't calculate more than 20 blocks if ((map_array[y][x] == 1)) { // If the array at this location is equal to 1, place a broken piece Sprite8((x - map_x_location) * 8, y * 8, 8, broken2_dark, GetPlane (DARK_PLANE), SPRT_XOR); Sprite8((x - map_x_location) * 8, y * 8, 8, broken2_light, GetPlane (LIGHT_PLANE), SPRT_XOR); } if ((map_array[y][x] == 2)) { // If the array at this location is equal to 1, place a broken piece Sprite8((x - map_x_location) * 8, y * 8, 8, broken1_dark, GetPlane (DARK_PLANE), SPRT_XOR); Sprite8((x - map_x_location) * 8, y * 8, 8, broken1_light, GetPlane (LIGHT_PLANE), SPRT_XOR); } if ((map_array[y][x] == 3)) { // .. and if it's 2, place block1 Sprite8((x - map_x_location) * 8, y * 8, 8, block1_dark, GetPlane (DARK_PLANE), SPRT_XOR); Sprite8((x - map_x_location) * 8, y * 8, 8, block1_light, GetPlane (LIGHT_PLANE), SPRT_XOR); } if ((map_array[y][x] == 4)) { // a 3 means the indestructible block Sprite8((x - map_x_location) * 8, y * 8, 8, solid1_light, GrayGetPlane(LIGHT_PLANE), SPRT_XOR); Sprite8((x - map_x_location) * 8, y * 8, 8, solid1_dark, GrayGetPlane(LIGHT_PLANE), SPRT_XOR); Sprite8((x - map_x_location) * 8, y * 8, 8, solid1_mid, GrayGetPlane(DARK_PLANE), SPRT_XOR); Sprite8((x - map_x_location) * 8, y * 8, 8, solid1_dark, GrayGetPlane(DARK_PLANE), SPRT_XOR); } y++; // Now.. we're increasing the Y value.. note that i'm drawing the world from LEFT to RIGHT // I've seen people who draw their world TOP to DOWN or otherwise, but i found LEFT to RIGHT // is the best way to draw the world.. if (y > 11) { // We've reached the limit.. restore the Y value, and move 1 block row forward.. y = 0; x++; } } }
static inline void RenderMaps(void *big_vscreen,void *dest) { short x=0,y=0,old_x=0,old_y=0,update=1; unsigned short i=0; do { // Affichage if(update) { RefreshGrayBuffer16B(20,&map[y>>4][x>>4],big_vscreen,sprts); update=0; } #ifndef USE_TI89 DrawGrayBufferWithShifts_RPLC(big_vscreen,x&15,y&15,dest,dh+((i>>3)&15),dv+((i>>3)&15)); #else DrawGrayBufferWithShifts89_RPLC(big_vscreen,x&15,y&15,dest,dh+((i>>3)&15),dv+((i>>3)&15)); #endif FastCopyScreen_R(dest,GrayGetPlane(LIGHT_PLANE)); FastCopyScreen_R(dest+LCD_SIZE,GrayGetPlane(DARK_PLANE)); /* memcpy(GrayGetPlane(LIGHT_PLANE),dest,LCD_SIZE); memcpy(GrayGetPlane(DARK_PLANE),dest+LCD_SIZE,LCD_SIZE); */ // Déplacement BEGIN_KEYTEST if(_keytest_optimized(RR_UP) && y>0) y--; if(_keytest_optimized(RR_DOWN) && y<12*16-HEIGHT-2) y++; if(_keytest_optimized(RR_LEFT) && x>0) x--; if(_keytest_optimized(RR_RIGHT) && x<19*16+11-WIDTH) x++; END_KEYTEST i++; update=(((x&16)^(old_x&16)) || ((y&16)^(old_y&16))); old_x=x;old_y=y; }while(!_keytest(RR_ESC)); }
void Draw_Map(int map_array[12][20], POSITION pos, POSITION laserPos, int laser, POSITION missilePos, int missile) { //int x = map_x_location; int x = 0; int y = 0; SetPlane (LIGHT_PLANE); ClrScr (); SetPlane (DARK_PLANE); ClrScr (); drawRType(pos); if (laser) drawLaser(laserPos); if (missile) drawMissile(missilePos); // Well.. the map_x_location will keep track of where we are on the X-plane on the map array // This way we mask out the stuff in the array that we use.. So we will only read 30x8 elements of the // array (instead of 60x8 which it is at the moment.. ).. This might sound unuseful, and it sort of is // with a small array as this one.. but i'm guessing you will create worlds that are much much bigger.. // so.. to gain more speed.. we mask it out ;) /*while (x<20) {// Again, we can't view more than 30 blocks.. so.. don't calculate more than 30 blocks if ((map_array[y][x]==7)) { // If the array at this location is equal to 1, place a ground piece Sprite8(x*8, y*8, 8, ground_down, GetPlane (DARK_PLANE), SPRT_XOR); Sprite8(x*8, y*8, 8, ground_down, GetPlane (LIGHT_PLANE), SPRT_XOR); } if ((map_array[y][x]==8)) { // .. and if it's 2, place block1 Sprite8(x*8, y*8, 8, ground_flat, GetPlane (DARK_PLANE), SPRT_XOR); Sprite8(x*8, y*8, 8, ground_flat, GetPlane (LIGHT_PLANE), SPRT_XOR); } if (map_array[y][x]==9) { Sprite8(x*8, y+8, 8, ground_up, GrayGetPlane(LIGHT_PLANE), SPRT_XOR); Sprite8(x*8, y+8, 8, ground_up, GrayGetPlane(DARK_PLANE), SPRT_XOR); } y++; // Now.. we're increasing the Y value.. note that i'm drawing the world from LEFT to RIGHT // I've seen people who draw their world TOP to DOWN or otherwise, but i found LEFT to RIGHT // is the best way to draw the world.. if (y>11) { // We've reached the limit.. restore the Y value, and move 1 block row forward.. y=0; x++; } }*/ for (x = 0; x <= 19; x++) { for (y = 0; y <= 11; y++) { if (map_array[y][x] == 7) { Sprite8(x*8, y*8, 8, ground_down, GrayGetPlane(DARK_PLANE), SPRT_XOR); Sprite8(x*8, y*8, 8, ground_down, GrayGetPlane(LIGHT_PLANE), SPRT_XOR); } else if (map_array[y][x] == 8) { Sprite8(x*8, y*8, 8, ground_flat, GrayGetPlane(DARK_PLANE), SPRT_XOR); Sprite8(x*8, y*8, 8, ground_flat, GrayGetPlane(LIGHT_PLANE), SPRT_XOR); } else if (map_array[y][x] == 9) { Sprite8(x*8, y*8, 8, ground_up, GrayGetPlane(DARK_PLANE), SPRT_XOR); Sprite8(x*8, y*8, 8, ground_up, GrayGetPlane(LIGHT_PLANE), SPRT_XOR); } } } }
// allocate and set up stuff void init() { // start the random number generator randomize(); // allocate our graphic buffers buffermem = malloc(LCD_WIDTH * LCD_HEIGHT * 2); // not enough RAM if (!buffermem) error(LC_MEMORY_ERROR_TEXT); lightbuffer = buffermem; darkbuffer = buffermem + LCD_WIDTH * LCD_HEIGHT; // quit if we can't switch to grayscale if (!GrayOn()) error(LC_GRAYSCALE_ERROR_TEXT); // clear the screen ClrScr(); // get the grayscale plane pointers lightplane = GrayGetPlane(LIGHT_PLANE); darkplane = GrayGetPlane(DARK_PLANE); }
inline void drawMissile(POSITION pos) { Sprite8(pos.x*8,pos.y*8,MISSILE_HT,missileLight,GrayGetPlane(LIGHT_PLANE),SPRT_XOR); //Sprite8((pos.x-map_x_location)*8,pos.y*8,MISSILE_HT,missileMid,GrayGetPlane(LIGHT_PLANE),SPRT_XOR); Sprite8(pos.x*8,pos.y*8,MISSILE_HT,missileMid,GrayGetPlane(DARK_PLANE),SPRT_XOR); //Sprite8((pos.x-map_x_location)*8,pos.y*8,MISSILE_HT,missileDark,GrayGetPlane(DARK_PLANE),SPRT_XOR); }
inline void drawRType(POSITION pos) { Sprite16(pos.x*8,pos.y*8,R_TYPE_HT,r_type_light,GrayGetPlane(LIGHT_PLANE),SPRT_XOR); Sprite16(pos.x*8,pos.y*8,R_TYPE_HT,r_type_dark,GrayGetPlane(LIGHT_PLANE),SPRT_XOR); Sprite16(pos.x*8,pos.y*8,R_TYPE_HT,r_type_mid,GrayGetPlane(DARK_PLANE),SPRT_XOR); Sprite16(pos.x*8,pos.y*8,R_TYPE_HT,r_type_dark,GrayGetPlane(DARK_PLANE),SPRT_XOR); }
inline void drawLaser(POSITION pos) { Sprite8(pos.x*8,pos.y*8,LASER_HT,laserLight,GrayGetPlane(LIGHT_PLANE),SPRT_XOR); Sprite8(pos.x*8,pos.y*8,LASER_HT,laserDark,GrayGetPlane(LIGHT_PLANE),SPRT_XOR); Sprite8(pos.x*8,pos.y*8,LASER_HT,laserMid,GrayGetPlane(DARK_PLANE),SPRT_XOR); Sprite8(pos.x*8,pos.y*8,LASER_HT,laserDark,GrayGetPlane(DARK_PLANE),SPRT_XOR); }
inline void drawUpMissile(POSITION pos, int map_x_location) { Sprite8((pos.x-map_x_location)*8,pos.y*8,MISSILE_HT,missileUpLight,GrayGetPlane(LIGHT_PLANE),SPRT_XOR); Sprite8((pos.x-map_x_location)*8,pos.y*8,MISSILE_HT,missileUpMid,GrayGetPlane(DARK_PLANE),SPRT_XOR); }
// same stuff for the other sprites inline void drawShip(POSITION pos, int map_x_location) { Sprite16((pos.x-map_x_location)*8,pos.y*8,SHIP_HT,ship_light,GrayGetPlane(LIGHT_PLANE),SPRT_XOR); Sprite16((pos.x-map_x_location)*8,pos.y*8,SHIP_HT,ship_dark,GrayGetPlane(LIGHT_PLANE),SPRT_XOR); Sprite16((pos.x-map_x_location)*8,pos.y*8,SHIP_HT,ship_mid,GrayGetPlane(DARK_PLANE),SPRT_XOR); Sprite16((pos.x-map_x_location)*8,pos.y*8,SHIP_HT,ship_dark,GrayGetPlane(DARK_PLANE),SPRT_XOR); }
// a function that draws the cannon on the screen inline void drawLaser(POSITION pos, int map_x_location) { Sprite8((pos.x-map_x_location)*8,pos.y*8,LASER_HT,laserLight,GrayGetPlane(LIGHT_PLANE),SPRT_XOR); Sprite8((pos.x-map_x_location)*8,pos.y*8,LASER_HT,laserDark,GrayGetPlane(LIGHT_PLANE),SPRT_XOR); Sprite8((pos.x-map_x_location)*8,pos.y*8,LASER_HT,laserMid,GrayGetPlane(DARK_PLANE),SPRT_XOR); Sprite8((pos.x-map_x_location)*8,pos.y*8,LASER_HT,laserDark,GrayGetPlane(DARK_PLANE),SPRT_XOR); }
// function to draw the pointer inline void drawPointer(POSITION pos) { Sprite8(pos.x,pos.y*15 + 20,8,pointer_sprite,GrayGetPlane(DARK_PLANE),SPRT_XOR); }
/*===========================================================================*/ void _main(void) { short i,j; unsigned long measure_val; char tmpstr[50] = "Measuring, please wait ..."; static const short modes[4] = {COLOR_LIGHTGRAY,COLOR_DARKGRAY,COLOR_BLACK,COLOR_WHITE}; unsigned short clippedcoord[4]; LCD_BUFFER screen; LCD_save(screen); OSFreeTimer(USER_TIMER); OSRegisterTimer(USER_TIMER,INITIAL_TIMER_VALUE); if (!GrayOn()) goto end; //--------------------------------------------------------------------- // built-in OS line drawing routine ... //--------------------------------------------------------------------- GrayClearScreen_R(); OSTimerRestart(USER_TIMER); for (j=0;j<4;j++) { short used_color = modes[j]; for (i=-40; i<280;i++) GrayDrawClipLine(120,64,i,-40,used_color); for (i=-40; i<168;i++) GrayDrawClipLine(120,64,280,i,used_color); for (i=280;i>=-40; i--) GrayDrawClipLine(120,64,i,168,used_color); for (i=168;i>=-40; i--) GrayDrawClipLine(120,64,-40,i,used_color); } measure_val = OSTimerCurVal(USER_TIMER); sprintf(tmpstr,"OS routine took %lu ticks",INITIAL_TIMER_VALUE-measure_val); GrayDrawRect(0,0,239,7,COLOR_WHITE,RECT_FILLED); GrayDrawStrExt(0,0,tmpstr,A_NORMAL | A_CENTERED | A_SHADOWED,F_4x6); if (ngetchx() == KEY_ESC) goto end; //--------------------------------------------------------------------- // new line drawing routine ... //--------------------------------------------------------------------- GrayClearScreen_R(); OSTimerRestart(USER_TIMER); for (j=0;j<4;j++) { short used_color = modes[j]; for (i=-40; i<280;i++) GrayClipDrawLine_R(120,64,i,-40,clippedcoord,used_color,GrayGetPlane(LIGHT_PLANE),GrayGetPlane(DARK_PLANE),GrayFastDrawLine2B_R); for (i=-40; i<280;i++) GrayClipDrawLine_R(120,64,280,i,clippedcoord,used_color,GrayGetPlane(LIGHT_PLANE),GrayGetPlane(DARK_PLANE),GrayFastDrawLine2B_R); for (i=280;i>=-40; i--) GrayClipDrawLine_R(120,64,i,168,clippedcoord,used_color,GrayGetPlane(LIGHT_PLANE),GrayGetPlane(DARK_PLANE),GrayFastDrawLine2B_R); for (i=168;i>=-40; i--) GrayClipDrawLine_R(120,64,-40,i,clippedcoord,used_color,GrayGetPlane(LIGHT_PLANE),GrayGetPlane(DARK_PLANE),GrayFastDrawLine2B_R); } measure_val = OSTimerCurVal(USER_TIMER); sprintf(tmpstr,"Own routine took %lu ticks",INITIAL_TIMER_VALUE-measure_val); GrayDrawRect(0,0,239,7,COLOR_WHITE,RECT_FILLED); GrayDrawStrExt(0,0,tmpstr,A_NORMAL | A_CENTERED | A_SHADOWED,F_4x6); if (ngetchx() == KEY_ESC) goto end; GrayOff(); ClrScr(); //--------------------------------------------------------------------- // built-in OS line drawing routine ... //--------------------------------------------------------------------- OSTimerRestart(USER_TIMER); for (j=0;j<4;j++) { WIN_RECT rect = {120, 64, 0, -40}; for (i=-40; i<280;i++) {rect.x1 = i; DrawClipLine(&rect,&(SCR_RECT){{0, 0, 239, 127}},A_XOR); } for (i=-40; i<168;i++) {rect.y1 = i; DrawClipLine(&rect,&(SCR_RECT){{0, 0, 239, 127}},A_XOR); } for (i=280;i>=-40; i--) {rect.x1 = i; DrawClipLine(&rect,&(SCR_RECT){{0, 0, 239, 127}},A_XOR); } for (i=168;i>=-40; i--) {rect.y1 = i; DrawClipLine(&rect,&(SCR_RECT){{0, 0, 239, 127}},A_XOR); } } measure_val = OSTimerCurVal(USER_TIMER); sprintf(tmpstr,"OS routine took %lu ticks",INITIAL_TIMER_VALUE-measure_val); GrayDrawRect2B(0,0,239,7,COLOR_WHITE,RECT_FILLED,LCD_MEM,LCD_MEM); GrayDrawStrExt2B(0,0,tmpstr,A_NORMAL | A_CENTERED,F_4x6,LCD_MEM,LCD_MEM); if (ngetchx() == KEY_ESC) goto end; //--------------------------------------------------------------------- // new line drawing routine ... //--------------------------------------------------------------------- ClrScr(); OSTimerRestart(USER_TIMER); for (j=0;j<4;j++) { for (i=-40; i<280;i++) ClipDrawLine_R(120,64,i,-40,clippedcoord,A_XOR,LCD_MEM,FastDrawLine_R); for (i=-40; i<280;i++) ClipDrawLine_R(120,64,280,i,clippedcoord,A_XOR,LCD_MEM,FastDrawLine_R); for (i=280;i>=-40; i--) ClipDrawLine_R(120,64,i,168,clippedcoord,A_XOR,LCD_MEM,FastDrawLine_R); for (i=168;i>=-40; i--) ClipDrawLine_R(120,64,-40,i,clippedcoord,A_XOR,LCD_MEM,FastDrawLine_R); } measure_val = OSTimerCurVal(USER_TIMER); sprintf(tmpstr,"Own routine took %lu ticks",INITIAL_TIMER_VALUE-measure_val); GrayDrawRect2B(0,0,239,7,COLOR_WHITE,RECT_FILLED,LCD_MEM,LCD_MEM); GrayDrawStrExt2B(0,0,tmpstr,A_NORMAL | A_CENTERED,F_4x6,LCD_MEM,LCD_MEM); ngetchx(); end: OSFreeTimer(USER_TIMER); GrayOff(); LCD_restore(screen); GKeyFlush(); ST_helpMsg(EXTGRAPH_VERSION_PWDSTR); }
/*===========================================================================*/ void _main(void) { short i,j; unsigned long measure_val; char tmpstr[50] = "Measuring, please wait ..."; short modes[4] = {COLOR_LIGHTGRAY,COLOR_DARKGRAY,COLOR_BLACK,COLOR_WHITE}; LCD_BUFFER screen; LCD_save(screen); if (!GrayOn()) return; OSFreeTimer(USER_TIMER); OSRegisterTimer(USER_TIMER,INITIAL_TIMER_VALUE); GrayClearScreen_R(); GrayDrawStrExt(0,0,tmpstr,A_REPLACE|A_CENTERED|A_SHADOWED,F_4x6); do { //--------------------------------------------------------------------- // built-in OS line drawing routine ... //--------------------------------------------------------------------- OSTimerRestart(USER_TIMER); for (j=0;j<4 && !kbhit();j++) { short used_color = modes[j]; for (i=0; i<160;i++) GrayDrawLine(80,50,i,8, used_color); for (i=8; i<100;i++) GrayDrawLine(80,50,159,i, used_color); for (i=159;i>=0; i--) GrayDrawLine(80,50,i,99, used_color); for (i=99; i>=8; i--) GrayDrawLine(80,50,0,i, used_color); } measure_val = OSTimerCurVal(USER_TIMER); sprintf(tmpstr,"OS routine took %lu ticks",INITIAL_TIMER_VALUE-measure_val); GrayDrawRect(0,0,239,7,COLOR_WHITE,RECT_FILLED); GrayDrawStrExt(0,0,tmpstr,A_REPLACE | A_CENTERED | A_SHADOWED,F_4x6); if (kbhit()) break; //--------------------------------------------------------------------- // new line drawing routine ... //--------------------------------------------------------------------- OSTimerRestart(USER_TIMER); for (j=0;j<4 && !kbhit();j++) { short used_color = modes[j]; for (i=0; i<160;i++) GrayFastDrawLine2B_R(GrayGetPlane(LIGHT_PLANE),GrayGetPlane(DARK_PLANE),80,50,i,8, used_color); for (i=8; i<100;i++) GrayFastDrawLine2B_R(GrayGetPlane(LIGHT_PLANE),GrayGetPlane(DARK_PLANE),80,50,159,i, used_color); for (i=159;i>=0; i--) GrayFastDrawLine2B_R(GrayGetPlane(LIGHT_PLANE),GrayGetPlane(DARK_PLANE),80,50,i,99, used_color); for (i=99; i>=8; i--) GrayFastDrawLine2B_R(GrayGetPlane(LIGHT_PLANE),GrayGetPlane(DARK_PLANE),80,50,0,i, used_color); } measure_val = OSTimerCurVal(USER_TIMER); sprintf(tmpstr,"Own routine took %lu ticks",INITIAL_TIMER_VALUE-measure_val); GrayDrawRect(0,0,239,8,COLOR_WHITE,RECT_FILLED); GrayDrawStrExt(0,0,tmpstr,A_REPLACE | A_CENTERED | A_SHADOWED,F_4x6); } while (!kbhit()); ngetchx(); OSFreeTimer(USER_TIMER); GrayOff(); LCD_restore(screen); GKeyFlush(); ST_helpMsg(EXTGRAPH_VERSION_PWDSTR); }