Mercurial > hg > old > magoroku_racing
changeset 106:0c4b7d74e292
add Magoroku.cc & .h (Dandy.cc & .h)
author | Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 08 Jun 2011 13:16:25 +0900 |
parents | ef64f1182dc8 |
children | 5d231c9754d1 |
files | Magoroku.cc Magoroku.h Makefile Makefile.def Makefile2 schedule.h test_vector |
diffstat | 7 files changed, 671 insertions(+), 69 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Magoroku.cc Wed Jun 08 13:16:25 2011 +0900 @@ -0,0 +1,509 @@ +#include "Magoroku.h" +#include "SgoexCerium.h" +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <ctype.h> +#include <math.h> +#include <time.h> +#include <SDL.h> +#include "SDL_opengl.h" +#include "object.h" +#include "tree_controll.h" +#include "xml.h" +#include "profile.h" +#include "syokika.h" +#include "sankaku.h" +#include "sgoex.h" +#include "sound.h" +#include "bool.h" +#include "bom.h" +#include "count2.h" +#include "tokuten.h" +#include "schedule.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; + +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; +// static char *pad_trace_file; + +extern void schedule(); +extern void tokuten(); +extern void Pad(); +extern void keybord(); +static int gamesyokika(int gamef); +static int game_pause(int); +//static char *pad_trace_file; + +/** + * 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(); +} + + +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); +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; +}; + +//ゲームの分岐に使用 +static int gamef = 0; + +//ゲームの分岐っぽそう。magoroku の schedule の処理と同等と考えてオッケーかな? +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; + } + return next; +}; + + + + +static void +task_init() +{ +} + +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]; + } + } + } + + task_init(); + task_initialize(); + manager->set_TMend(TMend); + + return init(manager,argc, argv); +} + +void +TMend(TaskManager *manager) +{ + printf("game end\n"); +} + +static int light_sysswitch = 0; +static int light_num = 4; + +static void +LightSysSwitch(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(); + } +} + + +static int +dandy_main_init(int gamef) +{ + //Timeprof timeprof_move; + //timeprof_move = timeprof_new(); + dbg_init("/dev/stdout"); + + /** + * timeprof があるんだけどね + */ + + 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[0].l1 != 0) && (pad[0].r1 != 0) && + (pad[0].l2 != 0) && (pad[0].r2 != 0)) { + gamef = gamesyokika(gamef); + } + + if (pad[0].quit != 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 { + Pad(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) +{ + 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[0].up=0; + pad[0].down=0; + pad[0].right=0; + pad[0].left=0; + pad[0].st=0; + pad[0].se=0; + + SoundStop(); + SoundPlay(7); + gamef = 2; + flip(); + return gamef; +} + +static int +opening(int gamef) +{ + if(use_keybord == 1) { + keybord(); + } else { + Pad(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[0].st > 1) { + jiki.bf = TRUE; + + //CdPlay(1,&cdp[0],0); + SoundStop(); + SoundPlay(0); + + gamef = 3; + pad[0].st = 1; + } else if ((pad[0].se > 0) && (pad[0].st > 0)) { + gamef = 2; + } + flip(); + return gamef; +} + +static int +game_pause(int gamef) +{ + gamef = 3; + if (jiki.zanki != 0 && jiki.bf != FALSE) { + if (pad[0].se == 1) { + //Mix_Pause(BGM); + PauseSdlMixer(BGM); + while(1){ + if(use_keybord == 1) { + keybord(); + } else { + Pad(joy); + } + if(pad[0].st == 0) + continue; + pad[0].up=0; + pad[0].down=0; + pad[0].right=0; + pad[0].left=0; + pad[0].se=0; + pad[0].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[0].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); + + Pad(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; + + pad[0].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; +} + + + +/* end */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Magoroku.h Wed Jun 08 13:16:25 2011 +0900 @@ -0,0 +1,21 @@ +#ifndef INCLUDE_MAGOROKU_H +#define INCLUDE_MAGOROKU_H + +#include "TaskManager.h" +#include "SceneGraph.h" +#include "Application.h" +#include "MainLoop.h" +#include "Func.h" + +class Magoroku : public Application { + bool app_loop(Viewer *viewer); + HTaskPtr application_task(HTaskPtr next, Viewer* viewer); + MainLoopPtr init(Viewer *viewer, int w, int h); +}; + +extern Viewer *droot; + +typedef void (*move)(SceneGraphPtr node, void *sgroot_, int w, int h); +typedef void (*coll)(SceneGraphPtr node, void *sgroot_, int w, int h, SceneGraphPtr tree); + +#endif
--- a/Makefile Thu Jun 02 23:37:51 2011 +0900 +++ b/Makefile Wed Jun 08 13:16:25 2011 +0900 @@ -1,79 +1,39 @@ -TARGET = main -CC = g++ -SRCS = main.cc game.cc car.cc col.cc quotanion.cc controler.cc field.cc camera.cc gSprite.cc schedule.cc mytype.cc gFont.cc carNode.cc light.cc title_scene.cc game_time.cc ps2util.cc sjoy.cc name_dictionary.cc -#linda/lindaapi.cc linda.c -OBJS = ${SRCS:.cc=.o} -VU1DIR = vu1code +# Makefile to build the SDL tests +include ./Makefile.def -#MPGOBJ = mpg.elf - -VPUSRCS = ${VU1DIR}/Makefile ${VU1DIR}/MPG.dsm ${VU1DIR}/basic.vsm ${VU1DIR}/vpu.cmd ${VU1DIR}/vumacros.h -VU1OBJ = ${VU1DIR}/mpg.elf +srcdir = . +ABI = -m$(ABIBIT) -INCLUDES = \ -#-I/usr/local/include/libps2a \ -#-I/usr/local/include/ps2util \ -#-I./Linda +SRCS = main.cc game.cc car.cc col.cc quotanion.cc controler.cc field.cc camera.cc gSprite.cc schedule.cc mytype.cc gFont.cc carNode.cc light.cc title_scene.cc game_time.cc ps2util.cc sjoy.cc name_dictionary.cc Magoroku.cc -#DEFINES = -DDEBUG -DLINDA -DEBUGFLAGS = -Wall -g -#LIBPS2ARC = /usr/local/lib/libps2a.a - -CFLAGS = ${INCLUDES} ${DEFINES} ${DEBUGFLAGS} - -#LIBS = `xml-config --libs` -lps2util -lpng -lps2a - -TEST = test_vector +CFLAGS += -DINVISIBLE_MODE -g $(ABI) -Wall `sdl-config --cflags` `xml2-config --cflags` $(INCLUDE) +LIBS += `sdl-config --libs`,-framework,OpenGL -lSDL_mixer -lSDL_image `xml2-config --libs` +LIBS += -lCerium -lFifoManager -all : ${TARGET} ${TEST} +TARGET = demo #dandy test1 +OBJS = ${SRCS:.cc=.o} -${VU1OBJ}: ${VPUSRCS} - cd ${VU1DIR}; make - cp ${VU1OBJ} . +all: $(TARGET) -#${TARGET} : ${OBJS} ${VU1OBJ} -# ${CC} -o ${TARGET} ${OBJS} ${LIBS} - -#${AR} x ${LIBPS2ARC} ${MPGOBJ} +test: $(TARGET) + ./demo -test -#${TARGET} : ${OBJS} -# ${CC} -po ${TARGET} ${OBJS} ${LIBS} -${TARGET} : ${OBJS} - ${CC} -o ${TARGET} ${OBJS} +demo: $(OBJS) + $(CC) $(ABI) -o $@ $(OBJS) $(LIBS) -${TEST} : test_vector.cc ps2util.cc - ${CC} -o ${TEST} $^ +dandy: $(OBJS) Dandy.o SgoexCerium.o + $(CC) $(ABI) -o $@ $(OBJS) Dandy.o SgoexCerium.o $(LIBS) -tag: - etags *.[ch] +test1: $(OBJS) Test.o SgoexCerium.o + $(CC) $(ABI) -o $@ $(OBJS) Test.o SgoexCerium.o $(LIBS) -clean : - rm -f ${OBJS} - rm -f ${TARGET} - rm -f ${MPGOBJ} - rm -f ${VU1OBJ} - rm -f *~ - cd ${VU1DIR}; make clean -depend: - makedepend -- ${CFLAGS} -- ${SRCS} ${MAINSRC} -# DO NOT DELETE +clean: + rm -f $(TARGET) $(OBJS) #main.o sgoex.o Dandy.o SgoexCerium.o Test.o -main.o: -game.o: #/Users/e095729/magoroku_racing/Linda/lindaapi.h -car.o: -col.o: -quotanion.o: -field.o: -camera.o: -gaSprite.o: -schedule.o: -demo.o: -mytype.o: -gFont.o: -carNode.o: -#linda.o: #/Users/e095729/magoroku_racing/Linda/lindaapi.h -light.o: -title_scene.o: -game_time.o: -sjoy.o: -name_dictionary.o: \ No newline at end of file +.c.o: + $(CC) $(CFLAGS) $(INCLUDES) -c $< + +.cc.o: + $(CC) $(CFLAGS) $(INCLUDES) -c $< + +debug.o:debug.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Makefile.def Wed Jun 08 13:16:25 2011 +0900 @@ -0,0 +1,20 @@ +# include/library path +# ex macosx + +#ex linux/ps3 +CERIUM = ../Cerium + +# OPT = -g + +ABIBIT = 64 + +INCLUDE = -I. -I.. -I${CERIUM}/include/TaskManager -I$(CERIUM)/Renderer/Engine -I$(CERIUM)/include/Cerium +LIBS = -L${CERIUM}/TaskManager -L$(CERIUM)/Renderer/Engine +TOOL = $(CERIUM)/bin + + +LIBS += `sdl-config --libs`, -framework, OpenGL -lSDL_mixer -lSDL_image `xml2-config --libs` +LIBS += -lCerium -lFifoManager + + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Makefile2 Wed Jun 08 13:16:25 2011 +0900 @@ -0,0 +1,89 @@ +# Makefile to build the SDL tests +# include ./Makefile.def + + +TARGET = main +CC = g++ +SRCS = main.cc game.cc car.cc col.cc quotanion.cc controler.cc field.cc camera.cc gSprite.cc schedule.cc mytype.cc gFont.cc carNode.cc light.cc title_scene.cc game_time.cc ps2util.cc sjoy.cc name_dictionary.cc Magoroku.cc +#linda/lindaapi.cc linda.c +OBJS = ${SRCS:.cc=.o} +VU1DIR = vu1code + +#MPGOBJ = mpg.elf +CERIUM = ../Cerium + +VPUSRCS = ${VU1DIR}/Makefile ${VU1DIR}/MPG.dsm ${VU1DIR}/basic.vsm ${VU1DIR}/vpu.cmd ${VU1DIR}/vumacros.h +VU1OBJ = ${VU1DIR}/mpg.elf + +#Dandy の Makefile をもとに追加 +INCLUDES = \ +-I. -I.. -I${CERIUM}/include/TaskManager -I$(CERIUM)/Renderer/Engine -I$(CERIUM)/include/Cerium + + +#DEFINES = -DDEBUG -DLINDA +DEBUGFLAGS = -Wall -g +#LIBPS2ARC = /usr/local/lib/libps2a.a + +CFLAGS = ${INCLUDES} ${DEFINES} ${DEBUGFLAGS} + +#LIBS = `xml-config --libs` -lps2util -lpng -lps2a +#Dandy の Makefile をもとに追加 +LIBS = -L${CERIUM}/TaskManager -L$(CERIUM)/Renderer/Engine +LIBS += `sdl-config --libs`, -framework,OpenGL -lSDL_mixer -lSDL_image `xml2-config --libs` +LIBS += -lCerium -lFifoManager + +TEST = test_vector + +all : ${TARGET} ${TEST} + +${VU1OBJ}: ${VPUSRCS} + cd ${VU1DIR}; make + cp ${VU1OBJ} . + +#${TARGET} : ${OBJS} ${VU1OBJ} +# ${CC} -o ${TARGET} ${OBJS} ${LIBS} + +#${AR} x ${LIBPS2ARC} ${MPGOBJ} + +#${TARGET} : ${OBJS} +# ${CC} -po ${TARGET} ${OBJS} ${LIBS} +${TARGET} : ${OBJS} + ${CC} -o ${TARGET} ${OBJS} ${LIBS} + +${TEST} : test_vector.cc ps2util.cc + ${CC} -o ${TEST} $^ + +tag: + etags *.[ch] + +clean : + rm -f ${OBJS} + rm -f ${TARGET} + rm -f ${MPGOBJ} + rm -f ${VU1OBJ} + rm -f *~ + cd ${VU1DIR}; make clean +depend: + makedepend -- ${CFLAGS} -- ${SRCS} ${MAINSRC} +# DO NOT DELETE + +main.o: +game.o: #/Users/e095729/magoroku_racing/Linda/lindaapi.h +car.o: +col.o: +quotanion.o: +field.o: +camera.o: +gaSprite.o: +schedule.o: +demo.o: +mytype.o: +gFont.o: +carNode.o: +#linda.o: #/Users/e095729/magoroku_racing/Linda/lindaapi.h +light.o: +title_scene.o: +game_time.o: +sjoy.o: +name_dictionary.o: +Magoroku.o: \ No newline at end of file