diff --git a/include/CArm.h b/include/CArm.h index f6bfcdb..2033910 100644 --- a/include/CArm.h +++ b/include/CArm.h @@ -7,7 +7,7 @@ #ifndef _CARM_H_ #define _CARM_H_ - #define DEFAULT_X 0 + #define DEFAULT_X 800 #define DEFAULT_Y 0 #include @@ -15,16 +15,36 @@ #include "CMap.h" #include "AnimSprite.h" + enum EArmState + { + EAS_NULL, + EAS_MOVE_GO, + EAS_MOVE_BA, + EAS_SET + }; + class CArm { private: int x, y; + int dx, dy; + int rx, ry; + + int curr; - AnimSprite *sprite; + CMap *map; + + int type; + + BITMAP *sprite[2]; + + EArmState state; public: CArm(); + void getMap(CMap *map); + // Setters void setX(int px); void setY(int py); @@ -33,9 +53,10 @@ int getX(); int getY(); - void armAction(CMap &map); + void armAction(); void show(BITMAP *buffer); + void update(); }; diff --git a/src/CArm.cpp b/src/CArm.cpp index 0d9d7c7..e4881d2 100644 --- a/src/CArm.cpp +++ b/src/CArm.cpp @@ -10,36 +10,43 @@ CArm::CArm(){ setX(DEFAULT_X); setY(DEFAULT_Y); - // Loading Arm sprite - sprite = new AnimSprite(); - - sprite->SetPosition(0, 0); - sprite->SetDelay(10); - - sprite->AddFrame("../media/mouse.bmp"); - //sprite->AddFrame("../media/arm2.bmp"); - - sprite->AddState(new State(0,0)); - //sprite->AddState(new State(1,2)); + state = EAS_NULL; - sprite->FitStates(); + // Loading Arm sprite + sprite[0] = load_bitmap("../media/arm.bmp", NULL); + sprite[1] = load_bitmap("../media/arm2.bmp", NULL); - sprite->SetCurrentState(0); + curr = 0; +} + +void CArm::getMap(CMap *map) +{ + this->map = map; } -void CArm::armAction(CMap &map){ - if (map.getFull() == false) +void CArm::armAction(){ + if (state == EAS_NULL) { - int rx, ry; - EItem** b; - do{ - rx = rand() % map.getWidth(); - ry = rand() % map.getHeight(); - b = map.getMap(); - }while(b[rx][ry] != EITEM_NULL); - - int type = (rand() % MAX_ITEMS) + 1; - b[rx][ry] = (EItem)type; + state = EAS_MOVE_GO; + + if (map->getFull() == false) + { + EItem** b; + do{ + rx = rand() % map->getWidth(); + ry = rand() % map->getHeight(); + b = map->getMap(); + }while(b[rx][ry] != EITEM_NULL); + + int i = rx; + int j = ry; + + dx = (map->getX() + GET_I) - 50; + dy = (map->getY() + GET_J) - 20; + + type = (rand() % MAX_ITEMS) + 1; + curr = 0; + } } } @@ -63,6 +70,66 @@ int CArm::getY(){ void CArm::show(BITMAP *buffer) { - textprintf_ex(buffer, font, 0, 0, 0, -1, "TEste"); - //sprite->run(buffer); + draw_sprite(buffer, sprite[curr], x, y); +} + +void CArm::update() +{ + switch(state) + { + case EAS_NULL: + { + armAction(); + break; + } + + case EAS_MOVE_GO: + { + if (x > dx) + { + x--; + } + + if (y < dy) + { + y++; + } + + if (x == dx && y == dy) + { + state = EAS_SET; + } + + break; + } + + case EAS_MOVE_BA: + { + if (x < DEFAULT_X) + { + x++; + } + + if (y > DEFAULT_Y) + { + y--; + } + + if (x == DEFAULT_X && y == DEFAULT_Y) + { + state = EAS_NULL; + } + + break; + } + + case EAS_SET: + { + EItem** b= map->getMap(); + b[rx][ry] = (EItem)type; + state = EAS_MOVE_BA; + curr = 1; + break; + } + } } diff --git a/src/CGame.cpp b/src/CGame.cpp index 1b7074e..26cd203 100644 --- a/src/CGame.cpp +++ b/src/CGame.cpp @@ -17,7 +17,7 @@ CGame::CGame() App->SetBuffer(buffer); - game_status = GAME_OPEN; + game_status = GAME_GAME; // Maps test Arm = new CArm(); @@ -26,6 +26,8 @@ CGame::CGame() // Load all bitmaps of the game =D loadImages(); + + Arm->getMap(&Map); } void CGame::run() @@ -86,7 +88,7 @@ void CGame::game_game() if (key[KEY_SPACE]) { - Arm->armAction(Map); + Arm->armAction(); rest(100); } @@ -99,6 +101,7 @@ void CGame::game_game() Map.update(); Arm->show(App->GetBuffer()); + Arm->update(); App->ShowMouse(); }