diff --git a/!TheEsc/!RunImage,ff8 b/!TheEsc/!RunImage,ff8 index 5a5f1ea..d241a35 100644 Binary files a/!TheEsc/!RunImage,ff8 and b/!TheEsc/!RunImage,ff8 differ diff --git a/!TheEsc/Makefile,fe1 b/!TheEsc/Makefile,fe1 index 72b35e4..65846c0 100644 --- a/!TheEsc/Makefile,fe1 +++ b/!TheEsc/Makefile,fe1 @@ -64,3 +64,6 @@ o.Mission1: c.Mission1 o.Mission1: h.Graphics o.Mission2: c.Mission2 o.Mission2: h.Graphics +o.Mission2: C:h.swis +o.Mission2: C:h.kernel +o.Mission2: C:h.kernel diff --git a/!TheEsc/Spr,ff9 b/!TheEsc/Spr,ff9 index fefda99..229141e 100644 Binary files a/!TheEsc/Spr,ff9 and b/!TheEsc/Spr,ff9 differ diff --git a/!TheEsc/Tiles,ff9 b/!TheEsc/Tiles,ff9 new file mode 100644 index 0000000..2ce8eb6 Binary files /dev/null and b/!TheEsc/Tiles,ff9 differ diff --git a/!TheEsc/c/CTheEscape b/!TheEsc/c/CTheEscape index 32c9722..0e38eb4 100644 --- a/!TheEsc/c/CTheEscape +++ b/!TheEsc/c/CTheEscape @@ -16,6 +16,8 @@ _kernel_swi_regs outreg; // Sprite buffer unsigned char *buffer; unsigned char *fontbuffer; +unsigned char *tilebuffer; + extern int screen; extern struct CompositionElement composition[128]; extern int current_element; @@ -50,8 +52,8 @@ int main(int argc, char *argv[]) screen_clear(); // Load sprite library - load_sprites("Spr"); - load_font("Font"); + load_sprites("Spr",&buffer); + load_sprites("Font",&fontbuffer); #ifndef SKIP_INTRO // Intro titles + music @@ -84,13 +86,15 @@ int main(int argc, char *argv[]) #ifndef SKIP_MISSION2 lastoutcome = 1; + load_sprites("Tiles",&tilebuffer); + // Mission 2 while(lastoutcome == 1) { outcome = 0; game2_briefing(); screen_clear(); - //game2_setup(); + game2_setup(); while(!outcome) { outcome = game2_tick(); diff --git a/!TheEsc/c/Graphics b/!TheEsc/c/Graphics index 6ccf123..948bc64 100644 --- a/!TheEsc/c/Graphics +++ b/!TheEsc/c/Graphics @@ -8,10 +8,12 @@ extern _kernel_swi_regs outreg; extern unsigned char *buffer; extern unsigned char *fontbuffer; +extern unsigned char *tilebuffer; + int screen = 1; // Loads sprite file into buffer -void load_sprites(char* filename) +void load_sprites(char* filename, unsigned char **buffername) { int length; @@ -38,74 +40,24 @@ void load_sprites(char* filename) } // Attempt malloc, die if we cant - buffer = (unsigned char *) malloc(length + 4); + *buffername = (unsigned char *) malloc(length + 4); - if(buffer==NULL) + if(buffername==NULL) { printf("Couldn't malloc %i bytes for sprite buffer",length); exit(0); } // Store size and other info as required for SpriteOp 9 to init sprite area - *(unsigned int *)buffer = length + 4; - *(unsigned int *)(buffer + 4) = 16; + *(unsigned int *)*buffername = length + 4; + *(unsigned int *)(*buffername + 4) = 16; inreg.r[0] = 256+9; - inreg.r[1] = (unsigned int) buffer; + inreg.r[1] = (unsigned int) *buffername; _kernel_swi(OS_SpriteOp,&inreg,&outreg); // Load sprite file into buffer inreg.r[0] = 256+10; - inreg.r[1] = (int) buffer; - inreg.r[2] = (int) filename; - _kernel_swi(OS_SpriteOp,&inreg,&outreg); -} - -// Loads sprite file into buffer -void load_font(char* filename) -{ - int length; - - // Attempt to get file info - inreg.r[0] = 13; - inreg.r[1] = (int) filename; - _kernel_swi(OS_File,&inreg,&outreg); - - // Length will be in R4 if it exists - length = outreg.r[4]; - - // If it's <1 it's fil not found - if(outreg.r[0] < 1) - { - printf("Sprite file %s not found",filename); - exit(0); - } - - // Stops us trying to mallocsomething mad if file is too big. - if(length > 200000) - { - printf("Sprite file %s seems unreasonably large at %i bytes",filename, length); - exit(0); - } - - // Attempt malloc, die if we cant - fontbuffer = (unsigned char *) malloc(length + 4); - - if(fontbuffer==NULL) - { - printf("Couldn't malloc %i bytes for sprite buffer",length); - exit(0); - } - - // Store size and other info as required for SpriteOp 9 to init sprite area - *(unsigned int *)fontbuffer = length + 4; - *(unsigned int *)(fontbuffer + 4) = 16; - inreg.r[0] = 256+9; - inreg.r[1] = (unsigned int) fontbuffer; - _kernel_swi(OS_SpriteOp,&inreg,&outreg); - - // Load sprite file into buffer - inreg.r[0] = 256+10; - inreg.r[1] = (int) fontbuffer; + inreg.r[1] = (int) *buffername; inreg.r[2] = (int) filename; _kernel_swi(OS_SpriteOp,&inreg,&outreg); } @@ -190,10 +142,21 @@ void draw_letter(char* spritename,int x, int y) inreg.r[2] = (int) spritename; inreg.r[3] = x; inreg.r[4] = y; - inreg.r[5] = 8; // GCOL dest=source and sprite mask + inreg.r[5] = 8; _kernel_swi(OS_SpriteOp,&inreg,&outreg); } +void draw_tile(char* spritename,int x, int y) +{ + // SpriteOp 34 to put sprite at a location + inreg.r[0] = 256+34; + inreg.r[1] = (int) tilebuffer; + inreg.r[2] = (int) spritename; + inreg.r[3] = x; + inreg.r[4] = y; + inreg.r[5] = 0; + _kernel_swi(OS_SpriteOp,&inreg,&outreg); +} void draw_spritetext(char* text, int x, int y) { @@ -214,9 +177,9 @@ void draw_spritetext(char* text, int x, int y) { case 't': case 'i': - case 'y': case '.': case ',': + case 'y': currentx += 12 + 4; break; case '\'': @@ -318,6 +281,23 @@ void screen_flipbuffer() } +void screen_nobuffer() +{ + // Hardware + inreg.r[0] = 113; + inreg.r[1] = 1; + _kernel_swi(OS_Byte,&inreg,&outreg); + + // Drivers + inreg.r[0] = 112; + inreg.r[1] = 1; + _kernel_swi(OS_Byte,&inreg,&outreg); + + inreg.r[0] = 19; + _kernel_swi(OS_Byte,&inreg,&outreg); + +} + void screen_clear() { inreg.r[0] = 12; diff --git a/!TheEsc/c/Mission1 b/!TheEsc/c/Mission1 index 48e5416..0bb1317 100644 --- a/!TheEsc/c/Mission1 +++ b/!TheEsc/c/Mission1 @@ -1006,7 +1006,7 @@ void game1_victory() screen_clear(); draw_spritetext( -"~~~~~~~~{ chief engineers log - uss archimedes - stardate 1234567890 ==}\n\n\nour shuttlepod has been rescued by the uss archimedes - but our \njob here isn't done. the archimedes is now under attack from the \ndurnovarians, and recoverying the shuttle has come at a cost. \nSeveral major systems are now offline.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n~~~~~~~~{======================~~~~~~~~===========================}" +"~~~~~~~~{ chief engineers log - uss archimedes - stardate 1234567890 ==}\n\n\nour shuttlepod has been rescued by the uss archimedes - but our \njob here isn't done. the archimedes is now under attack from the \ndurnovarians, and recoverying the shuttle has come at a cost. \nseveral major systems are now offline.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n~~~~~~~~{======================~~~~~~~~===========================}" , 50, 950); draw_sprite("spacebar",(DISPLAY_X/2)-106,50); @@ -1060,7 +1060,7 @@ int game1_tick() PROFILE(game_draw_player()); PROFILE(game_draw_npcs()); PROFILE(game_draw_projectiles()); - game_draw_comms("Shuttlepod Phoebe - this is the USS Archimedes.\nPower down your engines and stand by for\nimmediate tractor beam recovery."); + game_draw_comms("shuttlepod phoebe - this is the USS Archimedes.\npower down your engines and stand by for\nimmediate tractor beam recovery."); return 0; } else if(Player.integrity > 0) diff --git a/!TheEsc/c/Mission2 b/!TheEsc/c/Mission2 index 4fa3bdd..a944958 100644 --- a/!TheEsc/c/Mission2 +++ b/!TheEsc/c/Mission2 @@ -1,10 +1,60 @@ #include "Graphics.h" - -//#defene PROFILE(X) lastprofile = clock(); X; printf("\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t%s %i\n", #X, (clock() - lastprofile)) -#define PROFILE(X) X +#include "swis.h" +#include extern int tick; extern int lasttick; +extern int screen; + +extern _kernel_swi_regs inreg; +extern _kernel_swi_regs outreg; + + +#define TILESX 10 +#define TILESY 10 + +// map[0] is the 'master', [1] and [2] represents what is currently +// believed to be displayed in the corresponding (+1) screen buffer +// and we run a compare to see if re-drawing is needed. 0xFF is used +// for a re-draw being required (so it's set on the tile under the player +unsigned char map[3][TILESX][TILESY]; + +char tilenamebuffer[4]; +char textbuffer[63]; + +struct EntityLocation_s { + short signed int X,Y; +}; + +struct TilePlayer_s { + struct EntityLocation_s location; + struct EntityLocation_s hitbox_bl; + struct EntityLocation_s hitbox_tr; +}; + +struct TilePlayer_s TilePlayer; + +void game2_loadmap(char* filename) +{ + int length; + + // Attempt to get file info + inreg.r[0] = 13; + inreg.r[1] = (int) filename; + _kernel_swi(OS_File,&inreg,&outreg); + + // Length will be in R4 if it exists + length = outreg.r[4]; + + // Attempt to get file info + inreg.r[0] = 16; + inreg.r[1] = (int) filename; + inreg.r[2] = (int) map[0]; + inreg.r[3] = 0; + + _kernel_swi(OS_File,&inreg,&outreg); + +} void game2_death() { @@ -77,7 +127,7 @@ void game2_briefing() screen_clear(); draw_spritetext( -"~~~~~~~~{ chief engineers log - uss archimedes - stardate 1234567890 ==}\n\n\nYour mission is to be dead until I make mission 2. \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n~~~~~~~~{======================~~~~~~~~===========================}" +"~~~~~~~~{ chief engineers log - uss archimedes - stardate 1234567890 ==}\n\n\nyour mission is to be dead until i make mission 2. \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n~~~~~~~~{======================~~~~~~~~===========================}" , 50, 950); draw_sprite("spacebar",(DISPLAY_X/2)-106,50); @@ -95,23 +145,112 @@ void game2_briefing() } } +void game2_setup() +{ + screen_flipbuffer(); + screen_clear(); + screen_flipbuffer(); + screen_clear(); + TilePlayer.location.X = 0; + TilePlayer.location.Y = 0; + TilePlayer.hitbox_bl.X = 0; + TilePlayer.hitbox_bl.Y = 0; + TilePlayer.hitbox_tr.X = 60; + TilePlayer.hitbox_tr.Y = 50; + game2_loadmap("map"); +} + +void game2_tick_input() +{ + int x,y; + // Up arrow + if(input_readkey(57)) + { + TilePlayer.location.Y += 1 * (tick - lasttick); + } + + // Down arrow + if(input_readkey(41)) + { + TilePlayer.location.Y -= 1 * (tick - lasttick); + } + + // Right arrow + if(input_readkey(121)) + { + TilePlayer.location.X += 1 * (tick - lasttick); + } + + // Left arrow + if(input_readkey(25)) + { + TilePlayer.location.X -= 1 * (tick - lasttick); + } + + // Q + if(input_readkey(16)) + { + for(x = 0; x < TILESX; x++) + { + for(y = 0; y < TILESY; y++) + { + map[0][x][y] = 1; + } + } + } +} + int game2_tick() { + int x; + int y; + int udt = 0; lasttick = tick; tick = clock(); screen_flipbuffer(); - screen_clear(); - if(0) + if(1) { + for(x = 0; x < TILESX; x++) + { + for(y = 0; y < TILESY; y++) + { + if(game_hitbox_collide( + (TilePlayer.location.X + TilePlayer.hitbox_bl.X),(TilePlayer.location.Y + TilePlayer.hitbox_bl.Y), + (TilePlayer.hitbox_tr.X - TilePlayer.hitbox_bl.X),(TilePlayer.hitbox_tr.Y - TilePlayer.hitbox_bl.Y), + x*100,y*100, + 100,100 + )) + { + map[1][x][y] = 255; + map[2][x][y] = 255; + } + + if(map[0][x][y] ^ map[screen+1][x][y]) + { + map[screen+1][x][y] = map[0][x][y]; + sprintf(tilenamebuffer,"%i",map[screen+1][x][y]); + draw_tile(tilenamebuffer,x*100,y*100); + udt++; + } + } + + //draw_sprite("lcarsblack",1000,DISPLAY_Y-164); + + //sprintf(textbuffer,"CPF: %i\nUDT: %i",(tick-lasttick), udt); + //draw_spritetext(textbuffer, 1070, 950); + } + + game2_tick_input(); + + draw_sprite("man",TilePlayer.location.X,TilePlayer.location.Y); + return 0; }else{ - screen_flipbuffer(); +/* screen_flipbuffer(); screen_clear(); game2_death(); - return 1; + return 1;*/ } - - } diff --git a/!TheEsc/map,ffd b/!TheEsc/map,ffd new file mode 100644 index 0000000..79ad115 Binary files /dev/null and b/!TheEsc/map,ffd differ