พิซซ่าหน้าเห็ดเผาะ
Location :
กรุงเทพฯ Thailand

[ดู Profile ทั้งหมด]

ให้ทิปเจ้าของ Blog [?]
ฝากข้อความหลังไมค์
Rss Feed
Smember
ผู้ติดตามบล็อก : 1 คน [?]




Group Blog
 
<<
กันยายน 2554
 
 123
45678910
11121314151617
18192021222324
252627282930 
 
23 กันยายน 2554
 
All Blogs
 
Friends' blogs
[Add พิซซ่าหน้าเห็ดเผาะ's blog to your web]
Links
 

 

flyinganimals final

flyinganimalsSmiley final


Flying Animal

ทีมผู้พัฒนาเกมส์



อธิบาย code



Game




รันบน PSP




Code Game

#include
#include

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

CDXSprite* bg1;
CDXSprite* hp1;
int level = 1;
int hp = 1;
int speed_bg = 2;
int x, y, i, j, k;
int stage = 10;
CDXSnd *pick;
CDXSnd *hit;
CDXSnd *win;
CDXSnd *thm;
CDXSnd *intro;

POINT pos;

int all_time = 0;

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

} Sprite;

typedef struct
{
int x, y;
int acceleration;
CDXSprite *scr;
Sprite C;
} Character;

Character c1;

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

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

irr::core::array monsters;
irr::core::array hps;

int y_bl[] =
{ 45, 75, 105, 135, 170, 200 };

void addMonster1(void);
void addMonster2(void);
void addMonster3(void);
void addMonster4(void);
void addMonster5(void);
void updateMonster(void);
void deleteMonster(void);

void addHp(void);
void updateHp(void);
void deleteHp(void);

int mon_last_x = 0;

time_t start;
time_t end;
double diff_time;
int second;

bool isIntroductionWasEnd = false; // Check Introduction was end

int timepersec()
{
time(&end);
second = difftime(end, start);
return (second);
}

CDXSprite* company_logos[8];
CDXSprite* credit[4];

void create_intro()
{
for (int i = 0; i < 8; i++)
{
company_logos[i] = new CDXSprite();
char filename[60];
sprintf(filename, "Pgame/Story%d.jpg", i + 1);
company_logos[i]->Create(filename, 1);
}
}


CDXSprite* credit[4];

void create_end(){
for (int k = 0; k < 4; k++) {
SAFEDELETE(credit[k]);
credit[k] = new CDXSprite();
char filename[60];
sprintf(filename, "Pgame/end%d.jpg", k + 1);
credit[k]->Create(filename, 1 );
}
}


void delete_intro()
{
for (int i = 0; i < 8; i++)
{
SAFEDELETE(company_logos[i]);
}
}

// ------------------------------------------------------------------
// cdx_Init - handles initialization of the CDX objects
// ------------------------------------------------------------------

void addHp()
{

HP_S *hp = new HP_S();
hp->scr = new CDXSprite();
hp->scr->Create("Pgame/hp.png", 19, 17, 1);
hp->acceleration = 6;
hp->x = 500;
hp->y = y_bl[rand() % 6];
hp->scr->SetPos(hp->x, hp->y);
hp->active = true;
hps.push_back(hp);
return;
}

void updateHp()
{
for (i = 0; i < hps.size(); i++)
{
if (hps[i]->active)
{
hps[i]->x -= hps[i]->acceleration;
hps[i]->scr->SetPos(hps[i]->x, hps[i]->y);
hps[i]->scr->Draw(Screen->GetBack(), 0, 0, CDXBLT_TRANS);
}
}
}

void deleteHp()
{
for (i = 0; i < hps.size(); i++)
{
if (hps[i]->x < -100)
{
SAFEDELETE(hps[i]->scr);
hps.erase(i);
}
}
}

void addMonster1()
{
MonsterFamily *monster = new MonsterFamily();
monster->scr = new CDXSprite();
monster->scr->Create("Pgame/bl1.pcx", 32, 33, 1);
monster->acceleration = 2;
monster->x = 500;
monster->y = y_bl[rand() % 6];
monster->scr->SetPos(monster->x, monster->y);
monster->active = true;
monsters.push_back(monster);
return;
}

void addMonster2()
{
MonsterFamily *monster = new MonsterFamily();
monster->scr = new CDXSprite();
monster->scr->Create("Pgame/bl2.pcx", 33, 34, 1);
monster->acceleration = 3;
monster->x = 500;
monster->y = y_bl[rand() % 6];
monster->scr->SetPos(monster->x, monster->y);
monster->active = true;
monsters.push_back(monster);
return;
}

