Mercurial > hg > old > magoroku_racing.bad
changeset 113:8c96cadde050
after game_team
author | Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 09 Jun 2011 18:07:46 +0900 |
parents | 5106d8d12ded |
children | 3ffda5b493c2 31dd5c07f7c1 |
files | Magoroku.cc Makefile libps2.h ps2util.cc |
diffstat | 4 files changed, 470 insertions(+), 368 deletions(-) [+] |
line wrap: on
line diff
--- a/Magoroku.cc Thu Jun 09 14:59:24 2011 +0900 +++ b/Magoroku.cc Thu Jun 09 18:07:46 2011 +0900 @@ -1,53 +1,62 @@ +//magoroku 関係ココから #include "Magoroku.h" -#include "SgoexCerium.h" + #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" +//magoroku 関係ココまで + +#include "SgoexCerium.h" #include <ctype.h> #include <math.h> #include <time.h> #include <SDL.h> #include "SDL_opengl.h" -//#include "object.h" -#include "libps2.h" - -#include "tree_controll.h" +//#include "tree_controll.h" #include "xml.h" #include "profile.h" -#include "syokika.h" -#include "sankaku.h" - -//#include "sgoex.h" -#include "controler.h" +//#include "syokika.h" +//#include "sankaku.h" #include "sound.h" -#include <stdbool.h> -#include "bom.h" -#include "count2.h" -#include "tokuten.h" -#include "schedule.h" -#include "tama.h" -#include "debug.h" -#include "trace.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" - -static int use_keybord = 0; -// static int cdp[20] = { 16, 16, 16, 17, 18, 0 }; -static int i; +//#include "Character.h" +//#include "Character_state.h" -static int rswait = 0; -static int cf = 0; -static int cc = 0; -static int test_mode = 0; -static const char *test_object = "" ; //static SDL_Surface *screen; // static Uint32 background; @@ -55,8 +64,8 @@ extern void schedule(); extern void tokuten(); -extern void padCheck(); -extern void keybord(); +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; @@ -102,14 +111,41 @@ } -static int opening(int gamef); -static int dandy_closing(int gamef); -static int dandy_main_loop(int gamef); -static int dandy_main_init(int gamef); +//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 ); + + +//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); + //class Application の中の virtual bool app_loop( return 1 だけの関数?) を継承 bool Magoroku::app_loop(Viewer *viewer){ @@ -117,8 +153,11 @@ return 0; }; -//ゲームの分岐に使用 -static int gamef = 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 の処理と同等と考えてオッケーかな? @@ -126,13 +165,7 @@ HTaskPtr Magoroku::application_task(HTaskPtr next, Viewer* viewer){ // printf("gamef = %d\n",gamef); - switch (gamef) { - case 0: gamef= dandy_main_init(gamef); break; - case 1: gamef= gamesyokika(gamef); break; - case 2: gamef= opening(gamef); break; - case 3: gamef= dandy_main_loop(gamef); break; - case 4: gamef= dandy_closing(gamef); break; - } + schedule(&game); return next; }; @@ -192,334 +225,397 @@ */ -/* - 初期化の処理 - 初期化成功で return 1 だから、次の処理にいくっぽい -*/ -static int -dandy_main_init(int gamef) -{ - //Timeprof timeprof_move; - //timeprof_move = timeprof_new(); - dbg_init("/dev/stdout"); - - /** - * timeprof があるんだけどね - */ - //xml file 読み込む - droot->createFromXMLfile("xml/character.xml"); - droot->createFromXMLfile("xml/font.xml"); - droot->createFromXMLfile("xml/effect.xml"); - droot->createFromXMLfile("xml/boss.xml"); - - LightSysSwitch(droot); - - - init_sprite(0,0,0,0); - - __debug("syokikaが呼びだされました\n"); - joy=SDL_JoystickOpen(0); - if(!joy) { - fprintf(stderr,"failed to open joystick 0\n"); - use_keybord = 1; - } - - /** - * sound.c に移しました - * 代わりに InitSdlMixer(void); を使います。 - * まあ中身一緒なんだけどね - */ - /** - if (Mix_OpenAudio(MIX_DEFAULT_FREQUENCY,MIX_DEFAULT_FORMAT,2,1024) < 0) { - fprintf(stderr,"failed to initialize SDL_mixer.\n"); - SDL_Quit(); - exit(-1); - } - */ - - // SDL_mixer とかいろいろ初期化 - // もし Init に失敗したら - // 以後の Mixer 関連の関数を呼び出しても - // 中では何も行われないとかいう小細工を入れました。 - InitSdlMixer(); - - // 音楽ファイルの読み込み - LoadSdlMixer(); - - // ボリューム調整 - InitVolume(); - - // 音出しテスト - PlaySdlMixer(-1, BGM); - - if(!(init_chara_list(1024))){ - __debug("failed to init_chara_list\n"); - } - - __debug("finished init_chara_list\n"); - - return 1; -} - - -//メインループ -static int -dandy_main_loop(int gamef) -{ - - - if ((pad.l1 != 0) && (pad.r1 != 0) && - (pad.l2 != 0) && (pad.r2 != 0)) { - gamef = gamesyokika(gamef); - } - - if (pad.se != 0) { - gamef = 4; - } - flip(); - - //SDL_FillRect(screen, NULL, background); - - schedule(); - enemyfaste = count; - - // timeprof_begin(timeprof_move); - //Move(); //enemy move - collision_detect(); - outofwindow(); - // timeprof_end(timeprof_move); - state_update(); - asteroidi = 0; - //charpatern(); - //bosguage(); - - if (jiki.bf == true) { - Player(0); - count++; - PutSprite(count, jiki.x, jiki.y, jiki.ch); - } - - Putbom(); - tokuten(); - - count++; - //PutSprite(count, 0, 960 - 96, 10); - /*インフレゲージ */ - count++; - //PutSprite(count, 0, 0, 48); - - obj_draw(); - gamef = game_pause(gamef); - - if (use_keybord) { - keybord(); - } else { - padCheck(joy); - } - filpcount++; - count = 0; - - return gamef; -} - -static int -dandy_closing(int gamef) -{ - - //_______________________________________________ - // SDL_mixerの後始末 - Mix_CloseAudio(); - Mix_HaltMusic(); - FreeSdlMixer() ; - //_______________________________________________ - return 0; -} -static int -gamesyokika(int gamef) +static void +set_schedule(Game *game) { - laser_lv3[0].r = 62; - laser_lv3[0].r = 62; - for (i = 0; i < 3; i++) { - tlv3[i].y = -1; - } - filpcount = 0; - stage = 0; - //for (i = 0; i < 300; i++) - //enemy[i].f = false; - jiki.zanki = 3; - jiki.x = 60; - jiki.y = 200; - jiki.ch = 3; - jiki.point = 0; - jiki.bf = false; - jiki.muteki = 120; - enemycount = 0; - lg.stg = 4096; - pg.stg = 4096; - infg.stg = 0; - infg_level = 0; - //kyeenemyno = -1; - fastebos = 0; - jiki.ccount = 99; - p_extend = 200000; - pad.up=0; - pad.down=0; - pad.right=0; - pad.left=0; - pad.st=0; - pad.se=0; - - SoundStop(); - SoundPlay(7); - gamef = 2; - flip(); - return gamef; + sche_func = sche_func_assumption; + change_state = 0; } -static int -opening(int gamef) +static void +graphic_init() { - if(use_keybord == 1) { - keybord(); - } else { - padCheck(joy); - } - - count = 1; - - PutSprite(count, 700, 480, 53); // put `push start' string on screen. - count++; - PutSprite(count, 224, 776, 119); // put `super dandy' - count++; - // PutSprite(count, 200, 64, 190); - // PutSpriteEx(count, 8192, 8192, 0); - PutSpriteEx(190, 800, 264, 2, 2, 5); - count++; - PutSprite(count, 396, 432, 191); - //PutSpriteEx(count, 8192, 8192, 0); - count++; - PutSprite(count, 640, 640, 192); - //PutSpriteEx(count, 8192, 8192, 0); - - if (pad.st > 1) { - jiki.bf = true; - - //CdPlay(1,&cdp[0],0); - SoundStop(); - SoundPlay(0); - - gamef = 3; - pad.st = 1; - } else if ((pad.se > 0) && (pad.st > 0)) { - gamef = 2; - } - flip(); - return gamef; + gSprite_Init(); // グラフィック関連の初期化 + gFont_Init(); // フォント関連の初期化 } -static int -game_pause(int gamef) +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 ) { - gamef = 3; - if (jiki.zanki != 0 && jiki.bf != false) { - if (pad.se == 1) { - //Mix_Pause(BGM); - PauseSdlMixer(BGM); - while(1){ - if(use_keybord == 1) { - keybord(); - } else { - padCheck(joy); - } - if(pad.st == 0) - continue; - pad.up=0; - pad.down=0; - pad.right=0; - pad.left=0; - pad.se=0; - pad.st=0; - //Mix_Resume(BGM); - ResumeSdlMixer(BGM); - break; - } - } - } - if (jiki.zanki == 0) { - // RECT *recp; - if ((jiki.ccount > 0) && (cf == 0)) { - cf = 1; - count++; - //cgcg(2); - PutSprite(count, 480, 480, 110); - count++; - //cgcg(1); - } - if ((jiki.ccount > 0) && (cf == 1)) { - //スタートを押すまでココで止まり続けるから、これは最初のスタート画面か? - while (1) { - if (pad.st > 0) { - cf = 0; - jiki.ccount--; - jiki.zanki = 3; - enemycount++; - cc = 0; - for (i = 0; i < 4; i++) { - clear_result[i] = 0; - } - goto f; - } - cc++; - if (29 - cc / 60 < 20) { - cc = 0; - cf = 3; - break; - } - SDL_Delay(100); - PutSprite(1, 640, 640, 29 - CC / 60); - // PutSpriteEx(1, 409 * ((cc % 60) + 1), 409 * ((cc % 60) + 1), 0); - - padCheck(joy); - flip(); // THIS IS NOT CORRECT - } - } - IF (rswait > 60 * 6) { - cf = 0; - rswait = 0; - gamef = gamesyokika(gamef); - } - rswait++; - count++; - //cgcg(1); - PutSprite(1, 480, 480, 19); - return gamef; - } - if (jiki.bf == false) { - f: - if (rswait < 80) { - rswait++; - return gamef; - } else { - rswait = 0; - jiki.x = 60; - jiki.y = 200; - jiki.bf = true; + printf("linda_env_init\n"); +} - pad.st = 0; - lg.stg = 4096; - pg.stg = 4096; - laser_lv3[0].r = 62; - tlv3[0].r = 0; - tlv3[0].y = -1; - return gamef; - // sb_size = -1; - } - } - return gamef; +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(); } -/* end */ +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); + } + +}
--- a/Makefile Thu Jun 09 14:59:24 2011 +0900 +++ b/Makefile Thu Jun 09 18:07:46 2011 +0900 @@ -21,7 +21,7 @@ demo: $(OBJS) $(CC) $(ABI) -o $@ $(OBJS) $(LIBS) -dandy: $(OBJS) Dandy.o SgoexCerium.o +magoroku: $(OBJS) Dandy.o SgoexCerium.o $(CC) $(ABI) -o $@ $(OBJS) Dandy.o SgoexCerium.o $(LIBS) test1: $(OBJS) Test.o SgoexCerium.o
--- a/libps2.h Thu Jun 09 14:59:24 2011 +0900 +++ b/libps2.h Thu Jun 09 18:07:46 2011 +0900 @@ -9,7 +9,7 @@ //object.h よりコピー - +/* typedef struct texture { int width; // texture's width size int height; // texture's height size @@ -21,7 +21,7 @@ } TEXTURE; -//また object.h よりコピー +//また object.h よりコピー cerium 側にあわせる typedef struct surface { int size; char *surf_name; // object's surface name @@ -35,14 +35,18 @@ //またまた object.h よりコピー +//本当はSceneGraphで代用? typedef struct object { FVECTOR xyz; // position FVECTOR angle; // angle FMATRIX transfer; // transfer matrix char *name; // object's name char *free_me; // pointer for free myself - SURFACE *surfaces; + SURFACE *surfaces; //ポリゴン? } OBJECT; +*/ + +typedef SceneGraph OBJECT; // sprite.hから typedef struct {
--- a/ps2util.cc Thu Jun 09 14:59:24 2011 +0900 +++ b/ps2util.cc Thu Jun 09 18:07:46 2011 +0900 @@ -222,10 +222,12 @@ //none } - +//scenegra void ps2util_obj_Draw(OBJECT *object) { - //none + root->addChild(object); + //get_matrix( + //treeDandy のputSprite を持ってくればいいか? } @@ -236,7 +238,7 @@ - +//putSprite で置き換え? void ps2util_sprite_Set_basicAttribute(ps2utilSprite *p, unsigned short x, unsigned short y, unsigned short sptable_tw1, unsigned short sptable_th1,