// *** Mycket fint spel av Thomas Lindroth ***#include <iostream.h>#include <conio.h>#include "h:\lib.cpp"#include <dos.h>#include <stdlib.h>#include <time.h>#include <math.h>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;x<minoronscr;x++) g.put_sprite(minor[x].x, minor[x].y, mina); }void addmina() { // lgger in en mina lite d och d mynttagna++; if (mynttagna>uppno) { 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.y<myntet.y+minmyntyled) // kollar samma pos i y led { if (man.x+manxled>myntet.x && man.x<myntet.x+minmyntxled) { // d fr man myntet och ett nytt kommer fram sound(100*score); delay(10); nosound(); g.put_sprite(myntet.x, myntet.y, blankmynt); addmina(); // har ska det kollas om det finns minor // p den position som jag vill ha mynt p // OBS!!! Detta funkar inte ricktigt som det ska int myntpos_ok=0; while (myntpos_ok!=1) { myntet.y=random(200-15-15-15-5)+15; myntet.x=random(320-16-16-16)+16; for (int x=0;x<minoronscr;x++) { if (myntet.y+minmyntyled>minor[x].y && myntet.y<minor[x].y+minmyntyled) { if (myntet.x+minmyntxled>minor[x].x && myntet.x<minor[x].x+minmyntxled) {} // d befinne sig myntet p en mina och dr ska den inte vara else myntpos_ok=1; } } } g.put_sprite(myntet.x, myntet.y, mynt); redrawmines(); score++; } } // kollar om man nuddar mina for (int x=0;x<minoronscr;x++) { // kolla samma pos i x led if (man.y+manyled>minor[x].y && man.y<minor[x].y+minmyntyled) // kollar samma pos i y led { if (man.x+manxled>minor[x].x && man.x<minor[x].x+minmyntxled) { // d dr man exita=1; } } } } }void main() { randomize(); g.init(); g.load_pal("intro.pal"); g.save_pal(); g.set_pal_to_black(); g.load_pcx("intro.pcx"); g.fade_to_saved_pal(7); getch(); g.fade_to_black(7); loadgamedata(); do { gamecore(); // nr gamecore r slut r man dd g.cls(); g.load_pal("gameover.pal"); g.save_pal(); g.set_pal_to_black(); g.load_pcx("gameover.pcx"); g.fade_to_saved_pal(7); delay(2000); g.fade_to_black(7); g.setpal(0,63,63,63); g.cls(); cout<<"Du fick "<<score; int uturloop=0; while(uturloop!=1) { key=getch(); if (key==27) { uturprogram=1; uturloop=1; } if (key==13) uturloop=1; } clrscr(); score=0; uppno=1; mynttagna=0; madd=62; minoronscr=63; man.x=168; man.y=108; myntet.y=random(200-15-15-15-15-5)+15; myntet.x=random(320-16-16-16-16)+16; man.x_onoff=0; man.y_onoff=0; g.cls(); g.load_pal("grafik.pal"); redrawmines(); }while (uturprogram!=1); int farg; for(farg=0;farg<256;farg++) { g.setpal(farg,farg/4,farg/4,farg/4); } g.save_pal(); g.set_pal_to_black(); g.load_pcx("credits.pcx"); g.fade_to_saved_pal(7); delay(3000); g.fade_to_black(7); g.load_pcx("ending.pcx"); g.fade_to_saved_pal(7); delay(3000); g.fade_to_black(7); unloadsprites(); g.close(); }