rendered paste body#include <allegro.h>#include <string>#include <vector>#include "ent.h"#include "phys.h"#include "main.h"using namespace std;const int fire_rate = CLOCKS_PER_SEC * 3 / 2;const int projectile_speed = 4;ent::ent(void) { string directions[8] = {"n","ne","e","se","s","sw","w","nw"}; string temp; for (int i = 0; i<8; i++) { for (int b = 0; b<8; b++) { temp = "graphics/archer/walking_"+directions[i]+"000"; temp+=char('0'+b); temp+=".tga"; moving[0][i][b] = load_tga( temp.c_str(), NULL); animations[0][i].push_back(load_tga( temp.c_str(), NULL)); temp = "graphics/archer/running_"+directions[i]+"000"; temp+=char('0'+b); temp+=".tga"; moving[1][i][b] = load_tga( temp.c_str(), NULL); temp = "graphics/archer/paused_"+directions[i]+"000"; temp+=char('0'+b); temp+=".tga"; paused[i][b] = load_tga( temp.c_str(), NULL); } temp = "graphics/archer/paused_"+directions[i]+"0008.tga"; paused[i][8] = load_tga( temp.c_str(), NULL); for (int b = 0; b<10; b++) { temp = "graphics/archer/shooting_"+directions[i]+"000"; temp+=char('0'+b); temp+=".tga"; shooting[i][b] = load_tga( temp.c_str(), NULL); } for (int b = 0; b<3; b++) { temp = "graphics/archer/shooting_"+directions[i]+"001"; temp+=char('0'+b); temp+=".tga"; shooting[i][b+10] = load_tga( temp.c_str(), NULL); } } dir = 2; pos.x = 10; pos.y = 10; animation.locked = false; int shootcord_temp[8][2] = {{53,19},{49,54},{55,42},{35,37},{38,44},{38,29},{0,26},{0,0}}; for (int i = 0; i<8; i++) {shootcord[i][0] = shootcord_temp[i][0];shootcord[i][1] = shootcord_temp[i][1];}}int ent::check_movement(void) { int running = 0; if (key_shifts & KB_SHIFT_FLAG) running = 1; if (key[KEY_UP]) { pos.y-=1+running; dir = 0; if (key[KEY_RIGHT]) { pos.x+=1+running; dir = 1; } else if (key[KEY_LEFT]) { pos.x-=1+running; dir = 7; } } else if (key[KEY_DOWN]) { pos.y+=1+running; dir=4; if (key[KEY_RIGHT]) { pos.x+=1+running; dir = 3; } else if (key[KEY_LEFT]) { pos.x-=1+running; dir = 5; } } else if (key[KEY_RIGHT]) { pos.x+=1+running; dir = 2; } else if (key[KEY_LEFT]) { pos.x-=1+running; dir = 6; } else { return 2; } return running;}void ent::check(void) { if (animation.locked == false) animation.cur = check_movement(); if (animation.locked == false && key[KEY_SPACE]) animation.cur = 3; if (animation.prev != animation.cur) animation.frame = 0; if (animation.cur == 3) { animation.locked = true; draw_trans_sprite( buffer, shooting[dir][int(animation.frame/fast_animation_speed)], pos.x, pos.y); if (animation.frame == 5*fast_animation_speed) { int Y_FACTOR = 0; if (dir == 7 || dir == 0 || dir == 1) Y_FACTOR = -1; else if (dir == 3 || dir == 4 || dir == 5) Y_FACTOR = 1; int X_FACTOR = 0; if (dir == 1 || dir == 2 || dir == 3) X_FACTOR = 1; else if (dir == 5 || dir == 6 || dir == 7) X_FACTOR = -1; bullets.push_back(bullet(pos.x+shootcord[dir][0],pos.y+shootcord[dir][1],projectile_speed*X_FACTOR,projectile_speed*Y_FACTOR, dir)); } animation.frame++; if (animation.frame == 13*fast_animation_speed) { animation.locked = false; animation.frame = 0; } } else if (animation.cur == 2) { draw_trans_sprite( buffer, paused[dir][int(animation.frame/animation_speed)], pos.x, pos.y); animation.frame++; if (animation.frame == 9*animation_speed) animation.frame = 0; } else { draw_trans_sprite( buffer, moving[animation.cur][dir][int(animation.frame/animation_speed)], pos.x, pos.y); animation.frame++; if (animation.frame == 8*animation_speed) animation.frame = 0; } for (int i = 0; i<bullets.size();i++) { if (bullets[i].move()==true) bullets.erase(bullets.begin(),bullets.begin()+i); } animation.prev = animation.cur;}