Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

MGDW4 Online Camp #3b - State Management

823 views

Published on

  • Be the first to comment

  • Be the first to like this

MGDW4 Online Camp #3b - State Management

  1. 1. Mobile Game Developer War 4: Online CampMGDW4 Online Camp 3.2 State Management
  2. 2. Mobile Game Developer War 4: Online Camp Apa itu state?• Dalam game kita perlu menyimpan berbagai informasi: – Level dan status pemain Informasi-informasi tersebut – Stage yang sudah dibuka disebut juga dengan game state. – Highscore, achievements – Berbagai quest atau misi yang dijalankan pemain
  3. 3. Mobile Game Developer War 4: Online Camp State ManagementSuatu mekanisme untuk menyimpan danmengolah informasi state dalam sebuah game.
  4. 4. Mobile Game Developer War 4: Online Camp Contoh penggunaan• Screen transition – Menentukan layar apa yang kita tampilkan pada suatu saat – Misalnya: Main menu, option menu, in game, pause menu, dll
  5. 5. Mobile Game Developer War 4: Online Camp Contoh penggunaan• RPG Game State – Menentukan pemain sedang menjalani event/quest/misi apa – State tersebut akan mempengaruhi respon dari game – Contohnya: NPC X akan bergabung dengan party jika pemain sudah mengalahkan monster Y Di game Suikoden II, di akhir permainan akan ada event khusus jika kita berhasil mengumpulkan 108 karakter.
  6. 6. Mobile Game Developer War 4: Online CampKonsep di balik State Management• State management disimpan dalam bentuk graph atau flowchart – Sebuah state digambarkan dengan suatu node – Setiap state akan memiliki satu atau lebih transisi (baik dari atau menuju state tsb) – Setiap transisi akan dipengaruhi oleh suatu trigger atau nilai tertentu
  7. 7. Mobile Game Developer War 4: Online CampContoh Kasus: Screen Flow
  8. 8. Mobile Game Developer War 4: Online Camp Implementasi State Manager• Kita perlu menyimpan state dalam suatu variabel, misalnya integer untuk kode screen saat ini• Untuk mengecek state kita dapat menggunakan if atau switch-case• Pengecekan perlu dilakukan di setiap bagian yang terpengaruh• Misalnya untuk screen, akan mempengaruhi: – Input Untuk bagian koding materi ini bisa – Draw melanjutkan dari project yang sebelumnya, hanya draw dan – Update getInput yang banyak berubah :D
  9. 9. Mobile Game Developer War 4: Online Camp //fungsi draw //deklarasi variabel penting private void draw(){ int screenState; switch (screenState) { case SCREEN_MAIN_MENU: final int SCREEN_MAIN_MENU = 0; //... final int SCREEN_OPTION = 1; break; final int SCREEN_LEVEL_SELECTION= 2; case SCREEN_OPTION: final int SCREEN_TUTORIAL = 3; //... final int SCREEN_IN_GAME = 4; break; final int SCREEN_PAUSE = 5; case SCREEN_LEVEL_SELECTION: //... final int SCREEN_RESULT = 6; break; final int SCREEN_EXIT = 7; case SCREEN_IN_GAME: //... Kode untuk setiap state bisa kita simpan break; case SCREEN_TUTORIAL: dalam variabel dengan nama yang jelas //... break; case SCREEN_PAUSE:private void init(){ //... gameover = false; break; screenState = SCREEN_MAIN_MENU; case SCREEN_RESULT:} //... break; case SCREEN_EXIT:State awal perlu kita tentukan //... break; default: Implementasi state management break; } dengan switch-case -> }
  10. 10. Mobile Game Developer War 4: Online Camp Isi fungsi draw//...(lihat di slide sebelumnya)case SCREEN_MAIN_MENU: g.setColor(0x000000); g.drawString("Main Menu Screen", 10, 0, Graphics.TOP | Graphics.LEFT); g.drawString("^ Go to Option", 10, 50, Graphics.TOP | Graphics.LEFT); g.drawString("> Play Game", 10, 100, Graphics.TOP | Graphics.LEFT); g.drawString("< Exit", 10, 150, Graphics.TOP | Graphics.LEFT); break;case SCREEN_OPTION: g.setColor(0xff0000); g.drawString("Option Screen", 10, 0, Graphics.TOP | Graphics.LEFT); g.drawString("^ Back to main menu", 10, 50, Graphics.TOP | Graphics.LEFT); g.drawString(“> Play game", 10, 100, Graphics.TOP | Graphics.LEFT); break;case SCREEN_LEVEL_SELECTION: g.setColor(0x00ff00); g.drawString("Level Selection Screen", 10, 0, Graphics.TOP | Graphics.LEFT); g.drawString("^ Back to main menu", 10, 50, Graphics.TOP | Graphics.LEFT); break;case SCREEN_IN_GAME: g.setColor(0x0000ff); g.drawString("Game Screen", 10, 0, Graphics.TOP | Graphics.LEFT); break;//...(lihat di slide sebelumnya)
  11. 11. Mobile Game Developer War 4: Online Camp Isi fungsi draw//...(lihat di slide sebelumnya)case SCREEN_MAIN_MENU: g.setColor(0x000000); g.drawString("Main Menu Screen", 10, 0, Graphics.TOP | Graphics.LEFT); g.drawString("^ Go to Option", 10, 50, Graphics.TOP | Graphics.LEFT); g.drawString("> Play Game", 10, 100, Graphics.TOP | Graphics.LEFT); g.drawString("< Exit", 10, 150, Graphics.TOP | Graphics.LEFT); break;case SCREEN_OPTION: g.setColor(0xff0000); g.drawString("Option Screen", 10, 0, Graphics.TOP | Graphics.LEFT); g.drawString("^ Back to main menu", 10, 50, Graphics.TOP | Graphics.LEFT); g.drawString(“> Play game", 10, 100, Graphics.TOP | Graphics.LEFT); break;case SCREEN_LEVEL_SELECTION: g.setColor(0x00ff00); g.drawString("Level Selection Screen", 10, 0, Graphics.TOP | Graphics.LEFT); g.drawString("^ Back to main menu", 10, 50, Graphics.TOP | Graphics.LEFT); break;case SCREEN_IN_GAME: g.setColor(0x0000ff); g.drawString("Game Screen", 10, 0, Graphics.TOP | Graphics.LEFT); break;//...(lihat di slide sebelumnya)
  12. 12. Mobile Game Developer War 4: Online Camp Implementasi transisi screenprivate void getInput(){ 1 int keystate = getKeyStates(); Bagian yang berwarna merah adalah switch (screenState) { case SCREEN_MAIN_MENU: implementasi transisi antar state if (keystate == LEFT_PRESSED){ if(!lefthold){ screenState = SCREEN_EXIT; lefthold=true; case SCREEN_OPTION: } if(keystate == UP_PRESSED){ 2 }else lefthold=false; if(!uphold){ if(keystate == UP_PRESSED){ screenState = SCREEN_MAIN_MENU; if(!uphold){ uphold=true; screenState = SCREEN_OPTION; } uphold=true; }else uphold=false; } break; }else uphold=false; case SCREEN_LEVEL_SELECTION: if (keystate == RIGHT_PRESSED){ if(keystate == UP_PRESSED){ if(!righthold){ if(!uphold){ screenState = SCREEN_LEVEL_SELECTION; screenState = SCREEN_MAIN_MENU; righthold=true; uphold=true; } } }else righthold=false; }else uphold=false; break; break; //...silahkan lengkapi untuk setiap screen default: break; } }
  13. 13. Mobile Game Developer War 4: Online Camp Quest: Coba kalian lengkapi sampai semua flow menu pada flowchart diimplementasiHasil sejauh ini:
  14. 14. Mobile Game Developer War 4: Online Camp Cara menyelesaikan Quest1. Kirim source code MainCanvas.java ke email: quest@agateacademy.com2. Gunakan subject “Quest Online Camp 03b – State Management”
  15. 15. Mobile Game Developer War 4: Online Camp• Untuk menyelesaikan materi, kunjungi http://bit.ly/KsDbj1• Untuk pertanyaan atau diskusi, bisa dilakukan via forum: http://bit.ly/mgdw4forum

×