Skip to content

Commit

Permalink
Added the arm effect
Browse files Browse the repository at this point in the history
  • Loading branch information
CrociDB committed Aug 9, 2009
1 parent 5b7f8a1 commit 0b23ce5
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 32 deletions.
27 changes: 24 additions & 3 deletions include/CArm.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,44 @@
#ifndef _CARM_H_
#define _CARM_H_

#define DEFAULT_X 0
#define DEFAULT_X 800
#define DEFAULT_Y 0

#include <allegro.h>

#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);
Expand All @@ -33,9 +53,10 @@
int getX();
int getY();

void armAction(CMap &map);
void armAction();

void show(BITMAP *buffer);
void update();
};


Expand Down
121 changes: 94 additions & 27 deletions src/CArm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}

Expand All @@ -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;
}
}
}
7 changes: 5 additions & 2 deletions src/CGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ CGame::CGame()

App->SetBuffer(buffer);

game_status = GAME_OPEN;
game_status = GAME_GAME;

// Maps test
Arm = new CArm();
Expand All @@ -26,6 +26,8 @@ CGame::CGame()

// Load all bitmaps of the game =D
loadImages();

Arm->getMap(&Map);
}

void CGame::run()
Expand Down Expand Up @@ -86,7 +88,7 @@ void CGame::game_game()

if (key[KEY_SPACE])
{
Arm->armAction(Map);
Arm->armAction();
rest(100);
}

Expand All @@ -99,6 +101,7 @@ void CGame::game_game()
Map.update();

Arm->show(App->GetBuffer());
Arm->update();

App->ShowMouse();
}
Expand Down

0 comments on commit 0b23ce5

Please sign in to comment.