ԫ˹
Location :
ا෾ Thailand

[ Profile ]

ԻҢͧ Blog [?]
ҡͤѧ
Rss Feed
Smember
Դ͡ : 1 [?]




Group Blog
 
<<
ԧҤ 2554
 123456
78910111213
14151617181920
21222324252627
28293031 
 
12 ԧҤ 2554
 
All Blogs
 
Friends' blogs
[Add ԫ˹'s blog to your web]
Links
 

 
flyinganimalstest01


Thanks: Ro ҡٻ



#include
#include

// ------------------------------------------------------------------
// CDX Objects
// ------------------------------------------------------------------
CDXScreen *Screen = 0; // The screen object, every program must have one
CDXInput *Input = 0;
FPSmanager *Fps = 0;

CDXSprite* bg1 = 0;
CDXSprite* T1 = 0;
CDXSprite* B1 = 0;
CDXSprite* C1 = 0;
int level=1;
int hp=1;
int x,y,i,j=0;

POINT pos;


typedef struct Sprite {
int x, y;
int speed;
int hp;
CDXSprite *sprite;

} Sprite;

typedef struct bl{
int x, y;
int acceleration;
int size;
CDXSprite *scr;
Sprite bl1;
bool active ;
} bl;

const int $_bl = 10;
bl bl_1[$_bl];
int y_bl[] = {45,75,105,135,170,210};



// ------------------------------------------------------------------
// cdx_Init - handles initialization of the CDX objects
// ------------------------------------------------------------------
BOOL cdx_Init()
{
Screen = new CDXScreen();
Screen->Create( );
Screen->CreateWindowed( 480, 272, 32, SDL_DOUBLEBUF | SDL_HWSURFACE | SDL_INIT_TIMER );

Input = new CDXInput( );
Input->Create( );

Fps = new FPSmanager( );
SDL_initFramerate( Fps );
SDL_setFramerate( Fps, 30 );



bg1 = new CDXSprite( );
bg1->Create( "Pgame/bg1.jpg", 1 );

T1 = new CDXSprite( );
T1->Create( "Pgame/T1.png", 1 );

B1 = new CDXSprite( );
B1->Create( "Pgame/B1.png", 1 );

C1 = new CDXSprite( );
C1->Create( "Pgame/C1.png", 1 );

// TODO: Initialize your own CDX objects here


srand(time(NULL));
for (i=0; i < $_bl; i++) {
bl_1[i].x = rand () % 480+480;
bl_1[i].y = y_bl[rand()%6] ;
bl_1[i].active = true;
bl_1[i].acceleration= 2;//
bl_1[i].bl1.sprite=new CDXSprite();
bl_1[i].bl1.sprite->Create("Pgame/bl1.png", 32,32,1);
bl_1[i].bl1.sprite->SetPos(bl_1[i].x, bl_1[i].y);
}

return TRUE;
}

// ------------------------------------------------------------------
// cdx_DeInit - handles cleanup of CDX objects
// ------------------------------------------------------------------
void cdx_DeInit( void )
{

// TODO: Destroy your CDX objects here

for (i=0; i < $_bl; i++)
{
SAFEDELETE( bl_1[i].bl1.sprite );
}
SAFEDELETE( C1 );
SAFEDELETE( bg1 );


SAFEDELETE( Fps );
SAFEDELETE( Input );
SAFEDELETE( Screen );
}

// ------------------------------------------------------------------
// cdx_DoFrame - performs drawing of the current frame
// ------------------------------------------------------------------
void cdx_DoFrame()
{
Input->Update( );

Screen->GetBackEx()->Fill(0);






// TODO: Add code to draw your objects during each frame


bg1->Draw( Screen->GetBack(), 0, 0, CDXBLT_TRANS );
T1->Draw( Screen->GetBack(), 0, 0, CDXBLT_TRANS );
B1->Draw( Screen->GetBack(), 0, 0, CDXBLT_TRANS );
B1->SetPos( x=0,y=240);



if( Input->GetKeyState(SDLK_F1)||Input->GetKeyState(CDXKEY_JOYBUTN11) )
{hp=1;
C1->SetPos( pos.x=45,pos.y=50);
for (i=0; i < $_bl; i++) {
bl_1[i].active = false;}
}


for (i=0; i < $_bl; i++) {
if (
bl_1[i].bl1.sprite->GetPosX() < -120) {
bl_1[i].x = rand () % 480+480; ;
bl_1[i].acceleration = 2;
bl_1[i].bl1.sprite = new CDXSprite();
bl_1[i].active = true;
bl_1[i].bl1.sprite->Create("Pgame/bl1.png",32,32,1);
bl_1[i].bl1.sprite->SetPos(bl_1[i].x, bl_1[i].y);


} else {
bl_1[i].x = bl_1[i].bl1.sprite->GetPosX()-bl_1[i].acceleration;
}

bl_1[i].bl1.sprite->SetPosX( bl_1[i].x );

if(bl_1[i].active)
bl_1[i].bl1.sprite->Draw(Screen->GetBack(), 0, 0, CDXBLT_TRANS);
}




for( j = 0; j < $_bl; j++ )
{if( bl_1[j].bl1.sprite->SpriteHit(C1) && bl_1[j].active)
{
hp--;
}

}



if( C1->SpriteHit(B1) )
{ hp--;}






pos.y += 4;


if( Input->GetKeyState(SDLK_SPACE)||
Input->GetKeyState(CDXKEY_JOYBUTN3))
{pos.y -= 7;
C1->Create("Pgame/C1T.png",61,49,1); }
else { C1->Create("Pgame/C1.png",52,47,1); }

C1->SetPos( pos.x=45,pos.y);
C1->Draw( Screen->GetBack(), 0, 0, CDXBLT_TRANS );



if(hp<=0)
{
Screen->GetBackEx()->Fill(0);
TextXY( Screen->GetBack(), 0,130,1000,1000,1000,1000,ETA_CENTER,"GAME OVER");
TextXY( Screen->GetBack(), 0,150,1000,1000,1000,1000,ETA_CENTER,"Press F1 to play again");
}



Screen->Flip( 0, 0, 1 );
SDL_framerateDelay( Fps );
}

int main( int argc, char* args[] )
{
#ifdef _PSP

#ifndef NDEBUG
pspDebugScreenInit( );
#endif

SetupCallbacks( );
#endif

cdx_Init();

while(1)
{
#ifdef WIN32
if( Input->GetKeyState(SDLK_ESCAPE) )
break;
#endif

cdx_DoFrame();
}

cdx_DeInit();

return 0;
}



Thanks: Ro ҡٻ


Thanks: Ro ҡٻ


Thanks: Ro ҡٻ




Create Date : 12 ԧҤ 2554
Last Update : 12 ԧҤ 2554 13:09:33 . 0 comments
Counter : 218 Pageviews.

:
Comment :
  * code html 觢ͤ੾Ҫԡ
 
觢ͤ
س׹ѹ觢ͤ
 Pantip.com | PantipMarket.com | Pantown.com | © 2004 BlogGang.com allrights reserved.