// *** Mycket fint spel av Thomas Lindroth *** #include #include #include "h:\lib.cpp" #include #include #include #include graph g; sprite manfram, manleft, manright, manbak, mynt, mina, blankmynt, blankgubbe; class myntposi { public: int x; int y; }; class minaposi { public: int x; int y; }; class manposi { public: manposi(); int x; int y; int x_onoff; int y_onoff; }; manposi::manposi() { x_onoff=0; y_onoff=0; } manposi man; minaposi minor[400]; myntposi myntet; int minoronscr=63; int minmyntyled=15; int minmyntxled=14; int madd=62; int mynttagna=0; int manyled=18; int manxled=13; float uppno=1; int score=0; int uturprogram=0; int key=0; void redrawmines() { for (int x=0;xuppno) { uppno+=.2; mynttagna=0; minoronscr++; madd++; int minpos_ok=0; // kollar om man r fr nra while(minpos_ok!=1) { minor[madd].y=random(200-15-15-15-15-5)+15; minor[madd].x=random(320-16-16-16-16)+16; int kat_y=man.y-minor[madd].y; int kat_x=man.x-minor[madd].x; int hyponusa=kat_y*kat_y+kat_x*kat_x; if (hyponusa>7000) minpos_ok=1; } g.put_sprite(minor[madd].x, minor[madd].y, mina); } } void loadgamedata() { g.load_pal("grafik.pal"); g.save_pal(); g.set_pal_to_black(); g.load_pcx("grafik.pcx"); // Hr ska min fina grafik laddas sen. Som nu r laddad // Laddar sprite fr gubbe & freml g.get_sprite(34,54,48,73,&manfram); g.get_sprite(79,54,93,73,&manleft); g.get_sprite(64,54,78,73,&manright); g.get_sprite(49,54,63,73,&manbak); g.get_sprite(17,0,33,15,&mynt); g.get_sprite(0,0,16,15,&mina); g.cls(); g.get_sprite(50,0,67,16,&blankmynt); g.get_sprite(34,54,48,73,&blankgubbe); g.load_saved_pal(); // Initsierar variablar man.x=168; man.y=108; // lgger ut minorna runt om int xplus=0, yplus=0, x; for (x=0;x<20;x++) { minor[x].x=xplus; minor[x].y=0; g.put_sprite(xplus,0, mina); xplus+=16; } xplus=0; for (x=20;x<40;x++) { minor[x].x=xplus; minor[x].y=180; g.put_sprite(xplus,180, mina); xplus+=16; } yplus=15; for (x=40;x<51;x++) { minor[x].x=0; minor[x].y=yplus; g.put_sprite(0,yplus, mina); yplus+=15; } yplus=15; for (x=51;x<62;x++) { minor[x].x=304; minor[x].y=yplus; g.put_sprite(304,yplus, mina); yplus+=15; } // gr en starposition fr myntet myntet.y=random(200-15-15-15-15-5)+15; myntet.x=random(320-16-16-16-16)+16; } void unloadsprites() { g.free_sprite (manfram); g.free_sprite (manleft); g.free_sprite (manright); g.free_sprite (manbak); g.free_sprite (mynt); g.free_sprite (mina); g.free_sprite (blankmynt); g.free_sprite (blankgubbe); g.close(); } void gamecore() { g.put_sprite(myntet.x, myntet.y, mynt); char keypressed; int exita=0; while(exita!=1) { if (man.x_onoff==1) g.put_sprite(man.x,man.y,manright); if (man.x_onoff==-1) g.put_sprite(man.x,man.y,manleft); if (man.y_onoff==1) g.put_sprite(man.x,man.y,manfram); if (man.y_onoff==-1) g.put_sprite(man.x,man.y,manbak); if (man.x_onoff==0 && man.y_onoff==0) g.put_sprite(man.x,man.y,manfram); // Lser in en piltangent p ett konstigt stt delay(6); if (kbhit()) { keypressed=getch(); if (keypressed=='q'){unloadsprites(); exit(0); } if (keypressed==27) exita=1; if(keypressed==0) { keypressed=getch(); if(keypressed=='M') { man.x_onoff=1; man.y_onoff=0; } if(keypressed=='K') { man.x_onoff=-1; man.y_onoff=0; } if(keypressed=='P') { man.y_onoff=1; man.x_onoff=0; } if(keypressed=='H') { man.y_onoff=-1; man.x_onoff=0; } } } g.put_sprite(man.x, man.y,blankgubbe); man.x+=man.x_onoff; man.y+=man.y_onoff; // kollar om man tar myntet // kolla samma pos i x led if (man.y+manyled>myntet.y && man.ymyntet.x && man.xminor[x].y && myntet.yminor[x].x && myntet.xminor[x].y && man.yminor[x].x && man.x