diff Magoroku.cc @ 115:31dd5c07f7c1

class OBJECT:SceanGraph
author e085768
date Wed, 15 Jun 2011 23:31:59 +0900
parents 8c96cadde050
children ed702e49cc6c
line wrap: on
line diff
--- a/Magoroku.cc	Thu Jun 09 18:07:46 2011 +0900
+++ b/Magoroku.cc	Wed Jun 15 23:31:59 2011 +0900
@@ -2,28 +2,9 @@
 #include "Magoroku.h"
 
 #include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdbool.h>
+#include "game.h"
 #include "libps2.h"
 #include "ps2util.h"
-#include "field.h"
-#include "car.h"
-#include "gSprite.h"
-#include "gFont.h"
-#include "game.h"
-#include "controler.h"
-#include "camera.h"
-#include "carNode.h"
-#include "car.h"
-#include "light.h"
-#include "title_scene.h"
-#include "game_time.h"
-#include "schedule.h"
-#include "game.h"
-
-#include "mytype.h"
-#include "linda.h"
 
 #include "sjoy.h"
 //magoroku 関係ココまで
@@ -56,18 +37,23 @@
 //#include "Character.h"
 //#include "Character_state.h"
 
+#include "Light.h"
 
 
 //static SDL_Surface *screen;
 // static Uint32 background;
 // static char *pad_trace_file;
 
-extern void schedule();
-extern void tokuten();
+
+// tree_Dandy の schedule3.c 
+//extern void schedule();
+
+
+//extern void tokuten();
 extern bool padCheck(SDL_Joystick *joy);
 extern bool keybord(void);
-static int gamesyokika(int gamef);
-static int game_pause(int);
+//static int gamesyokika(int gamef);
+//static int game_pause(int);
 //static char *pad_trace_file;
 
 /**
@@ -84,8 +70,6 @@
 
 SDL_Joystick *joy;
 
-
-
 const char *usr_help_str = "Usage: ./twice [-length data_length] [-count task_num]\n\
   -length  Number of data (default DATA_NUM (Func.h))\n\
   -count   Number of task (default 1)\n";
@@ -99,15 +83,14 @@
 MainLoopPtr
 Magoroku::init(Viewer *sgroot_, int w, int h)
 {
-    screen_w = w;
-    screen_h = h;
-    droot = sgroot_;
-    return droot;
+  screen_w = w;
+  screen_h = h;
+  droot = sgroot_;
+  return droot;
 }
 
-Application *
-application() {
-    return new Magoroku();
+Application *application() {
+  return new Magoroku();
 }
 
 
@@ -125,22 +108,6 @@
 void linda_env_init( void );
 
 
-//Magoroku の処理
-static void set_schedule(Game *game);
-static void sche_game_init(Game *game);
-static void sche_game_opening(Game *game);
-static void sche_game_select_car(Game *game);
-static void sche_game_select_course(Game *game);
-static void sche_game_ready(Game *game);
-static void sche_game_main_init(Game *game);
-static void sche_game_main_ready(Game *game);
-static void sche_game_main(Game *game);
-static void sche_game_main_pause(Game *game);
-static void sche_game_main_goal(Game *game);
-static void sche_game_main_finish(Game *game);
-static void sche_game_main_finish2(Game *game);
-
-
 extern int init(TaskManager *manager, int argc, char *argv[]);
 extern void task_initialize();
 static void TMend(TaskManager *manager);
@@ -153,25 +120,30 @@
     return 0;
 };
 
-//ゲームの分岐に使用(コールバック)
-//static int gamef = 0;
-static void (*sche_func_assumption)(Game*);
-static void (*sche_func)(Game*) = &sche_game_init;
-static int change_state = 0;
 
 /*
   ゲームの分岐。magoroku の schedule の処理と同等と考えてオッケーかな?
 */
 HTaskPtr 
 Magoroku::application_task(HTaskPtr next, Viewer* viewer){
-    // printf("gamef = %d\n",gamef);
-    schedule(&game);
-    return next;
+
+  // magoroku_racing                                                                                                        
+  game_main();
+  
+  // Dandy
+  printf("gamef = %d\n",gamef);
+  switch (gamef) {
+  case 0:    gamef= magoroku_main_init(gamef); break;
+  case 1:    gamef= gamesyokika(gamef); break;
+  case 2:    gamef= opening(gamef); break;
+  case 3:    gamef= magoroku_main_loop(gamef); break;
+  case 4:    gamef= magoroku_closing(gamef); break;
+  }
+
+  return next;
 }; 
 
 
-
-
 static void
 task_init() 
 {
@@ -180,33 +152,34 @@
 int
 TMmain(TaskManager *manager,int argc, char *argv[])
 {
-    for(int i = 1; i<argc ; i++) {
-	if (strcmp(argv[i],"-t")) {
-	    test_mode=1;
-	    if (i+1<argc && argv[i+1]) {
-		i++;
-		test_object=argv[i];
-	    }
-	}
+  for(int i = 1; i<argc ; i++) {
+    if (strcmp(argv[i],"-t")) {
+      if (i+1<argc && argv[i+1]) {
+	i++;
+      }
     }
+  }
 
-    task_init();
-    task_initialize();
-    manager->set_TMend(TMend);
+  task_init();
+  task_initialize();
+  manager->set_TMend(TMend);
 
-    return init(manager,argc, argv);
+  // magoroku_racing の main.ccから
+  //game_main();
+    
+  return init(manager,argc, argv);
 }
 
 void
 TMend(TaskManager *manager)
 {
-    printf("game end\n");
+  printf("game end\n");
 }
 
 static int light_sysswitch = 0;
 static int light_num = 4;
 
-/*
+
 static void 
 LightSysSwitch(Viewer *sgroot) {
   if (light_sysswitch == 1) {
@@ -222,400 +195,3 @@
     sgroot->OffLightSysSwitch();
   }
 }
-*/
-
-
-
-
-static void
-set_schedule(Game *game)
-{
-  sche_func = sche_func_assumption;
-  change_state = 0;
-}
-
-static void
-graphic_init()
-{
-  gSprite_Init(); // グラフィック関連の初期化
-  gFont_Init();   // フォント関連の初期化
-}
-
-static void 
-play_init( Game *game )
-{
-  game->jiki = car_init(game->car_id);
-  carNode_append(game->jiki);
-  field_init(game->course_id);
-}
-
-// 適当に自作 :miya
-void linda_env_init( void )
-{
-  printf("linda_env_init\n");
-}
-
-static void game_env_init ( Game *game )
-{
-  game->car_id      = 1;
-  game->course_id   = 1;
-  game->camera_type = 0;
-  game->rap         = 1;
-  game->jiki        = NULL;
-
-  ranking = 0;
-
-  wait_init();
-  linda_env_init();
-}
-
-
-
-void
-sche_game_init(Game *game)
-{
-  game_env_init(game);
-  graphic_init();
-  camera_init();
-
-#ifdef LINDA
-  //sche_func = &sche_game_wait;
-  //set_schedule_assumption(sche_game_wait);
-#else
-  set_schedule_assumption(sche_game_opening);
-#endif
-}
-
-/**
- * 通信対戦専用
- * 全ユーザが接続するまで待つ
- * ・・・だったんだけど、現在 linda を切っているため worning が出る。
- * ので cut する。
- */
-
-/* linda を使用しないのでカットした
-static void
-sche_game_wait(Game *game)
-{
-  gFont_SetString("WAITING...", 200, 100);
-  set_schedule_assumption(sche_game_wait_ready);
-}
-*/
-
-
-/**
- * 通信対戦専用
- * 全ユーザの接続を確認したら呼び出す
- * こいつも、linda がないので cut
-*/ 
- /*
-static void
-sche_game_wait_ready(Game *game)
-{
-  gFont_SetString("CONNECT OK!!", 170, 300);
-  if (game->play_id == 1) {
-    gFont_SetString(" PUSH START ", 170, 400);
-    if (pad.st != 1) { goto WAIT_READY; }
-  }
-
-  set_schedule_assumption(sche_game_opening);
-    
- WAIT_READY:
-  return;
-}
- */
-
-
-void
-sche_game_opening(Game *game)
-{
-  static int blink_count = 0;
-  if (game->play_id==1){
-    if (blink_count < 35) {
-      gFont_SetString("PUSH START !!", 170, 380);
-    }
-    blink_count = (blink_count > 70) ? 0 : blink_count + 1;
-
-    if (pad.st != 1) { goto OPENING; }
-  }
-
-    
-  set_schedule_assumption(sche_game_select_car);
-
- OPENING:
-  return;
-
-
-  if (game->play_id == 1) {
-    if (title_scene() < 0){
-    }
-  } else if (game->play_id == 2) {
-    if (i==0){
-      title_init_call();
-      i=1;
-    }
-  }
-
-
-}
-
-void
-sche_game_select_car(Game *game)
-{
-  if (i==1){
-    title_finish_call();
-    i=2;
-  }
-  gSprite_PutSpriteEx(SP_SEL_CAR+game->car_id, 190, 200, 1.5, 1.5);
-  gSprite_PutSprite(24, 460, 300);
-  gSprite_PutSprite(25, 120, 300);
-  gFont_SetString("SELECT CAR", 180, 50);
- 
-  if (pad.right == 1) {
-    game->car_id =
-      (game->car_id > MAXCAR-1) ? 1 : game->car_id + 1;
-  }
-  if (pad.left == 1) {
-    game->car_id =
-      (game->car_id < 2) ? MAXCAR : game->car_id - 1;
-  }
-
-  if (game->play_id == 1)
-    if (pad.circle != 1) { goto SELECT_CAR; }
- 
-    
-  set_schedule_assumption(sche_game_select_course);
-    
- SELECT_CAR:
-  return;
-}
-
-void
-sche_game_select_course(Game *game)
-{
-  gSprite_PutSpriteEx(SP_SEL_COURSE+game->course_id, 190, 200, 1.7, 1.8);
-  gSprite_PutSprite(24, 460, 300);
-  gSprite_PutSprite(25, 120, 300);
-
-  gFont_SetString("SELECT COURSE", 150, 50);
-
-  if (game->play_id == 1) {
-    if (pad.right == 1) {
-      game->course_id =
-	(game->course_id > MAXFIELD-1) ? 1 : game->course_id + 1;
-      goto SELECT_COURSE;
-    }
-    if (pad.left == 1) {
-      game->course_id =
-	(game->course_id < 2) ? MAXFIELD : game->course_id - 1;
-      goto SELECT_COURSE;
-    }
-
-    if (pad.circle != 1) { goto SELECT_COURSE; }
-  }
-
-  set_schedule_assumption(sche_game_ready);
-
- SELECT_COURSE:
-  return;
-
-}
-
-void
-sche_game_ready(Game *game)
-{
-  static int blink_count = 0;//
-
-  gSprite_PutSprite(27+game->play_id,265,10);
-  gSprite_PutSpriteEx(SP_SEL_CAR+game->car_id, 50, 120, 1.5, 1.5);
-  gSprite_PutSpriteEx(SP_SEL_COURSE+game->course_id, 340, 120, 1.7, 1.8);
-	
-  /* 点滅 */
-  if (blink_count < 35) {
-    gFont_SetString("GAME START !!", 170, 380);
-  }
-  blink_count = (blink_count > 70) ? 0 : blink_count + 1;
-
-  set_schedule_assumption(sche_game_main_init);
-
-
-  if (pad.st == 1) {
-    set_schedule_assumption(sche_game_main_init);
-  }
-  if (pad.cross > 0) {
-    set_schedule_assumption(sche_game_select_car);
-  }
-
-}
-
-void
-sche_game_main_init(Game *game)
-{
-  if (!game->jiki)
-    play_init(game);
-  RUNNIG=0;
-
-  set_schedule_assumption(sche_game_main_ready);
-}
-
-static void
-sche_game_main_ready(Game *game)
-{
-  gFont_SetString("Loading....", 180, 100);
-  set_schedule_assumption(sche_game_main);
-}
-
-static void
-sche_game_main(Game *game)
-{
-  //flip
-  
-  /** begin: dispaly RAP TIME **/
-  if(RUNNIG==0){
-    start_time = game_time_get_msec();
-    RUNNIG=1;
-  }
-
-  time_count = game_time_get_msec() - start_time;
-  game_time_set_raptime(raptime,time_count);
-  gFont_SetString("TIME",300,20);
-  gFont_SetString(raptime,400,20);
-  /** end: dispaly RAP TIME **/
-
-  // light_init と init_lightの書き間違え?
-  init_light(&l);
-  set_light(&l);
-    
-  car_id_update(game, game->jiki);
-
-  field_update(game->jiki);
-  camera_update(game,game->jiki->body->transfer);
-  carNode_draw();
-
-  gFont_SetStringInt(game->rap, 50, 100);
-
-  /* スピードメーター */
-  gSprite_DefSprite(23, 1, 1,(int)(106.0*(game->jiki->speed/game->jiki->speed_max)), 34);
-  gSprite_PutSprite(23, 400, 400);
-  /* km/h */
-  gSprite_PutSprite(26, 470, 350);
-  /* Rap */
-  gSprite_PutSprite(27, 80, 100);
-
-  if (game->rap > MAXRAP) {
-    ranking = 1;
-    set_schedule_assumption(sche_game_main_goal);
-  }
-
-  gFont_SetStringInt((int)(100.0*game->jiki->speed), 380, 350);
-
-  
-  if ((pad.right > 0) && ((game->jiki->speed != 0) || (pad.circle > 0))) {
-    car_swerve(game->jiki, 1);
-  }
-  if ((pad.left > 0) && ((game->jiki->speed != 0) || (pad.circle > 0))) {
-    car_swerve(game->jiki, -1);
-  }
-  if (pad.circle > 0) {
-    car_accelerate(game->jiki, 1);
-  }
-  if (pad.cross > 0) {
-    car_accelerate(game->jiki, -1);
-  }
-
-  if (pad.r1 == 1) {
-    game->camera_type = !game->camera_type;
-  }
-  if (pad.st == 1) {
-    set_schedule_assumption(sche_game_main_pause);
-  }
-  
-  //S-dandy の obj てきな
-}
-
-
-void
-sche_game_main_pause(Game *game)
-{
-  static int select = 0;
-
-  field_update(game->jiki);
-  carNode_draw();
-      
-  if (game->play_id == 1) {
-    // 選択マーク 
-    gSprite_PutSprite(17, 100, 190+select*100);
-	
-    gFont_SetString("BACK TO GAME", 200, 200);
-    gFont_SetString("GO TO TITLE",  200, 300);
-  } else {
-    gFont_SetString("Pause ...", 200, 200);
-  }
-
-    
-  if (pad.circle == 1) {
-    if (select == 0) {
-      set_schedule_assumption(sche_game_main);
-    } else {
-      set_schedule_assumption(sche_game_main_finish);
-    }
-  } else if (pad.st == 1) {
-    set_schedule_assumption(sche_game_main);
-  } else if (pad.up == 1 || pad.down == 1) {
-    select = !select;
-  }
-   
-}
-
-
-void
-sche_game_main_goal(Game *game)
-{
-  /** dispaly TOTAL TIME **/ 
-  game_time_set_raptime(raptime,time_count);
-
-  gFont_SetString("TOTAL TIME",150,20);
-  gFont_SetString(raptime,400,20);
-  gFont_SetString("GOAL !!", 220, 150);
-
-#ifdef LINDA
-  if (ranking == 1)
-    gFont_SetString("You WIN!!", 200, 250);
-  else
-    gFont_SetString("You Lose...", 200, 250);
-#endif
-
-
-  // 宣言では引数が二つだったから、第一引数に game を入れてみた
-  car_update(game, game->jiki);
-  field_update(game->jiki);
-  carNode_draw();
-  camera_update(game,game->jiki->body->transfer);
-    
-  if (pad.st == 1) {
-    set_schedule_assumption(sche_game_main_finish);
-  }
-    
-}
-
-void
-sche_game_main_finish(Game *game)
-{
-  field_destroy();
-  carNode_destroy();
-  game_env_init(game);
-
-  set_schedule_assumption(sche_game_main_finish2);
-}
-
-void
-sche_game_main_finish2(Game *game)
-{
-  gFont_SetString("GAME OVER ...", 200, 200);
-
-
-  if (pad.st == 1) {
-    set_schedule_assumption(sche_game_opening);
-  }
-
-}