Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //#include <iostream>
- #include <windows.h>
- #include <SDL2/SDL.h>
- #include <time.h>
- #include <math.h>
- #include <stdio.h>
- #include <stdarg.h>
- #include <zlib.h>
- #include <vector>
- #include <bass.h>
- //#include "Mixer.h"
- #include "pack.h"
- #ifdef _DEBUG
- #define __BUILD_CONFIG__ "debug"
- #else
- #define __BUILD_CONFIG__ "release"
- #endif
- #if defined(__amd64__) || defined(_M_X64)
- #define __ARCH__ "x64"
- #elif defined(__i386__) || defined(_M_IX86) || defined(_X86_)
- #define __ARCH__ "x86"
- #else
- #define __ARCH__ "---"
- #endif
- #define __VERSION__ "rc1"
- #define MENU_BACK 0
- #define MENU_ACTION 1
- /*
- #define PACK_SIZE 9144070
- #define PACK_CRC32 0x007F4135*/
- #define MARKER_CRASH 1097459
- //#include "version.h"
- /*
- TODO:
- * elliptic collision
- */
- struct obj {
- int id; // obj texture id
- int x;
- int y; // const = 540?
- };
- std::vector<obj*> objs;
- using namespace std;
- //SDL_Surface* spajst, *slupt, *slup2t, *tlot, *turbinat, *pigulat;
- SDL_Texture* spajs, *goclaw, *slup, *tlo, *smuteg, *turbina, *fontRender, *pigula, *tlo_cz1, *chmura, *weeia, *cyfry;
- SDL_Texture* object[2];
- SDL_Texture* slonce1, *slonce2;
- SDL_Renderer* render;
- SDL_Window* win;
- SDL_TimerID timer, uptimer;
- SDL_Joystick* joy = NULL;
- SDL_Texture* fader; // for fading
- bool uiSet = false;
- // ---------- AUDIO DECLARE ----------
- HSAMPLE spajsW,menuMoveW,menuActionW,menuBackW,menuMusW,punktW,pszegrywW,cheatW;
- HCHANNEL musicCh;
- HSTREAM stream;
- int playMus = 0; // 0 - intro 1 - loop 2 - end
- float sndVol = 1.0f;
- // ---------- END AUDIO DECLARE ------
- bool debug = false;
- char font[16 * 94];
- int spajscepcja_wearoff;
- gzFile pack;
- //int przegrano = 0;
- int gracz = 0;
- SDL_Texture* graczT[2];
- char playerName[2][20] = { "SPICE","Goclaw" };
- int indeks = 0;
- int menuID = 0;
- int fade = 0;
- int fadeState = 2;
- int selPlayer = 0;
- char cheatPt = 0;
- bool goclawUnlock = false;
- //void _mixer_main(void* user, Uint8* stream, int len); // TODO: move to CMixer?
- void text_center_printf(char* text, int x, int y, int* strBegin, int* strEnd, ...);
- //CMixer* mixer;
- //std::vector<SDL_Rect*> sladSpice;
- typedef struct {
- unsigned int offset;
- //unsigned int uncompressedOffset;
- unsigned int size;
- unsigned int orgSize;
- unsigned char name[24];
- } fileEntry;
- std::vector<fileEntry*> fileDirectory;
- typedef struct {
- unsigned char player;
- unsigned int score;
- char name[16];
- } hallOfFameEntry;
- hallOfFameEntry hof[10];
- int state = 0; // 0 - menu, 1 - game, 2 - gameover, 3 - turbina debug, 4 = sun debug
- bool turbo = false;
- //bool __timerReady = false;
- struct scianka {
- int dist;
- double passY;
- bool spajscepcja;
- };
- scianka s[100];
- double sX = 0, sY = 360, sVY, tX, tY;
- int frame = 0, uptime = 0, fps = 0, frames = 0;
- int ms = 0;
- int nextSlup = 0;
- double gameSpeed = 1;
- Uint8* spajsWav,*spajsCur;
- Uint8* przegrywWav;
- unsigned int przegrywLen;
- unsigned int spajsLen,spajsPos;
- bool hofInput = false;
- int hofCursor = 0;
- bool koniec = false;
- void generateSlupki() {
- if (objs.size() > 0) {
- for (int i = objs.size() - 1; i > 0; i--) {
- delete objs[i];
- objs.pop_back();
- }
- }
- s[0].dist = 700 + (rand() % 500);
- s[0].passY = -400 + (rand() % 300);
- for (int i = 1; i<100; i++) {
- s[i].dist = s[i - 1].dist + (500 + (rand() % 500));
- s[i].passY = -200 + (rand() % 300);
- s[i].spajscepcja = (rand() % 100 > 75);
- }
- obj* newObj;
- newObj = new obj;
- newObj->x = 540;
- newObj->y = 540-62;
- newObj->id = 0;
- objs.push_back(newObj);
- }
- void renderGUI(int id) {
- SDL_Rect wybor;
- int beg, end;
- switch (id) {
- case 0:
- text_center_printf("Nowa gra", 640, 360, (indeks == 0 ? &beg : NULL), (indeks == 0 ? &end : NULL));
- text_center_printf("Opcje", 640, 360 + 16, (indeks == 1 ? &beg : NULL), (indeks == 1 ? &end : NULL));
- text_center_printf("Wyjscie", 640, 360 + 32, (indeks == 2 ? &beg : NULL), (indeks == 2 ? &end : NULL));
- break;
- case 10:
- char playa[512];
- memset(playa, 0, 512);
- sprintf(playa, "Gracz: %s",playerName[selPlayer]);
- text_center_printf(playa,640,360, (indeks == 0 ? &beg : NULL), (indeks == 0 ? &end : NULL),playa);
- if (joy == NULL) sprintf(playa, "%s", "Nie wykryto pada - podlacz i nacisnij ENTER");
- /*else sprintf(playa, "Ilosc padow: %d, wybrany padad: %s", SDL_NumJoysticks(), SDL_JoystickName(joy));
- text_center_printf(playa,640,360+16, NULL, NULL);*/
- sprintf(playa, "Dzwiek: %.0f%%", sndVol*100);
- text_center_printf(playa, 640, 360+16, (indeks == 1 ? &beg : NULL), (indeks == 1 ? &end : NULL));
- text_center_printf("Powrot", 640, 360 + 32, (indeks == 2 ? &beg : NULL), (indeks == 2 ? &end : NULL));
- break;
- default:
- text_center_printf("non-existent menu %d !", 640, 360, &beg, &end);
- break;
- }
- wybor.x = beg - 16;
- wybor.y = 352 + (indeks * 16);
- wybor.h = 16;
- wybor.w = 16;
- SDL_RenderCopyEx(render, spajs, NULL, &wybor, frame, NULL, SDL_FLIP_NONE);
- wybor.x = end;
- SDL_RenderCopyEx(render, spajs, NULL, &wybor, -frame, NULL, SDL_FLIP_NONE);
- }
- void handleGUI(int id,int action) {
- switch (id) {
- case 0: // main menu
- if (action == MENU_BACK) koniec = true;
- else if (action == MENU_ACTION) {
- switch (indeks) {
- case 0: // new game
- state = 1;
- sX = 0;
- sY = 360;
- sVY = 0;
- turbo = false;
- nextSlup = 0;
- ms = 0;
- spajscepcja_wearoff = 0;
- generateSlupki();
- break;
- case 1: // options
- menuID = 10;
- indeks = 0;
- break;
- case 2: // exit
- koniec = true;
- break;
- }
- }
- break;
- case 10:
- if (action == MENU_BACK) {
- indeks = 1;
- menuID = 0;
- }
- else if (action == MENU_ACTION) {
- switch (indeks) {
- case 0: // change player
- //przegrano++;
- if(goclawUnlock) selPlayer = (selPlayer + 1) % 2;
- break;
- case 1: // change sound volume
- sndVol += 0.1f;
- if (sndVol > 1.01f) {
- sndVol = 0.0f;
- }
- BASS_ChannelSetAttribute(musicCh, BASS_ATTRIB_VOL, sndVol*0.7f);
- break;
- case 2: // return to main
- indeks = 0;
- menuID = 0;
- break;
- }
- }
- break;
- }
- }
- void text_printf(char* text, int x, int y, ...) {
- va_list args;
- char buf[1024];
- va_start(args, text);
- memset(buf, 0, 1024);
- vsprintf(buf, text, args);
- va_end(args);
- SDL_SetRenderDrawColor(render, 0, 0, 0, 255);
- for (int k = 0; k<strlen(buf); k++) {
- if (buf[k] >= 0x21 && buf[k] <= 0x7E) {
- int offset = (buf[k] - 0x21) * 16;
- for (int i = 0; i<16; i++) {
- for (int j = 0; j<8; j++) {
- if (font[offset + i] & (1 << j)) SDL_RenderDrawPoint(render, (k * 8) + j + x, i + y);
- }
- }
- }
- }
- }
- void initFade() {
- fader = SDL_CreateTexture(render, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_TARGET, 1280, 720);
- SDL_SetRenderTarget(render, fader);
- SDL_SetRenderDrawColor(render, 255, 255, 255, 255);
- SDL_RenderClear(render);
- SDL_SetRenderTarget(render, NULL);
- }
- void flashFade() {
- fadeState = 2;
- SDL_Rect r;
- r.x = 0;
- r.y = 0;
- r.w = 1280;
- r.h = 720;
- SDL_SetRenderDrawColor(render, 255, 255, 255, fade);
- if (fadeState == 0) fade++;
- if (fade >= 255 && fadeState == 0) {
- fadeState = 1;
- fade = 255;
- }
- if (fadeState == 1) fade--;
- else if (fadeState == 1 && fade <= 0) {
- fadeState = 2;
- fade = 0;
- }
- }
- void text_center_printf(char* text, int x, int y, int* strBegin, int* strEnd, ...) {
- va_list args;
- int tx, ty;
- char buf[1024];
- va_start(args, text);
- memset(buf, 0, 1024);
- vsprintf(buf, text, args);
- va_end(args);
- SDL_SetRenderDrawColor(render, 0, 0, 0, 255);
- tx = x - ((strlen(buf) * 8) / 2);
- if (strBegin != NULL) *strBegin = tx;
- if (strEnd != NULL) *strEnd = tx + (strlen(buf)*8);
- ty = y - 8;
- for (int k = 0; k<strlen(buf); k++) {
- if (buf[k] >= 0x21 && buf[k] <= 0x7E) {
- int offset = (buf[k] - 0x21) * 16;
- for (int i = 0; i<16; i++) {
- for (int j = 0; j<8; j++) {
- if (font[offset + i] & (1 << j)) SDL_RenderDrawPoint(render, (k * 8) + j + tx, i + ty);
- }
- }
- }
- }
- }
- int getFileByName(char* name, char* data, fileEntry* meta) {
- for (int i = 0; i < fileDirectory.size(); i++) {
- if (!strcmp(name, (char*)fileDirectory[i]->name)) {
- if (meta != NULL) {
- meta->size = fileDirectory[i]->size;
- meta->orgSize = fileDirectory[i]->orgSize;
- meta->offset = fileDirectory[i]->offset;
- memcpy(meta->name, fileDirectory[i]->name, 24);
- if (data == NULL) return 1;
- }
- if (data != NULL) {
- gzseek(pack, fileDirectory[i]->offset, SEEK_SET);
- gzread(pack, data, fileDirectory[i]->orgSize);
- return 1;
- }
- }
- }
- return 0;
- }
- SDL_Texture* loadBMP(const char* path, bool transparency, bool setIcon = false) {
- SDL_Surface* temp;
- SDL_Texture* texture;
- SDL_RWops* op;
- char* mem;
- fileEntry info;
- char str[512];
- memset(str, 0, 512);
- if(getFileByName((char*)path, NULL, &info)) mem = new char[info.orgSize];
- else {
- sprintf(str, "Nie można wczytać pliku %s (%s)", path, SDL_GetError());
- SDL_ShowSimpleMessageBox(SDL_MessageBoxFlags::SDL_MESSAGEBOX_ERROR, "BÅ‚Ä…d", str, win);
- return NULL;
- }
- getFileByName((char*)path, mem, NULL);
- op = SDL_RWFromMem(mem, info.orgSize);
- temp = SDL_LoadBMP_RW(op, 0);
- delete[] mem;
- if (temp == NULL) {
- sprintf(str, "Nie można wczytać pliku %s (%s)", path, SDL_GetError());
- SDL_ShowSimpleMessageBox(SDL_MessageBoxFlags::SDL_MESSAGEBOX_ERROR, "BÅ‚Ä…d", str, win);
- return NULL;
- }
- if (transparency) SDL_SetColorKey(temp, SDL_TRUE, SDL_MapRGB(temp->format, 255, 128, 255));
- texture = SDL_CreateTextureFromSurface(render, temp);
- if (setIcon) SDL_SetWindowIcon(win, temp);
- SDL_FreeSurface(temp);
- return texture;
- }
- int isFileValid() {
- char* mem;
- fpos_t size;
- FILE* f = fopen("SpiceIsLove.img", "rb");
- if (f == NULL) return 0;
- fseek(f, 0, SEEK_END);
- fgetpos(f, &size);
- fseek(f, 0, SEEK_SET);
- if (size != PACK_SIZE) return 0;
- mem = new char[size];
- fread(mem, 1, size, f);
- fclose(f);
- if (crc32(0, (const Bytef*)mem, size) != PACK_CRC32) {
- delete mem;
- return 0;
- }
- delete mem;
- return 1;
- }
- HSAMPLE loadWAV(char* name, bool loop = false) {
- fileEntry info;
- HSAMPLE temp;
- getFileByName(name, NULL, &info);
- char* mem = new char[info.orgSize];
- getFileByName(name, mem, NULL);
- temp = BASS_SampleLoad(TRUE, mem, 0, info.orgSize, 3, (loop == true ? BASS_SAMPLE_LOOP : 0));
- delete[] mem;
- mem = NULL;
- return temp;
- }
- void playSound(HSAMPLE spl, bool fadeIn = false, float vol = 1, float pan = 0) {
- HCHANNEL chan = BASS_SampleGetChannel(spl, FALSE);
- BASS_ChannelSetAttribute(chan, BASS_ATTRIB_VOL, vol*sndVol);
- BASS_ChannelSetAttribute(chan, BASS_ATTRIB_PAN, pan);
- if (fadeIn) {
- BASS_ChannelSlideAttribute(chan, BASS_ATTRIB_VOL, 0.7, 5000);
- musicCh = chan;
- }
- BASS_ChannelPlay(chan, TRUE);
- }
- void load() {
- SDL_AudioSpec dummy;
- unsigned int fileCount;
- if (!isFileValid()) {
- SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Błąd", "Nie można otworzyć pliku \"SpiceIsLove.img\"", win);
- exit(1);
- }
- pack = gzopen("SpiceIsLove.img", "rb");
- initFade();
- SDL_SetRenderDrawColor(render, 255, 255, 255, 255); // render bg
- SDL_RenderClear(render);
- text_center_printf("Wczytywanie...",640,360,NULL,NULL);
- SDL_RenderPresent(render);
- gzread(pack, &fileCount, 4);
- if (fileCount == 0) {
- }
- for (unsigned int i = 0; i < fileCount; i++) {
- fileEntry* entry = new fileEntry;
- gzread(pack, &entry->offset, 4);
- //gzread(pack, &entry->uncompressedOffset, 4);
- gzread(pack, &entry->size, 4);
- gzread(pack, &entry->orgSize, 4);
- //uncompressedSize += entry->orgSize;
- gzread(pack, &entry->name, 24);
- fileDirectory.push_back(entry);
- }
- getFileByName("font.bin", font, NULL);
- goclaw = loadBMP("goclaw.bmp", true);
- spajs = loadBMP("spajs.bmp",true,true);
- graczT[0] = spajs;
- graczT[1] = goclaw;
- slup = loadBMP("slup.bmp",true);
- //slup2 = loadBMP("slup2.bmp",true);
- tlo = loadBMP("title.bmp",false);
- turbina = loadBMP("turbina.bmp",false);
- pigula = loadBMP("pigula.bmp", false);
- tlo_cz1 = loadBMP("tlo_cz1.bmp", false);
- chmura = loadBMP("chmura.bmp", true);
- weeia = loadBMP("weeia.bmp", true);
- smuteg = loadBMP("smuteg.bmp", true);
- slonce1 = loadBMP("slonce1.bmp", true);
- slonce2 = loadBMP("slonce2.bmp", true);
- cyfry = loadBMP("cyfry.bmp", true);
- object[0] = loadBMP("krzak1.bmp", true);
- spajsW = loadWAV("spajs.wav");
- menuMusW = loadWAV("loop.wav", true);
- menuActionW = loadWAV("menuAction.wav");
- menuMoveW = loadWAV("menuMove.wav");
- menuBackW = loadWAV("menuBack.wav");
- punktW = loadWAV("punkt.wav");
- pszegrywW = loadWAV("pszegryw2.wav");
- cheatW = loadWAV("cheat.wav");
- /*loadWAV("spajs.wav", &spajsWav, &spajsLen); spajsCur = spajsWav; spajsPos = spajsLen; //spajsP = spajsWL;
- loadWAV("przegryw.wav", &przegrywWav, &przegrywLen);
- loadWAV("intro.wav", &introW, &introWL); introP = introWL;
- loadWAV("loop.wav", &loopW, &loopWL); loopP = loopWL;
- musicC = introW;*/
- gzclose(pack);
- generateSlupki();
- playSound(menuMusW, true, 0.0f);
- FILE* f = fopen("SpiceIsLife.bin", "rb");
- if (f == NULL) {
- f = fopen("SpiceIsLife.bin", "wb");
- for (int i = 0; i < 10; i++) {
- hof[i].player = 0;
- hof[i].score = 0;
- memset(hof[i].name, '.', 15);
- hof[i].name[15] = 0;
- }
- fwrite(hof, 1, sizeof(hallOfFameEntry) * 10, f);
- }
- else {
- fread(hof, 1, sizeof(hallOfFameEntry) * 10, f);
- }
- fclose(f);
- }
- int placeInHall() {
- for (int i = 0; i < 10; i++) {
- if (nextSlup >= hof[i].score) return i;
- }
- return -1;
- }
- void jump() {
- if (state != 1) {
- sX = 0;
- sY = 360;
- sVY = 0;
- turbo = false;
- nextSlup = 0;
- ms = 0;
- spajscepcja_wearoff = 0;
- generateSlupki();
- state = 1;
- }
- else {
- if(selPlayer == 0) playSound(spajsW);
- if (turbo) sVY = -1.66*(gameSpeed / 3);
- else sVY = -1.66;
- }
- }
- void free() {
- SDL_FreeWAV(spajsWav);
- SDL_FreeWAV(przegrywWav);
- SDL_DestroyTexture(cyfry);
- SDL_DestroyTexture(object[0]);
- SDL_DestroyTexture(slonce1);
- SDL_DestroyTexture(slonce2);
- SDL_DestroyTexture(fader);
- SDL_DestroyTexture(smuteg);
- SDL_DestroyTexture(goclaw);
- SDL_DestroyTexture(chmura);
- SDL_DestroyTexture(tlo_cz1);
- SDL_DestroyTexture(spajs);
- SDL_DestroyTexture(slup);
- SDL_DestroyTexture(weeia);
- SDL_DestroyTexture(tlo);
- SDL_DestroyTexture(turbina);
- BASS_SampleFree(punktW);
- BASS_SampleFree(spajsW);
- BASS_SampleFree(menuMusW);
- BASS_SampleFree(menuBackW);
- BASS_SampleFree(menuMoveW);
- BASS_SampleFree(menuActionW);
- BASS_SampleFree(pszegrywW);
- BASS_SampleFree(cheatW);
- /*SDL_FreeWAV(spajsW);
- SDL_FreeWAV(loopW);
- SDL_FreeWAV(introW);*/
- //SDL_DestroyTexture(fontRender);
- }
- Uint32 waiter(Uint32 interval, void* param) {
- //__timerReady = true;
- //return 0;
- ms++;
- return interval;
- }
- Uint32 uptimeCounter(Uint32 interval, void* param) {
- uptime++;
- fps = frames;
- frames = 0;
- return interval;
- }
- Uint32 update(Uint32, void*) {
- //if(__timerReady) {
- if (state == 0) {
- if (menuID == 10 && indeks == 0) {
- if ((cheatPt & 7) && (goclawUnlock == false)) {
- playSound(cheatW);
- goclawUnlock = true;
- }
- }
- }
- if (state == 1) {
- if (frame > spajscepcja_wearoff) turbo = false;
- else turbo = true;
- if (turbo) gameSpeed = 6;
- else gameSpeed = 1;
- sVY += 0.008*gameSpeed;
- sY += sVY;
- sX+=gameSpeed;
- if (sX > s[nextSlup].dist && sY > (772 + s[nextSlup].passY - 550) && sY < (179 + s[nextSlup].passY + (250))) {
- //SDL_ShowSimpleMessageBox(0,"f","pkt",win);
- if (s[nextSlup].spajscepcja) spajscepcja_wearoff = frame + 300;
- nextSlup++;
- playSound(punktW);
- }
- else if (sX > s[nextSlup].dist && ((sY < (772 + s[nextSlup].passY - 550) || (179 + sY >(s[nextSlup].passY + (250)))))) {
- //__asm int 3;
- //SDL_ShowSimpleMessageBox(0,"uuu","przegryf :/",win);
- //if(joy != NULL) przegrano++;
- spajsCur = przegrywWav;
- spajsPos = przegrywLen;
- if(selPlayer == 0) playSound(pszegrywW);
- if (placeInHall() > -1) {
- hof[placeInHall()].score = nextSlup;
- hof[placeInHall()].player = selPlayer;
- hofInput = true;
- hofCursor = 0;
- memset(hof[placeInHall()].name, 0, 16);
- } else nextSlup = 0;
- state = 2;
- sX = 0;
- sY = 360;
- sVY = 0;
- turbo = false;
- ms = 0;
- spajscepcja_wearoff = 0;
- generateSlupki();
- }
- }
- //}
- return 0;
- }
- void blit(SDL_Texture* t, int x, int y, int w, int h) {
- static SDL_Rect r;
- r.x = x;
- r.y = y;
- if (w != 0) r.w = w;
- if (h != 0) r.h = h;
- SDL_RenderCopy(render, t, NULL, &r);
- }
- void draw() {
- SDL_Rect spajsr, slupr[200], turbinar, rect, src, dst; // TODO: this can be done with just one "slupr"
- spajsr.w = 143;
- spajsr.h = 179;
- spajsr.x = 60;
- spajsr.y = sY;
- rect.w = 32;
- rect.h = 32;
- //if(__timerReady) {
- if(fadeState == 2) SDL_SetRenderDrawColor(render, 123, 166, 237, 255); // render bg
- else SDL_SetRenderDrawColor(render, 0,0,0, 255); // render bg
- SDL_RenderClear(render);
- if (state == 0) {
- SDL_RenderCopy(render, tlo, NULL, NULL);
- text_printf("version " __VERSION__, 0, 688);
- text_printf("build date: " __DATE__ " " __TIME__ " (" __ARCH__ " " __BUILD_CONFIG__ " build)", 0, 704);
- renderGUI(menuID);
- }
- else if (state == 1) {
- if (turbo) {
- tX = cos((double)frame / 50) * 100;//(30-sin((double)frame/100)*20))*100;
- tY = sin((double)frame / 50) * 100;//(30+cos((double)frame/100)*20))*100;
- for (int i = -1; i<15; i++) {
- for (int j = -1; j<15; j++) {
- turbinar.x = j * 377 + tX;
- turbinar.y = i * 496 + tY;
- turbinar.w = 377;
- turbinar.h = 496;
- SDL_RenderCopy(render, turbina, NULL, &turbinar);
- SDL_RenderCopyEx(render, turbina, NULL, &turbinar, frame, NULL, SDL_FLIP_NONE);
- }
- }
- }
- rect.x = 0;
- rect.y = 0;
- rect.w = 300;
- rect.h = 300;
- SDL_RenderCopyEx(render, slonce1, NULL, &rect, frame, NULL, SDL_FLIP_NONE);
- SDL_RenderCopy(render, slonce2, NULL, &rect);
- for (int i = 0; i < (1280 / 24) + 2; i++) {
- rect.y = 720 - 180;
- rect.x = -24 + (((int)sX%24) + (i*24));
- rect.w = 24;
- rect.h = 180;
- SDL_RenderCopy(render, tlo_cz1, NULL, &rect);
- }
- for (int i = 0; i < objs.size(); i++) {
- rect.x = objs[i]->x - (sX/70);
- rect.y = objs[i]->y;
- SDL_QueryTexture(object[objs[i]->id], NULL, NULL, &rect.w, &rect.h);
- SDL_RenderCopy(render, object[objs[i]->id], NULL, &rect);
- }
- rect.x = 1000 - (sX / 70);
- rect.y = 180;
- rect.w = 353;
- rect.h = 204;
- SDL_RenderCopy(render, chmura, NULL, &rect);
- rect.x = 512 - (sX / 50);
- rect.y = 360;
- rect.w = 720;
- rect.h = 180;
- SDL_RenderCopy(render, weeia, NULL, &rect);
- //SDL_Texture* plyr = spajs;//((przegrano % 2) && joy != NULL ? goclaw : spajs);
- if (!turbo) SDL_RenderCopyEx(render, graczT[selPlayer], NULL, &spajsr, sVY * 18, NULL, SDL_FLIP_NONE);
- else SDL_RenderCopyEx(render, graczT[selPlayer], NULL, &spajsr, (-frame * 2) + sVY * 18, NULL, SDL_FLIP_NONE);
- for (int i = 0; i<100; i++) {
- slupr[(i * 2)].x = s[i].dist - sX;
- slupr[(i * 2)].y = s[i].passY - 566;
- slupr[(i * 2)].w = 133;
- slupr[(i * 2)].h = 772;
- SDL_RenderCopyEx(render, slup, NULL, &slupr[(i * 2)], 0, NULL, SDL_FLIP_VERTICAL);
- if (s[i].spajscepcja) {
- rect.x = s[i].dist + 16 - sX;
- rect.y = s[i].passY + 250;
- rect.w = 32;
- rect.h = 32;
- //SDL_SetRenderDrawColor(render, 255, 0, 0, 255);
- //SDL_RenderFillRect(render, &rect);
- SDL_RenderCopy(render, pigula, NULL, &rect);
- }
- slupr[(i * 2) + 1].x = s[i].dist - sX;
- slupr[(i * 2) + 1].y = s[i].passY + 666;
- slupr[(i * 2) + 1].w = 133;
- slupr[(i * 2) + 1].h = 772;
- if(s[i].dist - sX > -133 && s[i].dist - sX < 1413) SDL_RenderCopy(render, slup, NULL, &slupr[(i * 2) + 1]);
- /*if (debug) text_printf("FPS: %d, uptime: %d:%.2d, frame: %d, ms: %d, Y: %f, vY: %f, nextSlup: %d, passY: %f, minY: %f, maxY: %f", 0, 0, fps, uptime / 60, uptime % 60, frame, ms, sY, sVY, nextSlup, s[nextSlup].passY, double(s[nextSlup].passY - 550), double(s[nextSlup].passY + 550)); {
- }
- //else text_printf("%d",0,0,nextSlup);*/
- /* -- UI START -- */
- src.y = 0;
- src.w = 32;
- src.h = 48;
- dst.y = 96;
- dst.w = 32;
- dst.h = 48;
- src.x = (nextSlup / 10) * 32;
- dst.x = 624;
- SDL_RenderCopy(render, cyfry, &src, &dst);
- src.x = (nextSlup % 10) * 32;
- dst.x = 656;
- SDL_RenderCopy(render, cyfry, &src, &dst);
- }
- }
- else if (state == 2) {
- double ccX, ccY;
- int beg;
- char hofText[512];
- // table start 208
- text_center_printf("Najlepsze wyniki: ", 640, 176, NULL, NULL);
- for (int i = 0; i < 10; i++) {
- memset(hofText, 0, 512);
- sprintf(hofText, "%d %s", hof[i].score, hof[i].name);
- text_center_printf(hofText, 640, 208 + (i*16), &beg, NULL);
- blit(graczT[hof[i].player], beg - 16, 208 + (i * 16) - 8, 16, 16);
- }
- memset(hofText, 0, 512);
- if(placeInHall() > - 1) sprintf(hofText, "Zajales %d. miejsce, brawo, wpisz sie i nacisnij ENTER aby zapisac wyniki, ESC aby wyjsc do menu.",placeInHall()+1);
- else sprintf(hofText, "Niestety, nie udalo ci sie zdobyc zadnego miejsca. Wcisnij ENTER lub ESC aby powrocic do menu.");
- text_center_printf(hofText, 640, 400,NULL,NULL);
- ccX = 640 - (267 / 2) + double(cos(double(frame/66)) * 400);
- ccY = 400 + double(sin(double(frame/40))* 100);
- rect.x = ccX;
- rect.y = ccY;
- rect.w = 267;
- rect.h = 324;
- SDL_RenderCopy(render, smuteg, NULL, &rect);
- }
- /*else if (state == 3) {
- // moved to state 1 (game)
- }
- else if (state == 4) {
- SDL_Rect r;
- r.x = 0;
- r.y = 0;
- r.w = 300;
- r.h = 300;
- SDL_RenderCopyEx(render, slonce1, NULL, &r, frame, NULL, SDL_FLIP_NONE);
- SDL_RenderCopy(render, slonce2, NULL, &r);
- }*/
- else {
- text_center_printf("error unknown state %d", 640, 360, NULL, NULL, state);
- }
- //if(debug) printf("build %d (%s/%s/%s)",0,8,AutoVersion::BUILD,AutoVersion::DATE,AutoVersion::MONTH,AutoVersion::YEAR);
- //SDL_RenderCopy(render,fontRender,NULL,NULL);
- SDL_RenderPresent(render);
- frame = SDL_GetTicks() / 10;
- frames++;
- //__timerReady = false;
- //}
- //SDL_Delay(2);
- }
- int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
- {
- SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_JOYSTICK);
- atexit(SDL_Quit);
- win = SDL_CreateWindow("Flappy Spice " __VERSION__ " (" __DATE__ " " __TIME__ " - " __ARCH__ " " __BUILD_CONFIG__ " build)", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720, 0);
- render = SDL_CreateRenderer(win, -1, 0);
- SDL_ShowWindow(win);
- SDL_Event ev;
- srand(time(NULL));
- BASS_Init(-1, 44100, BASS_DEVICE_STEREO, 0, NULL);
- load();
- if (SDL_NumJoysticks() > 0) {
- joy = SDL_JoystickOpen(0);
- }
- else {
- joy = NULL;
- }
- /*SDL_AudioSpec format;
- memset(&format, 0, sizeof(SDL_AudioSpec));
- format.freq = 44100;
- format.channels = 2;
- format.format = AUDIO_S16;
- format.samples = 4096;
- format.callback = _mixer_main;
- audio = SDL_OpenAudioDevice(NULL, 0, &format, NULL, 0);
- spajsCur = spajsWav;
- spajsPos = spajsLen;*/
- //mixer = new CMixer();
- //SDL_PauseAudioDevice(audio, 0);
- //mixer->play(MIXER_STREAM, (unsigned char*) "getabrain_loop.wav", 0, 1);
- timer = SDL_AddTimer(1, waiter, NULL);
- uptimer = SDL_AddTimer(10, uptimeCounter, NULL);
- while (!koniec) {
- while (SDL_PollEvent(&ev)) {
- switch (ev.type) {
- case SDL_QUIT:
- koniec = true;
- break;
- case SDL_KEYUP:
- switch (ev.key.keysym.sym) {
- case SDLK_7:
- case SDLK_5:
- case SDLK_4:
- cheatPt = 0;
- break;
- }
- break;
- case SDL_KEYDOWN:
- if (state == 0) {
- switch (ev.key.keysym.sym) {
- case SDLK_UP:
- indeks = ((indeks == 0 ? indeks = 2 : --indeks)) % 3;
- playSound(menuMoveW);
- break;
- case SDLK_DOWN:
- indeks = (++indeks) % 3;
- playSound(menuMoveW);
- break;
- case SDLK_RETURN:
- handleGUI(menuID, MENU_ACTION);
- playSound(menuActionW);
- break;
- case SDLK_ESCAPE:
- handleGUI(menuID, MENU_BACK);
- playSound(menuBackW);
- case SDLK_7:
- cheatPt = cheatPt | 1;
- break;
- case SDLK_5:
- cheatPt = cheatPt | 2;
- break;
- case SDLK_4:
- cheatPt = cheatPt | 4;
- break;
- }
- }
- else if (state == 1) {
- //if (przegrano % 2 == 0) {
- if (state != 1) state = 1;
- if (state == 1 && ev.key.keysym.sym == SDLK_t) turbo = !turbo;
- if (state == 1 && ev.key.keysym.sym == SDLK_d) debug = !debug;
- if (state == 1 && ev.key.keysym.sym == SDLK_SPACE) jump();
- //}
- }
- else if (state == 2) {
- if (hofInput) {
- int place = placeInHall();
- if (ev.key.keysym.sym == SDLK_BACKSPACE) {
- hof[place].name[hofCursor] = 0;
- if (hofCursor > 0) hofCursor--;
- }
- else if (ev.key.keysym.sym == SDLK_RETURN) {
- hofInput = false;
- FILE* f = fopen("SpiceIsLife.bin", "wb");
- fwrite(hof, 1, sizeof(hallOfFameEntry) * 10, f);
- fclose(f);
- playSound(menuBackW);
- sX = 0;
- sY = 360;
- sVY = 0;
- turbo = false;
- ms = 0;
- spajscepcja_wearoff = 0;
- generateSlupki();
- state = 0;
- indeks = 0;
- menuID = 0;
- }
- else {
- if (hofCursor < 15) {
- hof[place].name[hofCursor] = ev.key.keysym.sym;
- hofCursor++;
- }
- }
- }
- }
- if (ev.key.keysym.sym == SDLK_ESCAPE && state != 0) {
- playSound(menuBackW);
- state = 0;
- sX = 0;
- sY = 360;
- nextSlup = 0;
- sVY = 0;
- turbo = false;
- ms = 0;
- spajscepcja_wearoff = 0;
- generateSlupki();
- }
- if (ev.key.keysym.sym == SDLK_F12) {
- SDL_Surface *sshot = SDL_CreateRGBSurface(0, 1280, 720, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000);
- SDL_RenderReadPixels(render, NULL, SDL_PIXELFORMAT_ARGB8888, sshot->pixels, sshot->pitch);
- SDL_SaveBMP(sshot, "screen.bmp");
- SDL_FreeSurface(sshot);
- }
- break;
- case SDL_JOYAXISMOTION:
- if (state == 0) {
- if (ev.jaxis.value < -16384 && ev.jaxis.axis == 1) {
- indeks = ((indeks == 0 ? indeks = 2 : --indeks)) % 3;
- playSound(menuMoveW);
- }
- else if (ev.jaxis.value > 16384 && ev.jaxis.axis == 1) {
- indeks = (++indeks) % 3;
- playSound(menuMoveW);
- }
- }
- else if (state == 1) {
- if (ev.jaxis.value < -16384 && ev.jaxis.axis == 1) {
- jump();
- }
- }
- break;
- case SDL_JOYBUTTONDOWN:
- if (state == 0) {
- if (ev.jbutton.button == 1) { // circle button
- handleGUI(menuID,MENU_BACK);
- playSound(menuBackW);
- } else if (ev.jbutton.button == 2) { // "X" button
- handleGUI(menuID, MENU_ACTION);
- playSound(menuActionW);
- }
- if (ev.jbutton.button == 1 && state != 0) {
- playSound(menuBackW);
- state = 0;
- sX = 0;
- sY = 360;
- nextSlup = 0;
- sVY = 0;
- turbo = false;
- ms = 0;
- spajscepcja_wearoff = 0;
- generateSlupki();
- }
- } else if(state == 1) jump();
- break;
- case SDL_JOYDEVICEADDED:
- if (SDL_NumJoysticks() > 0) joy = SDL_JoystickOpen(0);
- break;
- case SDL_JOYDEVICEREMOVED:
- if (SDL_NumJoysticks() <= 0) joy = NULL;
- break;
- case SDL_MOUSEBUTTONDOWN:
- if(state == 1) jump();
- break;
- }
- }
- if (ms > 0) {
- update(1, NULL);
- draw();
- ms = 0;
- }
- }
- free();
- //SDL_CloseAudioDevice(audio);
- //delete mixer;
- SDL_JoystickClose(joy);
- BASS_Free();
- SDL_RemoveTimer(timer);
- SDL_RemoveTimer(uptimer);
- SDL_DestroyRenderer(render);
- SDL_DestroyWindow(win);
- return 0;
- }
- // --------------------- AUDIO MIXER --------------------------
- void mixSpiceStream(Uint8* stream, int len) {
- for (int i = 0; i < len; i++) {
- }
- }
- void _mixer_main(void* user, Uint8* stream, int len) {
- memset(stream, 128, len); // silence
- /*
- switch (playMus) {
- case 0:
- if (introP > 0) {
- memcpy(stream, musicC, len);
- if (introP > len) {
- musicC += len;
- introP -= len;
- }
- else {
- musicC += introP;
- introP = 0;
- }
- }
- else {
- playMus++;
- musicC = loopW;
- loopP = loopWL;
- }
- break;
- case 1:
- if (loopP > 0) {
- memcpy(stream, musicC, len);
- if (loopP > len) {
- musicC += len;
- loopP -= len;
- }
- else {
- musicC += introP;
- loopP = 0;
- }
- }
- else {
- musicC = loopW;
- loopP = loopWL;
- }
- break;
- }
- mixSpiceStream();*/
- if (spajsPos > 0) {
- //SDL_MixAudio(stream, spajsCur, len, SDL_MIX_MAXVOLUME);
- memcpy(stream, spajsCur, len);
- if (spajsPos > len) {
- spajsCur += len;
- spajsPos -= len;
- }
- else {
- spajsCur += spajsPos;
- spajsPos -= spajsPos;
- return;
- }
- }
- //mixer->playAudio(stream, len);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement