Mercurial > hg > old > magoroku_racing
changeset 119:f2e2460b4011
draw_title
author | e085768 |
---|---|
date | Sun, 19 Jun 2011 02:16:20 +0900 |
parents | b6dc70f6aa7e |
children | 9a907a6fcdaa |
files | Magoroku.cc Magoroku.cc~ controler.cc controler.h gFont.cc gSprite.cc gSprite.cc~ gSprite.h game.cc game.cc~ ps2util.cc~ schedule.cc schedule.cc~ xml_file/title.xml |
diffstat | 14 files changed, 1735 insertions(+), 225 deletions(-) [+] |
line wrap: on
line diff
--- a/Magoroku.cc Fri Jun 17 10:31:39 2011 +0900 +++ b/Magoroku.cc Sun Jun 19 02:16:20 2011 +0900 @@ -9,55 +9,28 @@ #include "sjoy.h" //magoroku 関係ココまで -#include "SgoexCerium.h" #include <ctype.h> #include <math.h> #include <time.h> #include <SDL.h> #include "SDL_opengl.h" -//#include "tree_controll.h" #include "xml.h" #include "profile.h" //#include "syokika.h" -//#include "sankaku.h" #include "sound.h" -//#include "bom.h" -//#include "count2.h" -//#include "tokuten.h" -//#include "tama.h" -//#include "debug.h" -//#include "trace.h" #include "LoadSprite.h" #include <SDL_mixer.h> #include "error.h" #include "matrix_calc.h" -//#include "Character.h" -//#include "Character_state.h" - #include "Light.h" -//static SDL_Surface *screen; -// static Uint32 background; -// static char *pad_trace_file; - -// 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 char *pad_trace_file; - - - /** @@ -130,7 +103,7 @@ HTaskPtr Magoroku::application_task(HTaskPtr next, Viewer* viewer){ - // magoroku_racing + // magoroku_racing game_main(); /* @@ -173,7 +146,6 @@ } } } - task_init(); task_initialize(); manager->set_TMend(TMend); @@ -194,8 +166,11 @@ //static int light_num = 4; + +static int light_sysswitch = 0; +static int light_num = 4; + // ceriumuで同じ変数名があるから _2 って付け足しました -/* static void LightSysSwitch_2(Viewer *sgroot) { if (light_sysswitch == 1) { @@ -211,4 +186,4 @@ sgroot->OffLightSysSwitch(); } } -*/ +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Magoroku.cc~ Sun Jun 19 02:16:20 2011 +0900 @@ -0,0 +1,189 @@ +//magoroku 関係ココから +#include "Magoroku.h" + +#include <stdio.h> +#include "game.h" +#include "libps2.h" +#include "ps2util.h" + +#include "sjoy.h" +//magoroku 関係ココまで + +#include <ctype.h> +#include <math.h> +#include <time.h> +#include <SDL.h> +#include "SDL_opengl.h" + +#include "xml.h" +#include "profile.h" +//#include "syokika.h" + +#include "sound.h" +#include "LoadSprite.h" +#include <SDL_mixer.h> +#include "error.h" +#include "matrix_calc.h" + +#include "Light.h" + + + +extern bool padCheck(SDL_Joystick *joy); +extern bool keybord(void); + + +/** + * runmode: + * 0 - normal game + * 1 - capture mode + * program will capture all pad traces on a play and + * dump it into a file + * 2 - trace mode + * program will run with a trace file which is generated + * by capture-mode + */ +int runmode; + +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"; + +Viewer *droot; + +static int screen_w; +static int screen_h; + +//ウィンドウのサイズとかを指定? +MainLoopPtr +Magoroku::init(Viewer *sgroot_, int w, int h) +{ + screen_w = w; + screen_h = h; + droot = sgroot_; + return droot; +} + +Application *application() { + return new Magoroku(); +} + + +//Magoroku の初期化など +/* 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; +// schedule.ccで使用してる +void linda_env_init( void ); + + +extern int init(TaskManager *manager, int argc, char *argv[]); +extern void task_initialize(); +static void TMend(TaskManager *manager); + + +//class Application の中の virtual bool app_loop( return 1 だけの関数?) を継承 +bool +Magoroku::app_loop(Viewer *viewer){ + // don't use allExecute + return 0; +}; + + +/* + ゲームの分岐。magoroku の schedule の処理と同等と考えてオッケーかな? +*/ +HTaskPtr +Magoroku::application_task(HTaskPtr next, Viewer* viewer){ + + // 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() +{ + printf("task_init\n"); +} + +FILE *main_fp; + +int +TMmain(TaskManager *manager,int argc, char *argv[]) +{ + main_fp = fopen("/dev/stdout", "w"); + if (!main_fp) { + perror("main"); + } + + printf("trace_TMmain\n"); + + 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); + + // magoroku_racing の main.ccから + //game_main(); + + return init(manager,argc, argv); +} + +void +TMend(TaskManager *manager) +{ + printf("game end\n"); +} + +//static int light_sysswitch = 0; +//static int light_num = 4; + + + +static int light_sysswitch = 0; +static int light_num = 4; + +// ceriumuで同じ変数名があるから _2 って付け足しました +static void +LightSysSwitch_2(Viewer *sgroot) { + if (light_sysswitch == 1) { + sgroot->OnLightSysSwitch(); + for (int i = 0; i < light_num; i++) { + SceneGraphPtr light = sgroot->getLight(i); + sgroot->OnLightSwitch(i); + light->xyz[0] = screen_w / 2; + light->xyz[1] = screen_h / 2; + light->xyz[2] = -100; + } + } else if (light_sysswitch == 0) { + sgroot->OffLightSysSwitch(); + } +} +
--- a/controler.cc Fri Jun 17 10:31:39 2011 +0900 +++ b/controler.cc Sun Jun 19 02:16:20 2011 +0900 @@ -114,114 +114,114 @@ bool keybord() { - SDL_PumpEvents(); - Uint8 *keys = SDL_GetKeyState(NULL); + SDL_PumpEvents(); + Uint8 *keys = SDL_GetKeyState(NULL); - printf("key--\n"); + printf("key--\n"); - if (keys[SDLK_UP]) { - pad.up += (pad.up < 2) ? 1 : 0; - } else { - pad.up = 0; - } - if (keys[SDLK_DOWN]) { - pad.down += (pad.down < 2) ? 1 : 0; - } else { - pad.down = 0; - } + if (keys[SDLK_UP]) { + pad.up += (pad.up < 2) ? 1 : 0; + } else { + pad.up = 0; + } + if (keys[SDLK_DOWN]) { + pad.down += (pad.down < 2) ? 1 : 0; + } else { + pad.down = 0; + } - if (keys[SDLK_RIGHT]) { - pad.right += (pad.right < 2) ? 1 : 0; - } else { - pad.right = 0; - } + if (keys[SDLK_RIGHT]) { + pad.right += (pad.right < 2) ? 1 : 0; + } else { + pad.right = 0; + } - if (keys[SDLK_LEFT]) { - pad.left += (pad.left < 2) ? 1 : 0; - } else { - pad.left = 0; - } + if (keys[SDLK_LEFT]) { + pad.left += (pad.left < 2) ? 1 : 0; + } else { + pad.left = 0; + } - if (keys[SDLK_a]) { - pad.cross += (pad.cross < 2) ? 1 : 0; - } else { - pad.cross = 0; - } + if (keys[SDLK_a]) { + pad.cross += (pad.cross < 2) ? 1 : 0; + } else { + pad.cross = 0; + } - if (keys[SDLK_z]) { - pad.circle += (pad.circle < 2) ? 1 : 0; - } else { - pad.circle = 0; - } + if (keys[SDLK_z]) { + pad.circle += (pad.circle < 2) ? 1 : 0; + } else { + pad.circle = 0; + } - if (keys[SDLK_s]) { - pad.square += (pad.square < 2) ? 1 : 0; - } else { - pad.square = 0; - } + if (keys[SDLK_s]) { + pad.square += (pad.square < 2) ? 1 : 0; + } else { + pad.square = 0; + } - if (keys[SDLK_x]) { - pad.triangle += (pad.triangle < 2) ? 1 : 0; - } else { - pad.triangle = 0; - } + if (keys[SDLK_x]) { + pad.triangle += (pad.triangle < 2) ? 1 : 0; + } else { + pad.triangle = 0; + } - if (keys[SDLK_r]) { - pad.r2 += (pad.r2 < 2) ? 1 : 0; - } else { - pad.r2 = 0; - } + if (keys[SDLK_r]) { + pad.r2 += (pad.r2 < 2) ? 1 : 0; + } else { + pad.r2 = 0; + } - if (keys[SDLK_e]) { - pad.r1 += (pad.r1 < 2) ? 1 : 0; - } else { - pad.r1 = 0; - } + if (keys[SDLK_e]) { + pad.r1 += (pad.r1 < 2) ? 1 : 0; + } else { + pad.r1 = 0; + } - if (keys[SDLK_w]) { - pad.l1 += (pad.l1 < 2) ? 1 : 0; - } else { - pad.l1 = 0; - } + if (keys[SDLK_w]) { + pad.l1 += (pad.l1 < 2) ? 1 : 0; + } else { + pad.l1 = 0; + } - if (keys[SDLK_q]) { - pad.l1 += (pad.l2 < 2) ? 1 : 0; - } else { - pad.l2 = 0; - } + if (keys[SDLK_q]) { + pad.l1 += (pad.l2 < 2) ? 1 : 0; + } else { + pad.l2 = 0; + } - // START ボタンは Return が似合う気がする - //if(keys[SDLK_1]) - if (keys[SDLK_RETURN]) { - pad.st += (pad.st < 2) ? 1 : 0; - } else { - pad.st = 0; - } + // START ボタンは Return が似合う気がする + //if(keys[SDLK_1]) + if (keys[SDLK_RETURN]) { + pad.st += (pad.st < 2) ? 1 : 0; + } else { + pad.st = 0; + } - if (keys[SDLK_2]) { - pad.se += (pad.se < 2) ? 1 : 0; - } else { - pad.se = 0; - } + if (keys[SDLK_2]) { + pad.se += (pad.se < 2) ? 1 : 0; + } else { + pad.se = 0; + } - if (keys[SDLK_ESCAPE]) { - SDL_Quit(); - exit(1); - //pad[0].st = 1; - //pad[0].se = 1; - } + if (keys[SDLK_ESCAPE]) { + SDL_Quit(); + exit(1); + //pad[0].st = 1; + //pad[0].se = 1; + } - //SELECT, START, L1, R1, L2, R2 - if ( (keys[SDLK_2]) + //SELECT, START, L1, R1, L2, R2 + if ( (keys[SDLK_2]) && (keys[SDLK_RETURN]) && (keys[SDLK_w]) && (keys[SDLK_e]) && (keys[SDLK_q]) && (keys[SDLK_r]) - ){ - return false; - } + ){ + return false; + } - return true; + return true; }
--- a/controler.h Fri Jun 17 10:31:39 2011 +0900 +++ b/controler.h Sun Jun 19 02:16:20 2011 +0900 @@ -32,20 +32,20 @@ typedef struct SGO_PAD { - short st; - short se; - short left; - short right; - short up; - short down; - short r1; - short r2; - short l1; - short l2; - short cross; - short circle; - short triangle; - short square; + short st; + short se; + short left; + short right; + short up; + short down; + short r1; + short r2; + short l1; + short l2; + short cross; + short circle; + short triangle; + short square; } SGO_PAD;
--- a/gFont.cc Fri Jun 17 10:31:39 2011 +0900 +++ b/gFont.cc Sun Jun 19 02:16:20 2011 +0900 @@ -131,26 +131,26 @@ static void gFont_Clear() { - int i; + int i; - for (i=0; i<DEFOBJ; i++) { - sprite_disappear(&sp[i].attribute); - } - sp_counter = 0; + for (i=0; i<DEFOBJ; i++) { + sprite_disappear(&sp[i].attribute); + } + sp_counter = 0; } void gFont_Draw_Reset() { - if (flag_spriteInited == true) { - gFont_Clear(); - } + if (flag_spriteInited == true) { + gFont_Clear(); + } } static int get_number_char(char a) { - return (int)a-32; + return (int)a-32; } /*
--- a/gSprite.cc Fri Jun 17 10:31:39 2011 +0900 +++ b/gSprite.cc Sun Jun 19 02:16:20 2011 +0900 @@ -3,6 +3,7 @@ #include "TaskManager.h" #include "SceneGraph.h" #include "Application.h" +#include <iostream> #include <stdio.h> #include <stdlib.h> @@ -35,24 +36,24 @@ void flip() { - CameraPtr camera = droot->sgroot->getCamera(); + CameraPtr camera = droot->sgroot->getCamera(); - droot->sgroot->flip(); - droot->sgroot->lightCalc(); + droot->sgroot->flip(); + droot->sgroot->lightCalc(); - root = droot->createSceneGraph(); - //root->xyz[0] = screen_w/2; - //root->xyz[1] = screen_h/2;; - root->xyz[0] = 0; - root->xyz[1] = 0; - root->xyz[2] = 30.0f; + root = droot->createSceneGraph(); + //root->xyz[0] = screen_w/2; + //root->xyz[1] = screen_h/2;; + root->xyz[0] = 0; + root->xyz[1] = 0; + //root->xyz[2] = 30.0f; - /*親の回転、座標から、子の回転、座標を算出*/ - get_matrix(root->matrix, root->angle, root->xyz, camera->matrix); - /*法線用の行列。Cameraの行列を抜いている(Cameraのコンストラクタで、単位行列にしている)*/ - get_matrix(root->real_matrix, root->angle, root->xyz, camera->real_matrix); - //出力して、次のものを出力するための準備 - droot->setSceneData(root); + /*親の回転、座標から、子の回転、座標を算出*/ + get_matrix(root->matrix, root->angle, root->xyz, camera->matrix); + /*法線用の行列。Cameraの行列を抜いている(Cameraのコンストラクタで、単位行列にしている)*/ + get_matrix(root->real_matrix, root->angle, root->xyz, camera->real_matrix); + //出力して、次のものを出力するための準備 + droot->setSceneData(root); } @@ -83,21 +84,21 @@ } /*void -gSprite_PutSprite(int number, int x, int y) -{ - ps2utilSprite *p = &sp[sp_counter]; + gSprite_PutSprite(int number, int x, int y) + { + ps2utilSprite *p = &sp[sp_counter]; - ps2util_sprite_Set_basicAttribute( - p, - (unsigned short)x, (unsigned short)y, - (unsigned short)sptable[number].tw*2, (unsigned short)sptable[number].th*2, - (unsigned short)sptable[number].tx, (unsigned short)sptable[number].ty, - (unsigned short)sptable[number].tw, (unsigned short)sptable[number].th, - SPRITE_PRIO_FOREGROUND); + ps2util_sprite_Set_basicAttribute( + p, + (unsigned short)x, (unsigned short)y, + (unsigned short)sptable[number].tw*2, (unsigned short)sptable[number].th*2, + (unsigned short)sptable[number].tx, (unsigned short)sptable[number].ty, + (unsigned short)sptable[number].tw, (unsigned short)sptable[number].th, + SPRITE_PRIO_FOREGROUND); - ps2util_sprite_Request(p); - sp_counter++; -}*/ + ps2util_sprite_Request(p); + sp_counter++; + }*/ //void gSprite_PutSprite(int number, short x, short y, int zorder) @@ -110,32 +111,62 @@ printf("PutSprite %d unknown\n",number); return; } + SceneGraphPtr object = droot->createSceneGraph(name); - //object->c_xyz[0] = m->mx; - //object->c_xyz[1] = m->my; + + // object->c_xyz[0] = m->mx; + // object->c_xyz[1] = m->my; + + // 適当に初期設定:miya + object->xyz[0] = 600; + object->xyz[1] = 100; + object->xyz[2] = -500; + root->addChild(object); - object->xyz[0] -= object->c_xyz[0]*my_scale; - object->xyz[1] -= object->c_xyz[1]*my_scale; - object->xyz[2] -= object->c_xyz[2]; + /* + object->xyz[0] -= object->c_xyz[0]*my_scale; + object->xyz[1] -= object->c_xyz[1]*my_scale; + object->xyz[2] -= object->c_xyz[2]; - object->xyz[0] += x+m->mx; - object->xyz[1] += y+m->my; + object->xyz[0] += x+m->mx; + object->xyz[1] += y+m->my; + */ + // object->xyz[2] += zorder * 0.01; float scale[] = {my_scale,my_scale,1}; //float c_xyz[] = {0,0,0}; //scale_matrix(object->matrix, scale, c_xyz); + CameraPtr camera = droot->sgroot->getCamera(); + + camera->xyz[0] = camera->xyz[1] = 0; + camera->xyz[2] = -100; + camera->xyz[3] = 0; + + printf( "obj_x: %f", object->xyz[0]); + printf( " obj_y:%f", object->xyz[1]); + printf( " obj_z:%f", object->xyz[2]); + printf( " obj_[3]:%f\n", object->xyz[3]); + + printf( "Camera_x: %f", camera->xyz[0]); + printf( " Camera_y:%f", camera->xyz[1]); + printf( " Camera_z:%f", camera->xyz[2]); + printf( " Camera_[3]:%f\n", camera->xyz[3]); + + + /*親の回転、座標から、子の回転、座標を算出*/ get_matrix_scale(object->matrix, object->angle, object->xyz, scale, root->matrix); /*法線用の行列。Cameraの行列を抜いている(Cameraのコンストラクタで、単位行列にしている)*/ - // get_matrix(object->real_matrix, object->angle, object->xyz, root->real_matrix); + get_matrix(object->real_matrix, object->angle, object->xyz, root->real_matrix); + + } - /*void gSprite_PutSpriteEx(int number, int x, int y, float w, float h) { @@ -193,26 +224,26 @@ //ここいらはどうやら、スプライトを取得する部分。 /* -static void -gSprite_Init_Png(const char *texname) -{ + static void + gSprite_Init_Png(const char *texname) + { if (!(sprite_tex = read_png_file(texname))) { - fprintf(stderr, - "cannot creat texture - init_png().\n"); - fflush(stderr); - exit(EXIT_FAILURE); + fprintf(stderr, + "cannot creat texture - init_png().\n"); + fflush(stderr); + exit(EXIT_FAILURE); } if (ps2util_tex_Set(sprite_tex) == -1) { - fprintf(stderr, - "cannot set texture - init_png().\n"); - fflush(stderr); - exit(EXIT_FAILURE); + fprintf(stderr, + "cannot set texture - init_png().\n"); + fflush(stderr); + exit(EXIT_FAILURE); } -} + } */ /* @@ -240,26 +271,32 @@ void gSprite_Init() { + droot->createFromXMLfile("xml_file/title.xml"); + + droot->createFromXMLfile("xml_file/kuruma2.xml"); + ps2util_graphic_Init(); //gSprite_Init_Png("img/main2.png"); //gSprite_Create(); // スプライト生成 - - gSprite_DefSprite(10, "title", 512, 666, 1); // タイトル - gSprite_DefSprite(17, "select", 33, 33, 1); // 選択マーク - gSprite_DefSprite(23, "sp_meter", 106, 34, 1); // スピードメーター - gSprite_DefSprite(24, "r_arrow", 18, 20, 1); // 右矢印 - gSprite_DefSprite(25, "l_arrow", 17, 20, 1); // 左矢印 - gSprite_DefSprite(26, "km", 55, 26, 1); // km/h - gSprite_DefSprite(27, "rap", 39, 26, 1); // Rap - gSprite_DefSprite(28, "1p", 53, 46, 1); // 1p - gSprite_DefSprite(29, "2p", 53, 46, 1); // 2P - gSprite_DefSprite(51, "select_car_1", 165, 140, 1); // 選択画面の車 - gSprite_DefSprite(52, "select_car_2", 165, 140, 1); - gSprite_DefSprite(53, "select_car_3", 165, 140, 1); - gSprite_DefSprite(81, "select_corse_1", 148, 114, 1); // 選択画面のコース + // testCoeler + int tc = 32; + + gSprite_DefSprite(10, "title", 512, 666, tc); // タイトル + gSprite_DefSprite(17, "select", 33, 33, tc); // 選択マーク + gSprite_DefSprite(23, "sp_meter", 106, 34, tc); // スピードメーター + gSprite_DefSprite(24, "r_arrow", 18, 20, tc); // 右矢印 + gSprite_DefSprite(25, "l_arrow", 17, 20, tc); // 左矢印 + gSprite_DefSprite(26, "km", 55, 26, tc); // km/h + gSprite_DefSprite(27, "rap", 39, 26, tc); // Rap + gSprite_DefSprite(28, "1p", 53, 46, tc); // 1p + gSprite_DefSprite(29, "2p", 53, 46, tc); // 2P + gSprite_DefSprite(51, "select_car_1", 165, 140, tc); // 選択画面の車 + gSprite_DefSprite(52, "select_car_2", 165, 140, tc); + gSprite_DefSprite(53, "select_car_3", 165, 140, tc); + gSprite_DefSprite(81, "select_corse_1", 148, 114, tc); // 選択画面のコース // 本当は (82, 272,...)です。二つ目のコース絵がないので - gSprite_DefSprite(82, "select_corse_2", 148, 114 ,1); + gSprite_DefSprite(82, "select_corse_2", 148, 114 ,tc); }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gSprite.cc~ Sun Jun 19 02:16:20 2011 +0900 @@ -0,0 +1,330 @@ +//SgoexCerium.ccより +#include "matrix_calc.h" +#include "TaskManager.h" +#include "SceneGraph.h" +#include "Application.h" +#include <iostream> + +#include <stdio.h> +#include <stdlib.h> +#include "libps2.h" +#include "ps2util.h" +#include "gSprite.h" +#include <stdbool.h> + +#define DEFOBJ 100 +#define SPRITE_COL 0x4f +#define SCREEN_HALF_W 320 +#define SCREEN_HALF_H 240 + +static SpriteTable sptable[DEFOBJ]; +static ps2utilSprite sp[DEFOBJ]; // 表示スプライト用スタック +static unsigned int sp_counter; +static bool flag_spriteInited = false; // スプライトロードフラグ + +//static TEXTURE *sprite_tex; + + +extern Viewer *droot; + +/*static*/ SceneGraphPtr root; + +static float my_scale = 5; + + +//SgoexCerium.ccより +void +flip() +{ + CameraPtr camera = droot->sgroot->getCamera(); + + droot->sgroot->flip(); + droot->sgroot->lightCalc(); + + root = droot->createSceneGraph(); + //root->xyz[0] = screen_w/2; + //root->xyz[1] = screen_h/2;; + root->xyz[0] = 0; + root->xyz[1] = 0; + root->xyz[2] = 30.0f; + + /*親の回転、座標から、子の回転、座標を算出*/ + get_matrix(root->matrix, root->angle, root->xyz, camera->matrix); + /*法線用の行列。Cameraの行列を抜いている(Cameraのコンストラクタで、単位行列にしている)*/ + get_matrix(root->real_matrix, root->angle, root->xyz, camera->real_matrix); + //出力して、次のものを出力するための準備 + droot->setSceneData(root); +} + + + + + +/*void +gSprite_DefSprite(int number, int tx, int ty, int tw, int th) +{ + sptable[number].tx = tx; + sptable[number].ty = ty; + sptable[number].tw = tw; + sptable[number].th = th; +}*/ + +void +gSprite_DefSprite(int number, const char *name, float w, float h, int color)//, OBJECT *obj) +{ + SpriteTable *m = &sptable[number]; + m->w = w; + m->h = h; + m->color = (color & 32); + m->mx = w / 2; //画像の中心を座標としたいらしい。 + m->my = h / 2; + m->tex_w = power_of_two(m->w); + m->tex_h = power_of_two(m->h); + m->texture = (int *)name; +} + +/*void + gSprite_PutSprite(int number, int x, int y) + { + ps2utilSprite *p = &sp[sp_counter]; + + ps2util_sprite_Set_basicAttribute( + p, + (unsigned short)x, (unsigned short)y, + (unsigned short)sptable[number].tw*2, (unsigned short)sptable[number].th*2, + (unsigned short)sptable[number].tx, (unsigned short)sptable[number].ty, + (unsigned short)sptable[number].tw, (unsigned short)sptable[number].th, + SPRITE_PRIO_FOREGROUND); + + ps2util_sprite_Request(p); + sp_counter++; + }*/ + + +//void gSprite_PutSprite(int number, short x, short y, int zorder) +void gSprite_PutSprite(int number, int x, int y) +{ + SpriteTable *m = &sptable[number]; + + char *name = (char *) m->texture; + if (!name) { + printf("PutSprite %d unknown\n",number); + return; + } + + SceneGraphPtr object = droot->createSceneGraph(name); + + // object->c_xyz[0] = m->mx; + // object->c_xyz[1] = m->my; + + object->xyz[0] = 100; + object->xyz[1] = 100; + object->xyz[2] = 100; + + root->addChild(object); + + /* + object->xyz[0] -= object->c_xyz[0]*my_scale; + object->xyz[1] -= object->c_xyz[1]*my_scale; + object->xyz[2] -= object->c_xyz[2]; + + object->xyz[0] += x+m->mx; + object->xyz[1] += y+m->my; + */ + + // object->xyz[2] += zorder * 0.01; + + float scale[] = {my_scale,my_scale,1}; + //float c_xyz[] = {0,0,0}; + //scale_matrix(object->matrix, scale, c_xyz); + + + CameraPtr camera = droot->sgroot->getCamera(); + + camera->xyz[0] = camera->xyz[1] = 0; + camera->xyz[2] = -100; + camera->xyz[3] = 0; + + printf( "obj_x: %f", object->xyz[0]); + printf( " obj_y:%f", object->xyz[1]); + printf( " obj_z:%f", object->xyz[2]); + printf( " obj_[3]:%f\n", object->xyz[3]); + + printf( "Camera_x: %f", camera->xyz[0]); + printf( " Camera_y:%f", camera->xyz[1]); + printf( " Camera_z:%f", camera->xyz[2]); + printf( " Camera_[3]:%f\n", camera->xyz[3]); + + + + /*親の回転、座標から、子の回転、座標を算出*/ + get_matrix_scale(object->matrix, object->angle, object->xyz, scale, root->matrix); + + /*法線用の行列。Cameraの行列を抜いている(Cameraのコンストラクタで、単位行列にしている)*/ + get_matrix(object->real_matrix, object->angle, object->xyz, root->real_matrix); + + +} + + +/*void + gSprite_PutSpriteEx(int number, int x, int y, float w, float h) + { + ps2utilSprite *p = &sp[sp_counter]; + + ps2util_sprite_Set_basicAttribute( + p, + (unsigned short)x, (unsigned short)y, + (unsigned short)sptable[number].tw*w, (unsigned short)sptable[number].th*h, + (unsigned short)sptable[number].tx, (unsigned short)sptable[number].ty, + (unsigned short)sptable[number].tw, (unsigned short)sptable[number].th, + SPRITE_PRIO_FOREGROUND); + + ps2util_sprite_Request(p); + sp_counter++; + } +*/ + +void +gSprite_PutSpriteEx(int number, int x, int y, float scalex, float scaley, float angle) +{ + if (1) { + gSprite_PutSprite(number, x, y); + return; + } + + SpriteTable *m = &sptable[number]; + char *name = (char *) m->texture; + if (!name) { + printf("PutSpriteEx %d unknown\n",number); + return; + } + SceneGraphPtr object = droot->createSceneGraph(name); + root->addChild(object); + + float scale[] = {my_scale*scalex*4,my_scale*scaley*4,1}; + + /*親の回転、座標から、子の回転、座標を算出*/ + object->xyz[0] = x - object->c_xyz[0] * my_scale - m->w*my_scale; + object->xyz[1] = y - object->c_xyz[1] * my_scale - m->h*my_scale; + object->xyz[2] = number * 0.01; + //object->c_xyz[0] = m->mx; + //object->c_xyz[1] = m->my; + object->angle[3] = angle * (3.1415926*2/4096); + get_matrix(object->matrix, object->angle, object->xyz, root->matrix); + float c_xyz[] = {0,0,0}; + scale_matrix(object->matrix, scale, c_xyz); + /*法線用の行列。Cameraの行列を抜いている(Cameraのコンストラクタで、単位行列にしている)*/ + // get_matrix(object->real_matrix, object->angle, object->xyz, root->real_matrix); +} + + + + + +//ここいらはどうやら、スプライトを取得する部分。 +/* + static void + gSprite_Init_Png(const char *texname) + { + if (!(sprite_tex = read_png_file(texname))) { + fprintf(stderr, + "cannot creat texture - init_png().\n"); + fflush(stderr); + exit(EXIT_FAILURE); + } + + + if (ps2util_tex_Set(sprite_tex) == -1) { + fprintf(stderr, + "cannot set texture - init_png().\n"); + fflush(stderr); + exit(EXIT_FAILURE); + } + + + } +*/ + + /* +static void +gSprite_Create() +{ + int i; + + for (i=0; i<DEFOBJ; i++) { + if (ps2util_sprite_Create(&sp[i], sprite_tex) == -1) { + fprintf(stderr, + "cannot create sprite No.%d - create_sprite()\n", i); + fflush(stderr); + exit(EXIT_FAILURE); + } + ps2util_sprite_Unuse_alpha(&sp[i]); + } + + flag_spriteInited = false; + +} +*/ + + +void +gSprite_Init() +{ + droot->createFromXMLfile("xml_file/title.xml"); + + droot->createFromXMLfile("xml_file/kuruma2.xml"); + + ps2util_graphic_Init(); + //gSprite_Init_Png("img/main2.png"); + //gSprite_Create(); // スプライト生成 + + // testCoeler + int tc = 32; + + gSprite_DefSprite(10, "car", 512, 666, tc); // タイトル + gSprite_DefSprite(17, "select", 33, 33, tc); // 選択マーク + gSprite_DefSprite(23, "sp_meter", 106, 34, tc); // スピードメーター + gSprite_DefSprite(24, "r_arrow", 18, 20, tc); // 右矢印 + gSprite_DefSprite(25, "l_arrow", 17, 20, tc); // 左矢印 + gSprite_DefSprite(26, "km", 55, 26, tc); // km/h + gSprite_DefSprite(27, "rap", 39, 26, tc); // Rap + gSprite_DefSprite(28, "1p", 53, 46, tc); // 1p + gSprite_DefSprite(29, "2p", 53, 46, tc); // 2P + gSprite_DefSprite(51, "select_car_1", 165, 140, tc); // 選択画面の車 + gSprite_DefSprite(52, "select_car_2", 165, 140, tc); + gSprite_DefSprite(53, "select_car_3", 165, 140, tc); + gSprite_DefSprite(81, "select_corse_1", 148, 114, tc); // 選択画面のコース + // 本当は (82, 272,...)です。二つ目のコース絵がないので + gSprite_DefSprite(82, "select_corse_2", 148, 114 ,tc); + +} + + +static void +gSprite_Clear() +{ + int i; + + for (i=0; i<DEFOBJ; i++) { + sprite_disappear(&sp[i].attribute); + } + sp_counter = 0; +} + + + +void +gSprite_Draw_Reset() +{ + if (flag_spriteInited == true) { + gSprite_Clear(); + } +} + + + +void +gSprite_PutSprite_Pause() +{ +}
--- a/gSprite.h Fri Jun 17 10:31:39 2011 +0900 +++ b/gSprite.h Sun Jun 19 02:16:20 2011 +0900 @@ -5,8 +5,8 @@ #define SPRITE_PRIO_FOREGROUND 1 typedef struct SpriteTable { - short dx; - short dy; + // short dx; + // short dy; short w; short h; short mx; @@ -16,7 +16,7 @@ int tex_w; int tex_h; int *texture; - int tex_id; // for open gl + int tex_id; // for open gl } SpriteTable; @@ -31,3 +31,5 @@ void gSprite_DefSprite(int number, const char *name, float w, float h, int color);//, OBJECT *obj); #endif + +void flip();
--- a/game.cc Fri Jun 17 10:31:39 2011 +0900 +++ b/game.cc Sun Jun 19 02:16:20 2011 +0900 @@ -12,12 +12,9 @@ #include "schedule.h" - extern bool padCheck(SDL_Joystick *joy); extern bool keybord(void); - - /* linda.c */ #ifdef LINDA //extern int linda_init(); @@ -33,8 +30,10 @@ //#ifdef LINDA game.play_id = linda_init(); //#endif - - while (1) { + + // ここのwhile文を外したらウィンドウがウマく描画された + // 何故でしょうか?:miyahira + // while (1) { /* 引数の数を変更したので、 エラーが出ないように一時的に削除 @@ -45,7 +44,7 @@ flg = keybord(); if (flg == false) { - break; + // break; } schedule(&game); @@ -53,7 +52,7 @@ #ifdef LINDA psx_sync_n(); #endif - } + // } } //ceriumのmainルーチンに直す。
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/game.cc~ Sun Jun 19 02:16:20 2011 +0900 @@ -0,0 +1,56 @@ +/* game.c */ + +#include <stdio.h> +#include <stdlib.h> +#include <stdbool.h> +#include "libps2.h" +#include "ps2util.h" +#include "controler.h" +//#include "linda/lindaapi.h" +#include "game.h" +#include "car.h" + +#include "schedule.h" + +extern bool padCheck(SDL_Joystick *joy); +extern bool keybord(void); + +/* linda.c */ +#ifdef LINDA +//extern int linda_init(); +#else +#define linda_init() 1 +#endif + + +void game_main() +{ + Game game; + bool flg = true; + //#ifdef LINDA + game.play_id = linda_init(); + //#endif + + while (1) { + /* + 引数の数を変更したので、 + エラーが出ないように一時的に削除 + たぶん、後で新しく新調するはずなので・・・ + 代わりに、お試しkeybordを入れてみる。 + */ + //flg = padCheck(); + flg = keybord(); + + if (flg == false) { + break; + } + + schedule(&game); + +#ifdef LINDA + psx_sync_n(); +#endif + } +} + +//ceriumのmainルーチンに直す。
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ps2util.cc~ Sun Jun 19 02:16:20 2011 +0900 @@ -0,0 +1,359 @@ +/* ps2util.c */ + +#include <string.h> +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include "libps2.h" +#include "ps2util.h" +#include "name_dictionary.h" + +/* + たぶん、本当は読み込んだ xml file から情報を取得するとかそんなんだと思う + どんな処理か分からないので、とりあえず、初期化している。 +*/ + +OBJECT *ps2util_obj_Create_fromXML(const char *filename) +{ + OBJECT *body; + + /* + body->xyz = {0,0,0,0}; + body->angle = {0,0,0,0}; + body->transfer = { {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0} }; + body->*name = filename; + body->*free_me = NULL; + */ + + return body; +} + + + +void ps2util_obj_Set_effect(OBJECT *body, int def) +{ + //none +} + +// ベクトル v1 をベクトル v2 にコピーする +void ps2_vu0_copy_vector(FVECTOR directionA, FVECTOR directionB) +{ + memcpy(directionA, directionB, sizeof(FVECTOR)); +} + + +void ps2util_obj_Renew_transMatrix(OBJECT *car){ + //none +} + + + +/* + ps2 内の texture.c から +*/ +/* +TEXTURE* read_png_file(const char *texname) +{ + printf("trace\n"); + //とりあえず戻り値を返してエラーをどうにか + TEXTURE* tex; + + return tex; +} +*/ + + +int ps2util_tex_Set(OBJECT* tex) +{ + return -1; +} + +int ps2util_sprite_Create(ps2utilSprite *Sp, OBJECT *sprite_tex) +{ + return -1; +} + + +void ps2util_obj_Set_texture(OBJECT* car_body, OBJECT *tex) +{ + //none +} + + +// 与えられた行列を単位行列に変換する +void ps2_vu0_unit_matrix(FMATRIX m) +{ + m[0][1] = m[0][2] = m[0][3] = 0; + m[1][0] = m[1][2] = m[1][3] = 0; + m[2][0] = m[2][1] = m[2][3] = 0; + m[3][0] = m[3][1] = m[3][2] = 0; + m[0][0] = m[1][1] = m[2][2] = m[3][3] = 1.0; +} + +/* +Y軸を中心とした行列の回転 +回転角 rx より X 軸を中心とした回転マトリックスを求めて、マトリックス m1 に左側から乗算して、その結果をマトリックス m0 に与える。 +X 軸だけでなく Y 軸、Z 軸を中心とした関数もある。また3ついっんに回転させる関数もある。 +*/ +void ps2_vu0_rot_matrix_y(FMATRIX result, FMATRIX m, float radian) +//void ps2_vu0_rot_matrix_y(float *result, float *mm, float radian) +{ + // 回転行列を作ってかけてやれば良い + + m[0][1] = m[0][2] = m[0][3] = 0; + m[1][0] = m[1][2] = m[1][3] = 0; + m[2][0] = m[2][1] = m[2][3] = 0; + m[3][0] = m[3][1] = m[3][2] = 0; + m[0][0] = m[1][1] = m[2][2] = m[3][3] = 1.0; + + + m[0][0] = sinf(radian); + m[2][2] = sinf(radian); + m[0][2] = -cosf(radian); + m[2][0] = cosf(radian); + + FMATRIX m1;// = m; + memcpy(&m1, m, sizeof(FMATRIX)); + + ps2_vu0_mul_matrix(result, m1, m); +} + +// ベクトルの計算 +// マトリックス m にベクトル を右から乗算して result に与える +void ps2_vu0_apply_matrix(FVECTOR result, FMATRIX m, FVECTOR v) +{ + result[0] = m[0][0] * v[0] + m[0][1] * v[1] + m[0][2] * v[2] + m[0][3] * v[3] ; + result[1] = m[1][0] * v[0] + m[1][1] * v[1] + m[1][2] * v[2] + m[1][3] * v[3] ; + result[2] = m[2][0] * v[0] + m[2][1] * v[1] + m[2][2] * v[2] + m[2][3] * v[3] ; + result[3] = m[3][0] * v[0] + m[3][1] * v[1] + m[3][2] * v[2] + m[3][3] * v[3] ; +} + + +void ps2_vu0_scale_vector(FVECTOR mov, FVECTOR car_direction, float car_speed) +{ + mov[0] = car_direction[0] * car_speed ; + mov[1] = car_direction[1] * car_speed ; + mov[2] = car_direction[2] * car_speed ; + mov[3] = car_direction[3]; +} + +// ベクトル v1 の各要素とベクトル v2 の各要素を各々加算してv0に与える +// v0 = v1+v2 +void ps2_vu0_add_vector(FVECTOR result, FVECTOR v0, FVECTOR v1) +{ + result[0] = v0[0] + v1[0]; + result[1] = v0[1] + v1[1]; + result[2] = v0[2] + v1[2]; + // result[3] = v0[3] + v1[3]; + result[3] = v0[3]; +} + +// 外積 +void ps2_vu0_outer_product(FVECTOR result, FVECTOR v0, FVECTOR v1) +{ + result[0] = v0[1] * v1[2] - v0[2] * v1[1] ; + result[1] = v0[0] * v1[2] - v0[2] * v1[0] ; + result[2] = v0[0] * v1[1] - v0[1] * v1[0] ; + result[3] = 1; +} + +// 内積 +float ps2_vu0_inner_product(FVECTOR v0, FVECTOR v1) +{ + return v0[0] * v1[0] + v0[1] * v1[1] + v0[2] * v1[2]; +} + + +void ps2_vu0_mul_matrix(FMATRIX result, FMATRIX m0, FMATRIX m1) +{ + result[0][0] = m0[0][0] * m1[0][0] + m0[0][1] * m1[1][0] + m0[0][2] * m1[2][0] + m0[0][3] * m1[3][0]; + result[0][1] = m0[0][0] * m1[0][1] + m0[0][1] * m1[1][1] + m0[0][2] * m1[2][1] + m0[0][3] * m1[3][1]; + result[0][2] = m0[0][0] * m1[0][2] + m0[0][1] * m1[1][2] + m0[0][2] * m1[2][2] + m0[0][3] * m1[3][2]; + result[0][3] = m0[0][0] * m1[0][3] + m0[0][1] * m1[1][3] + m0[0][2] * m1[2][3] + m0[0][3] * m1[3][3]; + + result[1][0] = m0[1][0] * m1[0][0] + m0[1][1] * m1[1][0] + m0[1][2] * m1[2][0] + m0[1][3] * m1[3][0]; + result[1][1] = m0[1][0] * m1[0][1] + m0[1][1] * m1[1][1] + m0[1][2] * m1[2][1] + m0[1][3] * m1[3][1]; + result[1][2] = m0[1][0] * m1[0][2] + m0[1][1] * m1[1][2] + m0[1][2] * m1[2][2] + m0[1][3] * m1[3][2]; + result[1][3] = m0[1][0] * m1[0][3] + m0[1][1] * m1[1][3] + m0[1][2] * m1[2][3] + m0[1][3] * m1[3][3]; + + result[2][0] = m0[2][0] * m1[0][0] + m0[2][1] * m1[1][0] + m0[2][2] * m1[2][0] + m0[2][3] * m1[3][0]; + result[2][1] = m0[2][0] * m1[0][1] + m0[2][1] * m1[1][1] + m0[2][2] * m1[2][1] + m0[2][3] * m1[3][1]; + result[2][2] = m0[2][0] * m1[0][2] + m0[2][1] * m1[1][2] + m0[2][2] * m1[2][2] + m0[2][3] * m1[3][2]; + result[2][3] = m0[2][0] * m1[0][3] + m0[2][1] * m1[1][3] + m0[2][2] * m1[2][3] + m0[2][3] * m1[3][3]; + + result[3][0] = m0[3][0] * m1[0][0] + m0[3][1] * m1[1][0] + m0[3][2] * m1[2][0] + m0[3][3] * m1[3][0]; + result[3][1] = m0[3][0] * m1[0][1] + m0[3][1] * m1[1][1] + m0[3][2] * m1[2][1] + m0[3][3] * m1[3][1]; + result[3][2] = m0[3][0] * m1[0][2] + m0[3][1] * m1[1][2] + m0[3][2] * m1[2][2] + m0[3][3] * m1[3][2]; + result[3][3] = m0[3][0] * m1[0][3] + m0[3][1] * m1[1][3] + m0[3][2] * m1[2][3] + m0[3][3] * m1[3][3]; +} + + + +void ps2_vu0_copy_matrix(FMATRIX transfer, FMATRIX pose) +{ + memcpy(transfer, pose, sizeof(FMATRIX)); +} + +void ps2util_obj_Free(OBJECT* obj) +{ + free(obj); +} + + + +void ps2_vu0_sub_vector(FVECTOR result, FVECTOR v0, FVECTOR v1) +{ + result[0] = v0[0] - v1[0]; + result[1] = v0[1] - v1[1]; + result[2] = v0[2] - v1[2]; + result[3] = v0[3];// - v1[3]; +} + + + +void ps2_vu0_normalize(FVECTOR result, FVECTOR v) +{ + // 大きさで割ってるだけって + float d = sqrtf(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]); + result[0] = v[0] / d; + result[1] = v[1] / d; + result[2] = v[2] / d; + result[3] = 1; +} + + +void xml_free(PolygonInfo xml) +{ + //none +} + +extern SceneGraphPtr root; + +//scenegra +void ps2util_obj_Draw(OBJECT *object) +{ + root->addChild(object); // 画像の数数えとく + //get_matrix( + //treeDandy のputSprite を持ってくればいいか? +} + + +void ps2util_sprite_Destroy(ps2utilSprite *title_sprite ) +{ + //none +} + + +//putSprite で置き換え? +void ps2util_sprite_Set_basicAttribute(ps2utilSprite *p, + unsigned short x, unsigned short y, + unsigned short sptable_tw1, unsigned short sptable_th1, + unsigned short sptable_tx, unsigned short sptable_ty, + unsigned short sptable_tw2, unsigned short sptable_th2, + int sprite_prio_foreground) +{ + //none +} + +void ps2util_sprite_Request(ps2utilSprite *p) +{ + //none +} + + +void ps2util_sprite_Unuse_alpha(ps2utilSprite *sp) +{ + //none +} + +void ps2util_graphic_Init() +{ + //none +} + + +/* + ps2 依存関係の sprite.c より引用。 +*/ +#define SPRITE_HAS_4VERTEXIS 4 + +#define PS2_GS_XYZ3 1 // なにかわからん定数だから適当に作りました + +void +sprite_disappear( SPRITE* sprite ) +{ + int i; + GsSpritePacket* packet = sprite->gs_packet; + for (i=0; i<SPRITE_HAS_4VERTEXIS; i++) + packet->primData[i].xyz_addr = PS2_GS_XYZ3; +} + + +/* + ps2 依存関係から持ってきた。 + テクスチャに割り振ったメモリの解放処理? + 元ファイル:texture.c +*/ +/* +void free_texture(TEXTURE *tex) +{ + if (tex == NULL) return; + + //delete_name_dictionary(tex->name); + free(tex->free_texenv); + free(tex->free_image); + free(tex); +} +*/ + + +/* + ps2 依存関係内の、texture.c から拝借 + この malloc によるメモリ取得をあちこちで行っているっぽい + cerium にある。 +*/ +int malloc_align16(void *free, void *aligned, int size) +{ + char *index; + unsigned int *f=(unsigned int *)free,*a=(unsigned int *)aligned; + + if (free == NULL || aligned == NULL || size <= 0) return(-1); + + index = (char *)malloc(size + ALIGN_16BYTE); + if (index == NULL) { + return(-1); + } + + *f = *a = (unsigned long int)index; + if (((unsigned long int)index % ALIGN_16BYTE) != 0) { + index += ALIGN_16BYTE - ((unsigned long int)index % ALIGN_16BYTE); + *a = (unsigned long int)index; + } + + return(0); +} + + +/* +void ps2util_tex_Exclude( TEXTURE* t ) +{ + //const char *test = "test"; +} +*/ + +void ps2util_sprite_Draw() +{ + printf("ps2util_sprite_Draw()\n"); +} + +void ps2util_graphic_Finish() +{ + printf("ps2util_graphic_Finish()\n"); +} + + +// title.cに書いてた +void ps2util_sprite_Use_alpha( ps2utilSprite *title ) +{ + printf("ps2util_sprite_Use_alpha()\n"); +}
--- a/schedule.cc Fri Jun 17 10:31:39 2011 +0900 +++ b/schedule.cc Sun Jun 19 02:16:20 2011 +0900 @@ -98,22 +98,22 @@ static void graphic_init() { + printf("graphic_init()\n"); + gSprite_Init(); // グラフィック関連の初期化 gFont_Init(); // フォント関連の初期化 + } static void play_init( Game *game ) { - printf("plya_init1()\n"); printf("game->car_id = %d\n",game->car_id); //printf("game->jiki->speed = %f\n",game->jiki->speed); game->jiki = car_init(game->car_id); - printf("plya_init2()\n"); carNode_append(game->jiki); - printf("plya_init3()\n"); field_init(game->course_id); } @@ -142,7 +142,7 @@ sche_game_init(Game *game) { printf("sche_game_init()\n"); - + game_env_init(game); graphic_init(); camera_init(); @@ -202,6 +202,12 @@ static int blink_count = 0; + // 試しブレンダーで作ったタイトルを表示してみたひ + flip(); + gSprite_PutSprite(10, 100, 100); + //flip(); + + //ここを現在通らないらしい。 if (game->play_id==1){ if (blink_count < 35) { @@ -215,10 +221,11 @@ } /*処理をいったんifの外へ。これを見る限り、キー入力自体はokぽい - printf("pad.st = %d\n",pad.st); - if (pad.st != 1) { goto OPENING; } + printf("pad.st = %d\n",pad.st); + if (pad.st != 1) { goto OPENING; } */ + set_schedule_assumption(sche_game_select_car); OPENING: @@ -336,7 +343,6 @@ { printf("sche_game_main_init()\n"); if (!game->jiki){ - printf("sche_game_main_init()__________\n"); play_init(game); } @@ -420,7 +426,6 @@ } //S-dandy の obj てきな - } @@ -543,4 +548,7 @@ ps2util_sprite_Draw(); gSprite_Draw_Reset(); gFont_Draw_Reset(); + + // ここにgSprite_Init()があるのって良いのかな? + // gSprite_Init(); }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/schedule.cc~ Sun Jun 19 02:16:20 2011 +0900 @@ -0,0 +1,555 @@ +/* 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 3 // 選択可能機体 +#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; + +// 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() +{ + printf("graphic_init()\n"); + + gSprite_Init(); // グラフィック関連の初期化 + gFont_Init(); // フォント関連の初期化 + +} + +static void +play_init( Game *game ) +{ + printf("game->car_id = %d\n",game->car_id); + //printf("game->jiki->speed = %f\n",game->jiki->speed); + 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) +{ + printf("sche_game_init()\n"); + + 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) +{ + printf("sche_game_opening\n"); + + static int blink_count = 0; + + // 試しブレンダーで作ったタイトルを表示してみたひ + flip(); + gSprite_PutSprite(10, 100, 100); + //flip(); + + + //ここを現在通らないらしい。 + 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 (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(SP_SEL_CAR+game->car_id, 190, 200, 1.5, 1.5, 0.0); + 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) +{ + printf("sche_game_select_course()\n"); + gSprite_PutSpriteEx(SP_SEL_COURSE+game->course_id, 190, 200, 1.7, 1.8, 0.0); + 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) +{ + printf("sche_game_ready()\n"); + 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 , 0.0); + gSprite_PutSpriteEx(SP_SEL_COURSE+game->course_id, 340, 120, 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; + + 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) +{ + printf("sche_game_main_init()\n"); + 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) +{ + /** 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); + camera_update(game, &(game->jiki->body->matrix) ); + + 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_DefSprite(23, "name", (float)(106.0*(game->jiki->speed/game->jiki->speed_max)), 34.0, 100); + 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, (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) +{ + 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(); +}
--- a/xml_file/title.xml Fri Jun 17 10:31:39 2011 +0900 +++ b/xml_file/title.xml Sun Jun 19 02:16:20 2011 +0900 @@ -1,6 +1,6 @@ <?xml version="1.0"?> <OBJECT-3D> - <surface name="Cube" size="6" prim="Triangle" parent="NULL"> + <surface name="title" size="6" prim="Triangle" parent="NULL"> <coordinate> -46.684662 35.716764 -0.818169 -64.928226 35.754207 -0.003736 @@ -3772,4 +3772,4 @@ 7QQ6QfvhM0znr7B/d8++gP8CDAC7jKWNiV7QiAAAAABJRU5ErkJggg== </image> </surface> -</OBJECT-3D> \ No newline at end of file +</OBJECT-3D>