class Tiles2d { public: virtual int SizeX() const=0; virtual int SizeY() const=0; virtual int Tile(int x, int y) const=0; virtual int Tile2(int x, int y) const=0; virtual int Tile3(int x, int y) const=0; virtual Point2d Tile2Delta(int x, int y) const { Point2d p; p.x = 0.0; p.y=0.0; return p; } virtual int get_current_move1(int x, int y) const=0; virtual void set_current_move1(int x, int y, int val)=0; virtual int get_current_move2(int x, int y) const=0; virtual void set_current_move2(int x, int y, int val)=0; virtual float get_previous_time(int x, int y) const=0; virtual void set_previous_time(int x, int y, float val)=0; virtual float get_previous_time2(int x, int y) const=0; virtual void set_previous_time2(int x, int y, float val)=0; }; class Tiles3d { virtual int SizeX() const=0; virtual int SizeY() const=0; virtual int SizeZ() const=0; virtual int Tile(int x, int y, int z) const=0; }; class TileScroller { public: virtual Point get_pos() const=0; virtual void handle_event(MainLoopEvent &e)=0; virtual void execute(MainLoopEnv &e)=0; virtual void reset()=0; }; class TileRenderer2d { public: virtual MainLoopItem *get_renderer(TileScroller *scr) const=0; virtual void set_tiles_2d(Tiles2d *t, std::vector*> bm, std::vector vec)=0; }; class TileRenderer3d { public: virtual MainLoopItem *get_renderer() const=0; virtual void set_tiles_3d(Tiles3d *t) const=0; }; class TileHudInterface { public: virtual int get_score() const=0; virtual void set_score(int score)=0; virtual int get_health() const=0; virtual void set_health(int health)=0; virtual int get_lives() const=0; virtual void set_lives(int lives)=0; virtual void set_state(int state)=0; }; class TileSplashScreenInterface { public: virtual bool enabled() const=0; virtual void reset()=0; }; class TileSplashScreenCallback { public: virtual void reset()=0; }; class TileActivation { public: virtual void ActivateTile(int x, int y, int z)=0; virtual void DeactivateTile(int x, int y, int z)=0; }; class TileBehaviorMap { public: virtual void SetTiles2d(Tiles2d *t)=0; virtual void SetTiles3d(Tiles3d *t)=0; virtual int NumBehaviours() const=0; virtual int Tile(int behavior_num) const=0; virtual bool Condition(int behavior_num, int x, int y, int z) const=0; virtual void SubmitActivations(int behavior_num, int x, int y, int z, TileActivation *target) const=0; virtual int TargetTile(int behavior_num) const=0; }; class TilePlayer { public: virtual void SetTiles2d(Tiles2d *t)=0; virtual void SetTiles3d(Tiles3d *t)=0; virtual void handle_event(MainLoopEvent &e)=0; virtual int player_pos_x() const=0; virtual int player_pos_y() const=0; virtual int player_pos_z() const=0; virtual Point delta_pos() const=0; virtual int player_tile() const=0; virtual int player_type() const=0; virtual bool weapon_active() const=0; virtual int player_dir() const=0; virtual bool in_jump() const=0; virtual void kill_player()=0; }; class TileEnemies { public: virtual void SetTiles2d(Tiles2d *t)=0; virtual void SetTiles3d(Tiles3d *t)=0; virtual int NumEnemies() const=0; virtual int enemy_pos_x(int e) const=0; virtual int enemy_pos_y(int e) const=0; virtual int enemy_pos_z(int e) const=0; virtual int enemy_tile(int e) const=0; virtual int enemy_type(int e) const=0; virtual int enemy_behavior_num(int e) const=0; }; //-------------------------- class FlipTileBitmap : public Bitmap { public: FlipTileBitmap(GameApi::Env &env, GameApi::BitmapApi *api, GameApi::BM bm, int sx, int sy, bool is_x) :e(env), api(api),bm(bm), sx(sx), sy(sy),is_x(is_x) { firsttime=true; res.id=-1; } virtual void Collect(CollectVisitor &vis) { BitmapHandle *handle = find_bitmap(e, bm); ::Bitmap *b2 = find_color_bitmap(handle); b2->Collect(vis); vis.register_obj(this); } void HeavyPrepare() { Prepare(); } virtual int SizeX() const { if (res.id==-1) return 0; BitmapHandle *handle = find_bitmap(e, res); ::Bitmap *b2 = find_color_bitmap(handle); return b2->SizeX(); } virtual int SizeY() const { if (res.id==-1) return 0; BitmapHandle *handle = find_bitmap(e, res); ::Bitmap *b2 = find_color_bitmap(handle); return b2->SizeY(); } virtual Color Map(int x, int y) const { if (res.id==-1) return Color(0x000000); BitmapHandle *handle = find_bitmap(e, res); ::Bitmap *b2 = find_color_bitmap(handle); return b2->Map(x,y); } virtual void Prepare() { if (firsttime) { firsttime=false; int ssx = api->size_x(bm); int ssy = api->size_y(bm); res = api->newbitmap(ssx,ssy,0x00000000); for(int j=0;jsubbitmap(bm,i*sx,j*sy,sx,sy); GameApi::BM flipped; if (is_x) { flipped = api->flip_x(part); } else { flipped = api->flip_y(part); } res = api->blitbitmap(res,flipped,i*sx,j*sy); } } } } private: GameApi::Env &e; GameApi::BitmapApi *api; GameApi::BM bm; int sx; int sy; bool is_x; GameApi::BM res; bool firsttime; }; GameApi::BM GameApi::BitmapApi::flip_tile_bitmap(BM bm, int sx, int sy, bool is_x) { Bitmap *b = new FlipTileBitmap(e,this,bm,sx,sy,is_x); BitmapColorHandle *handle2 = new BitmapColorHandle; handle2->bm = b; BM bm2 = add_bitmap(e, handle2); return bm2; } class TileRendererMainLoop : public MainLoopItem { public: TileRendererMainLoop(GameApi::Env &env, GameApi::EveryApi &ev, Tiles2d *t, std::vector *> bm, std::vector num_tiles_in_bm, int tile_sx, int tile_sy, int player_tile_sx, int player_tile_sy, TileScroller *scr) : env(env), ev(ev), t(t), bm(bm), num_tiles_in_bm(num_tiles_in_bm), tile_sx(tile_sx), tile_sy(tile_sy), player_tile_sx(player_tile_sx), player_tile_sy(player_tile_sy), scr(scr) { } virtual void Collect(CollectVisitor &vis) { vis.register_obj(this); } virtual void HeavyPrepare() { if (tile_sx==0||tile_sy==0) return; int ss = bm.size(); //std::cout << 0 << "::" << 0 << std::endl; for(int kk=0;kk* bm2 = bm[kk]; int numtiles = num_tiles_in_bm[kk]; int tx=tile_sx; int ty=tile_sy; if (kk==4||kk==5||kk==6||kk==7) { tx=player_tile_sx; ty=player_tile_sy; } if (kk==8||kk==9) { /* weapon */ tx=player_tile_sx*2; ty=player_tile_sy; } if (kk==10||kk==11) { /* player death */ tx=player_tile_sx*2; ty=player_tile_sy; } int sx= bm2->SizeX()/tx; int sy= bm2->SizeY()/ty; //std::cout << numtiles << "::" << sx << " " << sy << std::endl; int count=0; for(int y=0;y(bm2,x*tx,y*ty,tx,ty)); count++; if (count==numtiles) break; } if (count==numtiles) break; } //std::cout << "COUNT=" << count << std::endl; //std::cout << kk+1 << "::" << tiles.size() << std::endl; } int s = tiles.size(); std::cout << s << std::endl; for(int i=0;ibm = tiles[i]; GameApi::BM bm2 = add_bitmap(env, handle2); bms.push_back(bm2); } for(int i=0;iPrepare(); mls.push_back(ml); } blk = add_block(); } virtual void Prepare() { //std::cout << "Prepare" << std::endl; int s = bm.size(); for(int i=0;iPrepare(); HeavyPrepare(); } virtual void FirstFrame() { } virtual void execute(MainLoopEnv &e) { //std::cout << "execute" << std::endl; int sx = t->SizeX(); int sy = t->SizeY(); //std::cout << "SX: " << sx << " " << sy << std::endl; int c = get_current_block(); set_current_block(blk); std::vector vec; scr->execute(e); Point scroll_pos = scr->get_pos(); for(int y=0;yTile(x,y); if (tile>=0 && tileTile2(x,y); Point2d delta = t->Tile2Delta(x,y); //if (tile2==5) std::cout << "Blob" << " " << tile2 << " " << mls.size() << std::endl; if (tile2>=0 && tile2Tile3(x,y); //std::cout << tile2 << "," << std::endl; //if (tile2==5) std::cout << "Blob" << " " << tile2 << " " << mls.size() << std::endl; if (tile2>=0 && tile2Prepare(); move_2->execute(e); //std::cout << std::endl; clear_block(blk); recreate_block(blk); set_current_block(c); } virtual void handle_event(MainLoopEvent &e) { scr->handle_event(e); } virtual std::vector shader_id() { return std::vector(); } private: GameApi::Env &env; GameApi::EveryApi &ev; Tiles2d *t; std::vector *> bm; std::vector num_tiles_in_bm; std::vector *> tiles; std::vector bms; std::vector mls; int blk=-1; int tile_sx, tile_sy; int player_tile_sx, player_tile_sy; TileScroller *scr; }; class TileHud : public MainLoopItem, public TileHudInterface { public: TileHud(GameApi::Env &env, GameApi::EveryApi &ev, GameApi::FI font, GameApi::BM status_bm) :env(env), ev(ev), font(font), status_bm(status_bm) { } virtual int get_score() const { return score; } virtual void set_score(int score1) { score=score1; } virtual int get_health() const { return health; } virtual void set_health(int health1) { health=health1; } virtual int get_lives() const { return lives; } virtual void set_lives(int lives1) { lives=lives1; } virtual void set_state(int state1) { state=state1; } virtual void Collect(CollectVisitor &vis) { vis.register_obj(this); } virtual void HeavyPrepare() { int s = 10; for(int i=0;iPrepare(); nodes.push_back(ml); } GameApi::BM bm2 = ev.font_api.draw_text_string(font,"Score", 5,30); score_ml = ev.sprite_api.vertex_array_render(ev,bm2); GameApi::BM bm3 = ev.font_api.draw_text_string(font,"Health", 5, 30); health_ml = ev.sprite_api.vertex_array_render(ev,bm3); GameApi::BM bm4 = ev.font_api.draw_text_string(font,"Lives", 5, 30); lives_ml = ev.sprite_api.vertex_array_render(ev,bm4); GameApi::PT pt1 = ev.point_api.point(0.0,0.0,0.0); GameApi::PT pt2 = ev.point_api.point(0.0,64.0,0.0); GameApi::BM bm_grad = ev.bitmap_api.gradient(pt1,pt2,0xff884422,0xff442211, 1280,64); gradient_ml = ev.sprite_api.vertex_array_render(ev,bm_grad); } virtual void Prepare() { HeavyPrepare(); } virtual void FirstFrame() { } virtual void execute(MainLoopEnv &e) { //int c = get_current_block(); //blk = add_block(); //set_current_block(blk); std::vector vec; vec.push_back(gradient_ml); int score_pos = 100.0; int health_pos = 500.0; int lives_pos = 1000.0; std::stringstream ss; ss << score; std::string label = ss.str(); int s = label.size(); for(int i=0;iPrepare(); move_2->execute(e); //clear_block(blk); //set_current_block(c); } virtual void handle_event(MainLoopEvent &e) { } virtual std::vector shader_id() { return std::vector(); } private: GameApi::Env &env; GameApi::EveryApi &ev; int score=0; int health=100; int lives=3; int state=0; std::vector nodes; GameApi::FI font; GameApi::BM status_bm; GameApi::ML score_ml, health_ml, lives_ml; GameApi::ML gradient_ml; int blk=-1; }; class TileSplashScreen : public MainLoopItem, public TileSplashScreenInterface { public: TileSplashScreen(GameApi::Env &env, GameApi::EveryApi &ev, GameApi::BM bm, TileSplashScreenCallback *cb) : env(env), ev(ev), bm(bm),cb(cb) { } virtual void Collect(CollectVisitor &vis) { vis.register_obj(this); } bool enabled() const { return !disable; } virtual void HeavyPrepare() { ml = ev.sprite_api.vertex_array_render(ev,bm); MainLoopItem *ml3 = find_main_loop(env,ml); ml3->Prepare(); } virtual void Prepare() { HeavyPrepare(); } virtual void FirstFrame() { } virtual void execute(MainLoopEnv &e) { if (!disable) { BitmapHandle *handle = find_bitmap(env, bm); ::Bitmap *b2 = find_color_bitmap(handle); float bm_size = b2->SizeX(); float bm_size_y = b2->SizeY(); //int c = get_current_block(); //blk = add_block(); //set_current_block(blk); GameApi::MN mn0 = ev.move_api.mn_empty(); GameApi::MN mn = ev.move_api.trans2(mn0,(1280-bm_size)/2,(900-bm_size_y)/2,0); GameApi::ML move = ev.move_api.move_ml(ev, ml, mn, 1, 10); GameApi::ML ml4 = ev.sprite_api.turn_to_2d(ev,move,0.0,0.0,1200.0,900.0); MainLoopItem *move_2 = find_main_loop(env,ml4); //move_2->Prepare(); move_2->execute(e); //clear_block(blk); //set_current_block(c); } } virtual void handle_event(MainLoopEvent &e) { if ((e.type==0x300 && (e.ch==32||e.ch==13)) || e.button ==0) { disable=true; } } void reset() { disable=false; cb->reset(); } private: GameApi::Env &env; GameApi::EveryApi &ev; bool disable=false; GameApi::BM bm; GameApi::ML ml; TileSplashScreenCallback *cb; int blk=-1; }; class TileScroller2d : public TileScroller { public: TileScroller2d(TilePlayer *player, float speed, int cell_sx, int cell_sy, int screen_sx, int screen_sy) : player(player), speed(speed), cell_sx(cell_sx), cell_sy(cell_sy), screen_sx(screen_sx), screen_sy(screen_sy) { } virtual Point get_pos() const { return Point(-current_pos.x,-current_pos.y,0); } virtual void handle_event(MainLoopEvent &e) { } virtual void execute(MainLoopEnv &e) { float delta_x = target_pos.x-current_pos.x; float delta_y = target_pos.y-current_pos.y; bool rest_x=false; bool rest_y=false; if (fabs(delta_x)0.0) current_pos.x+=speed; if (delta_x<0.0) current_pos.x-=speed; if (delta_y>0.0) current_pos.y+=speed; if (delta_y<0.0) current_pos.y-=speed; int pos_x = player->player_pos_x(); int pos_y = player->player_pos_y(); pos_x *= cell_sx; pos_y *= cell_sy; pos_x += cell_sx/2; pos_y += cell_sy/2; pos_x -=current_pos.x; pos_y -=current_pos.y; pos_x += player->delta_pos().x; pos_y += player->delta_pos().y; if (rest_x) { if (pos_x < screen_sx/10) { target_pos.x -= cell_sx*(screen_sx/cell_sx/2); } if (pos_x > screen_sx*9/10) { target_pos.x += cell_sx*(screen_sx/cell_sx/2); } } if (rest_y) { if (pos_y < screen_sy/10) { target_pos.y -= cell_sy*(screen_sy/cell_sy/2); } if (pos_y > screen_sy*9/10) { target_pos.y += cell_sy*(screen_sy/cell_sy/2); } } } void reset() { current_pos.x=0.0; current_pos.y=0.0; target_pos.x=0.0; target_pos.y=0.0; } private: Point current_pos; Point target_pos; float speed; TilePlayer *player; int cell_sx, cell_sy; int screen_sx, screen_sy; }; class TileRender2d : public TileRenderer2d { public: TileRender2d(GameApi::Env &env, GameApi::EveryApi &ev, int sx, int sy) :env(env), ev(ev), sx(sx), sy(sy) { } void set_tiles_2d(Tiles2d *t, std::vector *> bm, std::vector vec) { m_t = t; m_bm = bm; num_tiles_in_bm=vec; } MainLoopItem *get_renderer(TileScroller *scr) const { return new TileRendererMainLoop(env,ev,m_t, m_bm, num_tiles_in_bm, sx,sy,sx,sy*2,scr); } private: GameApi::Env &env; GameApi::EveryApi &ev; Tiles2d *m_t; std::vector *> m_bm; std::vector num_tiles_in_bm; int sx,sy; }; class AnimTiles2d : public Tiles2d, public MainLoopItem { public: AnimTiles2d(GameApi::Env &env, Tiles2d *tiles, std::string tiles_strings, std::string tiles_strings2, std::string url, std::string homepage) : env(env), tiles(tiles), tiles_strings(tiles_strings), tiles_strings2(tiles_strings2), url(url), homepage(homepage) { } int SizeX() const { return tiles->SizeX(); } int SizeY() const { return tiles->SizeY(); } int Tile(int x, int y) const { int val = tiles->Tile(x,y); if (val>=0&&valget_current_move1(x,y); float previous_time2 = tiles->get_previous_time(x,y); if (current_time>previous_time2+pos1[i]) { //pos++; mv++; tiles->set_current_move1(x,y,mv); //previous_time2 = current_time; tiles->set_previous_time(x,y,current_time); } ch=anims[i][(pos+mv)%(anims[i].size())]; } int s = tiles_strings.size(); for(int i=0;iTile2(x,y); } int Tile3(int x, int y) const { int val = tiles->Tile3(x,y); if (val>=0&&valget_current_move2(x,y); float previous_time = tiles->get_previous_time2(x,y); if (current_time>previous_time+pos2[i]) { mv++; //pos++; tiles->set_current_move2(x,y,mv); tiles->set_previous_time2(x,y,current_time); //previous_time=current_time; } ch=anims2[i][(pos+mv)%(anims2[i].size())]; //std::cout << "CH chosen: " << ch << std::endl; break; } int s = tiles_strings2.size(); for(int i=0;iget_current_move1(x,y); } virtual void set_current_move1(int x, int y, int val) { tiles->set_current_move1(x,y,val); } virtual int get_current_move2(int x, int y) const { return tiles->get_current_move2(x,y); } virtual void set_current_move2(int x, int y, int val) { tiles->set_current_move2(x,y,val); } virtual float get_previous_time(int x, int y) const { return tiles->get_previous_time(x,y); } virtual void set_previous_time(int x, int y, float val) { return tiles->set_previous_time(x,y,val); } virtual float get_previous_time2(int x, int y) const { return tiles->get_previous_time2(x,y); } virtual void set_previous_time2(int x, int y, float val) { tiles->set_previous_time2(x,y,val); } virtual void Collect(CollectVisitor &vis) { vis.register_obj(this); } virtual void HeavyPrepare() { #ifndef EMSCRIPTEN env.async_load_url(url, homepage); #endif GameApi::ASyncVec *vec = env.get_loaded_async_url(url); if (!vec) { std::cout << "async not ready!" << std::endl; return; } std::string s(vec->begin(), vec->end()); std::stringstream ss(s); std::string line; bool mode=false; while(std::getline(ss,line)) { if (line=="@") { mode=true; continue; } std::stringstream ss2(line); float time_delta=1.0; std::string line2; ss2 >> time_delta >> line2; if (!mode) { anims.push_back(line2); pos1.push_back(time_delta); } else { anims2.push_back(line2); pos2.push_back(time_delta); } } } virtual void Prepare() { HeavyPrepare(); } virtual void FirstFrame() { } virtual void execute(MainLoopEnv &e) { current_time = e.time; } virtual void handle_event(MainLoopEvent &e) { } virtual std::vector shader_id() { return std::vector(); } private: GameApi::Env &env; Tiles2d *tiles; std::string tiles_strings, tiles_strings2; std::string url; std::string homepage; std::vector anims; std::vector pos1; std::vector anims2; std::vector pos2; float current_time; //mutable float previous_time=0.0; //mutable float previous_time2=0.0; float time_delta=1.0; }; class NetworkTiles2d : public Tiles2d, public MainLoopItem { public: NetworkTiles2d(GameApi::Env &env, std::string url, std::string homepage, std::string tiles_string, std::string tiles_string2) : env(env), url(url), homepage(homepage), tiles_string(tiles_string), tiles_string2(tiles_string2) { } int SizeX() const { return sx; } int SizeY() const { return sy; } int Tile(int x, int y) const { int i = tiles[std::pair(x,y)]; //if (i<0) return 0; return i; } int Tile2(int x, int y) const { return -1; } int Tile3(int x, int y) const { return tiles3[std::pair(x,y)]; } virtual void Collect(CollectVisitor &vis) { vis.register_obj(this); } virtual void HeavyPrepare() { #ifndef EMSCRIPTEN env.async_load_url(url, homepage); #endif GameApi::ASyncVec *ptr = env.get_loaded_async_url(url); if (!ptr) { std::cout << "p_url async not ready yet, failing..." << std::endl; return; } std::string data(ptr->begin(),ptr->end()); std::stringstream ss(data); std::string line; int linenum = 0; int linenum2=0; int width=0; int width2=0; bool mode=false; while(std::getline(ss,line)) { if (line=="@") mode=true; if (!mode) { int s = line.size(); width=std::max(width,s); for(int i=0;i shader_id() { return std::vector(); } virtual int get_current_move1(int x, int y) const { return moves1[std::pair(x,y)]; } virtual void set_current_move1(int x, int y, int val) { moves1[std::pair(x,y)]=val; } virtual int get_current_move2(int x, int y) const { return moves2[std::pair(x,y)]; } virtual void set_current_move2(int x, int y, int val) { moves2[std::pair(x,y)]=val; } virtual float get_previous_time(int x, int y) const { return time[std::pair(x,y)]; } virtual void set_previous_time(int x, int y, float val) { time[std::pair(x,y)]=val; } virtual float get_previous_time2(int x, int y) const { return time2[std::pair(x,y)]; } virtual void set_previous_time2(int x, int y, float val) { time2[std::pair(x,y)]=val; } private: GameApi::Env &env; std::string url; std::string homepage; std::string tiles_string; std::string tiles_string2; int sx=0; int sy=0; mutable std::map,int> tiles; mutable std::map,int> tiles3; mutable std::map,int> moves1; mutable std::map,int> moves2; mutable std::map,float> time; mutable std::map,float> time2; }; class ItemsTile : public MainLoopItem { public: ItemsTile(GameApi::Env &env, GameApi::EveryApi &ev, TilePlayer &pl, std::string url, std::string homepage, int cell_sx, int cell_sy, TileScroller *scr, std::vector item_types, TileHudInterface &hud) : env(env), ev(ev), pl(pl), url(url), homepage(homepage), cell_sx(cell_sx), cell_sy(cell_sy),scr(scr), item_types(item_types),hud(hud){ } virtual void Collect(CollectVisitor &vis) { vis.register_obj(this); } virtual void HeavyPrepare() { #ifndef EMSCRIPTEN env.async_load_url(url, homepage); #endif GameApi::ASyncVec *vec = env.get_loaded_async_url(url); if (!vec) { std::cout << "async not ready!" << std::endl; return; } std::string s(vec->begin(), vec->end()); std::stringstream ss(s); std::string line; instances.clear(); while(std::getline(ss,line)) { std::stringstream ss2(line); Item i; i.type=0; if (ss2 >> i.x >> i.y >> i.type) { } else { continue; } i.enabled=true; i.delta_x=0.0; //std::cout << "LINE:" << line << std::endl; //std::cout << i.x << " " << i.y << " " << i.type << std::endl; instances.push_back(i); } item_types_ml.clear(); int s3 = item_types.size(); for(int i=0;iPrepare(); item_types_ml.push_back(ml); } } virtual void Prepare() { HeavyPrepare(); } virtual void FirstFrame() { } virtual void execute(MainLoopEnv &e) { int xx = pl.player_pos_x(); int yy = pl.player_pos_y(); Point scroll_pos = scr->get_pos(); //int c = get_current_block(); //blk = add_block(); //set_current_block(blk); std::vector vec; int s = instances.size(); for(int i=0;i=0 && typePrepare(); move_2->execute(e); //clear_block(blk); //set_current_block(c); } virtual void handle_event(MainLoopEvent &e) { } virtual std::vector shader_id() { return std::vector(); } void add_random_item(int x, int y, float delta_x) { Item i; i.x = x; i.y = y; static int types=-1; types++; if (types>=item_types_ml.size()) types=0; i.type = types; i.enabled=true; i.delta_x=delta_x; instances.push_back(i); } private: GameApi::Env &env; GameApi::EveryApi &ev; TilePlayer &pl; Tiles2d *next; std::string url, homepage; std::vector item_types; std::vector item_types_ml; struct Item { int x,y; int type; bool enabled; float delta_x; }; std::vector instances; int cell_sx, cell_sy; TileScroller *scr; TileHudInterface &hud; int blk=-1; }; class EnemyTile : public MainLoopItem { public: EnemyTile(GameApi::Env &env, GameApi::EveryApi &ev, TilePlayer &pl, std::string url, std::string homepage, int cell_sx, int cell_sy, TileScroller *scr, std::vector item_types, TileHudInterface &hud, TileSplashScreenInterface &splash, std::vector child_death, std::vector child_death_flip, TileEnemyCallback *ene_cb) : env(env), ev(ev), pl(pl), url(url), homepage(homepage), cell_sx(cell_sx), cell_sy(cell_sy),scr(scr), item_types(item_types),hud(hud),splash(splash), child_death(child_death), child_death_flip(child_death_flip),ene_cb(ene_cb) { } virtual void Collect(CollectVisitor &vis) { vis.register_obj(this); } virtual void HeavyPrepare() { int s1 = child_death.size(); for(int i=0;i *b2 = find_color_bitmap(handle); b2->Prepare(); } int s2 = child_death_flip.size(); for(int i=0;i *b3 = find_color_bitmap(handle2); b3->Prepare(); } #ifndef EMSCRIPTEN env.async_load_url(url, homepage); #endif GameApi::ASyncVec *vec = env.get_loaded_async_url(url); if (!vec) { std::cout << "async not ready!" << std::endl; return; } std::string s(vec->begin(), vec->end()); std::stringstream ss(s); std::string line; instances.clear(); while(std::getline(ss,line)) { std::stringstream ss2(line); Item i; i.type=0; if (ss2 >> i.x0 >> i.x1 >> i.y >> i.type) { } else { continue; } i.x = (i.x0+i.x1)*cell_sx/2; i.dir=false; i.frame=0; i.enabled=true; i.death_frame=-1; i.death_frame_after=0; i.start_timer = 0; //std::cout << "LINE:" << line << std::endl; //std::cout << i.x << " " << i.y << " " << i.type << std::endl; instances.push_back(i); } item_types_ml.clear(); item_types_flip_ml.clear(); int s3 = item_types.size(); for(int i=0;i vec_ml; for(int j=0;jPrepare(); vec_ml.push_back(ml); } item_types_ml.push_back(vec_ml); } int s4 = item_types.size(); for(int i=0;i *b2 = find_color_bitmap(handle); b2->Prepare(); int sx = ev.bitmap_api.size_x(bm); sx/=cell_sx; std::vector vec_ml; for(int j=0;jPrepare(); vec_ml.push_back(ml); } item_types_flip_ml.push_back(vec_ml); } child_d_frames.clear(); child_d_frames_flip.clear(); int d = child_death.size(); for(int i=0;i frms; for(int j=0;jPrepare(); frms.push_back(ml); } child_d_frames.push_back(frms); } int d2 = child_death_flip.size(); for(int i=0;i frms; for(int j=0;jPrepare(); frms.push_back(ml); } child_d_frames_flip.push_back(frms); } } virtual void Prepare() { HeavyPrepare(); } virtual void FirstFrame() { } virtual void execute(MainLoopEnv &e) { static int m_frame=0; static int m_num=0; m_frame++; if (m_frame==100) { m_frame=0; m_num++; int s = instances.size(); if (s) { int i = m_num%s; Item ii = instances[i]; ii.dir=!ii.dir; ii.death_frame=-1; ii.frame=0; ii.start_timer=100; instances.push_back(ii); } } int xx = pl.player_pos_x(); int yy = pl.player_pos_y(); Point scroll_pos = scr->get_pos(); //int c = get_current_block(); //blk = add_block(); //set_current_block(blk); std::vector vec; int s = instances.size(); for(int i=0;i0) ii.start_timer--; if (ii.start_timer==0 && ii.enabled && ii.death_frame==-1 && !pl.in_jump() && (x+cell_sx/2)/cell_sx==xx&&y==yy) { pl.kill_player(); ii.enabled=false; hud.set_lives(hud.get_lives()-1); if (hud.get_lives()==0) { std::cout << "GAME OVER" << std::endl; splash.reset(); } } if (ii.death_frame==-1) { if (dir) x+=1; if (!dir) x-=1; if (xx1) dir=!dir; } ii.frame++; if (ii.frame>=item_types_ml[ii.type].size()) ii.frame=0; ii.dir=dir; ii.x=x; int frame=ii.frame; int type = ii.type; bool enabled = ii.enabled; if (enabled) { GameApi::ML ml; if (!ii.dir) { ml=item_types_flip_ml[type][frame]; } else { ml=item_types_ml[type][frame]; } int dd=pl.player_dir(); //std::cout << pl.weapon_active() << " " << ii.death_frame << " " << (x+cell_sx/2)/cell_sx << " " << xx-dd << " " << y << " " << yy << std::endl; if (pl.weapon_active() && ii.death_frame==-1 && (x+cell_sx/2)/cell_sx==xx-dd&&y==yy) { //std::cout << "ANIM_START" << std::endl; ii.death_frame=0; ii.death_frame_counter=0; } if (ii.death_frame!=-1) { ii.death_frame_counter++; } if (ii.death_frame!=-1) { if (ii.death_frame_counter>10) { ii.death_frame++; ii.death_frame_counter=0; } if (ii.death_frame>=std::min(child_d_frames[type].size(),child_d_frames_flip[type].size())) { ii.death_frame=std::min(child_d_frames[type].size(),child_d_frames_flip[type].size())-1; ii.death_frame_after++; if (ii.death_frame_after>=60) { ene_cb->add_random_item(ii.x/64,ii.y,std::fmod(ii.x,64.0)); ii.enabled=false; } } if (ii.death_frame!=-1) { if (!ii.dir) { ml=child_d_frames_flip[type][ii.death_frame]; } else { ml=child_d_frames[type][ii.death_frame]; } } } GameApi::MN mn0 = ev.move_api.mn_empty(); GameApi::MN mn1 = ev.move_api.trans2(mn0,x+scroll_pos.x,scroll_pos.y+y*cell_sy+64.0,0.0); GameApi::ML ml2 = ev.move_api.move_ml(ev,ml,mn1,1,10); vec.push_back(ml2); } } GameApi::ML ml3 = ev.mainloop_api.array_ml(ev,vec); GameApi::ML ml4 = ev.sprite_api.turn_to_2d(ev,ml3,0.0,0.0,1200.0,900.0); MainLoopItem *move_2 = find_main_loop(env,ml4); // move_2->Prepare(); move_2->execute(e); //clear_block(blk); //set_current_block(c); } virtual void handle_event(MainLoopEvent &e) { } virtual std::vector shader_id() { return std::vector(); } private: GameApi::Env &env; GameApi::EveryApi &ev; TilePlayer &pl; Tiles2d *next; TileSplashScreenInterface &splash; std::string url, homepage; std::vector item_types; std::vector > item_types_ml; std::vector > item_types_flip_ml; struct Item { int x0,x1,y; float x; int type; int frame; bool enabled; bool dir; int death_frame; int death_frame_counter; int death_frame_after; int start_timer; }; std::vector instances; int cell_sx, cell_sy; TileScroller *scr; TileHudInterface &hud; TileEnemyCallback *ene_cb; std::vector child_death; std::vector child_death_flip; std::vector > child_d_frames; std::vector > child_d_frames_flip; int blk=-1; //MatrixMovement *mat; //MainLoopItem *item; }; class PlayerTileMapping : public Tiles2d { public: PlayerTileMapping(TilePlayer &pl, Tiles2d &next) : pl(pl), next(next) { } virtual int SizeX() const { return next.SizeX(); } virtual int SizeY() const { return next.SizeY(); } virtual int Tile(int x, int y) const { return next.Tile(x,y); } virtual int Tile2(int x, int y) const { int xx = pl.player_pos_x(); int yy = pl.player_pos_y(); if (x==xx && y==yy) return pl.player_tile(); //if (x==xx && y==yy+1) return 3; return -1; } virtual int Tile3(int x, int y) const { return next.Tile3(x,y); } virtual Point2d Tile2Delta(int x, int y) const { int xx = pl.player_pos_x(); int yy = pl.player_pos_y(); if (x==xx && y==yy) { Point p = pl.delta_pos(); Point2d p2; p2.x=p.x; p2.y=p.y; return p2; } Point2d p; p.x=0.0; p.y=0.0; return p; } virtual int get_current_move1(int x, int y) const { return next.get_current_move1(x,y); } virtual void set_current_move1(int x, int y, int val) { next.set_current_move1(x,y,val); } virtual int get_current_move2(int x, int y) const { return next.get_current_move2(x,y); } virtual void set_current_move2(int x, int y, int val) { next.set_current_move2(x,y,val); } virtual float get_previous_time(int x, int y) const { return next.get_previous_time(x,y); } virtual void set_previous_time(int x, int y, float val) { next.set_previous_time(x,y,val); } virtual float get_previous_time2(int x, int y) const { return next.get_previous_time2(x,y); } virtual void set_previous_time2(int x, int y, float val) { next.set_previous_time2(x,y,val); } private: TilePlayer &pl; Tiles2d &next; }; bool is_transparent_tile(int val) { if (val>=5+8 && val<5+8+3) return true; return val<0; } bool is_not_wall(int val) { if (val!=0) return true; return false; } class PlayerTile : public TilePlayer { public: PlayerTile(int tile_sx, int tile_sy, int start_pos_x, int start_pos_y, int player_start_tile, int player_end_tile, float delta_time, float delta_move_time, TileHudInterface *hud) : tile_sx(tile_sx), tile_sy(tile_sy), pos_x(start_pos_x), pos_y(start_pos_y), player_start_tile(player_start_tile), player_end_tile(player_end_tile), delta_time(delta_time), delta_move_time(delta_move_time),hud(hud) { tile=player_start_tile; } virtual void SetTiles2d(Tiles2d *t) { tiles=t; } virtual void SetTiles3d(Tiles3d *t) { } virtual void handle_event(MainLoopEvent &e) { //if (e.type==0x300 && e.ch=='w') { pos_y--; move_freeze=true; y_dir=true; } //std::cout << "Event:" << e.type << " " << e.ch << std::endl; if (death_frame==-1) { if (e.type==0x300 && (e.ch=='w'||e.ch==26||e.ch==82||e.ch==1073741906)&&(!jump_ongoing||jump_aborted)) { jump_aborted=false; jump_trigger=true; jump_ongoing=true; jump_state=0; } } if (e.type==0x301 && (e.ch=='w'||e.ch==26||e.ch==82||e.ch==1073741906) && jump_ongoing && (jump_state==0||jump_state==1)) { if (jump_height<-64) { jump_state=2; jump_trigger=true; jump_max_height=jump_height; jump_aborted=true; } else { jump_abort_delayed=true; } } if (death_frame==-1) { if (e.type==0x300 && e.ch==32) { weapon_start = true; } } if (e.type==0x301 && e.ch==32) { weapon_start=false; weapon_ongoing = false; } if (death_frame==-1) { if (e.type==0x300 && (e.ch=='d'||e.ch==7||e.ch==79||e.ch==1073741903)) { dir_x=1; int val_x = tiles->Tile(player_pos_x()+dir_x,player_pos_y()+(delta_pos().y+64)/64); if ((!jump_ongoing &&!is_not_wall(val_x)) ||(jump_ongoing && !is_transparent_tile(val_x))) { dir_x=0; } } if (e.type==0x300 && (e.ch=='a'||e.ch==4||e.ch==80||e.ch==1073741904)) { dir_x=-1; int val_x = tiles->Tile(player_pos_x()+dir_x,player_pos_y()+(delta_pos().y+64)/64); if ((jump_ongoing && !is_transparent_tile(val_x))||(!jump_ongoing && !is_not_wall(val_x))) { dir_x=0; } } } //if (e.type==0x300 && e.ch=='s') { pos_y++; move_freeze=true; y_dir=true; } if (e.type==0x301 && (e.ch=='d'||e.ch==7||e.ch==79||e.ch==1073741903)) { dir_x=0; } if (e.type==0x301 && (e.ch=='a'||e.ch==4||e.ch==80||e.ch==1073741904)) { dir_x=0; } /* else { if (e.type==0x300 && e.ch=='w') { prepare_move_dir_x=0; prepare_move_dir_y=-1; } if (e.type==0x300 && e.ch=='d') { prepare_move_dir_x=1; prepare_move_dir_y=0; } if (e.type==0x300 && e.ch=='a') { prepare_move_dir_x=-1; prepare_move_dir_y=0; } if (e.type==0x300 && e.ch=='s') { prepare_move_dir_x=0; prepare_move_dir_y=1; } }*/ } virtual void execute(MainLoopEnv &e) { if (death_frame==-1) { hud->set_health(100); } if (death_frame!=-1) { static int frame=0; frame++; if (frame>=10) { death_frame++; if (death_frame>=5) { death_frame=4; } else frame=0; if (death_frame==4 && frame>400) death_frame=-1; if (death_frame!=-1) { hud->set_health(100-death_frame*20); } } } if (weapon_start) { weapon_ongoing=true; weapon_start_time=e.time; weapon_start=false; } if (weapon_ongoing && e.time>weapon_start_time+100.0) { //std::cout << "TIME" << std::endl; weapon_ongoing=false; } current_weapon = int((e.time-weapon_start_time)*10.0)%4; //MainLoopEvent ee; if (!move_freeze) { if (dir_x==1) { if (last_x==-1) { has_flipped=true; } else { has_flipped=false; } move_x=1; move_freeze=true; flip=false; y_dir=false; last_x=1; } if (dir_x==-1) { if (last_x==1) { has_flipped=true; } else { has_flipped=false; } move_x=-1; move_freeze=true; flip=true; y_dir=false; last_x=-1; } } //ee.type=771; //ee.ch=-1; //handle_event(ee); if (jump_abort_delayed && jump_height<-64) { jump_state=2; jump_trigger=true; jump_max_height=jump_height; jump_aborted=true; jump_abort_delayed=false; } if (jump_trigger) { jump_start_time=e.time; jump_trigger=false; } float jump_delta = e.time-jump_start_time; if (jump_ongoing && jump_state==3) { //std::cout << "Event3" << std::endl; jump_height=jump_max_height+jump_speed*jump_delta; if(jump_height>0.0) { jump_ongoing=false; jump_height=0.0; } } if (jump_ongoing && jump_state==2) { //std::cout << "Event2" << std::endl; jump_height=jump_max_height+jump_speed*jump_delta; if(jump_height>-64.0*0.5) jump_state=3; } if (jump_ongoing && jump_state==1) { //std::cout << "Event1" << std::endl; jump_height=-jump_speed*jump_delta; if (jump_height<-64.0*3.0) { jump_state=2; jump_start_time=e.time; jump_max_height=jump_height;} } if (jump_ongoing && jump_state==0) { //std::cout << "Event0" << std::endl; jump_height=-jump_speed*jump_delta; if (jump_height<-64.0*0.5) jump_state=1; } //std::cout << "Jump state: " << jump_state << " " << jump_height << std::endl; if (old_move_freeze!=move_freeze) { last_move_time=e.time; old_move_freeze=move_freeze; } if (old_flip!=flip) { last_move_time=e.time; old_flip=flip; } if (move_freeze && !y_dir) { delta_position = (e.time-last_move_time)/delta_move_time; if (delta_position<0.0) delta_position=0.0; while (delta_position>1.0) { delta_position-=1.0; pos_x+=move_x; } if (flip) delta_position=1.0-delta_position; //if (has_flipped) delta_position=1.0-delta_position; } if (e.time > last_move_time+delta_move_time) { //delta_position-=1.0; //pos_x+=move_x; has_flipped=false; move_x=0; last_move_time = e.time; move_freeze = false; if (prepare_move_dir_x!=0||prepare_move_dir_y!=0) { if (prepare_move_dir_x>0) flip=false; if (prepare_move_dir_x<0) flip=true; //pos_x += prepare_move_dir_x; //pos_y += prepare_move_dir_y; prepare_move_dir_x=0; prepare_move_dir_y=0; //move_freeze=true; } } if (move_freeze && !y_dir && e.time > last_change_time+delta_time) { last_change_time = e.time; tile++; if (tile>=player_end_tile-1) { tile-=(player_end_tile-player_start_tile-1); } //std::cout << "TILE: " << tile << " " << player_end_tile << " " << player_start_tile << std::endl; } int val = tiles->Tile(player_pos_x(),player_pos_y()+(delta_pos().y+64+64)/64); int val_x = dir_x!=0 ? tiles->Tile(player_pos_x()+dir_x,player_pos_y()+(delta_pos().y+64)/64) : -1; if ((!jump_ongoing && !is_transparent_tile(val_x)) || (jump_ongoing && !is_not_wall(val_x))) { dir_x=0; } if (player_pos_y()+(delta_pos().y+64+64)/64<3) val=5+8; //std::cout << "VAL=" << val << std::endl; if (fmod(-delta_pos().y,64)>56.0) { //if (x==int(player_pos_x()) && y==int(pl.player_pos_y()+(pl.delta_pos().y+64)/64)) return 3; if (jump_ongoing && jump_state==2 && !is_transparent_tile(val)) { jump_ongoing=false; pos_y=pos_y+std::ceil(float(delta_pos().y)/64.0); jump_height=0.0; } } float fall_delta2 = e.time-fall_start_time; bool curr=false; if (!jump_ongoing && !fall_ongoing && is_transparent_tile(val)) { //std::cout << "Fall start" << std::endl; fall_ongoing=true; fall_start_time=e.time; curr=true; } if (fall_ongoing && !curr) { //std::cout << "Fall ongoing" << std::endl; fall_delta=fall_speed*fall_delta2; //if (fmod(-delta_pos().y-fall_delta,64)>56.0) { int val = tiles->Tile(player_pos_x(),player_pos_y()+(fall_delta+delta_pos().y+64+64)/64); if (player_pos_y()+(delta_pos().y+64+64)/64<3) val=5+8; //std::cout << "VAL2=" << val << std::endl; if (!is_transparent_tile(val)) {fall_ongoing=false; pos_y+=std::ceil(fall_delta/64.0); fall_delta=0.0; } //} } } virtual int player_pos_x() const { return pos_x; } virtual int player_pos_y() const { return pos_y; } virtual int player_pos_z() const { return 0; } virtual int player_tile() const { //std::cout << jump_ongoing << " " << jump_state << " " << fall_ongoing << " " << move_freeze << " " << dir_x << " " << flip << "->"; // std::cout << weapon_ongoing << " " << flip << " " << current_weapon << std::endl; if (death_frame!=-1) { if (flip) { return death_frame+56+5; } else { return death_frame+56; } } if (weapon_ongoing) { int val=0; if(flip) { val=52+current_weapon; } else { val=48+current_weapon; } return val; } int jump_val = 0; if (jump_ongoing && jump_state==0) { jump_val=0; } if (jump_ongoing && jump_state==1) { jump_val=1; } if (jump_ongoing && jump_state==2) { jump_val=2; } if (jump_ongoing && jump_state==3) { jump_val=3; } if (fall_ongoing) { jump_val=3; } if ((fall_ongoing||jump_ongoing) && !flip) { jump_val+=40; } if ((fall_ongoing||jump_ongoing) && flip) { jump_val+=44; } if (fall_ongoing||jump_ongoing) { /*std::cout << "1::" << jump_val<< std::endl;*/ return jump_val; } if (!move_freeze && dir_x==0) { /*std::cout << "2::" << (!flip?player_end_tile-1:player_end_tile+(player_end_tile-1-player_start_tile)) << std::endl;*/ return !flip?player_end_tile-1:player_end_tile+(player_end_tile-1-player_start_tile); } /*std::cout << "3::" << (!flip?tile:player_end_tile+(tile-player_start_tile)) << std::endl;*/ return !flip?tile:player_end_tile+(tile-player_start_tile); } virtual int player_type() const { return 0; } virtual Point delta_pos() const { int weapon_delta=0; if (death_frame!=-1&&flip) weapon_delta=-64; else if (weapon_ongoing&&flip) weapon_delta=-64; return Point(weapon_delta+delta_position*tile_sx-(flip?tile_sx:0),jump_height+fall_delta-64,0.0); } void reset() { pos_x=10; pos_y=9; flip=false; jump_ongoing=false; jump_state=0; fall_ongoing=0; jump_height=0.0; last_change_time=0.0; last_move_time=0.0; delta_position=0.0; jump_trigger=false; move_x=0; prepare_move_dir_x=0; prepare_move_dir_y=0; old_move_freeze=false; y_dir=false; old_flip=false; last_x=0; has_flipped=false; dir_x=0; jump_start_time=0.0; jump_aborted=false; jump_abort_delayed=false; fall_delta=0.0; fall_start_time=0.0; } bool weapon_active() const { return weapon_ongoing; } int player_dir() const { return dir_x; } void kill_player() { death_frame=0; } bool in_jump() const { return jump_ongoing; } private: int pos_x, pos_y; int player_start_tile, player_end_tile; float last_change_time=0.0; int tile; int prepare_move_dir_x=0; int prepare_move_dir_y=0; int move_x=0; bool move_freeze=false; float last_move_time=0.0; float delta_time; float delta_move_time; bool flip=false; float delta_position=0.0; int tile_sx, tile_sy; bool old_move_freeze=false; bool y_dir=false; bool old_flip=false; int last_x=0; bool has_flipped=false; int dir_x=0; bool jump_ongoing=false; float jump_height=0.0; float jump_start_time=0.0; float jump_speed=300.0; float jump_max_height=0.0; bool jump_trigger=false; bool jump_aborted=false; bool jump_abort_delayed=false; int jump_state=0; // 0=going up, displaying 1st // 1=going up, displaying 2nd // 2=going down, displaying 3rd // 3=going down, displaying 4th bool fall_ongoing=false; float fall_delta=0.0; float fall_start_time=0.0; float fall_speed=300.0; Tiles2d *tiles=0; bool weapon_start=false; bool weapon_ongoing=false; float weapon_start_time=0.0; int current_weapon=0; int death_frame=-1; TileHudInterface *hud; }; class Game : public MainLoopItem, public TileSplashScreenCallback, public TileEnemyCallback { public: Game(GameApi::Env &env, GameApi::EveryApi &ev, int tile_sx, int tile_sy, std::string url, std::string url2, std::string url3, std::string url4,std::string homepage, std::string tiles_string, std::string tiles_string2, int start_pos_x, int start_pos_y, int player_start_tile, int player_end_tile, Bitmap *tile_bm, Bitmap *player_bm, Bitmap *player_flip_bm, Bitmap *ruohikko_bm, Bitmap *corn_bm, Bitmap *vesisade_bm, Bitmap *jump_bm, Bitmap *jump_flip_bm, GameApi::FI font, GameApi::BM status_bm, GameApi::BM splash, std::vector item_types, std::vector enemy_types, Bitmap *player_weapon_bm, Bitmap *player_weapon_flip_bm, std::vector child_death, std::vector child_death_flip, GameApi::BM aku_death, GameApi::BM aku_death_flip) : env(env), ev(ev), render(env,ev,tile_sx,tile_sy), tiles(env,url,homepage,tiles_string,tiles_string2), player(tile_sx,tile_sy,start_pos_x, start_pos_y, player_start_tile, player_end_tile, 0.1/4.0, 1.0/4.0,&hud), anim_tiles(env,&tiles,tiles_string,tiles_string2,url2,homepage), player_tiles(player, anim_tiles), tile_bm(tile_bm), player_bm(player_bm), player_flip_bm(player_flip_bm), ruohikko_bm(ruohikko_bm), corn_bm(corn_bm), vesisade_bm(vesisade_bm), jump_bm(jump_bm), jump_flip_bm(jump_flip_bm),hud(env,ev,font,status_bm), splashscreen(env,ev,splash,this), url3(url3), url4(url4), homepage(homepage), item_types(item_types), enemy_types(enemy_types), player_weapon_bm(player_weapon_bm), player_weapon_flip_bm(player_weapon_flip_bm), child_death(child_death), child_death_flip(child_death_flip) { BitmapHandle *handle5 = find_bitmap(env, aku_death); aku_death2 = find_color_bitmap(handle5); BitmapHandle *handle6 = find_bitmap(env, aku_death_flip); aku_death_flip2 = find_color_bitmap(handle6); } virtual void Collect(CollectVisitor &vis) { tile_bm->Collect(vis); player_bm->Collect(vis); jump_bm->Collect(vis); tiles.Collect(vis); anim_tiles.Collect(vis); hud.Collect(vis); splashscreen.Collect(vis); vis.register_obj(this); } virtual void HeavyPrepare() { std::vector*> tile_bms; tile_bms.push_back(tile_bm); // 0 tile_bms.push_back(ruohikko_bm); // 1 tile_bms.push_back(corn_bm); //2 tile_bms.push_back(vesisade_bm); //3 tile_bms.push_back(player_bm); //4 tile_bms.push_back(player_flip_bm); //5 tile_bms.push_back(jump_bm); //6 tile_bms.push_back(jump_flip_bm); //7 tile_bms.push_back(player_weapon_bm); //8 tile_bms.push_back(player_weapon_flip_bm); // 9 tile_bms.push_back(aku_death2); // 10 tile_bms.push_back(aku_death_flip2); //11 std::vector tile_counts; tile_counts.push_back(5); // 0..5 tile_counts.push_back(8); // 5..13 tile_counts.push_back(3); // 13..16 tile_counts.push_back(8); // 16 .. 24 tile_counts.push_back(8); // 24 .. 32 tile_counts.push_back(8); // 32 .. 40 tile_counts.push_back(4); // 40 .. 43 tile_counts.push_back(4); // 43 .. 47 tile_counts.push_back(4); // 47 .. 51 tile_counts.push_back(4); // 51 .. 55 tile_counts.push_back(5); tile_counts.push_back(5); render.set_tiles_2d(&player_tiles, tile_bms,tile_counts); player.SetTiles2d(&tiles); scr = new TileScroller2d(&player, 10.0, 64,64,1200,900); renderer = render.get_renderer(scr); renderer->Prepare(); items_tile = new ItemsTile(env,ev,player,url3,homepage,64,64,scr,item_types,hud); items_tile->Prepare(); enemy_tile = new EnemyTile(env,ev,player,url4,homepage,64,64,scr,enemy_types, hud,splashscreen,child_death, child_death_flip, this); enemy_tile->Prepare(); } virtual void Prepare() { tile_bm->Prepare(); player_bm->Prepare(); tiles.Prepare(); anim_tiles.Prepare(); hud.Prepare(); splashscreen.Prepare(); HeavyPrepare(); } virtual void FirstFrame() { } virtual void execute(MainLoopEnv &e) { player.execute(e); anim_tiles.execute(e); if (renderer) renderer->execute(e); hud.execute(e); items_tile->execute(e); enemy_tile->execute(e); splashscreen.execute(e); } virtual void handle_event(MainLoopEvent &e) { if (!splashscreen.enabled()) { player.handle_event(e); anim_tiles.handle_event(e); hud.handle_event(e); if (renderer) renderer->handle_event(e); items_tile->handle_event(e); enemy_tile->handle_event(e); } else { splashscreen.handle_event(e); } } virtual std::vector shader_id() { return renderer->shader_id(); } void reset() { if (items_tile) items_tile->HeavyPrepare(); if (enemy_tile) enemy_tile->HeavyPrepare(); hud.set_score(0); hud.set_lives(3); hud.set_health(100); player.reset(); if (scr) scr->reset(); } void add_random_item(int x, int y, float delta_x) { if (items_tile) items_tile->add_random_item(x,y,delta_x); } private: GameApi::Env &env; GameApi::EveryApi &ev; TileRender2d render; NetworkTiles2d tiles; PlayerTile player; AnimTiles2d anim_tiles; PlayerTileMapping player_tiles; TileHud hud; TileSplashScreen splashscreen; TileScroller *scr=0; Bitmap *tile_bm; Bitmap *player_bm; Bitmap *player_flip_bm; Bitmap *ruohikko_bm; Bitmap *corn_bm; Bitmap *vesisade_bm; Bitmap *jump_bm; Bitmap *jump_flip_bm; Bitmap *player_weapon_bm; Bitmap *player_weapon_flip_bm; std::vector child_death; std::vector child_death_flip; Bitmap *aku_death2; Bitmap *aku_death_flip2; MainLoopItem *renderer=0; std::string url3; std::string url4; std::string homepage; std::vector item_types; ItemsTile *items_tile; std::vector enemy_types; EnemyTile *enemy_tile; }; GameApi::ML GameApi::MainLoopApi::game(GameApi::EveryApi &ev, int tile_sx, int tile_sy, std::string url, std::string url2, std::string url3, std::string url4, std::string tiles_string, std::string tiles_string2, int start_pos_x, int start_pos_y, int player_start_tile, int player_end_tile, BM tile_bm, BM player_bm, BM ruohikko_bm, BM corn_bm, BM vesisade_bm, BM player_jump_bm, FI font, BM status_bm, BM splash, std::vector item_types, std::vector enemy_types, BM player_weapon_bm, std::vector child_death, BM aku_death) { BitmapHandle *handle = find_bitmap(e, tile_bm); ::Bitmap *tile_bm2 = find_color_bitmap(handle); BitmapHandle *handle3 = find_bitmap(e, player_bm); ::Bitmap *player_bm2 = find_color_bitmap(handle3); GameApi::BM player_flipped = ev.bitmap_api.flip_tile_bitmap(player_bm,64,64,true); BitmapHandle *handle4 = find_bitmap(e, player_flipped); ::Bitmap *player_bm4 = find_color_bitmap(handle4); BitmapHandle *handle5 = find_bitmap(e, ruohikko_bm); ::Bitmap *ruohikko_bm2 = find_color_bitmap(handle5); BitmapHandle *handle6 = find_bitmap(e, corn_bm); ::Bitmap *corn_bm2 = find_color_bitmap(handle6); BitmapHandle *handle7 = find_bitmap(e, vesisade_bm); ::Bitmap *vesisade_bm2 = find_color_bitmap(handle7); BitmapHandle *handle8 = find_bitmap(e, player_jump_bm); ::Bitmap *jump_bm2 = find_color_bitmap(handle8); GameApi::BM player_jump_flipped = ev.bitmap_api.flip_tile_bitmap(player_jump_bm,64,64,true); BitmapHandle *handle9 = find_bitmap(e, player_jump_flipped); ::Bitmap *jump_bm4 = find_color_bitmap(handle9); BitmapHandle *handle10 = find_bitmap(e, player_weapon_bm); ::Bitmap *weapon_bm = find_color_bitmap(handle10); GameApi::BM player_weapon_flipped = ev.bitmap_api.flip_tile_bitmap(player_weapon_bm,128,128,true); BitmapHandle *handle11 = find_bitmap(e, player_weapon_flipped); ::Bitmap *weapon_flip_bm = find_color_bitmap(handle11); // BitmapHandle *handle12 = find_bitmap(e, child_death); //::Bitmap *child_death_bm = find_color_bitmap(handle12); std::vector death_flip; int s = child_death.size(); for(int i=0;i *child_death_flip_bm = find_color_bitmap(handle13); return add_main_loop(e, new Game(e,ev,tile_sx, tile_sy, url, url2, url3,url4,gameapi_homepageurl, tiles_string, tiles_string2, start_pos_x, start_pos_y, player_start_tile, player_end_tile, tile_bm2, player_bm2, player_bm4, ruohikko_bm2, corn_bm2,vesisade_bm2, jump_bm2, jump_bm4, font,status_bm, splash,item_types,enemy_types, weapon_bm, weapon_flip_bm, child_death, death_flip,aku_death, aku_death_flip)); } //--------------- BM I1=ev.bitmap_api.loadbitmapfromurl(http://tpgames.org/farm3.jpeg); BM I2=ev.bitmap_api.scale_bitmap_fullscreen(ev,I1); ML I3=ev.sprite_api.vertex_array_render(ev,I2); MN I997=ev.move_api.mn_empty(); MN I998=ev.move_api.scale2(I997,1.5,1.5,1.5); ML I999=ev.move_api.move_ml(ev,I3,I998,1,10); ML I4=ev.sprite_api.turn_to_2d(ev,I999,0.0,0.0,800.0,600.0); BM I5=ev.bitmap_api.loadbitmapfromurl(http://tpgames.org/tiles.png); BM I6=ev.bitmap_api.loadbitmapfromurl(http://tpgames.org/aku.png); BM I7=ev.bitmap_api.loadbitmapfromurl(http://tpgames.org/ruohikko.png); BM I8=ev.bitmap_api.loadbitmapfromurl(http://tpgames.org/corn.png); BM I9=ev.bitmap_api.loadbitmapfromurl(http://tpgames.org/rain.png); BM I10=ev.bitmap_api.loadbitmapfromurl(http://tpgames.org/aku_jump.png); FI I11=ev.font_api.load_font(http://tpgames.org/Chunkfive.otf,20,20); BM I12=ev.bitmap_api.loadbitmapfromurl(http://tpgames.org/gameapi_logo.png); BM I13=ev.bitmap_api.loadbitmapfromurl(http://tpgames.org/cover6.png); BM I14=ev.bitmap_api.loadbitmapfromurl(http://tpgames.org/brain.png); BM I15=ev.bitmap_api.loadbitmapfromurl(http://tpgames.org/liver.png); BM I16=ev.bitmap_api.loadbitmapfromurl(http://tpgames.org/heart.png); BM I17=ev.bitmap_api.loadbitmapfromurl(http://tpgames.org/lungs.png); BM I18=ev.bitmap_api.loadbitmapfromurl(http://tpgames.org/knifechild.png); BM I19=ev.bitmap_api.loadbitmapfromurl(http://tpgames.org/aku_ase_isku.png); BM I20=ev.bitmap_api.loadbitmapfromurl(http://tpgames.org/knifechild_death.png); BM I21=ev.bitmap_api.loadbitmapfromurl(http://tpgames.org/aku_death.png); ML I22=ev.mainloop_api.game(ev,64,64,https://tpgames.org/test.map,https://tpgames.org/anim.map,https://tpgames.org/items.map,https://tpgames.org/enemy.map,abcde--------ghi,-----abcdefghijklmno,10,9,24,32,I5,I6,I7,I8,I9,I10,I11,I12,I13,std::vector{I14,I15,I16,I17},std::vector{I18},I19,std::vector{I20},I21); ML I23=ev.mainloop_api.or_elem_ml(ev,I4,I22); ML I24=ev.mainloop_api.load_song(ev,I23,http://tpgames.org/cornharvest.mp3); RUN I25=ev.blocker_api.game_window2(ev,I24,false,false,0.0,100000.0);