void addMonster3()
{
MonsterFamily *monster = new MonsterFamily();
monster->scr = new CDXSprite();
monster->scr->Create("Pgame/bl3.pcx", 32, 33, 1);
monster->acceleration = 4;
monster->x = 500;
monster->y = y_bl[rand() % 6];
monster->scr->SetPos(monster->x, monster->y);
monster->active = true;
monsters.push_back(monster);
return;
}

void addMonster4()
{
MonsterFamily *monster = new MonsterFamily();
monster->scr = new CDXSprite();
monster->scr->Create("Pgame/bl4.pcx", 32, 33, 1);
monster->acceleration = 5;
monster->x = 500;
monster->y = y_bl[rand() % 6];
monster->scr->SetPos(monster->x, monster->y);
monster->active = true;
monsters.push_back(monster);
return;
}

void addMonster5()
{
MonsterFamily *monster = new MonsterFamily();
monster->scr = new CDXSprite();
monster->scr->Create("Pgame/bl5.pcx", 38, 39, 1);
monster->acceleration = 5;
monster->x = 500;
monster->y = y_bl[rand() % 6];
monster->scr->SetPos(monster->x, monster->y);
monster->active = true;
monsters.push_back(monster);
return;
}

void updateMonster()
{
for (i = 0; i < monsters.size(); i++)
{
if (monsters[i]->active)
{
monsters[i]->x -= monsters[i]->acceleration;
monsters[i]->scr->SetPos(monsters[i]->x, monsters[i]->y);
monsters[i]->scr->Draw(Screen->GetBack(), 0, 0, CDXBLT_TRANS);

}
}
}

void deleteMonster()
{
for (i = 0; i < monsters.size(); i++)
{
if (monsters[i]->x < -100)
{
SAFEDELETE(monsters[i]->scr);
monsters.erase(i);
}
}
}

BOOL village()
{
if (!bg1)
{
bg1 = new CDXSprite();
bg1->Create("Pgame/BG1.png", 0);
}

if (!thm) {
thm = new CDXSnd();
thm->Create();
thm->Play("sound/1.wav");
}

return TRUE;
}

BOOL desert()
{
if (!bg1)
{
bg1 = new CDXSprite();
bg1->Create("Pgame/BG2.png", 0);
}

if (!thm) {
thm = new CDXSnd();
thm->Create();
thm->Play("sound/2.wav");
}

return TRUE;
}

BOOL underwater()
{
if (!bg1)
{
bg1 = new CDXSprite();
bg1->Create("Pgame/BG3.png", 0);
}

if (!thm) {
thm = new CDXSnd();
thm->Create();
thm->Play("sound/3.wav");
}

return TRUE;
}

BOOL sky()
{
if (!bg1)
{
bg1 = new CDXSprite();
bg1->Create("Pgame/BG4.png", 0);
}
if (!thm) {
thm = new CDXSnd();
thm->Create();
thm->Play("sound/4.wav");
}

return TRUE;
}

BOOL cave()
{
if (!bg1)
{
bg1 = new CDXSprite();
bg1->Create("Pgame/BG5.png", 0);
}

if (!thm) {
thm = new CDXSnd();
thm->Create();
thm->Play("sound/5.wav");
}

return TRUE;
}

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);

time(&start);

c1.scr = new CDXSprite();
c1.scr->Create("Pgame/C1S.png", 60, 45, 1);

if (!hit) {
hit = new CDXSnd();
hit->Create();
}

if (!win) {
win = new CDXSnd();
win->Create();
}

if (!pick) {
pick = new CDXSnd();
pick->Create();
}


if (!intro) {
intro = new CDXSnd();
intro->Create();
}

if (!hp1)
{
hp1 = new CDXSprite();
hp1->Create("Pgame/hp.png", 19, 17, 1);
hp1->SetPos(5, 250);
}

create_intro();

time(&start);

return TRUE;
}

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

SAFEDELETE(bg1);
bg1 = 0;
SAFEDELETE(thm);
thm = 0;
}

void cdx_DeInit(void)
{

// TODO: Destroy your CDX objects here
SAFEDELETE(intro);
SAFEDELETE(win);
SAFEDELETE(pick);
SAFEDELETE(hit);
SAFEDELETE(c1.scr);
SAFEDELETE(bg1);
SAFEDELETE(Fps);
SAFEDELETE(Input);
SAFEDELETE(Screen);
}

