All pastes #1282151 Raw Edit

ent.cpp

public cpp v1 · immutable
#1282151 ·published 2008-12-11 00:31 UTC
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);			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;		shootcord[0][0]=53;	shootcord[1][0]=19;	shootcord[0][1]=49;	shootcord[1][1]=54;	shootcord[0][2]=55;	shootcord[1][2]=42;	shootcord[0][3]=35;	shootcord[1][3]=37;	shootcord[0][4]=38;	shootcord[1][4]=44;	shootcord[0][5]=38;	shootcord[1][5]=29;	shootcord[0][6]=0;	shootcord[1][6]=26;	shootcord[0][7]=0;	shootcord[1][7]=0;}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[0][dir],pos.y+shootcord[1][dir],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;}