Sorry... I was trying to avoid this.. The reason is because I am well into the development of the game, but yes, I can show you the code, but it''ll be a bit hidden I guess you could say.. but just do a search and you''ll see it. I''ve taken away alot of the code so I don''t have practically my whole game in here, most of it is just summary
SPRITE ship;SPRITE back;SPRITE bullet;SPRITE startup;SPRITE hp;int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){ srand((unsigned)time(NULL)); //JUST FYI, I TOOK OUT THE WINDOWS CODE HERE initdd(800,600,32); //initialize dd with 800x600x32 for the display mode initdi(hinstance); //initialize di with keyboard //create the sprites CreateSprite(&back,800,600,"level1.bmp"); CreateSprite(&ship, 100,100, "space.bmp"); //CFFromCell means CreateFrameFromCell(the sprite // then the frame #, then the x, y in the image CFFromCell(&ship,0,0,0); //frame 0 at 0,0 CFFromCell(&ship,1,1,0); //frame 1 at 1,0 CFFromCell(&ship,2,2,0); //frame 2 at 2,0 CFFromCell(&ship,3,3,0); //frame 3 at 3,0 CFFromCell(&ship,4,0,1); //frame 4 at 1,0 CFFromCell(&ship,5,1,1); //frame 5 at 1,1 CFFromCell(&ship,6,2,1); //frame 6 at 2,1 CFFromCell(&ship,7,3,1); //frame 7 at 3,1 assignrect(back.frames[0], 0,0, 800,600);//get the back image into 0 int shoot[]={6,7}; //integer animations int fleft[]={4,5}; //frames for fly left int fright[]={2,3}; //frames for fly right int fly[]= {0,1}; //frames for fly straight ship.y=500; //ship''s pos ship.x=200; //ship''s pos ship.updatecounter=2; //how often does the ship update? MakeAnimation(&ship,0,1,fly); //create the straight anim MakeAnimation(&ship,1,1,fright); //create the right anim MakeAnimation(&ship,2,1,fleft); //Create the left anim MakeAnimation(&ship,3,1,shoot); ship.curanim=0; //set ship''s current animation to normal flying back.curframe=0; //right now, the back does not animate CreateSprite(&hp,100,20,"hp.bmp"); CFFromCell(&hp,0,0,0); //create bullet CreateSprite(&bullet,2,17,"fire.bmp"); CFFromCell(&bullet,0,0,0); assignrect(hp.frames[0],0,0,99,19);//get the back image into 0 hp.curframe=0; initenemies(); Startup(); while (1) { if(PeekMessage(&msg, NULL, 0,0, PM_REMOVE)) { if (msg.message==WM_QUIT) break; TranslateMessage(&msg); DispatchMessage(&msg); } else { if(isbullet==false)bulletspeed=18; UpdateEnemies(); hp.frames[0].right=CurHp*5; hp.width=CurHp*5; GetKeyStatus(); UseKeys(); if(keydown(DIK_ESCAPE)) break; // if you press escape, quit game UseBounds(); // make sure the ship is within it''s boundaries fillsurface(lpddsback,0); //fill the back surface with black UpdateSprite(&ship); //Update the ships anim DrawSprite(&back, lpddsback); //''draw the background first, DrawSprite(&ship, lpddsback); // then draw the ship for(int i=0; i<5; i++) { if(enemies[i].isthere) DrawSprite(&enemies[i].ship,lpddsback); if(enemies[i].isbullet)DrawSprite(&enemies[i].bullet,lpddsback); } if(isbullet){ //Move the bullet bulletspeed--; if (bulletspeed<10) bulletspeed=10; bullet.y-=bulletspeed; if(bullet.y<0)isbullet=false; DrawSprite(&bullet,lpddsback); } if(isbullet) { for(int z=0; z<5; z++) { if(enemies[z].isthere==true) { //can''t hit a dead enemy! if(contact(&bullet, &enemies[z].ship)){ enemies[z].curhp--; isbullet=false;} //hit the enemy if contact with sprite } } } DrawSprite(&hp, lpddsback); lpddsprime->Flip(NULL, DDFLIP_WAIT); //flip the surfaces Sleep(33); // and synchronize 30fps } } Shutdown(); return(msg.wParam);}
Jeeze... I know thats hard to keep clean, but hopefully you can pick out the unimportant stuff, because if I started taking it out, I know I would do a bad job, so bare with me.
Now, here is the code for initializing the enemies: (haha, I was about to do a {
)
oid initenemies() { for(int i=0; i<5; i++) { //5 enemies atm int enemfly[]= {0,1}; //frames for fly straight CreateSprite(&enemies[i].ship,47,47,"enemy.bmp"); //load from enemy.bmp CreateSprite(&enemies[i].bullet,2,17,"enemfire.bmp"); CFFromCell(&enemies[i].bullet,0,0,0); enemies[i].bullet.curframe=0; if(i<3) { //1-3 are from 0,0 in enemy.bmp CFFromCell(&enemies[i].ship,0,0,0); CFFromCell(&enemies[i].ship,1,2,0); } else{ CFFromCell(&enemies[i].ship,0,1,0); //4-5 are from 1,0 in enemy.bmp CFFromCell(&enemies[i].ship,1,3,0); } enemies[i].ship.y=100; enemies[i].ship.x=200; enemies[i].isthere=true; enemies[i].curstate=attack; enemies[i].oldstate=attack; enemies[i].state.states[attack]=.2; enemies[i].state.states[avoid]=.35; enemies[i].state.states[randommove]=.4; enemies[i].state.states[useold]=.9; enemies[i].state.states[still]=1.0; enemies[i].fullhp=3; enemies[i].curhp=3; enemies[i].damage=1; enemies[i].isbullet=false; enemies[i].ship.updatecounter=2; MakeAnimation(&enemies[i].ship,0,1,enemfly); enemies[i].ship.curanim=0; enemies[i].curstate=still; }
I also edited a lot out of this, but it should be pretty straightforward.
I apologize for having such ugly code atm, Its much easier to pick through once you''ve seen it a hundred times.
Thanks in advance!
Sponge Factory --Muzlack