Browse Source

Add HUD, fix movement bug

master
Josh Gordon 4 years ago
parent
commit
768a9808bc
  1. 32
      app/action/Character.cpp
  2. 1
      app/action/Character.h
  3. 4
      app/action/Map.cpp
  4. BIN
      app/action/action
  5. 1
      app/action/main.cpp

32
app/action/Character.cpp

@ -9,20 +9,20 @@ void Character::handleEvent(SDL_Event& e) {
case SDLK_RIGHT: vx_ += CHAR_SPEED; break;
}
if(turnTimer.isPaused()) {
//printf("Unpause\n");
printf("Unpause\n");
turnTimer.unpause();
}
} else if(e.type == SDL_KEYUP && e.key.repeat == 0) {
if(vy_ == 0 && vx_ == 0) //this is what's called a pro gamer move
return;
//if(vy_ == 0 && vx_ == 0) //this is what's called a pro gamer move
// return;
switch(e.key.keysym.sym) {
case SDLK_UP: vy_ += CHAR_SPEED; break;
case SDLK_DOWN: vy_ -= CHAR_SPEED; break;
case SDLK_LEFT: vx_ += CHAR_SPEED; break;
case SDLK_RIGHT: vx_ -= CHAR_SPEED; break;
case SDLK_UP: vy_ = 0; break;// += CHAR_SPEED; break;
case SDLK_DOWN: vy_ = 0; break;// -= CHAR_SPEED; break;
case SDLK_LEFT: vx_ = 0; break;// += CHAR_SPEED; break;
case SDLK_RIGHT: vx_ = 0; break;// -= CHAR_SPEED; break;
}
if(!turnTimer.isPaused() && vy_ == 0 && vx_ == 0) {
//printf("Pause\n");
printf("Pause\n");
turnTimer.pause();
}
}
@ -78,6 +78,22 @@ void Character::render(SDL_Rect camera) {
sprite_.render(x_ - camera.x, y_ - camera.y);
}
/*
* Beware ye who enter here; raw SDL calls roam free
*/
void Character::renderHUD() {
double proportionTimeLeft = 1 - turnTimer.getTicks()/(double)(10*speed*MAX_FPS/TICKS_PER_FRAME);
//printf("Proportion time left is %d/%d, computed as %f\n",turnTimer.getTicks(),10*speed*MAX_FPS/TICKS_PER_FRAME,proportionTimeLeft);
SDL_Rect moveTimeOutline = {S_W/10,8*S_H/10,8*S_W/10,S_H/10};
int barWidth = proportionTimeLeft*8*S_W/10;
SDL_Rect moveTimeFill = {S_W/10,8*S_H/10,barWidth,S_H/10};
SDL_SetRenderDrawColor(renderer,0xFF,0x00,0xFF,0xFF); //magenta
SDL_RenderDrawRect(renderer,&moveTimeOutline);
SDL_RenderFillRect(renderer,&moveTimeFill);
SDL_SetRenderDrawColor(renderer,0xFF,0xFF,0xFF,0xFF); //white
}
SDL_Rect Character::getCamera() {
return camera_;
}

1
app/action/Character.h

@ -53,6 +53,7 @@ public:
void move(Quad*);
void render(SDL_Rect);
void renderHUD();
bool isTurn() { return turnTimer.getTicks() < 10*speed*MAX_FPS/TICKS_PER_FRAME; };
void resetTurn() {

4
app/action/Map.cpp

@ -128,10 +128,10 @@ void Quad::reveal(int x, int y, int vision) {
for(int dy = -vision; dy < vision; ++dy) {
ry = y+dy;
if(rx < 0 || ry < 0 || rx >= L_W || ry >= L_H){
printf("Reveal out of bounds\n");
//printf("Reveal out of bounds\n");
} else {
lookup(rx,ry)->discovered = true;
printf("Revealed (%d,%d)\n",rx,ry);
//printf("Revealed (%d,%d)\n",rx,ry);
}
}
}

BIN
app/action/action

1
app/action/main.cpp

@ -85,6 +85,7 @@ int main(int argc, char** argv) {
map.render(active->getCamera());
active->render(active->getCamera());
active->renderHUD();
for(auto itr = characters.begin(); itr != characters.end(); ++itr) {
if(itr != active) {

Loading…
Cancel
Save