Created
October 26, 2020 02:30
-
-
Save cobalthex/8efd080355444d60377da2e1d95b8d73 to your computer and use it in GitHub Desktop.
Pillars (old old old crusty shit)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //headers for fake music (to disable it) | |
| typedef struct { } Mix_Music; | |
| int Mix_PlayMusic(void* dat, int n) { return 0; } | |
| Mix_Music* Mix_LoadMUS(char* s) { return 0; } | |
| int Mix_GetError() { return 0; } | |
| int Mix_FadeOutMusic(int n) { return 0; } | |
| int Mix_FadeInMusic(void* d, int nn, int n) { return 0; } | |
| int Mix_PlayingMusic() { return 0; } | |
| int Mix_CloseAudio() { return 0; } | |
| #pragma comment(lib, "SDL.lib") | |
| #pragma comment(lib, "SDLmain.lib") | |
| //Pillars -- By Matt H. and Ryan O. | |
| //some inclusions | |
| #include <ctime> | |
| #include <SDL12/SDL.h> | |
| // #include <SDL/SDL_mixer.h> | |
| #include <cmath> | |
| #include <vector> | |
| //our images | |
| #include "PS.h" | |
| #include "LOGO.h" | |
| #include "HPBAR.h" | |
| #include "FONT.h" | |
| //all of the maps | |
| #include "MAP.h" | |
| //define all the screen stuff for later | |
| #define WIDTH 320 | |
| #define HEIGHT 240 | |
| #define COLOR_DEPTH 32 | |
| //some other definitions | |
| #define INTRO_LENGTH 1024 //length of intro | |
| #define CREDITS "PICWIN STUDIOS" //credits txt | |
| const short sinTbl[] = {0,1,1,2,3,4,5,5,6,6,6,7,7,7,7,6,6,6,5,5,4,3,2,1,1}; //pre-calc'd sine table | |
| //create the screen, sprites, and our surfaces | |
| SDL_Surface* screen; | |
| SDL_Surface* sprites; | |
| SDL_Surface* icon; | |
| //a global color | |
| int Col[3] = {0,64,128}; | |
| //allow for events | |
| SDL_Event event = {0}; | |
| //our game data file | |
| FILE * gameFile; | |
| //scores | |
| //game variables | |
| long Score = 0, Top = 0; | |
| int sShots = 0, lvl = 0, ticker = 0, lives = 3, x = 0, y = 0, dir = 0; | |
| int map[9][9]; //current map being used | |
| //option menu varibales (clicked is so we dont accidentally click 2 buttons at the same time) | |
| bool sound=true,fullscreen=false,music=true,cursor=true,clicked=false; | |
| //all of the prototypes | |
| void end(); | |
| void redrawBG(); | |
| void update(); | |
| void create_Window(); | |
| void showMouse(bool fullscreen); | |
| void drawdot(int x, int y, int R, int G, int B); | |
| void drawline(int x1, int y1, int x2, int y2, int R, int G, int B); | |
| void drawtext(int x, int y, char* text); | |
| void drawscore(int x, int y, int score); | |
| void resetmap(); | |
| int saveGame(); | |
| void loadGame(); | |
| void dropBomb(int x, int y); | |
| class sprite | |
| { | |
| //make sure anything else can access it | |
| public: | |
| //two classes to hold the rect data | |
| SDL_Rect rect; | |
| SDL_Rect position; | |
| //define the sheet (to allow it to draw) | |
| SDL_Surface *sheet; | |
| //a constructor | |
| void drawsprite(int x, int y); | |
| }; | |
| //create a class for the enemies | |
| class enemy | |
| { | |
| public: | |
| //some data | |
| int x, y, dir; | |
| bool alive; | |
| //a constructor | |
| enemy(); | |
| }; | |
| //the program | |
| int main(int argc, char *argv[]) | |
| { | |
| //create the window | |
| create_Window(); | |
| //open the sound mixer | |
| /*if (Mix_OpenAudio(44100, 16, 2, 1656)) | |
| { | |
| fprintf(stderr, "Unable to open audio!\n"); | |
| }*/ | |
| //allow for us to draw on our buffer | |
| sprites = SDL_CreateRGBSurface(SDL_HWSURFACE, screen->w, screen->h, screen->format->BitsPerPixel, | |
| screen->format->Rmask, screen->format->Gmask, screen->format->Bmask, screen->format->Amask); | |
| //draw the sprites pixel by pixel | |
| for (int iX = 0; iX <= PS_WIDTH * PS_HEIGHT; iX++) | |
| { | |
| //set the RGB for the font and sprites | |
| int SPRB = ((Uint32)PS[iX] / 65536) % 256; | |
| int SPRG = ((Uint32)PS[iX] / 256) % 256; | |
| int SPRR = (Uint32)PS[iX] % 256; | |
| //create the x and y | |
| int XX = (iX % PS_WIDTH), YY = (iX / PS_WIDTH); | |
| // printf("%d, %d: %d %d %d\n", XX, YY, SPRR, SPRG, SPRB); | |
| //draw the image | |
| ((unsigned int*)sprites->pixels)[YY * sprites->pitch / 4 + XX] = SDL_MapRGB(sprites->format, SPRR, SPRG, SPRB); | |
| } | |
| //draw the font pixel by pixel | |
| for (int iX = 0; iX <= FT_WIDTH * FT_HEIGHT; iX++) | |
| { | |
| //set the RGB | |
| int FNTB = ((Uint32)FT[iX] / 65536) % 256; | |
| int FNTG = ((Uint32)FT[iX] / 256) % 256; | |
| int FNTR = (Uint32)FT[iX] % 256; | |
| int XX = (iX % FT_WIDTH) + 160, YY = iX / FT_WIDTH; | |
| ((unsigned int*)sprites->pixels)[YY * sprites->pitch / 4 + XX] = SDL_MapRGB(sprites->format, FNTR, FNTG, FNTB); | |
| } | |
| //load the logo | |
| for (int iX = 0; iX <= LOGO_WIDTH * LOGO_HEIGHT; iX++) | |
| { | |
| //set the RGB | |
| int LOGB = ((Uint32)LOGO[iX] / 65536) % 256; | |
| int LOGG = ((Uint32)LOGO[iX] / 256) % 256; | |
| int LOGR = (Uint32)LOGO[iX] % 256; | |
| int XX = (iX % LOGO_WIDTH) + 150, YY = (iX / LOGO_WIDTH) + 180; | |
| ((unsigned int*)sprites->pixels)[YY * sprites->pitch / 4 + XX] = SDL_MapRGB(sprites->format, LOGR, LOGG, LOGB); | |
| } | |
| //load the HP bar | |
| for (int iX = 0; iX <= HPBAR_WIDTH * HPBAR_HEIGHT; iX++) | |
| { | |
| //set the RGB | |
| int HPB = ((Uint32)HPBAR[iX] / 65536) % 256; | |
| int HPG = ((Uint32)HPBAR[iX] / 256) % 256; | |
| int HPR = (Uint32)HPBAR[iX] % 256; | |
| int XX = (iX % HPBAR_WIDTH) + 60, YY = iX / HPBAR_WIDTH; | |
| ((unsigned int*)sprites->pixels)[YY * sprites->pitch / 4 + XX] = SDL_MapRGB(sprites->format, HPR, HPG, HPB); | |
| } | |
| //color key the surfaces | |
| SDL_SetColorKey(sprites, SDL_SRCCOLORKEY, SDL_MapRGB(sprites->format, 0xFF, 0x00, 0xFF)); | |
| drawtext(120, 115, "*LOADING*"); //show loading text | |
| //sprite test | |
| //SDL_FillRect(screen, &screen->clip_rect, 0xff00ff); | |
| //SDL_BlitSurface(sprites, 0, screen, 0); | |
| update(); //update the screen | |
| //rects for the logo | |
| SDL_Rect logoPos; | |
| SDL_Rect logoRect; | |
| logoRect.x = 150; | |
| logoRect.y = 180; | |
| logoRect.w = LOGO_WIDTH; | |
| logoRect.h = LOGO_HEIGHT; | |
| //position of the logo | |
| logoPos.x = 84; | |
| logoPos.y = -80; | |
| //health bar | |
| SDL_Rect Health_cRect; //filled | |
| SDL_Rect Health_cRect2; //unfilled | |
| SDL_Rect Health_dRect; //where to draw | |
| Health_cRect.x = 60; | |
| Health_cRect.y = 0; | |
| Health_cRect.w = 64; | |
| Health_cRect.h = 14; | |
| Health_cRect2.x = 60; | |
| Health_cRect2.y = 14; | |
| Health_cRect2.w = 64; | |
| Health_cRect2.h = 14; | |
| Health_dRect.x = 236; | |
| Health_dRect.y = 90; | |
| //define the sprite classes | |
| sprite bluesprite; | |
| sprite bluesprite1; | |
| sprite bluesprite2; | |
| sprite bluesprite3; | |
| sprite greensprite; | |
| sprite greensprite1; | |
| sprite greensprite2; | |
| sprite greensprite3; | |
| sprite top; | |
| sprite score; | |
| sprite greenbull1; | |
| sprite greenbull2; | |
| sprite greenbull3; | |
| sprite bluebull1; | |
| sprite bluebull2; | |
| sprite bluebull3; | |
| sprite redbull1; | |
| sprite redbull2; | |
| sprite redbull3; | |
| sprite rubble; | |
| sprite greenbull0; | |
| sprite bluebull0; | |
| sprite redbull0; | |
| sprite pillar; | |
| sprite hole; | |
| sprite pointer1; | |
| sprite pointer2; | |
| sprite pointer3; | |
| sprite bomb; | |
| sprite nuke1; | |
| sprite nuke2; | |
| sprite battery; | |
| //bluesprite settings | |
| bluesprite.rect.x=7; | |
| bluesprite.rect.y=148; | |
| bluesprite.rect.w=21; | |
| bluesprite.rect.h=21; | |
| bluesprite1.rect.x=29; | |
| bluesprite1.rect.y=148; | |
| bluesprite1.rect.w=21; | |
| bluesprite1.rect.h=21; | |
| bluesprite2.rect.x=7; | |
| bluesprite2.rect.y=170; | |
| bluesprite2.rect.w=21; | |
| bluesprite2.rect.h=21; | |
| bluesprite3.rect.x=29; | |
| bluesprite3.rect.y=170; | |
| bluesprite3.rect.w=21; | |
| bluesprite3.rect.h=21; | |
| //greensprite | |
| greensprite.rect.x=7; | |
| greensprite.rect.y=193; | |
| greensprite.rect.w=21; | |
| greensprite.rect.h=21; | |
| greensprite1.rect.x=29; | |
| greensprite1.rect.y=193; | |
| greensprite1.rect.w=21; | |
| greensprite1.rect.h=21; | |
| greensprite2.rect.x=7; | |
| greensprite2.rect.y=215; | |
| greensprite2.rect.w=21; | |
| greensprite2.rect.h=21; | |
| greensprite3.rect.x=29; | |
| greensprite3.rect.y=215; | |
| greensprite3.rect.w=21; | |
| greensprite3.rect.h=21; | |
| //'top' | |
| top.rect.x=0; | |
| top.rect.y=0; | |
| top.rect.w=56; | |
| top.rect.h=19; | |
| //score | |
| score.rect.x=0; | |
| score.rect.y=20; | |
| score.rect.w=56; | |
| score.rect.h=19; | |
| //green bullet: furthest left | |
| greenbull1.rect.x=0; | |
| greenbull1.rect.y=72; | |
| greenbull1.rect.w=16; | |
| greenbull1.rect.h=16; | |
| //green bullet: middle | |
| greenbull2.rect.x=16; | |
| greenbull2.rect.y=72; | |
| greenbull2.rect.w=16; | |
| greenbull2.rect.h=16; | |
| //green bullet: furthest right | |
| greenbull3.rect.x=32; | |
| greenbull3.rect.y=72; | |
| greenbull3.rect.w=16; | |
| greenbull3.rect.h=16; | |
| //blue bullet: furthest left | |
| bluebull1.rect.x=0; | |
| bluebull1.rect.y=56; | |
| bluebull1.rect.w=16; | |
| bluebull1.rect.h=16; | |
| //blue bullet: middle | |
| bluebull2.rect.x=16; | |
| bluebull2.rect.y=56; | |
| bluebull2.rect.w=16; | |
| bluebull2.rect.h=16; | |
| //blue bullet: furthest right | |
| bluebull3.rect.x=32; | |
| bluebull3.rect.y=56; | |
| bluebull3.rect.w=16; | |
| bluebull3.rect.h=16; | |
| //red bullet: furthest left | |
| redbull1.rect.x=0; | |
| redbull1.rect.y=40; | |
| redbull1.rect.w=16; | |
| redbull1.rect.h=16; | |
| //red bullet: middle | |
| redbull2.rect.x=16; | |
| redbull2.rect.y=40; | |
| redbull2.rect.w=16; | |
| redbull2.rect.h=16; | |
| //red bullet: furthest right | |
| redbull3.rect.x=32; | |
| redbull3.rect.y=40; | |
| redbull3.rect.w=16; | |
| redbull3.rect.h=16; | |
| //original bullets | |
| redbull0.rect.x=23; | |
| redbull0.rect.y=93; | |
| redbull0.rect.w=9; | |
| redbull0.rect.h=9; | |
| greenbull0.rect.x=33; | |
| greenbull0.rect.y=93; | |
| greenbull0.rect.w=9; | |
| greenbull0.rect.h=9; | |
| bluebull0.rect.x=43; | |
| bluebull0.rect.y=93; | |
| bluebull0.rect.w=9; | |
| bluebull0.rect.h=9; | |
| //rubble | |
| rubble.rect.x=0; | |
| rubble.rect.y=88; | |
| rubble.rect.w=17; | |
| rubble.rect.h=19; | |
| //pillar and hole | |
| pillar.rect.x=0; | |
| pillar.rect.y=108; | |
| pillar.rect.w=23; | |
| pillar.rect.h=23; | |
| hole.rect.x=24; | |
| hole.rect.y=108; | |
| hole.rect.w=23; | |
| hole.rect.h=23; | |
| //pointers (no, not the * and & crap) | |
| pointer1.rect.x=48; | |
| pointer1.rect.y=111; | |
| pointer1.rect.w=8; | |
| pointer1.rect.h=3; | |
| pointer2.rect.x=48; | |
| pointer2.rect.y=116; | |
| pointer2.rect.w=8; | |
| pointer2.rect.h=5; | |
| pointer3.rect.x=48; | |
| pointer3.rect.y=122; | |
| pointer3.rect.w=8; | |
| pointer3.rect.h=7; | |
| //bomb | |
| bomb.rect.x=39; | |
| bomb.rect.y=132; | |
| bomb.rect.w=11; | |
| bomb.rect.h=15; | |
| //nukes | |
| nuke1.rect.x=17; | |
| nuke1.rect.y=132; | |
| nuke1.rect.w=9; | |
| nuke1.rect.h=9; | |
| nuke2.rect.x=28; | |
| nuke2.rect.y=132; | |
| nuke2.rect.w=9; | |
| nuke2.rect.h=9; | |
| //battery | |
| battery.rect.x=1; | |
| battery.rect.y=132; | |
| battery.rect.w=14; | |
| battery.rect.h=8; | |
| //set what page we're on | |
| char* page = "Intro"; | |
| char* prevpage = "Menu"; | |
| //create a temp var for the intro, 2x the size needed so no fuckups | |
| char* tmpTxt = new char[56]; | |
| //create 2 temp rects to hold positions for players and other pieces on the screen in intro | |
| SDL_Rect bluePos; | |
| bluePos.x = -16; | |
| bluePos.y = 187; | |
| SDL_Rect greenPos; | |
| greenPos.x = -48; | |
| greenPos.y = 187; | |
| //make sure that the key is correctly released | |
| int keypress = 0; | |
| //some positions | |
| int blockx = 0, blocky = 0; | |
| //create a timer for the messages | |
| int msgDelay = 0; | |
| //create a message | |
| char* msg; | |
| //create a timer | |
| int timer = 1500; | |
| //some temp integers for the credits | |
| int credI[] = {240,280,320,360,400,440,480,520,560}; | |
| //create an intro var to hold where we are in the intro | |
| int intro = 0; | |
| //load up the sounds/music | |
| Mix_Music * mainSong = Mix_LoadMUS("Song"); //main song | |
| Mix_Music * PWSSnd = Mix_LoadMUS("PWS"); //pws intro | |
| Mix_Music * pfallSnd = Mix_LoadMUS("PFall"); //when u push over a pillar play this | |
| Mix_Music * explSnd = Mix_LoadMUS("Expl"); //explosion sound | |
| //errors? | |
| if (!mainSong || !PWSSnd || !pfallSnd || !explSnd) | |
| { | |
| fprintf(stderr, "Unable to load music file: %s\n", Mix_GetError()); | |
| } | |
| //oodles of vars | |
| int inv[3], tmpInt[2]; tmpInt[0] = 0; tmpInt[1] = 0; | |
| int block, rb, gb, bb, bX, bY, bD, mX, mY, invs, blockxx, blockyy, direction, paused, pausevar, | |
| increased, bulletdisplay, bXX, bYY; | |
| lives = 3; | |
| //create some enemies | |
| enemy *greenGuy[9]; //create nine green guys(enemies) | |
| for (int i = 0; i < 9; i++) | |
| greenGuy[i] = new enemy(); //load the values into the enemies | |
| //reset point | |
| map: | |
| block = 0; | |
| //set the inventory variables | |
| inv[0] = 0; | |
| inv[1] = 0; | |
| inv[2] = 0; | |
| invs=0; | |
| //set up our bullets - and one for the active one, having it set to -1 so we dont draw it | |
| rb = 1; | |
| gb = 0; | |
| bb = 0; | |
| bX = -1; | |
| bY = -1; | |
| bD = -1; | |
| //set the direction | |
| direction=0; | |
| //def vals, just incase | |
| blockx = 0; | |
| blocky = 0; | |
| blockxx = 0; | |
| blockyy = 0; | |
| //give myself some variables for the pause menu :O | |
| paused=0; | |
| pausevar=0; | |
| //set some bullet stuff | |
| bulletdisplay=0; | |
| char firing; | |
| //set up the map | |
| //var for # of enemies | |
| short enemies = 0; | |
| for (int a=0;a<9;++a) | |
| { | |
| for (int b=0;b<9;++b) | |
| { | |
| //if the map tile is the player's position | |
| if (level[a][b] == 8) | |
| { | |
| //set the players pos | |
| blockx = b; | |
| blocky = a; | |
| blockxx = b; | |
| blockyy = a; | |
| map[a][b] = 0; //reset the map piece | |
| } | |
| //if the map tile is an enemy's position | |
| else if (level[a][b] == 9) | |
| { | |
| //load the enemies pos | |
| greenGuy[enemies]->x = b; | |
| greenGuy[enemies]->y = a; | |
| greenGuy[enemies]->alive = true; | |
| map[a][b] = 0; //reset the map piece | |
| enemies++; //increase the enemies | |
| } | |
| //otherwise its just a map piece | |
| else map[a][b]=level[lvl*9+a][b]; | |
| } | |
| } | |
| while (1) | |
| { | |
| while (SDL_PollEvent(&event)) | |
| { | |
| //make sure the game ends when we want it to | |
| if (event.type == SDL_QUIT) end(); | |
| if (event.type == SDL_KEYDOWN) | |
| { | |
| keypress = 1; //tell the program we have pressed a key | |
| //check if we want to quick exit the game by pressing end | |
| if (event.key.keysym.sym == SDLK_END) end(); | |
| //take a screenshot | |
| if (event.key.keysym.sym == SDLK_F12) | |
| { | |
| if (SDL_SaveBMP(screen, "screenshot.bmp") != 0) | |
| fprintf(stderr, "Error taking screenshot!\n"); | |
| sShots++; //increase the number of screenshots | |
| } | |
| //when we pause, we go here | |
| if (page == "Paused") | |
| { | |
| switch (event.key.keysym.sym) | |
| { | |
| case SDLK_ESCAPE: | |
| //clear the page | |
| for (int a=0;a<WIDTH;++a) | |
| for (int b=0;b<HEIGHT;++b) | |
| drawdot(a,b,0,0,0); | |
| //goto back to the game | |
| page = "Play"; | |
| showMouse(fullscreen); | |
| break; | |
| case SDLK_p: | |
| case SDLK_o: | |
| //clear screen | |
| for (int a=0;a<WIDTH;++a) | |
| for (int b=0;b<HEIGHT;++b) | |
| drawdot(a,b,0,0,0); | |
| page="Options"; | |
| prevpage="Paused"; | |
| break; | |
| case SDLK_s: | |
| if (saveGame()) drawtext(10, 10, "*GAME SAVED*"); | |
| else drawtext(10, 10, "*SAVING FAILED*"); | |
| break; | |
| case SDLK_e: | |
| end(); | |
| break; | |
| case SDLK_m: | |
| for (int a=0;a<WIDTH;++a) | |
| for (int b=0;b<HEIGHT;++b) | |
| drawdot(a,b,0,0,0); | |
| page="Menu"; | |
| break; | |
| } | |
| } | |
| else if (page=="Play") | |
| { | |
| //key events | |
| //when we want to pause, do this: | |
| if (event.key.keysym.sym == SDLK_ESCAPE) | |
| { | |
| //clear the page | |
| for (int a=0;a<WIDTH;++a) | |
| for (int b=0;b<HEIGHT;++b) | |
| drawdot(a,b,0,0,0); | |
| //goto the pause page | |
| page = "Paused"; | |
| showMouse(fullscreen); | |
| } | |
| //goto the easter egg page :) | |
| if (event.key.keysym.sym == SDLK_F2 && event.key.keysym.mod & KMOD_RCTRL) | |
| { | |
| page = "Easter"; | |
| } | |
| switch (event.key.keysym.sym) | |
| { | |
| case SDLK_RIGHT: | |
| blockxx=blockx+1; | |
| direction=3; | |
| break; | |
| case SDLK_LEFT: | |
| blockxx=blockx-1; | |
| direction=1; | |
| break; | |
| case SDLK_UP: | |
| blockyy=blocky-1; | |
| direction=2; | |
| break; | |
| case SDLK_DOWN: | |
| blockyy=blocky+1; | |
| direction=0; | |
| break; | |
| //level up! | |
| case SDLK_p: | |
| ++lvl; | |
| redrawBG(); | |
| //number of enemies | |
| enemies = 0; | |
| for (int a=0;a<9;++a) | |
| { | |
| for (int b=0;b<9;++b) | |
| { | |
| //if the map tile is the player's position | |
| if (level[lvl*9+a][b] == 8) | |
| { | |
| //set the players pos | |
| blockx = b; | |
| blocky = lvl*9+a; | |
| blockxx = b; | |
| blockyy = a; | |
| map[a][b] = 0; //reset the map piece | |
| } | |
| //if the map tile is an enemy's position | |
| else if (level[lvl*9+a][b] == 9) | |
| { | |
| //load the enemies pos | |
| greenGuy[enemies]->x = b; | |
| greenGuy[enemies]->y = lvl*9+a; | |
| greenGuy[enemies]->alive = true; | |
| map[a][b] = 0; //reset the map piece | |
| enemies++; //increase the enemies | |
| } | |
| //otherwise its just a map piece | |
| else map[a][b]=level[lvl*9+a][b]; | |
| } | |
| } | |
| break; | |
| //bullets | |
| case SDLK_q: | |
| case SDLK_w: | |
| case SDLK_e: | |
| //make sure theres no other bullets | |
| if (bD<0) | |
| { | |
| //check if your facing a wall or a pillar | |
| switch (event.key.keysym.sym) | |
| { | |
| case SDLK_q: | |
| firing='r'; | |
| break; | |
| case SDLK_w: | |
| firing='g'; | |
| break; | |
| case SDLK_e: | |
| firing='b'; | |
| break; | |
| } | |
| if ((direction==1 && (blockx==0 || map[blocky][blockx-1]==1)) | |
| || (direction==0 && (blocky==8 || map[blocky+1][blockx]==1)) | |
| || (direction==2 && (blocky==0 || map[blocky-1][blockx]==1)) | |
| || (direction==3 && (blockx==8 || map[blocky][blockx+1]==1))) | |
| bD=-1; | |
| else | |
| { | |
| bX=blockx; | |
| bY=blocky; | |
| bD = direction; | |
| bulletdisplay=0; | |
| increased=10; | |
| break; | |
| } | |
| } | |
| break; | |
| case SDLK_1: | |
| if (inv[0] == 4 || inv[0] == 5 || inv[0] == 6) | |
| { | |
| if (inv[0] == 4) lives = lives<2?(lives + 1):3; //battery | |
| else if (inv[0] == 5) //bomb | |
| { | |
| //blow up everything around the player | |
| dropBomb(blockx, blocky); | |
| } | |
| else if (inv[0] == 6) | |
| { | |
| page = "Complete"; | |
| tmpInt[0] = rb + gb + bb; | |
| } //nuke | |
| inv[0] = 0; //remove that entry | |
| } | |
| break; | |
| case SDLK_2: | |
| if (inv[1] == 4 || inv[1] == 5 || inv[1] == 6) | |
| { | |
| if (inv[1] == 4) lives = lives<2?(lives + 1):3; //battery | |
| else if (inv[1] == 5) //bomb | |
| { | |
| //blow up everything around the player | |
| dropBomb(blockx, blocky); | |
| } | |
| else if (inv[1] == 6) | |
| { | |
| page = "Complete"; //nuke | |
| tmpInt[0] = rb + gb + bb; | |
| } | |
| inv[1] = 0; //remove that entry | |
| } | |
| break; | |
| case SDLK_3: | |
| if (inv[2] == 4 || inv[2] == 5 || inv[2] == 6) | |
| { | |
| if (inv[2] == 4) lives = lives<2?(lives + 1):3; //battery | |
| else if (inv[2] == 5) //bomb | |
| { | |
| //blow up everything around the player | |
| dropBomb(blockx, blocky); | |
| } | |
| else if (inv[2] == 6) | |
| { | |
| page = "Complete"; //nuke | |
| tmpInt[0] = rb + gb + bb; | |
| } | |
| inv[2] = 0; //remove that entry | |
| } | |
| break; | |
| } | |
| } | |
| //good old credits | |
| if (page == "Credits") | |
| { | |
| //when we press escape to go home | |
| if (event.key.keysym.sym == SDLK_ESCAPE) | |
| { | |
| //clear the page | |
| for (int a=0;a<WIDTH;++a) | |
| for (int b=0;b<HEIGHT;++b) | |
| drawdot(a,b,0,0,0); | |
| //reset the vars | |
| timer = 2000; | |
| credI[0] = 240; | |
| credI[1] = 280; | |
| credI[2] = 320; | |
| credI[3] = 360; | |
| credI[4] = 400; | |
| credI[5] = 440; | |
| credI[6] = 480; | |
| credI[7] = 520; | |
| credI[8] = 560; | |
| //goto the menu | |
| page = "Menu"; | |
| } | |
| } | |
| //what about options!? | |
| if (page == "Options") | |
| { | |
| //when we press escape to go home | |
| switch (event.key.keysym.sym) | |
| { | |
| case SDLK_ESCAPE: | |
| //clear the page | |
| for (int a=0;a<=320;++a) | |
| for (int b=0;b<=240;++b) | |
| drawdot(a,b,0,0,0); | |
| //go back | |
| page = prevpage; | |
| saveGame(); | |
| break; | |
| case SDLK_s: | |
| if (saveGame()) drawtext(10, 10, "*GAME SAVED*"); | |
| else drawtext(10, 10, "*SAVING FAILED*"); | |
| break; | |
| } | |
| } | |
| //never fear, the intro is here | |
| if (page == "Intro") | |
| { | |
| //when we press escape to go home | |
| if (event.key.keysym.sym == SDLK_ESCAPE) | |
| { | |
| //clear the page | |
| for (int a=0;a<=320;++a) | |
| for (int b=0;b<=240;++b) | |
| drawdot(a,b,0,0,0); | |
| //goto the menu | |
| page = "Menu"; | |
| //start playing music | |
| if (music == true) | |
| { | |
| if (Mix_PlayMusic(mainSong, -1) == -1) | |
| { | |
| fprintf(stderr, "Error playing song: %s\n", Mix_GetError()); //if we have an error | |
| } | |
| } | |
| } | |
| } | |
| if (page=="Play") | |
| { | |
| //make sure we dont go outside of the playing area | |
| if (blockxx<0) blockxx=0; | |
| else if (blockxx>8) blockxx=8; | |
| else if (blockyy<0) blockyy=0; | |
| else if (blockyy>8) blockyy=8; | |
| switch (map[blockyy][blockxx]) | |
| { | |
| //if its a regular space | |
| case 0: | |
| blockx=blockxx; | |
| blocky=blockyy; | |
| break; | |
| //if its a pillar | |
| case 1: | |
| //make sure we're not dropping rubble on top of rubble | |
| if (map[blockyy][blockxx+1]==3 && event.key.keysym.sym==SDLK_RIGHT | |
| || map[blockyy][blockxx-1]==3 && event.key.keysym.sym==SDLK_LEFT | |
| || map[blockyy-1][blockxx]==3 && event.key.keysym.sym==SDLK_UP | |
| || map[blockyy+1][blockxx]==3 && event.key.keysym.sym==SDLK_DOWN) | |
| { | |
| blockxx=blockx; | |
| blockyy=blocky; | |
| break; | |
| } | |
| //change pillar to a hole | |
| map[blockyy][blockxx]=2; | |
| //drop rubble in the correct spot | |
| switch (event.key.keysym.sym) | |
| { | |
| case SDLK_RIGHT: | |
| map[blockyy][blockxx+1]=3; | |
| break; | |
| case SDLK_LEFT: | |
| map[blockyy][blockxx-1]=3; | |
| break; | |
| case SDLK_UP: | |
| map[blockyy-1][blockxx]=3; | |
| break; | |
| case SDLK_DOWN: | |
| map[blockyy+1][blockxx]=3; | |
| break; | |
| } | |
| //dont move the character position | |
| blockxx=blockx; | |
| blockyy=blocky; | |
| //increase the score | |
| Score+=500; | |
| break; | |
| //if we fall in a hole, decrease lives and reset | |
| case 2: | |
| //reset my position | |
| blockx = 0; | |
| blocky = 0; | |
| //add a timer and a message | |
| msgDelay = 100; | |
| msg = "YOU DIED"; | |
| //decrease lives and check if we died | |
| lives--; | |
| if (lives < 0) | |
| { | |
| //clear the page | |
| for (int a=0;a<WIDTH;++a) | |
| for (int b=0;b<HEIGHT;++b) | |
| drawdot(a,b,0,0,0); | |
| page = "Lose"; | |
| } | |
| //reset the map | |
| goto map; | |
| break; | |
| //if it is a powerup... | |
| case 4: | |
| case 5: | |
| case 6: | |
| //increase the score | |
| Score += 1000; | |
| //add a message and timer | |
| msgDelay = 100; | |
| switch (map[blockyy][blockxx]) | |
| { | |
| case 4: | |
| msg="COLLECTED BATTERY"; | |
| inv[invs]=4; | |
| break; | |
| case 5: | |
| msg="COLLECTED BOMB"; | |
| inv[invs]=5; | |
| break; | |
| case 6: | |
| msg="COLLECTED NUKE"; | |
| inv[invs]=6; | |
| break; | |
| } | |
| ++invs; | |
| //remove the battery | |
| map[blockyy][blockxx] = 0; | |
| //move the character | |
| blockx=blockxx; | |
| blocky=blockyy; | |
| break; | |
| //anything we cant move through | |
| default: | |
| blockxx=blockx; | |
| blockyy=blocky; | |
| break; | |
| } | |
| } | |
| } | |
| } | |
| //win or lose | |
| if (page == "Win" || page == "Lose") | |
| { | |
| if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE) | |
| { | |
| //clear | |
| for (int a=0;a<WIDTH;++a) | |
| for (int b=0;b<HEIGHT;++b) | |
| drawdot(a,b,0,0,0); | |
| page = "Menu"; | |
| //reset game | |
| lives = 3; | |
| Score = 0; | |
| invs = 0; | |
| inv[0] = 0; | |
| inv[1] = 0; | |
| inv[2] = 0; | |
| lvl = 0; | |
| //reset map | |
| for (int a=0;a<9;++a) | |
| { | |
| for (int b=0;b<9;++b) | |
| { | |
| //if the map tile is the player's position | |
| if (level[a][b] == 8) | |
| { | |
| //set the players pos | |
| blockx = b; | |
| blocky = a; | |
| blockxx = b; | |
| blockyy = a; | |
| map[a][b] = 0; //reset the map piece | |
| } | |
| //if the map tile is an enemy's position | |
| else if (level[a][b] == 9) | |
| { | |
| //load the enemies pos | |
| greenGuy[enemies]->x = b; | |
| greenGuy[enemies]->y = a; | |
| greenGuy[enemies]->alive = true; | |
| map[a][b] = 0; //reset the map piece | |
| enemies++; //increase the enemies | |
| } | |
| //otherwise its just a map piece | |
| else map[a][b]=level[lvl*9+a][b]; | |
| } | |
| } | |
| } | |
| } | |
| //if the page is the easter egg page | |
| if (page == "Easter") | |
| { | |
| if (event.key.keysym.sym == SDLK_ESCAPE) | |
| page = "Paused"; | |
| } | |
| //if the page is the menu | |
| if (page == "Menu") | |
| { | |
| if (event.key.keysym.sym == SDLK_ESCAPE) | |
| { | |
| end(); | |
| return 0; | |
| } | |
| //what happens when we press some buttons | |
| if (event.type == SDL_MOUSEBUTTONDOWN && event.button.button == SDL_BUTTON_LEFT) | |
| { | |
| mX = event.button.x; | |
| mY = event.button.y; | |
| //the play button | |
| if (mX > 26 && mX < 148 && mY > 116 && mY < 167) | |
| { | |
| //switch the page to play | |
| page = "Play"; | |
| showMouse(fullscreen); | |
| //show a loading screen incase you have a slow computer | |
| for (int a=0;a<WIDTH;++a) | |
| for (int b=0;b<HEIGHT;++b) | |
| drawdot(a,b,0,0,0); | |
| drawtext(10, 10, "LOADING"); | |
| } | |
| //the credits button | |
| if (mX > 170 && mX < 293 && mY > 116 && mY < 167 && clicked == false) | |
| { | |
| //show a loading screen incase you have a slow computer | |
| for (int a=0;a<WIDTH;++a) | |
| for (int b=0;b<HEIGHT;++b) | |
| drawdot(a,b,0,0,0); | |
| page = "Credits"; | |
| } | |
| //the options button | |
| if (mX > 26 && mX < 148 && mY > 175 && mY < 226) | |
| { | |
| //show a loading screen incase you have a slow computer | |
| for (int a=0;a<WIDTH;++a) | |
| for (int b=0;b<HEIGHT;++b) | |
| drawdot(a,b,0,0,0); | |
| page = "Options"; | |
| } | |
| //the exit button | |
| if (mX > 170 && mX < 293 && mY > 175 && mY < 226) | |
| { | |
| //end the game | |
| end(); | |
| } | |
| } | |
| //reset the keys so we can press it again without the player flying | |
| if (event.type == SDL_KEYUP) keypress = 0; | |
| } | |
| if (page == "Play") | |
| { | |
| //draw the background and all the sprites | |
| redrawBG(); | |
| score.drawsprite(218, 2); | |
| top.drawsprite(218, 42); | |
| switch (direction) | |
| { | |
| case 0: | |
| bluesprite.drawsprite(24*blockx+2, 24*blocky+2); | |
| break; | |
| case 1: | |
| bluesprite1.drawsprite(24*blockx+2, 24*blocky+2); | |
| break; | |
| case 2: | |
| bluesprite2.drawsprite(24*blockx+2, 24*blocky+2); | |
| break; | |
| case 3: | |
| bluesprite3.drawsprite(24*blockx+2, 24*blocky+2); | |
| break; | |
| } | |
| for (int i = 0; i < 9; i++) | |
| { | |
| if (greenGuy[i]->alive = true) | |
| { | |
| short gX = greenGuy[i]->x, gY = greenGuy[i]->y, gD = greenGuy[i]->dir; //shortened versions | |
| //draw the sprite | |
| if (gD == 0) greensprite.drawsprite(gX * 24 + 2, gY * 24 + 2); | |
| if (gD == 1) greensprite1.drawsprite(gX * 24 + 2, gY * 24 + 2); | |
| if (gD == 2) greensprite2.drawsprite(gX * 24 + 2, gY * 24 + 2); | |
| if (gD == 3) greensprite3.drawsprite(gX * 24 + 2, gY * 24 + 2); | |
| } | |
| } | |
| //draw the score and Top | |
| drawscore(218, 26, Score); | |
| drawscore(218, 66, Top); | |
| //update top and scoress | |
| if (Score > Top) Top = Score; | |
| //draw the map pieces | |
| for (int mty = 0; mty <= 8; mty++) | |
| { | |
| for (int mtx = 0; mtx <= 8; mtx++) | |
| { | |
| //draw the selected piece | |
| switch (map[mty][mtx]) | |
| { | |
| //a pillar | |
| case 1: | |
| pillar.drawsprite(mtx * 24 + 1, mty * 24 + 1); | |
| break; | |
| //a hole | |
| case 2: | |
| hole.drawsprite(mtx * 24 + 1, mty * 24 + 1); | |
| break; | |
| //a pile of rubble | |
| case 3: | |
| rubble.drawsprite(mtx * 24 + 4, mty * 24 + 3); | |
| break; | |
| //a battery powerup | |
| case 4: | |
| battery.drawsprite(mtx * 24 + 6, mty * 24 + 9); | |
| break; | |
| //a bomb | |
| case 5: | |
| bomb.drawsprite(mtx * 24 + 7, mty * 24 + 5); | |
| break; | |
| //an unactive nuke | |
| case 6: | |
| nuke1.drawsprite(mtx * 24 + 8, mty * 24 + 9); | |
| break; | |
| //an active nuke | |
| case 7: | |
| nuke2.drawsprite(mtx * 24 + 8, mty * 24 + 9); | |
| break; | |
| } | |
| } | |
| } | |
| //enemies | |
| for (int i = 0; i < 9; i++) | |
| { | |
| if (greenGuy[i]->alive = true) //only update if he's alive | |
| { | |
| int gX = greenGuy[i]->x, gY = greenGuy[i]->y, gD = greenGuy[i]->dir; //shortened versions | |
| //basic movements | |
| if (ticker % (20 + (60 - (lvl * 2))) == 0) | |
| { | |
| if (gX > blockx) | |
| { | |
| greenGuy[i]->dir = 1; | |
| if (map[gY][gX - 1] == 0) greenGuy[i]->x--; | |
| } | |
| else if (gY < blocky) | |
| { | |
| greenGuy[i]->dir = 0; | |
| if (map[gY + 1][gX] == 0) greenGuy[i]->y++; | |
| } | |
| else if (gX < blockx) | |
| { | |
| greenGuy[i]->dir = 3; | |
| if (map[gY][gX + 1] == 0) greenGuy[i]->x++; | |
| } | |
| else if (gY > blocky) | |
| { | |
| greenGuy[i]->dir = 2; | |
| if (map[gY - 1][gX] == 0) greenGuy[i]->y--; | |
| } | |
| } | |
| } | |
| } | |
| //draw bullets | |
| if (bD >= 0) | |
| { | |
| ++increased; | |
| if (bulletdisplay==0) | |
| { | |
| switch (bD) | |
| { | |
| case 0: | |
| bXX=bX; | |
| bYY=bY+1; | |
| break; | |
| case 1: | |
| bXX=bX-1; | |
| bYY=bY; | |
| break; | |
| case 2: | |
| bXX=bX; | |
| bYY=bY-1; | |
| break; | |
| case 3: | |
| bXX=bX+1; | |
| bYY=bY; | |
| break; | |
| } | |
| //check where the bullet is | |
| if (bXX<0) | |
| { | |
| bXX=0; | |
| bulletdisplay=1; | |
| increased=0; | |
| } | |
| else if (bXX>8) | |
| { | |
| bXX=8; | |
| bulletdisplay=1; | |
| increased=0; | |
| } | |
| if (bYY<0) | |
| { | |
| bYY=0; | |
| bulletdisplay=1; | |
| increased=0; | |
| } | |
| else if (bYY>8) | |
| { | |
| bYY=8; | |
| bulletdisplay=1; | |
| increased=0; | |
| } | |
| if (increased>=5) | |
| { | |
| increased=0; | |
| switch (map[bYY][bXX]) | |
| { | |
| case 0: | |
| case 2: | |
| bX=bXX; | |
| bY=bYY; | |
| break; | |
| case 1: | |
| if (firing=='b') | |
| { | |
| map[bYY][bXX]=2; | |
| switch (bD) | |
| { | |
| case 0: | |
| map[bYY+1][bXX]=3; | |
| break; | |
| case 1: | |
| map[bYY][bXX-1]=3; | |
| break; | |
| case 2: | |
| map[bYY-1][bXX]=3; | |
| break; | |
| case 3: | |
| map[bYY][bXX+1]=3; | |
| break; | |
| } | |
| bX=bXX; | |
| bY=bYY; | |
| Score+=500; | |
| } | |
| bulletdisplay=1; | |
| increased=0; | |
| break; | |
| case 3: | |
| map[bYY][bXX]=0; | |
| bX=bXX; | |
| bY=bYY; | |
| Score+=250; | |
| bulletdisplay=1; | |
| increased=0; | |
| break; | |
| default: | |
| bulletdisplay=1; | |
| increased=0; | |
| break; | |
| } | |
| } | |
| switch (firing) | |
| { | |
| case 'r': | |
| redbull0.drawsprite(bX * 24 + 8, bY * 24 + 8); | |
| break; | |
| case 'g': | |
| greenbull0.drawsprite(bX * 24 + 8, bY * 24 + 8); | |
| break; | |
| case 'b': | |
| bluebull0.drawsprite(bX * 24 + 8, bY * 24 + 8); | |
| break; | |
| } | |
| } | |
| else if (bulletdisplay==1) | |
| { | |
| if (increased==3) | |
| { | |
| bulletdisplay=2; | |
| increased=0; | |
| } | |
| switch (firing) | |
| { | |
| case 'r': | |
| redbull1.drawsprite(bX * 24 + 5, bY * 24 + 5); | |
| break; | |
| case 'g': | |
| greenbull1.drawsprite(bX * 24 + 5, bY * 24 + 5); | |
| break; | |
| case 'b': | |
| bluebull1.drawsprite(bX * 24 + 5, bY * 24 + 5); | |
| break; | |
| } | |
| } | |
| else if (bulletdisplay==2) | |
| { | |
| if (increased==3) | |
| { | |
| bulletdisplay=3; | |
| increased=0; | |
| } | |
| switch (firing) | |
| { | |
| case 'r': | |
| redbull2.drawsprite(bX * 24 + 5, bY * 24 + 5); | |
| break; | |
| case 'g': | |
| greenbull2.drawsprite(bX * 24 + 5, bY * 24 + 5); | |
| break; | |
| case 'b': | |
| bluebull2.drawsprite(bX * 24 + 5, bY * 24 + 5); | |
| break; | |
| } | |
| } | |
| else if (bulletdisplay==3) | |
| { | |
| if (increased==3) bD=-1; | |
| switch (firing) | |
| { | |
| case 'r': | |
| redbull3.drawsprite(bX * 24 + 5, bY * 24 + 5); | |
| break; | |
| case 'g': | |
| greenbull3.drawsprite(bX * 24 + 5, bY * 24 + 5); | |
| break; | |
| case 'b': | |
| bluebull3.drawsprite(bX * 24 + 5, bY * 24 + 5); | |
| break; | |
| } | |
| } | |
| } | |
| //healthbar | |
| SDL_BlitSurface(sprites, &Health_cRect2, screen, &Health_dRect); | |
| Health_cRect.w = lives * 22; | |
| SDL_BlitSurface(sprites, &Health_cRect, screen, &Health_dRect); | |
| //the inventory | |
| drawline(238,120,296,120,Col[0],Col[1],Col[2]); | |
| drawline(238,145,296,145,Col[0],Col[1],Col[2]); | |
| drawline(238,120,238,145,Col[0],Col[1],Col[2]); | |
| drawline(296,120,296,145,Col[0],Col[1],Col[2]); | |
| for (int a=0;a<invs;++a) | |
| { | |
| switch (inv[a]) | |
| { | |
| case 6: | |
| nuke2.drawsprite(242 + (a * 20), 129); | |
| break; | |
| case 5: | |
| bomb.drawsprite(240 + (a * 20), 125); | |
| break; | |
| case 4: | |
| battery.drawsprite(240 + (a * 20), 129); | |
| break; | |
| } | |
| } | |
| } | |
| //the credits page | |
| else if (page == "Credits") | |
| { | |
| //clear the page | |
| for (int a=0;a<=320;++a) | |
| for (int b=0;b<=240;++b) | |
| drawdot(a,b,0,0,0); | |
| drawtext(128, 20, "CREDITS"); | |
| drawtext(129, 33, "*******"); | |
| //make sure the logo is where we want it | |
| if (logoPos.x != 84 || logoPos.y != 60) | |
| { | |
| logoPos.x = 84; | |
| logoPos.y = 60; | |
| } | |
| //draw the logo | |
| SDL_BlitSurface(sprites, &logoRect, screen, &logoPos); | |
| //looping credits | |
| if (timer <= 0) | |
| { | |
| //reset the credits | |
| timer = 1500; | |
| credI[0] = 240; | |
| credI[1] = 280; | |
| credI[2] = 320; | |
| credI[3] = 360; | |
| credI[4] = 400; | |
| credI[5] = 440; | |
| credI[6] = 480; | |
| credI[7] = 520; | |
| credI[8] = 560; | |
| } | |
| if (timer <= 500) | |
| { | |
| //loop through the different credits and make them scroll down | |
| for (int i = 0; i < 9; i++) | |
| { | |
| if (credI[i] < 241 + (i * 12)) | |
| { | |
| credI[i]++; | |
| } | |
| } | |
| } | |
| else | |
| { | |
| //loop through the different credits and make them scroll up | |
| for (int i = 0; i < 9; i++) | |
| { | |
| if (credI[i] > 117 + (i * 12)) | |
| { | |
| credI[i]--; | |
| } | |
| } | |
| } | |
| //draw all of the texts | |
| drawtext(7, credI[0], "**********************************"); | |
| drawtext(115, credI[1], "CREATED BY"); | |
| drawtext(43, credI[2], "MATT HINES AND RYAN O HARA"); | |
| drawtext(151, credI[3], "OF"); | |
| drawtext(91, credI[4], "PICWIN STUDIOS"); | |
| drawtext(70, credI[5], "AUDIO BY AVIEL TURUZ"); | |
| drawtext(61, credI[6], "GRAPHICS BY MATT HINES"); | |
| drawtext(65, credI[7], "CONCEPT BY MATT HINES"); | |
| drawtext(7, credI[8], "**********************************"); | |
| } | |
| //the pause page | |
| else if (page == "Paused") | |
| { | |
| //new and improved clear on small box on the screen for loops :) | |
| for (int a=0;a<=WIDTH;++a) | |
| { | |
| for (int b=70;b<=90;++b) | |
| { | |
| drawdot(a,b,0,0,0); | |
| } | |
| } | |
| drawtext(133, 20, "PAUSED"); | |
| drawtext(134, 33, "******"); | |
| //top right | |
| drawline(171,117,292,117, Col[0],Col[1],Col[2]); | |
| drawline(171,166,292,166, Col[0],Col[1],Col[2]); | |
| drawline(171,117,171,166, Col[0],Col[1],Col[2]); | |
| drawline(292,117,292,166, Col[0],Col[1],Col[2]); | |
| drawtext(215,137,"MENU"); | |
| //top left | |
| drawline(27,117,147,117, Col[0],Col[1],Col[2]); | |
| drawline(27,166,147,166, Col[0],Col[1],Col[2]); | |
| drawline(27,117,27,166, Col[0],Col[1],Col[2]); | |
| drawline(147,117,147,166, Col[0],Col[1],Col[2]); | |
| drawtext(68, 137, "SAVE"); | |
| //bottom right | |
| drawline(171,176,292,176, Col[0],Col[1],Col[2]); | |
| drawline(171,225,292,225, Col[0],Col[1],Col[2]); | |
| drawline(171,176,171,225, Col[0],Col[1],Col[2]); | |
| drawline(292,176,292,225, Col[0],Col[1],Col[2]); | |
| drawtext(213, 197, "EXIT"); | |
| //bottom left | |
| drawline(27,176,147,176, Col[0],Col[1],Col[2]); | |
| drawline(27,225,147,225, Col[0],Col[1],Col[2]); | |
| drawline(27,176,27,225, Col[0],Col[1],Col[2]); | |
| drawline(147,176,147,225, Col[0],Col[1],Col[2]); | |
| drawtext(55, 197, "OPTIONS"); | |
| //draw the 2 dudes running around muahahaha | |
| paused++; | |
| if (paused>WIDTH) paused=0; | |
| if (paused==0) pausevar=rand()%11; | |
| if (pausevar<11 && pausevar>2) | |
| { | |
| bluesprite3.drawsprite(paused,70); | |
| greensprite3.drawsprite(paused+30,70); | |
| } | |
| else | |
| { | |
| bluesprite3.drawsprite(paused,70); | |
| greensprite3.drawsprite(paused+60,70); | |
| if (paused+60<WIDTH) | |
| { | |
| switch (pausevar) | |
| { | |
| case 0: | |
| redbull0.drawsprite(paused+45,76); | |
| break; | |
| case 1: | |
| greenbull0.drawsprite(paused+45,76); | |
| break; | |
| case 2: | |
| bluebull0.drawsprite(paused+45,76); | |
| break; | |
| } | |
| } | |
| else if (paused+60>=WIDTH && paused+58<=WIDTH) | |
| { | |
| switch (pausevar) | |
| { | |
| case 0: | |
| redbull1.drawsprite(WIDTH-15,76); | |
| break; | |
| case 1: | |
| greenbull1.drawsprite(WIDTH-15,76); | |
| break; | |
| case 2: | |
| bluebull1.drawsprite(WIDTH-15,76); | |
| break; | |
| } | |
| } | |
| else if (paused+57>=WIDTH && paused+55<=WIDTH) | |
| { | |
| switch (pausevar) | |
| { | |
| case 0: | |
| redbull2.drawsprite(WIDTH-15,76); | |
| break; | |
| case 1: | |
| greenbull2.drawsprite(WIDTH-15,76); | |
| break; | |
| case 2: | |
| bluebull2.drawsprite(WIDTH-15,76); | |
| break; | |
| } | |
| } | |
| else if (paused+54>=WIDTH && paused+52<=WIDTH) | |
| { | |
| switch (pausevar) | |
| { | |
| case 0: | |
| redbull3.drawsprite(WIDTH-15,76); | |
| break; | |
| case 1: | |
| greenbull3.drawsprite(WIDTH-15,76); | |
| break; | |
| case 2: | |
| bluebull3.drawsprite(WIDTH-15,76); | |
| break; | |
| } | |
| } | |
| } | |
| if (event.type == SDL_MOUSEBUTTONDOWN && event.button.button == SDL_BUTTON_LEFT) | |
| { | |
| mX = event.button.x; | |
| mY = event.button.y; | |
| //the save button | |
| if (mX > 26 && mX < 148 && mY > 116 && mY < 167) | |
| { | |
| //save game | |
| if (saveGame()) drawtext(10, 10, "*GAME SAVED*"); | |
| else drawtext(10, 10, "*ERROR SAVING*"); | |
| } | |
| //the menu button | |
| if (mX > 170 && mX < 293 && mY > 116 && mY < 167) | |
| { | |
| //clear the screen | |
| for (int a=0;a<WIDTH;++a) | |
| for (int b=0;b<HEIGHT;++b) | |
| drawdot(a,b,0,0,0); | |
| page="Menu"; | |
| clicked = true; | |
| } | |
| //the options button | |
| if (mX > 26 && mX < 148 && mY > 175 && mY < 226) | |
| { | |
| //rawr | |
| for (int a=0;a<=320;++a) | |
| for (int b=0;b<=240;++b) | |
| drawdot(a,b,0,0,0); | |
| prevpage = "Paused"; | |
| page = "Options"; | |
| } | |
| //the exit button... kinda explains itself | |
| if (mX > 170 && mX < 293 && mY > 175 && mY < 226) end(); | |
| } | |
| //reset the keys so we can press it again without the player flying | |
| if (event.type == SDL_KEYUP && event.button.button == SDL_BUTTON_LEFT) keypress = 0; | |
| } | |
| //the options page | |
| else if (page == "Options") | |
| { | |
| drawtext(128, 20, "OPTIONS"); | |
| drawtext(129, 33, "*******"); | |
| //sound | |
| if (sound) drawtext(20,50,"SOUND: ON"); | |
| else drawtext(20,50,"SOUND: OFF"); | |
| //music | |
| if (music) drawtext(20,75,"MUSIC: ON"); | |
| else drawtext(20,75,"MUSIC: OFF"); | |
| //full screen | |
| drawtext(20,100,"FULLSCREEN"); | |
| if (event.type == SDL_MOUSEBUTTONDOWN && event.button.button == SDL_BUTTON_LEFT && !keypress) | |
| { | |
| mX = event.button.x; | |
| mY = event.button.y; | |
| keypress=1; | |
| if (mX >=20 && mX <= 150 && mY >= 50 && mY <= 60) | |
| { | |
| for (int a=60;a<=150;a++) for (int b=50;b<=60;b++) drawdot(a,b,0,0,0); | |
| if (sound) sound=false; | |
| else sound=true; | |
| } | |
| else if (mX >=20 && mX <= 150 && mY >= 75 && mY <= 85) | |
| { | |
| for (int a=60;a<=150;a++) for (int b=75;b<=85;b++) drawdot(a,b,0,0,0); | |
| if (music) | |
| { | |
| if (Mix_PlayingMusic()) Mix_FadeOutMusic(500); //fade the music out | |
| music=false; | |
| } | |
| else | |
| { | |
| if (Mix_FadeInMusic(mainSong, -1,500) == -1) | |
| { | |
| fprintf(stderr, "Error playing song: %s\n", Mix_GetError()); //if we have an error | |
| } | |
| music=true; | |
| } | |
| } | |
| else if (mX >=20 && mX <= 150 && mY >= 100 && mY <= 110) | |
| { | |
| if (!fullscreen) | |
| { | |
| screen = SDL_SetVideoMode(WIDTH, HEIGHT, COLOR_DEPTH, SDL_HWSURFACE | SDL_HWPALETTE | SDL_DOUBLEBUF | SDL_FULLSCREEN); | |
| fullscreen=true; | |
| } | |
| else | |
| { | |
| screen = SDL_SetVideoMode(WIDTH, HEIGHT, COLOR_DEPTH, SDL_HWSURFACE | SDL_HWPALETTE | SDL_DOUBLEBUF); | |
| fullscreen=false; | |
| } | |
| } | |
| } | |
| if (event.type == SDL_MOUSEBUTTONUP && event.button.button == SDL_BUTTON_LEFT) keypress = 0; | |
| } | |
| //the menu page | |
| else if (page == "Menu") | |
| { | |
| puts("test"); | |
| //border | |
| drawline(0, 0, WIDTH - 1, 0, Col[0],Col[1],Col[2]); | |
| drawline(0, 0, 0, HEIGHT - 1, Col[0],Col[1],Col[2]); | |
| drawline(WIDTH - 1, 0, WIDTH - 1, HEIGHT - 1, Col[0],Col[1],Col[2]); | |
| drawline(0, HEIGHT - 1, WIDTH - 1, HEIGHT - 1, Col[0],Col[1],Col[2]); | |
| //inner border | |
| //a temp variable to control whether to draw a bright rect or a non bright one | |
| int t = (unsigned)time(0) % 2; | |
| if (t == 0) | |
| { | |
| drawline(2, 2, WIDTH - 3, 2, 0,127,255); | |
| drawline(2, 2, 2, HEIGHT - 3, 0,127,255); | |
| drawline(WIDTH - 3, 2, WIDTH - 3, HEIGHT - 3, 0,127,255); | |
| drawline(2, HEIGHT - 3, WIDTH - 3, HEIGHT - 3, 0,127,255); | |
| } | |
| else | |
| { | |
| drawline(2, 2, WIDTH - 3, 2, Col[0],Col[1],Col[2]); | |
| drawline(2, 2, 2, HEIGHT - 3, Col[0],Col[1],Col[2]); | |
| drawline(WIDTH - 3, 2, WIDTH - 3, HEIGHT - 3, Col[0],Col[1],Col[2]); | |
| drawline(2, HEIGHT - 3, WIDTH - 3, HEIGHT - 3, Col[0],Col[1],Col[2]); | |
| } | |
| //logo box | |
| drawline(27,15,292,15, Col[0],Col[1],Col[2]); | |
| drawline(27,104,292,104, Col[0],Col[1],Col[2]); | |
| drawline(27,15,27,104, Col[0],Col[1],Col[2]); | |
| drawline(292,15,292,104, Col[0],Col[1],Col[2]); | |
| //top right | |
| drawline(171,117,292,117, Col[0],Col[1],Col[2]); | |
| drawline(171,166,292,166, Col[0],Col[1],Col[2]); | |
| drawline(171,117,171,166, Col[0],Col[1],Col[2]); | |
| drawline(292,117,292,166, Col[0],Col[1],Col[2]); | |
| drawtext(200,137,"CREDITS"); | |
| //top left | |
| drawline(27,117,147,117, Col[0],Col[1],Col[2]); | |
| drawline(27,166,147,166, Col[0],Col[1],Col[2]); | |
| drawline(27,117,27,166, Col[0],Col[1],Col[2]); | |
| drawline(147,117,147,166, Col[0],Col[1],Col[2]); | |
| drawtext(68, 137, "PLAY"); | |
| //bottom right | |
| drawline(171,176,292,176, Col[0],Col[1],Col[2]); | |
| drawline(171,225,292,225, Col[0],Col[1],Col[2]); | |
| drawline(171,176,171,225, Col[0],Col[1],Col[2]); | |
| drawline(292,176,292,225, Col[0],Col[1],Col[2]); | |
| drawtext(213, 197, "EXIT"); | |
| //bottom left | |
| drawline(27,176,147,176, Col[0],Col[1],Col[2]); | |
| drawline(27,225,147,225, Col[0],Col[1],Col[2]); | |
| drawline(27,176,27,225, Col[0],Col[1],Col[2]); | |
| drawline(147,176,147,225, Col[0],Col[1],Col[2]); | |
| drawtext(55, 197, "OPTIONS"); | |
| //if the logo pos is not where we want it, make it | |
| if (logoPos.x != 84 || logoPos.y != 40) | |
| logoPos.x = 84; | |
| logoPos.y = 40; | |
| //draw the logo | |
| SDL_BlitSurface(sprites, &logoRect, screen, &logoPos); | |
| } | |
| //the intro! | |
| else if (page == "Intro") | |
| { | |
| //clear the page | |
| for (int a=0;a<WIDTH;++a) | |
| for (int b=0;b<HEIGHT;++b) | |
| drawdot(a,b,0,0,0); | |
| //draw the pillars, but only if the intro variable is less than 500 | |
| if (intro < INTRO_LENGTH) drawtext(3, 140, tmpTxt); | |
| //draw the logo if the intro is greater than 280 | |
| if (intro >= 280) SDL_BlitSurface(sprites, &logoRect, screen, &logoPos); | |
| //draw the info | |
| if (intro >= 352) drawtext((WIDTH / 2) - ((strlen(CREDITS) * 9) / 2), 40, CREDITS); | |
| if (intro >= 382) drawtext(123, 55, "PRESENTS"); | |
| //draw the 2 sprites for the intro cutscene | |
| if (intro < 642) | |
| { | |
| if (bluePos.x >= 0) | |
| SDL_BlitSurface(sprites, &bluesprite3.rect, screen, &bluePos); | |
| if (greenPos.x >= 0) | |
| SDL_BlitSurface(sprites, &greensprite3.rect, screen, &greenPos); | |
| } | |
| if (intro >= 643) | |
| { | |
| if (bluePos.x <= 320 && bluePos.x >= 0) | |
| SDL_BlitSurface(sprites, &bluesprite1.rect, screen, &bluePos); | |
| if (greenPos.x <= 320 && greenPos.x >= 0) | |
| SDL_BlitSurface(sprites, &greensprite1.rect, screen, &greenPos); | |
| } | |
| //end the intro and go to the menu | |
| if (intro >= INTRO_LENGTH) | |
| { | |
| //clear the page | |
| for (int a=0;a<WIDTH;++a) | |
| for (int b=0;b<HEIGHT;++b) | |
| drawdot(a,b,0,0,0); | |
| intro = -1; | |
| page = "Menu"; | |
| //start playing the main song | |
| if (music == true) | |
| { | |
| if (Mix_PlayMusic(mainSong, -1) == -1) | |
| { | |
| fprintf(stderr, "Error playing song: %s\n", Mix_GetError()); //if we have an error | |
| } | |
| } | |
| } | |
| //2 players running in opposite dirs | |
| else if (intro >= 643) | |
| { | |
| //increase blue's & green's pos until they are off screen | |
| if (bluePos.x >= -16 && intro % 8 == 0) | |
| { | |
| greenPos.x -= 16; | |
| bluePos.x -= 16; | |
| } | |
| } | |
| else if (intro >= 642) | |
| { | |
| //update our positions | |
| bluePos.x = 368; | |
| greenPos.x = 336; | |
| } | |
| //2 players running - cutscene | |
| else if (intro >= 430) | |
| { | |
| //increase blue's & green's pos until they are off screen | |
| if (greenPos.x <= 320 && intro % 8 == 0) | |
| { | |
| greenPos.x += 16; | |
| bluePos.x += 16; | |
| } | |
| } | |
| //logo falling a second time | |
| else if (intro >= 322) | |
| { | |
| //only sink if the logo is less than the pillars | |
| if (logoPos.y < 140 - LOGO_HEIGHT) logoPos.y += 1; | |
| } | |
| //logo bouncing | |
| else if (intro >= 312) | |
| { | |
| //bounce the logo until it reaches 120 | |
| if (logoPos.y > 120 - LOGO_HEIGHT) logoPos.y -= 2; | |
| } | |
| //logo falling | |
| else if (intro >= 280) | |
| { | |
| //only sink if the logo is less than the pillars | |
| if (logoPos.y < 140 - LOGO_HEIGHT) logoPos.y += 3; | |
| } | |
| //start the intro screen | |
| else if (intro >= 0 && intro < 241) | |
| { | |
| //only if the intro var is even, to slow it down | |
| if ((intro % 8) == 0) | |
| { | |
| //set the length of the pillars tmp value | |
| int texLen = strlen(tmpTxt); | |
| //set the tmp value to 1 so we dont have extra pillars shoing up | |
| memset(tmpTxt, '*', 1); | |
| //set the tmp variable to the length of the new set of pillars | |
| memset(tmpTxt, '*', texLen+1); | |
| } | |
| } | |
| //start sound | |
| if (intro == 322) | |
| { | |
| if (Mix_PlayMusic(PWSSnd, 1) == -1) | |
| { | |
| fprintf(stderr, "Error playing sound: %s\n", Mix_GetError()); | |
| } | |
| } | |
| } | |
| //we lost, darn | |
| else if (page == "Lose") | |
| { | |
| //clear the screen when needed | |
| if (time(0) % 4 == 0) | |
| { | |
| //clear the page | |
| for (int a=0;a<WIDTH;++a) | |
| for (int b=0;b<HEIGHT;++b) | |
| drawdot(a,b,0,0,0); | |
| } | |
| drawtext(119, 30, "YOU LOSE!"); | |
| drawtext(80, 80, "SCORE:"); | |
| drawscore(136, 80, Score); | |
| drawtext(61, 100, "HIGHSCORE:"); | |
| drawscore(157, 100, Top); | |
| if (Score >= Top) | |
| { | |
| Top = Score; //make sure we don't go overboard | |
| if (time(0) % 4 != 0) drawtext(43, 120, "YOU GOT THE NEW HIGHSCORE!"); //draw the 'new highscore' message | |
| } | |
| } | |
| //yay, we somehow won! | |
| else if (page == "Win") | |
| { | |
| //clear the page | |
| for (int a=0;a<WIDTH;++a) | |
| for (int b=0;b<HEIGHT;++b) | |
| drawdot(a,b,0,0,0); | |
| drawtext(124, 30, "YOU WON!"); | |
| //rot. box | |
| if (time(0) % 2 == 0) | |
| { | |
| drawtext(25, 60, " * * * * * * * * * * * * * * *"); | |
| drawtext(25, 200, "* * * * * * * * * * * * * * * "); | |
| for (int i = 0; i < 5; i++) | |
| { | |
| drawtext(290, 84 + (i * 26), "*"); | |
| drawtext(20, 72 + (i * 26), "*"); | |
| } | |
| } | |
| else | |
| { | |
| drawtext(25, 60, "* * * * * * * * * * * * * * * "); | |
| drawtext(25, 200, " * * * * * * * * * * * * * * *"); | |
| for (int i = 0; i < 5; i++) | |
| { | |
| drawtext(290, 72 + (i * 26), "*"); | |
| drawtext(20, 84 + (i * 26), "*"); | |
| } | |
| } | |
| drawtext(80, 80, "SCORE:"); | |
| drawscore(136, 80, Score); | |
| drawtext(61, 100, "HIGHSCORE:"); | |
| drawscore(157, 100, Top); | |
| if (Score >= Top) | |
| { | |
| Top = Score; //make sure we don't go overboard | |
| if (time(0) % 4 != 0) drawtext(43, 120, "YOU GOT THE NEW HIGHSCORE!"); //draw the 'new highscore' message | |
| } | |
| } | |
| //gotta have it! :) | |
| else if (page == "Easter") | |
| { | |
| SDL_FillRect(screen, &screen->clip_rect, 0x000000); //clear BG | |
| for (int j = 0; j < 22; j++) | |
| { | |
| for (int i = 0; i < 42; i++) | |
| { | |
| drawtext(((i * 8) - 8), ((j * 12) - 12) + ((sinTbl[(i + ticker) % 23] * 4) - 15), "*"); //draw the BG | |
| } | |
| } | |
| //move the pillars logo around randomly | |
| int randPos = rand() % 4; | |
| if (randPos == 0) logoPos.x++; | |
| if (randPos == 1) logoPos.y++; | |
| if (randPos == 2) logoPos.x--; | |
| if (randPos == 3) logoPos.y--; | |
| if (logoPos.x < 0) logoPos.x = 0; | |
| if (logoPos.y < 0) logoPos.y = 0; | |
| if (logoPos.x > 165) logoPos.x = 165; | |
| if (logoPos.y > 195) logoPos.y = 195; | |
| SDL_BlitSurface(sprites, &logoRect, screen, &logoPos); //draw the logo | |
| } | |
| //we won the level, whoopee | |
| else if (page == "Complete") | |
| { | |
| SDL_FillRect(screen, &screen->clip_rect, 0000000); | |
| drawtext(52, 30, "YOU COMPLETED THE LEVEL!"); | |
| drawtext(80, 60, "SCORE: "); | |
| drawscore(143, 60, Score); | |
| drawtext(69, 100, "BULLETS:"); | |
| drawscore(149, 100, tmpInt[0]); | |
| drawtext(69, 130, "PILLARS:"); | |
| drawscore(149, 130, tmpInt[1]); | |
| //addup effect | |
| if (tmpInt[0] > 0 && ticker % 10 == 0) | |
| { | |
| tmpInt[0]--; | |
| Score += 1000; | |
| } | |
| if (tmpInt[1] > 0 && ticker % 10 == 0) | |
| { | |
| tmpInt[1]--; | |
| Score += 500; | |
| } | |
| } | |
| else page = "Menu"; //if we get lost, go back to the main page | |
| if (event.type == SDL_MOUSEBUTTONUP) clicked = false; //reset clicked | |
| //update the intro var if its a positive nubmer | |
| if (intro >= 0) intro++; | |
| //update the timer if its greater than 0 | |
| if (msgDelay) msgDelay--; | |
| //if the timer = 0 unset the message | |
| if (msgDelay <= 0) msg = NULL; | |
| //update the timers | |
| if (timer) timer--; | |
| //draw a message if it esists | |
| if (msg != NULL && page=="Play") drawtext(4, 223, msg); | |
| //update the screen | |
| update(); | |
| //increase the ticker | |
| ticker += 1 % 12800; | |
| //wait 5 milliseconds before looping again | |
| SDL_Delay(5); | |
| } | |
| return 0; | |
| } | |
| //a function to end the game | |
| void end() | |
| { | |
| puts("GAME ENDING"); | |
| //fprintf(gameFile, "SET%xÿ%xÿ%x%xÿ%x", (int)fullscreen, (int)music, (int)sound, sShots, Top); //save the settings | |
| Mix_CloseAudio(); //make sure we clean up the audio | |
| SDL_Quit(); //quit SDL | |
| exit(0); //exit the program | |
| } | |
| //update the screen anyone? | |
| void update() | |
| { | |
| SDL_Flip(screen); | |
| } | |
| //restore the playing background | |
| void redrawBG() | |
| { | |
| //ensure that background color is 0,0,0 | |
| for (int a=0;a<WIDTH;++a) | |
| for (int b=0;b<HEIGHT;++b) | |
| drawdot(a,b,0,0,0); | |
| //institute the vertical/horizontal lines | |
| for (int a=0;a!=10;++a) | |
| { | |
| drawline(24 * a,0,24 * a,216, Col[0],Col[1],Col[2]); | |
| drawline(0,24 * a,216,24 * a, Col[0],Col[1],Col[2]); | |
| } | |
| //draw a box around the screen | |
| drawline(0, 0, WIDTH - 1, 0, Col[0],Col[1],Col[2]); | |
| drawline(0, 0, 0, HEIGHT - 1, Col[0],Col[1],Col[2]); | |
| drawline(WIDTH - 1, 0, WIDTH - 1, HEIGHT - 1, Col[0],Col[1],Col[2]); | |
| drawline(0, HEIGHT - 1, WIDTH - 1, HEIGHT - 1, Col[0],Col[1],Col[2]); | |
| } | |
| //create the window | |
| void create_Window() | |
| { | |
| SDL_putenv("SDL_VIDEO_CENTERED=1"); //center the window on the screen | |
| //initialize audio and video(all we need) | |
| if (SDL_Init(SDL_INIT_AUDIO | SDL_INIT_VIDEO) != 0) | |
| { | |
| printf("Unable to init SDL: %s\n", SDL_GetError()); | |
| end(); | |
| } | |
| //load the game | |
| loadGame(); | |
| //on the program exit, turn off SDL | |
| atexit(SDL_Quit); | |
| //tell screen to be shown (and check for fullscreen | |
| if (fullscreen == 1) | |
| screen = SDL_SetVideoMode(WIDTH, HEIGHT, COLOR_DEPTH, SDL_HWSURFACE | SDL_HWPALETTE | SDL_DOUBLEBUF | SDL_FULLSCREEN); | |
| else | |
| screen = SDL_SetVideoMode(WIDTH, HEIGHT, COLOR_DEPTH, SDL_HWSURFACE | SDL_HWPALETTE | SDL_DOUBLEBUF); | |
| //if theres no screen, whoops | |
| if (screen == NULL) | |
| { | |
| printf("Unable to set video: %s\n", SDL_GetError()); | |
| end(); | |
| } | |
| //set the window caption | |
| SDL_WM_SetCaption("Pillars", NULL); | |
| } | |
| //draw the sprite | |
| void sprite::drawsprite(int x, int y) | |
| { | |
| //set the position | |
| position.x = x; | |
| position.y = y; | |
| //draw the sprite | |
| SDL_BlitSurface(sprites, &rect, screen, &position); | |
| } | |
| //draw a dot | |
| void drawdot(int x, int y, int R, int G, int B) | |
| { | |
| if (x < 0 || y < 0 || x >= WIDTH || y >= HEIGHT) return; | |
| ((unsigned int*)screen->pixels)[y * screen->pitch / 4 + x] = SDL_MapRGB(screen->format, R, G, B); | |
| } | |
| //Bresenham line algorithm | |
| //from (x1,y1) to (x2,y2) with rgb color | |
| void drawline (int x1, int y1, int x2, int y2, int R, int G, int B) | |
| { | |
| int deltax = std::abs(x2 - x1); //The difference between the x's | |
| int deltay = std::abs(y2 - y1); //The difference between the y's | |
| int x = x1; //Start x off at the first pixel | |
| int y = y1; //Start y off at the first pixel | |
| int xinc1, xinc2, yinc1, yinc2, den, num, numadd, numpixels, curpixel; | |
| if (x2 >= x1) //The x-values are increasing | |
| { | |
| xinc1 = 1; | |
| xinc2 = 1; | |
| } | |
| else //The x-values are decreasing | |
| { | |
| xinc1 = -1; | |
| xinc2 = -1; | |
| } | |
| if (y2 >= y1) //The y-values are increasing | |
| { | |
| yinc1 = 1; | |
| yinc2 = 1; | |
| } | |
| else //The y-values are decreasing | |
| { | |
| yinc1 = -1; | |
| yinc2 = -1; | |
| } | |
| if (deltax >= deltay) //There is at least one x-value for every y-value | |
| { | |
| xinc1 = 0; //Don't change the x when numerator >= denominator | |
| yinc2 = 0; //Don't change the y for every iteration | |
| den = deltax; | |
| num = deltax / 2; | |
| numadd = deltay; | |
| numpixels = deltax; //There are more x-values than y-values | |
| } | |
| else //There is at least one y-value for every x-value | |
| { | |
| xinc2 = 0; //Don't change the x for every iteration | |
| yinc1 = 0; //Don't change the y when numerator >= denominator | |
| den = deltay; | |
| num = deltay / 2; | |
| numadd = deltax; | |
| numpixels = deltay; //There are more y-values than x-values | |
| } | |
| for (curpixel = 0; curpixel <= numpixels; curpixel++) | |
| { | |
| drawdot(x % WIDTH, y % HEIGHT, R, G, B); //Draw the current pixel | |
| num += numadd; //Increase the numerator by the top of the fraction | |
| if (num >= den) //Check if numerator >= denominator | |
| { | |
| num -= den; //Calculate the new numerator value | |
| x += xinc1; //Change the x as appropriate | |
| y += yinc1; //Change the y as appropriate | |
| } | |
| x += xinc2; //Change the x as appropriate | |
| y += yinc2; //Change the y as appropriate | |
| } | |
| } | |
| void drawtext(int x, int y, char* text) | |
| { | |
| //a temp integer to hold the ascii value of the character | |
| int asc; | |
| //a temp rect to draw a specific char | |
| SDL_Rect fontRect; | |
| fontRect.w = 8; | |
| fontRect.h = 11; | |
| //a temp rect for where to draw on the screen | |
| SDL_Rect fontPos; | |
| fontPos.x = x; | |
| fontPos.y = y; | |
| //loop through each character | |
| for (int i = 0; i < (int)strlen(text); i++) | |
| { | |
| //change each character to its ascii value | |
| asc = (int)text[i]; | |
| //if the char is a number | |
| if (asc > 47 && asc < 58) | |
| { | |
| fontRect.x = 160 + ((asc - 48) * fontRect.w); | |
| fontRect.y = 0; | |
| } | |
| //if the key is a letter | |
| else if (asc > 64 && asc < 91) | |
| { | |
| fontRect.x = 160 + ((asc - 65) % 10) * fontRect.w; | |
| fontRect.y = fontRect.h + ((asc - 65) / 10) * fontRect.h; | |
| } | |
| else if (asc == 58) | |
| { | |
| fontRect.x = 225; | |
| fontRect.y = 33; | |
| } | |
| else if (asc == 42) | |
| { | |
| fontRect.x = 233; | |
| fontRect.y = 33; | |
| } | |
| //if the key is a space | |
| else if (asc == 32) | |
| { | |
| fontRect.x = 321; | |
| fontRect.y = 1; | |
| } | |
| //exclamation | |
| else if (asc == 33) | |
| { | |
| fontRect.x = 209; | |
| fontRect.y = 33; | |
| } | |
| //question mark | |
| else if (asc == 63) | |
| { | |
| fontRect.x = 217; | |
| fontRect.y = 33; | |
| } | |
| //if the key is none of the above | |
| else continue; | |
| //draw the font | |
| SDL_BlitSurface(sprites, &fontRect, screen, &fontPos); | |
| //update where to draw | |
| fontPos.x += 9; | |
| } | |
| } | |
| void drawscore(int x, int y, int score) | |
| { | |
| //draw all of the zeros | |
| drawtext(x, y, "0000000000"); | |
| //change the score to a string | |
| char str[10]; | |
| itoa(score,str,10); | |
| //draw the score over the 0s | |
| drawtext(x + ((11 - strlen(str)) * 9), y, str); | |
| } | |
| enemy::enemy() | |
| { | |
| //set the values of our data | |
| alive = false; | |
| x = 0; | |
| y = 0; | |
| dir = 0; | |
| } | |
| int saveGame() | |
| { | |
| gameFile = fopen("PS.set", "w"); | |
| if (gameFile == NULL) return 0; | |
| //write out the data | |
| fprintf(gameFile, "SET%xÿ%xÿ%x%xÿ%xÿ%x%x%x%x%x%x\n", | |
| (int)fullscreen, (int)music, (int)sound, sShots, Top, lvl, lives, x, y, dir, Score); | |
| //close the file | |
| fclose(gameFile); | |
| //return sucsess! | |
| return 1; | |
| } | |
| void loadGame() | |
| { | |
| gameFile = fopen("PS.set", "r"); | |
| if (gameFile == NULL) | |
| { | |
| fullscreen = false; | |
| music = true; | |
| sound = true; | |
| sShots = 1; | |
| Top = 0; | |
| lvl = 0; | |
| lives = 3; | |
| x = 0; | |
| y = 0; | |
| dir = 0; | |
| } | |
| else | |
| { | |
| //write out the data | |
| fscanf(gameFile, "SET%xÿ%xÿ%x%xÿ%xÿ%x%x%x%x%x%x\n", | |
| &fullscreen, &music, &sound, &sShots, &Top, &lvl, &lives, &x, &y, &dir, &Score); | |
| //close the file | |
| fclose(gameFile); | |
| } | |
| } | |
| //whether or not to show the mouse(based on whether your in fullscreen or not) | |
| void showMouse(bool fullscreen) | |
| { | |
| if (fullscreen) | |
| { | |
| if (SDL_ShowCursor(SDL_QUERY) == SDL_ENABLE) SDL_ShowCursor(0); | |
| else SDL_ShowCursor(1); | |
| } | |
| } | |
| //buby | |
| void dropBomb(int x, int y) | |
| { | |
| for (int i = 0; i < 3; i++) | |
| for (int j = 0; j < 3; j++) | |
| { | |
| short mapTile = map[(y - 1) + j][(x - 1) + i]; //lazyness | |
| if (mapTile == 1) //pillar goes to rubble | |
| map[(y - 1) + j][(x - 1) + i] = 2; | |
| else if (i != 1 && j != 1) //make sure it's not us | |
| map[(y - 1) + j][(x - 1) + i] = 0; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment