Mercurial > hg > old > magoroku_racing
view schedule.cc @ 134:42337585fb7c
fix merge
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 22 Jul 2011 18:32:39 +0900 |
parents | 4f50f5a3b363 |
children | 993d5f7e5f30 |
line wrap: on
line source
/* schedule.c */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <stdbool.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" #ifdef LINDA bool linda_update(int p, Game *game); #else #define linda_update(change_state, game) true #endif #define MAXCAR 4 // 選択可能機体 #define MAXFIELD 2 // 選択可能コース #define MAXRAP 3 // ラップ数 #define SP_SEL_CAR 50 #define SP_SEL_COURSE 80 // controler.cより extern SGO_PAD pad; static void set_schedule(Game *game); static void sche_game_init(Game *game); //static void sche_game_wait(Game *game); //プロトタイプも消しといた //static void sche_game_wait_ready(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); /* timer */ static int start_time,time_count; static int RUNNIG=0; char raptime[10]; static int ranking = 0; static LIGHT l; static int i=0; static void (*sche_func_assumption)(Game*); static void (*sche_func)(Game*) = &sche_game_init; static int change_state = 0; // test void testCarControll( Game *game ); // schedule.ccで使用してる void linda_env_init( void ); static void set_schedule_assumption(void (*_func)(Game*) ) { sche_func_assumption = _func; change_state = 1; } static void unset_schedule() { change_state = 0; } static void set_schedule(Game *game) { sche_func = sche_func_assumption; change_state = 0; } static void graphic_init() { // flip(); printf("graphic_init()\n"); gSprite_Init(); // グラフィック関連の初期化 gFont_Init(); // フォント関連の初期化 } static void play_init( Game *game ) { printf("play_init()\n"); // ここで、car_idには1か2か3が入らんとダメ game->jiki = car_init(game->car_id); // carNode.cc内のcar_listに追加 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) { printf("sche_game_init()\n"); game_env_init(game); graphic_init(); camera_init(); FVECTOR cP = { 0, 0, 0, 0 }; FVECTOR cA = { 0, 0, 0, 0 }; // FVECTOR cA = { 0, 0, 0, 0 }; set_cameraPos( cP, cA ); #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; // gSprite_PutSprite( true, TITLE, 600, 100, -00 ); gSprite_PutSprite( true, TITLE, 285, -300, -600 ); //ここを現在通らないらしい。 if (game->play_id==1){ if (blink_count < 35) { gFont_SetString("PUSH START !!", 170, 380); } blink_count = (blink_count > 70) ? 0 : blink_count + 1; printf("pad.st = %d\n",pad.st); if (pad.st != 1) { goto OPENING; } } /*処理をいったんifの外へ。これを見る限り、キー入力自体はokぽい printf("pad.st = %d\n",pad.st); 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) { printf("sche_game_select_car()\n"); if (i==1){ title_finish_call(); i=2; } gSprite_PutSpriteEx(true,SP_SEL_CAR+game->car_id, 600, 200, TEST_Z_GRID,1.5, 1.5, 0.0); gSprite_PutSprite(true,R_ARROW, 750, 200, TEST_Z_GRID); gSprite_PutSprite(true,L_ARROW, 450, 200, TEST_Z_GRID); 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) { printf("sche_game_select_course()\n"); gSprite_PutSpriteEx(true, SP_SEL_COURSE+game->course_id, 600, 200, TEST_Z_GRID ,1.7, 1.8, 0.0); gSprite_PutSprite(true, R_ARROW, 750, 200, TEST_Z_GRID); gSprite_PutSprite(true, L_ARROW, 450, 200, TEST_Z_GRID); 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) { printf("sche_game_ready()\n"); static int blink_count = 0;// int tesX = 500; // PLAYER_1 or PLAYER_2 今は通信対戦できないから常にPLAYER_1 ( PLAYER_1 = 28 , PLAYER_2 = 29 ) gSprite_PutSprite(true, 27+game->play_id, 265 + 50 , 200, TEST_Z_GRID + 400 ); gSprite_PutSpriteEx(true, SP_SEL_CAR+game->car_id, 50 + tesX, 120, TEST_Z_GRID - 300, 1.5, 1.5 , 0.0); gSprite_PutSpriteEx(true, SP_SEL_COURSE+game->course_id, 340 + tesX, 120, TEST_Z_GRID - 300, 1.7, 1.8 , 0.0); /* 点滅 */ if (blink_count < 35) { gFont_SetString("GAME START !!", 170, 380); } blink_count = (blink_count > 70) ? 0 : blink_count + 1; 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) { printf("sche_game_main_init()\n"); if (!game->jiki){ play_init(game); } RUNNIG=0; set_schedule_assumption(sche_game_main_ready); // とりあえず、トップビューで // FVECTOR cPos = { 0, 877, -2000, 0 }; FVECTOR cPos = { 0, 877, 7500, 0 }; //FVECTOR cPos = { 0, 300, -7500, 0 }; FVECTOR cAngle = { 90, 0, 0, 0 }; /* FVECTOR cPos = { 0, 0, -5000, 0 }; FVECTOR cAngle = { 0, 0, 0, 0 }; */ set_cameraPos( cPos, cAngle ); } 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) { printf("sche_game_main()\n"); FVECTOR cPos = { game->jiki->location[0],game->jiki->location[1], -game->jiki->location[2] ,0 }; FVECTOR a={180,0,0,0}; /** 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); // 宣言では引数が二つだったから、第一引数に game を入れてみた car_update(game, game->jiki); field_update(game->jiki); // 車のDraw関数 carNode_draw(); // jikiによってカメラも移動( camera_update()って関数のほう使うからイラんね ) set_cameraPos( cPos , a ); //camera_update(game, game->jiki->body->transfer); gFont_SetStringInt(game->rap, 50, 100); /* スピードメーター */ //gSprite_DefSprite(SP_METER, 1, 1,(int)(106.0*(game->jiki->speed/game->jiki->speed_max)), 34); //とりあえずコンパイル通すためにコメント。あとで調べましょう //gSprite_DefSprite(SP_METER, "name", (float)(106.0*(game->jiki->speed/game->jiki->speed_max)), 34.0, 100); gSprite_PutSprite(true,SP_METER, 400, 400, TEST_Z_GRID); /* km/h */ gSprite_PutSprite(true, KM, 470, 350, TEST_Z_GRID); /* Rap */ gSprite_PutSprite(true,RAP, 80, 100, TEST_Z_GRID); if (game->rap > MAXRAP) { ranking = 1; set_schedule_assumption(sche_game_main_goal); } gFont_SetStringInt((int)(100.0*game->jiki->speed), 380, 350); // testCarControll( game ); 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); } // テスト用関数 // cameraControl( ); if (pad.r1 == 1) { game->camera_type = !game->camera_type; } // startボタン押したらpause画面へ if (pad.st == 1) { set_schedule_assumption(sche_game_main_pause); } } void sche_game_main_pause(Game *game) { printf("sche_game_main_pause\n"); static int select = 0; field_update(game->jiki); carNode_draw(); if (game->play_id == 1) { // 選択マーク gSprite_PutSprite(true, SELECT, 100 + 250, 190+select*100 + 10, TEST_Z_GRID + 400 ); 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, (FMATRIX)(game->jiki->body->matrix) ); 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); } } // 適当に作りました void wait_sync(Game *game) { printf("wait_sync\n"); } // 適当に void swap_dbuff() { printf("swap_dbuff()\n"); } void schedule(Game *game) { flip(); printf("----------------------\n"); printf("schedule()\n"); sche_func(game); if (linda_update(change_state, game) == true){ set_schedule(game); } else{ unset_schedule(); } wait_sync(game); swap_dbuff(); // この関数はなんなのかな sjoy_poll(); ps2util_sprite_Draw(); gSprite_Draw_Reset(); gFont_Draw_Reset(); // ここにgSprite_Init()があるのって良いのかな? // gSprite_Init(); } void testCarControll( Game *game ) { FVECTOR xyz; FVECTOR angle; for( int i = 0; i < 4; i ++ ){ xyz[i] = game->jiki->direction[i]; angle[i] = game->jiki->location[i]; } float speed = 1.0f; bool esc = false; if( pad.se > 0 ){ esc = true; printf("press selectButton\n"); } if( pad.l1 > 0 ){ speed = 10.0f; printf("press W_key\n"); } if( pad.left > 0 ){ if ( esc == true ) angle[0] -= speed; else xyz[0] -= speed; } if( pad.right > 0 ){ if ( esc == true ) angle[0] += speed; else xyz[0] += speed; } if( pad.up > 0 ){ if ( esc == true ) angle[1] -= speed; else xyz[1] -= speed; } if( pad.down > 0 ){ if ( esc == true ) angle[1] += speed; else xyz[1] += speed; } if( pad.circle > 0 ){ if ( esc == true ) angle[2] += speed; else xyz[2] += speed; } if( pad.cross > 0 ){ if ( esc == true ) angle[2] -= speed; else xyz[2] -= speed; } for( int i = 0; i < 3; i ++ ){ if (angle[i] > 360.0f || angle[i] < -360.0f ) { angle[i] = 0.0f; } } for( int i = 0; i < 4; i ++ ){ game->jiki->direction[i] = angle[i]; game->jiki->location[i] = xyz[i]; } /* for( int i = 0; i < 4; i ++ ){ printf("cameraPos[%d] = %f ", i, cameraMan_pos[i] ); } printf("\n"); for( int i = 0; i < 4; i ++ ){ printf("cameraAngle[%d] = %f ", i, cameraMan_angle[i] ); } printf("\n"); */ }