Chào các bạn [IMG]images/smilies/biggrin.png[/IMG] ! Hôm nay mình mạn phép đưa lên một game mình viết trên C++ xài đồ họa DirectX (có sử dụng library, nhưng library cũng do mình viết nốt), csdl đơn giản (lưu score) xài sqlite3 (có xài thêm library hỗ trợ CPPSQLite3 - cái này là người khác viết [IMG]images/smilies/21.gif[/IMG] ).
Melody Memory
http://myfreefilehosting.com/f/6ad344403b_3MB
Đã fix lại lỗi thiếu library khi chạy trên máy không cài vs2008
<font color="Blue">DirectX 9 March 2009 Redist
http://myfreefilehosting.com/f/1324f17d09_18.45MB
Một vài lưu ý:
+ Project xài VS2008
+ Sử dụng DirectX SDK March 2009
+ Nếu máy bạn đã có' DirectX SDK March 2009 rồi thì thôi, còn nếu chưa thì phải tải cái DX Redist March 2009 ở trên xuống cài thì mới chạy được game
Hiện tại thì mình sẽ chỉ post executable, và code nhưng code không compile được vì mình không post library SG2E của mình, chỉ post code cho mọi người khỏi nghi mình ăn cắp project của người khác (cũng nói trước là code mình không comment vì mình cực ngại comment khi code, chỉ khi nào project hoàn thiện và mình có thời gian rảnh thì mình mới comment)
Một vài hình ảnh: [IMG]images/smilies/clap_grin.gif[/IMG]
Một vài đoạn code: [IMG]images/smilies/clap_grin.gif[/IMG]
Hai hàm update và render của cái bàn có mấy cái nút xanh đỏ
Mã:
void MelodyPad::update(InputDevice *input, SoundDevice *sound){ Vector2 mousePos = input->getMousePos(); if (isActived_ && input->isMouseButtonPressed(MouseButtons::left)) { if (isPointInRect(mousePos, btns_real_rects[0][0])) { btns_tex_currentIndex[0] = 1; btns_flash_coolDown[0] = btns_flash_time; lastPressedButton = 1; if (btns_chn[0] == 0) btns_chn[0] = sound->play(btns_snd[0]); else btns_chn[0]->play(); } else if (isPointInRect(mousePos, btns_real_rects[1][0])) { btns_tex_currentIndex[1] = 1; btns_flash_coolDown[1] = btns_flash_time; lastPressedButton = 2; if (btns_chn[1] == 0) btns_chn[1] = sound->play(btns_snd[1]); else btns_chn[1]->play(); } else if (isPointInRect(mousePos, btns_real_rects[2][0])) { btns_tex_currentIndex[2] = 1; btns_flash_coolDown[2] = btns_flash_time; lastPressedButton = 3; if (btns_chn[2] == 0) btns_chn[2] = sound->play(btns_snd[2]); else btns_chn[2]->play(); } } else lastPressedButton = 0; for (int i = 0; i < 3; i++) if (btns_flash_coolDown[i] > 0) btns_flash_coolDown[i] -= 1; else btns_tex_currentIndex[i] = 0;} void MelodyPad::render(GraphicDevice *g){ g->drawTexture(btns_texs[0][btns_tex_currentIndex[0]], btns_texs_rect[0][btns_tex_currentIndex[0]], btns_real_centers[0][btns_tex_currentIndex[0]], Vector2(1, 1), 0, btns_texs_center[0][btns_tex_currentIndex[0]]); g->drawTexture(btns_texs[1][btns_tex_currentIndex[1]], btns_texs_rect[1][btns_tex_currentIndex[1]], btns_real_centers[1][btns_tex_currentIndex[1]], Vector2(1, 1), 0, btns_texs_center[1][btns_tex_currentIndex[1]]); g->drawTexture(btns_texs[2][btns_tex_currentIndex[2]], btns_texs_rect[0][btns_tex_currentIndex[2]], btns_real_centers[2][btns_tex_currentIndex[2]], Vector2(1, 1), 0, btns_texs_center[2][btns_tex_currentIndex[2]]);}
Score screen
Mã:
class ScoreScreen : public IGameScreen{private: static SG2E::Texture *background_tex; static SG2E::Texture *btnMenu_tex; static SG2E::Font *text_fnt; public: ScoreScreen(MelodyMemoryGame *game); virtual ~ScoreScreen(); static bool loadContent(SG2E::ContentManager *content); static void unloadContent(SG2E::ContentManager *content); virtual void update(SG2E::InputDevice *input, SG2E::SoundDevice *sound); virtual void render(SG2E::GraphicDevice *g); MelodyMemoryGame * getOwner(); private: MelodyMemoryGame *owner; std::vector<Common::String> names; std::vector<int> scores;};
Thêm đoạn xài sqlite3
Mã:
void ScoreData::readEntries(std::vector<String> &names, std::vector<int> &scores){ names.clear(); scores.clear(); try { db.open(dataFile); if (!db.tableExists("scoretable")) return; CppSQLite3Query q; q = db.execQuery("select * from scoretable order by score desc;"); while (!q.eof()) { names.push_back(String(stringToWString(q.getStringField(0)).c_str())); scores.push_back(q.getIntField(1)); q.nextRow(); } db.close(); } catch (CppSQLite3Exception &e) { std::cerr << e.errorCode() << ":" << e.errorMessage() << std::endl; }}
Ưu điểm:
+ Học được về DirectX
+ Có được một library làm game là SG2E
+ Biết sử dụng sqlite làm csdl
Nhược điểm:
+ Game chưa thực sự hoàn tất
+ Có vài hạt sạn mà ai tinh ý sẽ thấy
+ Graphic hơi kì [IMG]images/smilies/17.gif[/IMG]
Về library SG2E mình sẽ cố gắng hoàn thiện trong thời gian sớm nhất để post lên cho các bạn tham khảo và sử dụng [IMG]images/smilies/daydreaming.gif[/IMG]
Mong các bạn đóng góp ý kiến [IMG]images/smilies/daydreaming.gif[/IMG]</font>
Pallet nhựa Long An đã trở thành một trong những lựa chọn phổ biến cho nhu cầu vận chuyển và lưu trữ hàng hóa trong nhiều ngành công nghiệp. Với đặc tính nhẹ nhàng, chắc chắn và dễ vận chuyển, các...
Thanh lý pallet nhựa Long An giá rẻ