// ------------------------------------------------------------------
// cdx_DoFrame - performs drawing of the current frame
// ------------------------------------------------------------------
int myPosX = 0;
int logo_index = 0;
int l = 0;
void cdx_DoFrame()
{
Input->Update();
intro->Play("sound/intro.wav");
time(&end);
diff_time = difftime(end, start);
if (logo_index < 7)
{
if (diff_time == 5)
{
logo_index++;
time(&start);
}
company_logos[logo_index]->Draw(Screen->GetBack(), 0, 0, CDXBLT_TRANS);
}
else
{
isIntroductionWasEnd = true;
delete_intro();
}

if (isIntroductionWasEnd == true)
{

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

if (stage == 10)
{
village();
stage = 9;
}

if (stage == 8)
{
village_DeInit();
desert();
stage = 7;
}

if (stage == 6)
{
village_DeInit();
underwater();
stage = 5;
}

if (stage == 4)
{
village_DeInit();
sky();
stage = 3;
}

if (stage == 2)
{
village_DeInit();
cave();
stage = 1;
}

bg1->SetPosX(myPosX -= speed_bg);
bg1->Draw(Screen->GetBack(), 0, 0, CDXBLT_TRANS);

if ((all_time == 600) || (all_time == 900) || (all_time == 1200))
{
addHp();
} // ไอเท็มพิเศษ เลือด
updateHp();
deleteHp();
hp1->Draw(Screen->GetBack(), 0, 0, CDXBLT_TRANS);
TextXY(Screen->GetBack(), 0, 10, 255, 255, 255, 255, 255, "%d", all_time);
TextXY(Screen->GetBack(), 25, 255, 0, 0, 0, 1000, ":%d", hp);
//ความเร็วการลงของตัวละคร
c1.y += 4;

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

if (speed_bg >= 5)
{
speed_bg = 5;
}
all_time++;

if (level == 1)
{
if (all_time % 100 == 0)
{
addMonster1();
}
if ((c1.y <= 30) && (all_time <= 1500) && (all_time >= 20))
{
hp--;
} //ชนบน
if ((c1.y >= 200) && (all_time <= 1500))
{
hp--;
} //ชนล่าง
if (Input->GetKeyState(SDLK_SPACE) || Input->GetKeyState(CDXKEY_JOYBUTN3))
{
c1.y -= 7;
if (c1.scr) c1.scr->SetFrame(1);
}
else
{
if (c1.scr) c1.scr->SetFrame(0);
}
if (c1.scr)
{
c1.scr->SetPos(c1.x = 45, c1.y);
c1.scr->Draw(Screen->GetBack(), 0, 0, CDXBLT_TRANS);
}
}

if (level == 2)
{
if (all_time % 80 == 0)
{
addMonster2();
}
if ((c1.y <= 30) && (all_time <= 1500))
{
hp--;
} //ชนบน
if ((c1.y >= 200) && (all_time <= 1500))
{
hp--;
} //ชนล่าง
if (Input->GetKeyState(SDLK_SPACE) || Input->GetKeyState(CDXKEY_JOYBUTN3))
{
c1.y -= 7;
if (c1.scr) c1.scr->SetFrame(3);
}
else
{
if (c1.scr) c1.scr->SetFrame(2);
}
if (c1.scr)
{
c1.scr->SetPos(c1.x = 45, c1.y);
c1.scr->Draw(Screen->GetBack(), 0, 0, CDXBLT_TRANS);
}
}

if (level == 3)
{
if (all_time % 60 == 0)
{
addMonster3();
}
if ((c1.y <= 30) && (all_time <= 1500))
{
hp--;
} //ชนบน
if ((c1.y >= 210) && (all_time <= 1500))
{
hp--;
} //ชนล่าง
if (Input->GetKeyState(SDLK_SPACE) || Input->GetKeyState(CDXKEY_JOYBUTN3))
{
c1.y -= 7;
if (c1.scr) c1.scr->SetFrame(5);
}
else
{
if (c1.scr) c1.scr->SetFrame(4);
}
if (c1.scr)
{
c1.scr->SetPos(c1.x = 45, c1.y);
c1.scr->Draw(Screen->GetBack(), 0, 0, CDXBLT_TRANS);
}
}

if (level == 4)
{
if (all_time % 50 == 0)
{
addMonster4();
}
if ((c1.y <= 30) && (all_time <= 1500))
{
hp--;
} //ชนบน
if ((c1.y >= 195) && (all_time <= 1500))
{
hp--;
} //ชนล่าง
if (Input->GetKeyState(SDLK_SPACE) || Input->GetKeyState(CDXKEY_JOYBUTN3))
{
c1.y -= 7;
if (c1.scr) c1.scr->SetFrame(7);
}
else
{
if (c1.scr) c1.scr->SetFrame(6);
}
if (c1.scr)
{
c1.scr->SetPos(c1.x = 45, c1.y);
c1.scr->Draw(Screen->GetBack(), 0, 0, CDXBLT_TRANS);
}
}

if (level == 5)
{
if (all_time % 40 == 0)
{
addMonster5();
}
if ((c1.y <= 35) && (all_time <= 1500))
{
hp--;
} //ชนบน
if ((c1.y >= 200) && (all_time <= 1500))
{
hp--;
} //ชนล่าง
if (Input->GetKeyState(SDLK_SPACE) || Input->GetKeyState(CDXKEY_JOYBUTN3))
{
c1.y -= 7;
if (c1.scr) c1.scr->SetFrame(9);
}
else
{
if (c1.scr) c1.scr->SetFrame(8);
}
if (c1.scr)
{
c1.scr->SetPos(c1.x = 45, c1.y);
c1.scr->Draw(Screen->GetBack(), 0, 0, CDXBLT_TRANS);
}
}

for (i = 0; i < monsters.size(); i++)
{
if (c1.scr->SpriteHit(monsters[i]->scr) && monsters[i]->active)
{
hit->Play("sound/hit.wav");
monsters[i]->active = false;
hp--;
}
}

for (i = 0; i < hps.size(); i++)
{
if (hps[i]->scr->SpriteHit(c1.scr) && hps[i]->active)
{
pick->Play("sound/pick.wav");
hps[i]->active = false;
hp++;
}
}

if ((Input->GetKeyState(SDLK_F1) == CDXKEY_PRESS || Input->GetKeyState(CDXKEY_JOYBUTN11) == CDXKEY_PRESS) && (level == 1))
{
if (level == 1)
{
hp = 1;
speed_bg = 1;
}
all_time = 0;
bg1->SetPosX(myPosX = 0);
c1.scr->SetPos(c1.x = 45, c1.y = 50);
for (i = 0; i < monsters.size(); i++)
{
SAFEDELETE(monsters[i]->scr);
}
monsters.clear();
}

if ((Input->GetKeyState(SDLK_F1) == CDXKEY_PRESS || Input->GetKeyState(CDXKEY_JOYBUTN11) == CDXKEY_PRESS) && (level >= 2))
{
all_time = 0;
bg1->SetPosX(myPosX = 0);
c1.scr->SetPos(c1.x = 45, c1.y = 50);
for (i = 0; i < monsters.size(); i++)
{
SAFEDELETE(monsters[i]->scr);
}
monsters.clear();
}

if (all_time == 1500)
{
level = level + 1;
speed_bg = speed_bg + 1;
stage = stage - 1;
win->Play("sound/win.wav");
}
if ((all_time >= 1500) && (level <= 5))
{
Screen->GetBackEx()->Fill(0);
TextXY(Screen->GetBack(), 0, 130, 255, 255, 255, 255, ETA_CENTER, "YOU CLEAR THE MISSION %d", level - 1);
TextXY(Screen->GetBack(), 0, 150, 255, 255, 255, 255, ETA_CENTER, "Press Start to Continue.");
for (i = 0; i < monsters.size(); i++)
{
SAFEDELETE(monsters[i]->scr);
}
monsters.clear();

for (i = 0; i < monsters.size(); i++)
{
SAFEDELETE(monsters[i]->scr);
}
monsters.clear();

}
if (level == 6)
{
create_end();
time(&end);
diff_time = difftime(end, start);
if (l < 3)
{
if (diff_time == 5)
{
l++;
time(&start);
}
credit[l]->Draw(Screen->GetBack(), 0, 0, CDXBLT_TRANS);
}
}
if (l == 3)
{
credit[3]->Draw(Screen->GetBack(), 0, 0, CDXBLT_TRANS);
}

if (hp <= 0)
{
SAFEDELETE(bg1);
level = 1;
stage = 10;
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 Start to play again");
for (i = 0; i < monsters.size(); i++)
{
SAFEDELETE(monsters[i]->scr);
}
monsters.clear();

for (i = 0; i < hps.size(); i++)
{
SAFEDELETE(hps[i]->scr);
}
hps.clear();
}

updateMonster();
deleteMonster();

}
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;
}






 

Create Date : 23 กันยายน 2554
1 comments
Last Update : 24 กันยายน 2554 6:01:34 น.
Counter : 1348 Pageviews.

 

ขอบคุณสำหรับข้อมูลดีๆ Thank you nice post.

makita mac700 black friday

 

โดย: aomzon (aomzon ) 1 ตุลาคม 2554 9:21:15 น.  

ชื่อ :
Comment :
  *ใช้ code html ตกแต่งข้อความได้เฉพาะสมาชิก
 
รหัสส่งข้อความ
กรุณายืนยันรหัสส่งข้อความ

 Pantip.com | PantipMarket.com | Pantown.com | © 2004 BlogGang.com allrights reserved.