Ulrik04

Ulrik04

Name: Ulrik Flænø Damm
Age: 17
Location: Denmark, Hillerød
Description: #include "SDL/SDL.h" #include "SDL/SDL_image.h" #include "SDL/SDL_ttf.h" #include "headers/timer.h" #include "headers/func.h" #include <string> #include <sstream> #include <vector> #include <math.h> ///////////////////////INITIALIZATION/////////////////////// class shop{ public: shop(int x, int y, int id); void paint(); int get_x(); int get_y(); int get_id(); private: int m_x, m_y, m_id; }; class person{ public: person(int x, int y); void paint(); bool additem(int itemid); bool rmvitem(int itemid); bool rmvitem_place(int place); void move(int direc, int speed = 3); void move(int x, int y, bool abs); int getitem(int place); int getwep(); bool checkcol(int direc, int speed); void checkcol(); int get_x(); int get_y(); int get_empty_spaces(); int get_hp(); void set_hp(int hp_inp, bool rel); bool attack(); void attackcountdown(); void updatevalues(); private: int m_x, m_y, dir, gotwep, hp, m_attackspeed, m_state, m_power, m_attackcount; int items[5]; }; class bone{ public: bone(int x, int y, int id); void paint(); int get_x(); int get_y(); int get_id(); private: int m_x, m_y, m_id; }; class block{ public: block(int x, int y, int width, int height); int get_x(); int get_y(); int get_w(); int get_h(); private: int m_x, m_y, m_width, m_height; }; class human{ public: human(int x, int y, int dir, std::string say, int room); int get_x(); int get_y(); int get_dir(); std::string talk(); void paint(); void setTText(std::string text); private: int m_x, m_y, m_dir; std::string m_say; }; class object{ public: object(int x, int y, int width, int height, int sprite, bool solid, int room, int d); int get_x(); int get_y(); int get_w(); int get_h(); int get_sprite(); int get_room(); bool get_solid(); void paint(); private: int m_x, m_y, m_width, m_height, m_sprite, m_room; bool m_solid; }; class enemy{ public: enemy(int x, int y, int hp, int stength, int sprite, int dir, int speed, int attackspeed, int room); int get_x(); int get_y(); int get_total_hp(); int get_current_hp(); int get_strength(); int get_sprite(); int get_state(); int get_room(); int get_dir(); void set_hp(int hp, bool rel); void paint(); void move(person** pers); private: int m_x, m_y, m_state, m_total_hp, m_hp, m_str, m_sprite, m_room, m_dir, m_speed, m_attackcount, m_attackspeed, m_id; }; SDL_Surface* load_image(std::string file); void apply_surface(int x, int y, SDL_Surface* source, SDL_Surface* dest); bool init(); bool load_files(); void clean_up(); void changeroom(int from, int to, person* pers); ///////////////////////GLOBAL VARIABLES/////////////////////// const int SCREEN_WIDTH = 640; const int SCREEN_HEIGHT = 480; const int SCREEN_BPP = 32; SDL_Surface* screen = NULL; SDL_Surface* background = NULL; SDL_Surface* man[3][4] = {{NULL, NULL, NULL, NULL}, {NULL, NULL, NULL, NULL}, {NULL, NULL, NULL, NULL}}; SDL_Surface* status = NULL; SDL_Surface* spr_shop = NULL; SDL_Surface* status_back = NULL; SDL_Surface* hpbar = NULL; SDL_Surface* ws = NULL; SDL_Surface* sprites[] = {NULL, NULL, NULL, NULL}; SDL_Surface* hence = NULL; SDL_Surface* message = NULL; SDL_Surface* infomsg = NULL; SDL_Surface* blackfade = NULL; SDL_Surface* woody = NULL; SDL_Surface* spr_bone = NULL; SDL_Surface* moneymsg = NULL; SDL_Surface* shopbox = NULL; SDL_Surface* shopmsg[] = {NULL, NULL, NULL, NULL}; SDL_Surface* house = NULL; SDL_Surface* houseinside = NULL; SDL_Surface* talkmsg = NULL; SDL_Surface* object_spr[] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}; SDL_Surface* enemy_spr[1][2][4] = {{{NULL, NULL, NULL, NULL}, {NULL, NULL, NULL, NULL}}}; SDL_Event event; TTF_Font* adventure = NULL; TTF_Font* adventure_big = NULL; SDL_Color c_black = {0, 0, 0}; SDL_Color c_blue = {50, 50, 255}; SDL_Color c_white = {250, 250, 250}; // 0 1 2 3 4 5 int backgrounds[] = {0, 0, 1, 2, 2, 0}; int shop_rooms[] = {0, 0, 1, 0, 0, 0}; std::vector<shop*> shops; std::vector<int> shoprooms; std::vector<int> shoptargets; std::vector<SDL_Surface**> shopsprites; std::vector<block*> blocks; std::vector<int> blockrooms; std::vector<human*> humans; std::vector<int> humanrooms; std::vector<bone*> bones; std::vector<int> bonerooms; std::vector<object*> objects; std::vector<enemy*> enemies; std::vector<int> depth; // 1 2 3 4 const std::string items_n[] = {"sword", "shield", "potion", "bone"}; const int items_value[] = { -1, -1, 5, 2 }; const int GAME_SPEED = 40; int frame; Timer fps; const int RIGHT = 0, UP = 1, LEFT = 2, DOWN = 3; int money = 0; int infomsg_count = -1; int roomchange = -1; int fadenr = -1; int roomchangeto = -1; int spaceroomtarget = -1; int atitem = -1; int atitem_id = -1; int room = 0; int shopstate = -1; bool inbattle = false; // [shopstate][message] std::string shop_msg[3][4] = {{"", "", "", ""}, {"", "", "", ""}, {"", "", "", ""}}; std::string caption = "Totally RPG FTW (alpha)"; std::string message_str = ""; std::string infomsg_str = ""; std::string talkmsg_str = ""; int maxval, minval; ///////////////////////GLOBAL FUNCTIONS/////////////////////// SDL_Surface* load_image(std::string file){ SDL_Surface* loadedImage = NULL; SDL_Surface* optimizedImage = NULL; loadedImage = IMG_Load(file.c_str()); if(loadedImage != NULL){ optimizedImage = SDL_DisplayFormat(loadedImage); SDL_FreeSurface(loadedImage); if(optimizedImage != NULL){ Uint32 colorkey = SDL_MapRGB(optimizedImage->format, 0xFF, 0xFF, 0xFF); SDL_SetColorKey(optimizedImage, SDL_SRCCOLORKEY, colorkey); } } return optimizedImage; } void apply_surface(int x, int y, SDL_Surface* source, SDL_Surface* dest){ SDL_Rect offset; offset.x = x; offset.y = y; SDL_BlitSurface(source, NULL, dest, &offset); } bool init(){ if(SDL_Init(SDL_INIT_EVERYTHING) == -1){ return false; } screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT+150, SCREEN_BPP, SDL_SWSURFACE); if(screen == NULL){ return false; } if(TTF_Init() == -1){ return false; } SDL_WM_SetCaption(caption.c_str(), NULL); return true; } bool load_files(){ background = load_image("images/background.png"); status = load_image("images/status.png"); spr_shop = load_image("images/shop.png"); status_back = load_image("images/status_back.png"); hpbar = load_image("images/hpbar.png"); sprites[0] = load_image("images/sword.png"); sprites[1] = load_image("images/shield.png"); sprites[2] = load_image("images/ws.png"); sprites[3] = load_image("images/bone.png"); ws = load_image("images/ws.png"); hence = load_image("images/hence.png"); blackfade = load_image("images/blackfade.png"); woody = load_image("images/woody.png"); spr_bone = load_image("images/bone.png"); shopbox = load_image("images/shopbox.png"); house = load_image("images/house.png"); houseinside = load_image("images/houseinside.png"); object_spr[0] = load_image("images/plant.png"); object_spr[1] = load_image("images/table.png"); object_spr[2] = load_image("images/chair0.png"); object_spr[3] = load_image("images/chair1.png"); object_spr[4] = load_image("images/chair2.png"); object_spr[5] = load_image("images/chair3.png"); object_spr[6] = load_image("images/carpet.png"); object_spr[7] = load_image("images/cooking.png"); object_spr[8] = load_image("images/bed.png"); object_spr[9] = load_image("images/mountain.png"); object_spr[10] = load_image("images/tree.png"); for(int o = 0; o <= enemies.size()-1; o++){ for(int m = 0; m <= 1; m++){ for(int g = 0; g <= 3; g++){ std::stringstream s; s << "images/enemy" << o+1 << m+1 << g+1 << ".png"; enemy_spr[o][m][g] = load_image(s.str()); if(enemy_spr[o][m][g] == NULL){ enemy_spr[o][m][g] = load_image("images/enemy111.png"); } } } } for(int i = 0; i <= 2; i++){ for(int j = 0; j <= 3; j++){ std::stringstream n; n << "images/man" << i << j << ".png"; man[i][j] = load_image(n.str()); if(man[i][j] == NULL){ man[i][j] = load_image("images/man00.png"); } } } adventure = TTF_OpenFont("fonts/adventure.ttf", 15); adventure_big = TTF_OpenFont("fonts/adventure.ttf", 20); if(background == NULL){ return false; } return true; } void clean_up(){ SDL_FreeSurface(background); SDL_FreeSurface(status); SDL_FreeSurface(spr_shop); SDL_FreeSurface(status_back); SDL_FreeSurface(hpbar); SDL_FreeSurface(sprites[0]); SDL_FreeSurface(sprites[1]); SDL_FreeSurface(ws); SDL_FreeSurface(hence); SDL_FreeSurface(blackfade); SDL_FreeSurface(woody); SDL_FreeSurface(spr_bone); SDL_FreeSurface(shopbox); SDL_FreeSurface(house); for(int i = 0; i <= 1; i++){ for(int j = 0; j <= 3; j++){ SDL_FreeSurface(man[i][j]); } } SDL_FreeSurface(message); TTF_CloseFont(adventure); TTF_Quit(); SDL_Quit(); } void changeroom(int from, int to, person** pers){ switch(from){ case 0: switch(to){ case 1: (*pers)->move(SCREEN_WIDTH-48, SCREEN_HEIGHT/2, true); break; case 2: (*pers)->move(300, 400, true); shop_msg[0][0] = "Welcome to the shop :D"; shop_msg[0][1] = "Press the shortcut key to interact"; shop_msg[0][2] = "Buy stuff (B)"; shop_msg[0][3] = "Sell items (S)"; shop_msg[1][0] = "To sell an item, click it's number on the keyboard numbers"; shop_msg[1][1] = "The items number is it's place (eg first item is 1)"; shop_msg[1][2] = "You will get money when selling stuff ^_^"; shop_msg[1][3] = "To go back, just press (Q)"; shop_msg[2][0] = "You can currently buy this:"; shop_msg[2][1] = "Sword and shield"; shop_msg[2][2] = "Cost: 10$ (and requires 2 empty spaces in inventory)"; shop_msg[2][3] = "to buy click (C) to go back click (Q)"; shopstate = 0; break; case 3: (*pers)->move(300, 400, true); break; case 4: (*pers)->move(300, 400 ,true); break; } break; case 1: switch(to){ case 0: (*pers)->move(16, SCREEN_HEIGHT/2, true); break; case 5: (*pers)->move(SCREEN_WIDTH-48, SCREEN_HEIGHT/2, true); break; } break; case 2: shopstate = -1; switch(to){ case 0: (*pers)->move(260, 375, true); break; } break; case 3: switch(to){ case 0: (*pers)->move(415, 220, true); break; } break; case 4: switch(to){ case 0: (*pers)->move(120, 220, true); break; } break; } room = to; } void createbone(int x, int y, int room){ bones.push_back(new bone(x, y, bones.size())); bonerooms.push_back(room); } int human_near(int x, int y){ for(int i = 0; i <= humans.size()-1; i++){ //int xdiff = abs(humans[i]->get_x()+16-x); //int ydiff = abs(humans[i]->get_y()+16-y); //int dist = sqrt(xdiff*xdiff+ydiff*ydiff); //if(dist < 48){ // return i; //} if(sqrt(pow(abs(humans[i]->get_x()+16-x),2)+pow(abs(humans[i]->get_y()+16-y),2)) < 48 && humanrooms[i] == room){ return i; } } return -1; } //////////////////////////////////////////////CLASSES////////////////////////////////////////////// person::person(int x, int y): m_x(x), m_y(y){ dir = 3; gotwep = 0; for(int i = 0; i <= 4; i++){ items[i] = -1; } hp = 100; m_attackspeed = 0; m_state = 0; m_power = 0; m_attackcount = 0; } void person::paint(){ apply_surface(m_x, m_y, man[gotwep==1?m_state+1:0][dir], screen); for(int i = 0; i <= hp; i++){ apply_surface(25+i*3, SCREEN_HEIGHT+50, hpbar, screen); } } bool person::additem(int itemid){ for(int i = 0; i <= 4; i++){ if(items[i] == -1){ items[i] = itemid; if(itemid == 1){ gotwep = 1; } return true; } } return false; } bool person::rmvitem(int itemid){ for(int i = 0; i <= 4; i++){ if(items[i] == itemid){ if(itemid == 1){ gotwep = 0; } items[i] = -1; return true; } } return false; } bool person::rmvitem_place(int place){ if(items[place] != -1){ if(items[place] == 1){ gotwep = 0; } items[place] = -1; return true; } return false; } bool person::checkcol(int direc, int speed){ switch(direc){ case 0: for(int j = 0; j <= blocks.size()-1; j++){ if(blocks[j] != NULL){ if(blocks[j]->get_x() <= m_x+speed+32 && blocks[j]->get_x()+blocks[j]->get_w() >= m_x+speed && blocks[j]->get_y()-32 <= m_y && blocks[j]->get_y()+blocks[j]->get_h() >= m_y && blockrooms[j] == room){ return true; } } } for(int i = 0; i <= shops.size()-1; i++){ if(shops[i] != NULL){ if(shops[i]->get_x() <= m_x+speed+32 && shops[i]->get_x()+64 >= m_x+speed && shops[i]->get_y()-32 <= m_y && shops[i]->get_y()+64 >= m_y && shoprooms[i] == room){ return true; } } } if(room == 0 && m_x > SCREEN_WIDTH-64){ return true; } if((room == 2 || room == 3 || room == 4) && m_x > SCREEN_WIDTH-50-32){ return true; } break; case 1: for(int j = 0; j <= blocks.size()-1; j++){ if(blocks[j] != NULL){ if(blocks[j]->get_y()+blocks[j]->get_h() >= m_y-speed && blocks[j]->get_y() <= m_y-speed && blocks[j]->get_x()-32 <= m_x && blocks[j]->get_x()+blocks[j]->get_w() >= m_x && blockrooms[j] == room){ return true; } } } for(int i = 0; i <= shops.size()-1; i++){ if(shops[i] != NULL){ if(shops[i]->get_y()+64 >= m_y-speed && shops[i]->get_y() <= m_y-speed && shops[i]->get_x()-32 <= m_x && shops[i]->get_x()+64 >= m_x && shoprooms[i] == room){ return true; } } } if(room == 0 && m_y < 32){ return true; } if(room == 2 && m_y < 360){ return true; } if((room == 3 || room == 4) && m_y < 32){ return true; } break; case 2: for(int j = 0; j <= blocks.size()-1; j++){ if(blocks[j] != NULL){ if(blocks[j]->get_x()+blocks[j]->get_w() >= m_x-speed && blocks[j]->get_x() <= m_x-speed && blocks[j]->get_y()-32 <= m_y && blocks[j]->get_y()+blocks[j]->get_h() >= m_y && blockrooms[j] == room){ return true; } } } for(int i = 0; i <= shops.size()-1; i++){ if(shops[i] != NULL){ if(shops[i]->get_x()+64 >= m_x-speed && shops[i]->get_x() <= m_x-speed && shops[i]->get_y()-32 <= m_y && shops[i]->get_y()+64 >= m_y && shoprooms[i] == room){ return true; } } } if((room == 2 || room == 3 || room == 4) && m_x < 50){ return true; } break; case 3: for(int j = 0; j <= blocks.size()-1; j++){ if(blocks[j] != NULL){ if(blocks[j]->get_y() <= m_y+speed+32 && blocks[j]->get_y()+blocks[j]->get_h() >= m_y+speed && blocks[j]->get_x()-32 <= m_x && blocks[j]->get_x()+blocks[j]->get_w() >= m_x && blockrooms[j] == room){ return true; } } } for(int i = 0; i <= shops.size()-1; i++){ if(shops[i] != NULL){ if(shops[i]->get_y() <= m_y+speed+32 && shops[i]->get_y()+64 >= m_y+speed && shops[i]->get_x()-32 <= m_x && shops[i]->get_x()+64 >= m_x && shoprooms[i] == room){ return true; } } } if(room == 0 && m_y > SCREEN_HEIGHT-64){ return true; } if((room == 2 || room == 3 || room == 4) && m_y > SCREEN_HEIGHT-32-32){ return true; } break; } return false; } void person::checkcol(){ spaceroomtarget = -1; atitem = -1; for(int i = 0; i <= shops.size()-1; i++){ if(shops[i] != NULL){ if(m_x+32 > shops[i]->get_x() && m_x < shops[i]->get_x()+64 && m_y > shops[i]->get_y()+64 && m_y < shops[i]->get_y()+64+16 && shoprooms[i] == room){ message_str = "Space to go"; spaceroomtarget = shoptargets[i]; } } } if(m_x < 32 && room == 0){ message_str ="Space to go"; spaceroomtarget = 1; }else if(m_x > SCREEN_WIDTH-64 && room == 1){ message_str = "Space to go"; spaceroomtarget = 0; }else if(m_x > 280 && m_x < 360 && m_y > 400 && (room == 2 || room == 3 || room == 4)){ message_str = "Space to go"; spaceroomtarget = 0; }else if(m_x < 32 && room == 1){ message_str = "Space to go"; spaceroomtarget = 5; }else if(human_near(m_x, m_y) != -1){ if(humanrooms[human_near(m_x, m_y)] == room){ message_str = "Space to talk"; } } for(int j = 0; j <= bones.size()-1; j++){ if(bones[j] != NULL){ if(m_x+16 > bones[j]->get_x() && m_x+16 < bones[j]->get_x()+32 && m_y+16 > bones[j]->get_y() && m_y+16 < bones[j]->get_y()+32 && bonerooms[j] == room){ atitem = 3; message_str = "Space to pick up"; spaceroomtarget = -1; atitem_id = bones[j]->get_id(); } } } } void person::move(int x, int y, bool abs){ m_x = x; m_y = y; } void person::move(int direc, int speed){ talkmsg_str = ""; dir = direc; switch(direc){ case 0: if(m_x < SCREEN_WIDTH-32 && !checkcol(direc, speed)){ m_x += speed; } break; case 1: if(m_y > 0 && !checkcol(direc, speed)){ m_y -= speed; } break; case 2: if(m_x > 0 && !checkcol(direc, speed)){ m_x -= speed; } break; case 3: if(m_y < SCREEN_HEIGHT-32 && !checkcol(direc, speed)){ m_y += speed; } break; } } int person::getitem(int place){ return items[place]; } int person::getwep(){ return gotwep; } int person::get_x(){ return m_x; } int person::get_y(){ return m_y; } int person::get_empty_spaces(){ int spaces = 0; for(int i = 0; i <= 4; i++){ if(getitem(i) == -1){ spaces++; } } return spaces; } int person::get_hp(){ return hp; } void person::set_hp(int hp_inp, bool rel){ if(rel == true){ hp += hp_inp; }else{ hp = hp_inp; } } bool person::attack(){ if(m_attackcount != 0){ return false; } enemy** target = NULL; int dist = 50; for(int i = 0; i <= enemies.size()-1; i++){ if(func_dist(m_x, m_y, enemies[i]->get_x(), enemies[i]->get_y()) < dist){ dist = func_dist(m_x, m_y, enemies[i]->get_x(), enemies[i]->get_y()); target = &enemies[i]; } } if(target == NULL){ return false; } (*target)->set_hp(-5, true); m_attackcount = m_attackspeed; return true; } void person::attackcountdown(){ if(m_attackcount > 0){ m_attackcount--; } } void person::updatevalues(){ if(gotwep == 1){ m_attackspeed = 10; m_power = 10; } } //shop shop::shop(int x, int y, int id): m_x(x), m_y(y), m_id(id){ //do nothing } void shop::paint(){ if(room == shoprooms[m_id]){ apply_surface(m_x, m_y, *shopsprites[m_id], screen); } } int shop::get_x(){ return m_x; } int shop::get_y(){ return m_y; } int shop::get_id(){ return m_id; } //bone bone::bone(int x, int y, int id): m_x(x), m_y(y), m_id(id){ //do nothing } void bone::paint(){ if(room == bonerooms[m_id]){ apply_surface(m_x, m_y, spr_bone, screen); } } int bone::get_x(){ return m_x; } int bone::get_y(){ return m_y; } int bone::get_id(){ return m_id; } //block block::block(int x, int y, int width, int height): m_x(x), m_y(y), m_height(height), m_width(width){ //do nothing } int block::get_x(){ return m_x; } int block::get_y(){ return m_y; } int block::get_w(){ return m_width; } int block::get_h(){ return m_height; } //human human::human(int x, int y, int dir, std::string say, int room): m_x(x), m_y(y), m_dir(dir), m_say(say){ blocks.push_back(new block(x, y, 32, 32)); blockrooms.push_back(room); humanrooms.push_back(room); } int human::get_x(){ return m_x; } int human::get_y(){ return m_y; } int human::get_dir(){ return m_dir; } std::string human::talk(){ return m_say; } void human::paint(){ apply_surface(m_x, m_y, man[0][m_dir], screen); } void human::setTText(std::string text){ m_say = text; } object::object(int x, int y, int width, int height, int sprite, bool solid, int room, int d): m_x(x), m_y(y), m_width(width), m_height(height), m_sprite(sprite), m_solid(solid), m_room(room){ if(solid == true){ blocks.push_back(new block(x, y, width, height)); blockrooms.push_back(room); } depth.push_back(d); } int object::get_x(){ return m_x; } int object::get_y(){ return m_y; } int object::get_w(){ return m_width; } int object::get_h(){ return m_height; } int object::get_sprite(){ return m_sprite; } int object::get_room(){ return m_room; } bool object::get_solid(){ return m_solid; } void object::paint(){ apply_surface(m_x, m_y, object_spr[m_sprite], screen); } enemy::enemy(int x, int y, int hp, int stength, int sprite, int dir, int speed, int attackspeed, int room): m_x(x), m_y(y), m_total_hp(hp), m_hp(hp), m_str(stength), m_sprite(sprite), m_room(room), m_dir(dir), m_speed(speed), m_attackspeed(attackspeed){ m_state = 0; m_attackcount = 0; m_id = enemies.size()-1; } int enemy::get_x(){ return m_x; } int enemy::get_y(){ return m_y; } int enemy::get_total_hp(){ return m_total_hp; } int enemy::get_current_hp(){ return m_hp; } int enemy::get_strength(){ return m_str; } int enemy::get_sprite(){ return m_sprite; } int enemy::get_state(){ return m_state; } int enemy::get_room(){ return m_room; } int enemy::get_dir(){ return m_dir; } void enemy::paint(){ apply_surface(m_x, m_y, enemy_spr[m_sprite][m_state][m_dir], screen); } void enemy::move(person** pers){ m_state = 0; if(m_attackcount > 0){ m_attackcount--; } int pers_x = (*pers)->get_x()+16; int pers_y = (*pers)->get_y()+16; double dist = (double)(sqrt(pow(fabs(m_x-pers_x),2)+pow(fabs(m_y-pers_y),2))); if(dist < 200.0 && dist > 50){ //calculate double xdif = (double)(pers_x-m_x); double ydif = (double)(pers_y-m_y); double V = asin(xdif/dist); double U = 90-V; double xinc = sin(V)*(m_speed/sin(90)); double yinc = sin(U)*(m_speed/sin(90)); //move m_x += (int)(xinc); if(pers_y < m_y){ m_y -= (int)(yinc); }else{ m_y += (int)(yinc); } //stay inside room if(m_x < 0){ m_x = 0; }else if(m_x > SCREEN_WIDTH-32){ m_x = SCREEN_WIDTH-32; } if(m_y < 0){ m_y = 0; }else if(m_y > SCREEN_HEIGHT-32){ m_y = SCREEN_HEIGHT-32; } } if(dist < 50.0){ //attack! if(m_attackcount == 0){ m_state = 1; m_attackcount = m_attackspeed; (*pers)->set_hp(-m_str, true); } } if(dist > 200.0){ m_attackcount = 0; } } void enemy::set_hp(int hp, bool rel){ if(rel == true){ m_hp += hp; }else{ m_hp = hp; } if(m_hp <= 0){ delete enemies[m_id]; enemies[m_id] = NULL; } } //////////////////////////////////////////////MAIN FUNCTION////////////////////////////////////////////// int main(int argc, char* args []){ //init bool quit = false; if(init() == false){ return 1; } //CREATE OBJECTS shops.push_back(new shop(250, 300, shops.size())); shoprooms.push_back(0); shoptargets.push_back(2); shopsprites.push_back(&spr_shop); shops.push_back(new shop(400, 150, shops.size())); shoprooms.push_back(0); shoptargets.push_back(3); shopsprites.push_back(&house); shops.push_back(new shop(100, 150, shops.size())); shoprooms.push_back(0); shoptargets.push_back(4); shopsprites.push_back(&house); createbone(100, 100, 1); createbone(400, 200, 1); createbone(234, 323, 1); createbone(500, 150, 0); createbone(375, 100, 3); blocks.push_back(new block(0, 0, 0, 0)); blockrooms.push_back(1); humans.push_back(new human(200, 400, 3, "I'm saving up for a book I want", 2)); humans.push_back(new human(300, 280, 3, "Welcome ^_^", 2)); humans.push_back(new human(450, 220, 3, "It's finally summer :)", 0)); humans.push_back(new human(16, 275, 0, "This way leads out of town. It could be dangerous!", 0)); humans.push_back(new human(320, 100, 0, "You can take my bone if you want", 3)); humans.push_back(new human(75, 320, 2, "I really likes my new kitchen ^_^", 3)); humans.push_back(new human(200, 400, 0, "Someday, I'll travel around the world", 4)); humans.push_back(new human(100, 100, 4, "I'm training every day, so I can protect the village", 4)); humans.push_back(new human(464, 107, 3, "....", 4)); objects.push_back(new object(100-32, 150, 32, 32, 0, true, 0, 0)); objects.push_back(new object(100-32, 150+32, 32, 32, 0, true, 0, 0)); objects.push_back(new object(165, 150, 32, 32, 0, true, 0, 0)); objects.push_back(new object(165, 150+32, 32, 32, 0, true, 0, 0)); objects.push_back(new object(400, 300, 64, 32, 1, true, 3, 0)); objects.push_back(new object(400, 300-32, 32, 32, 5, true, 3, 0)); objects.push_back(new object(400+32, 300-32, 32, 32, 5, true, 3, 0)); objects.push_back(new object(400-32, 300, 32, 32, 2, true, 3, 0)); objects.push_back(new object(400+64, 300, 32, 32, 4, true, 3, 0)); objects.push_back(new object(400, 300+32, 32, 32, 3, true, 3, 0)); objects.push_back(new object(400+32, 300+32, 32, 32, 3, true, 3, 0)); objects.push_back(new object(285, 350, 64, 96, 6, false, 3, 0)); objects.push_back(new object(55, 300, 32, 128, 7, true, 3, 0)); objects.push_back(new object(55, 75, 32, 64, 8, true, 3, 0)); objects.push_back(new object(130, 75, 32, 64, 8, true, 3, 0)); objects.push_back(new object(64, 64, 96, 64, 6, true, 4, 0)); objects.push_back(new object(128, 64, 96, 64, 6, true, 4, 0)); objects.push_back(new object(400, 300-32-200, 32, 32, 5, true, 4, 0)); objects.push_back(new object(400+32, 300-32-200, 32, 32, 5, true, 4, 0)); objects.push_back(new object(400-32, 300-200, 32, 32, 2, true, 4, 0)); objects.push_back(new object(400+64, 300-200, 32, 32, 5, true, 4, 0)); objects.push_back(new object(400, 300+32-200, 32, 32, 3, true, 4, 0)); objects.push_back(new object(400+32, 300+32-200, 32, 32, 3, true, 4, 0)); objects.push_back(new object(400, 300-200, 64, 32, 1, true, 4, 0)); //mountains objects.push_back(new object(-5, -10, 64, 64, 9, true, 1, 0)); objects.push_back(new object(50, 5, 64, 64, 9, true, 1, 0)); objects.push_back(new object(100, 30, 64, 64, 9, true, 1, 0)); objects.push_back(new object(200, 10, 64, 64, 9, true, 1, 0)); objects.push_back(new object(300, -10, 64, 64, 9, true, 1, -1)); objects.push_back(new object(400, 20, 64, 64, 9, true, 1, 0)); objects.push_back(new object(500, 0, 64, 64, 9, true, 1, 0)); objects.push_back(new object(600, 20, 64, 64, 9, true, 1, 0)); objects.push_back(new object(75, -40, 64, 64, 9, true, 1, -1)); objects.push_back(new object(150, -15, 64, 64, 9, true, 1, -1)); objects.push_back(new object(265, 0, 64, 64, 9, true, 1, 0)); objects.push_back(new object(340, 20, 64, 64, 9, true, 1, -1)); objects.push_back(new object(450, -20, 64, 64, 9, true, 1, -1)); objects.push_back(new object(560, 42, 64, 64, 9, true, 1, 1)); objects.push_back(new object(585, -15, 64, 64, 9, true, 1, -1)); //trees objects.push_back(new object(-10, 400, 32, 64, 10, true, 1, 1)); objects.push_back(new object(20, 440, 32, 64, 10, true, 1, 1)); objects.push_back(new object(50, 420, 32, 64, 10, true, 1, 1)); objects.push_back(new object(75, 451, 32, 64, 10, true, 1, 1)); objects.push_back(new object(107, 415, 32, 64, 10, true, 1, 1)); objects.push_back(new object(149, 450, 32, 64, 10, true, 1, 1)); objects.push_back(new object(175, 435, 32, 64, 10, true, 1, 1)); objects.push_back(new object(195, 430, 32, 64, 10, true, 1, 1)); objects.push_back(new object(225, 454, 32, 64, 10, true, 1, 1)); objects.push_back(new object(250, 440, 32, 64, 10, true, 1, 1)); objects.push_back(new object(275, 400, 32, 64, 10, true, 1, 1)); objects.push_back(new object(290, 430, 32, 64, 10, true, 1, 1)); objects.push_back(new object(337, 410, 32, 64, 10, true, 1, 1)); objects.push_back(new object(360, 431, 32, 64, 10, true, 1, 1)); objects.push_back(new object(400, 432, 32, 64, 10, true, 1, 1)); objects.push_back(new object(433, 445, 32, 64, 10, true, 1, 1)); objects.push_back(new object(465, 423, 32, 64, 10, true, 1, 1)); objects.push_back(new object(500, 400, 32, 64, 10, true, 1, 1)); objects.push_back(new object(534, 390, 32, 64, 10, true, 1, 1)); objects.push_back(new object(515, 430, 32, 64, 10, true, 1, 1)); objects.push_back(new object(543, 415, 32, 64, 10, true, 1, 1)); objects.push_back(new object(576, 440, 32, 64, 10, true, 1, 1)); objects.push_back(new object(600, 432, 32, 64, 10, true, 1, 1)); objects.push_back(new object(100, 350, 32, 64, 10, true, 1, 0)); objects.push_back(new object(400, 375, 32, 64, 10, true, 1, 0)); objects.push_back(new object(354, 360, 32, 64, 10, true, 1, 0)); objects.push_back(new object(120, 390, 32, 64, 10, true, 1, 0)); objects.push_back(new object(211, 214, 32, 64, 10, true, 1, 1)); objects.push_back(new object(350, 234, 32, 64, 10, true, 1, 1)); objects.push_back(new object(280, 300, 32, 64, 10, true, 1, 1)); objects.push_back(new object(490, 283, 32, 64, 10, true, 1, 1)); objects.push_back(new object(52, 344, 32, 64, 10, true, 1, 1)); enemies.push_back(new enemy(150, 150, 20, 3, 0, 3, 5, 15, 5)); person* pers = new person(200,200); if(load_files() == false){ return 1; } //first draw apply_surface(0, 0, background, screen); if(SDL_Flip(screen) == -1){ return 1; } //main loop while(quit == false){ fps.start(); //resetting message_str = ""; //quitting if the user wants to while(SDL_PollEvent(&event)){ switch(event.type){ case SDL_QUIT: quit = true; break; } } if(roomchange != -1){ if(roomchange == 0){ fadenr++; if(fadenr >= SCREEN_WIDTH/30/2){ roomchange = 1; changeroom(room, roomchangeto, &pers); } }else if(roomchange == 1){ fadenr--; if(fadenr <= 0){ roomchange = -1; fadenr = -1; roomchangeto = -1; } } } //keyboard input Uint8* keystates = SDL_GetKeyState(NULL); unsigned char numberkeys[] = {keystates[SDLK_1], keystates[SDLK_2], keystates[SDLK_3], keystates[SDLK_4], keystates[SDLK_5]}; if(roomchange == -1){ if(keystates[SDLK_LEFT]){ pers->move(LEFT); }else if(keystates[SDLK_RIGHT]){ pers->move(RIGHT); } if(keystates[SDLK_UP]){ pers->move(UP); }else if(keystates[SDLK_DOWN]){ pers->move(DOWN); } if(keystates[SDLK_ESCAPE]){ quit = true; } if(keystates[SDLK_RETURN]){ //infomsg_count = 250; //infomsg_str = "I lol'd"; //shops[1]->remove(); //delete shops[1]; //shops[1] = NULL; //pers->additem(3); //pers->additem(3); //pers->additem(3); //pers->additem(3); //pers->additem(3); pers->additem(0); pers->additem(1); } if(keystates[SDLK_SPACE]){ if(spaceroomtarget != -1 && roomchange == -1){ roomchange = 0; fadenr = 0; roomchangeto = spaceroomtarget; }else if(roomchange == 0){ //do nothing }else if(atitem != -1 && atitem_id != -1){ if(pers->additem(atitem) == true){ delete bones[atitem_id]; bones[atitem_id] = NULL; infomsg_count = 150; infomsg_str = "got item: "+items_n[atitem]+"!"; if(room == 3){ for(int i = 0; i <= humans.size()-1; i++){ if(humanrooms[i] == room && humans[i]->get_x() == 320){ humans[i]->setTText("Remember that you can sell bones"); } } } }else{ infomsg_count = 150; infomsg_str = "Inventory full!"; } }else if(human_near(pers->get_x(), pers->get_y()) != -1){ talkmsg_str = humans[human_near(pers->get_x(), pers->get_y())]->talk(); }else if(!pers->attack()){ //... } } if(keystates[SDLK_s]){ if(shopstate == 0){ shopstate = 1; } } if(keystates[SDLK_b]){ if(shopstate == 0){ shopstate = 2; } } if(keystates[SDLK_q]){ if(shopstate == 1 || shopstate == 2){ shopstate = 0; } } if(keystates[SDLK_c]){ if(shopstate == 2){ if(pers->getwep() == false){ if(pers->get_empty_spaces() >= 2){ if(money >= 10){ if(pers->additem(0) == true && pers->additem(1) == true){ money -= 10; infomsg_count = 100; infomsg_str = "got sword and shield!"; shopstate = 0; } }else{ infomsg_count = 100; infomsg_str = "not enough money!"; } }else{ infomsg_count = 100; infomsg_str = "not enough bagspace!"; } }else{ infomsg_count = 100; infomsg_str = "already have this!"; } } } } for(int i = 0; i <= 4; i++){ if(numberkeys[i]){ if(shopstate == 1){ if(pers->getitem(i) != -1){ int item = pers->getitem(i); if(items_value[item] != -1){ if(pers->rmvitem_place(i)){ money += items_value[item]; infomsg_count = 100; std::stringstream s; s << "sold " << items_n[item] << " to a value of " << items_value[item] << "$"; infomsg_str = s.str().c_str(); } }else{ infomsg_count = 100; infomsg_str = "can't sell this item!"; } } } } } //collision check pers->checkcol(); //random things to do pers->attackcountdown(); //move enemies for(int i = 0; i <= enemies.size()-1; i++){ if(enemies[i]->get_room() == room){ enemies[i]->move(&pers); } } //main draw loop if(inbattle == false){ switch(backgrounds[room]){ case 0: apply_surface(0, 0, background, screen); break; case 1: apply_surface(0, 0, woody, screen); break; case 2: apply_surface(0, 0, houseinside, screen); break; } //room independent drawings switch(room){ case 0: for(int i = 0; i <= SCREEN_WIDTH/32; i++){ apply_surface(i*32, 0, hence, screen); apply_surface(i*32, SCREEN_HEIGHT-32, hence, screen); } for(int j = 2; j <= SCREEN_HEIGHT/24; j++){ apply_surface(SCREEN_WIDTH-32, j*24-32, hence, screen); } break; case 2: apply_surface(20, 20, shopbox, screen); break; } for(int k = 0; k <= shops.size()-1; k++){ if(shops[k] != NULL){ if(shoprooms[k] == room){ shops[k]->paint(); } } } maxval = 0; minval = 0; for(int h = 0; h <= depth.size()-1; h++){ if(depth[h] > maxval){ maxval = depth[h]; }else if(depth[h] < minval){ minval = depth[h]; } } for(int g = minval; g <= maxval; g++){ for(int m = 0; m <= objects.size()-1; m++){ if(objects[m] != NULL){ if(depth[m] == g){ if(objects[m]->get_room() == room){ objects[m]->paint(); } } } } } for(int l = 0; l <= bones.size()-1; l++){ if(bones[l] != NULL){ if(bonerooms[l] == room){ bones[l]->paint(); } } } //enemies for(int o = 0; o <= enemies.size()-1; o++){ if(enemies[o] != NULL){ if(enemies[o]->get_room() == room){ enemies[o]->paint(); } } } //humans for(int i = 0; i <= humans.size()-1; i++){ if(humans[i] != NULL){ if(humanrooms[i] == room){ humans[i]->paint(); } } } //status box apply_surface(0, SCREEN_HEIGHT, status_back, screen); apply_surface(0, SCREEN_HEIGHT, status, screen); for(int i = 0; i <= 4; i++){ if(pers->getitem(i) != -1){ apply_surface(365+i*35, SCREEN_HEIGHT+53, ws, screen); apply_surface(365+i*35, SCREEN_HEIGHT+53, sprites[pers->getitem(i)], screen); } } //person pers->paint(); //text if(infomsg_count != -1){ infomsg_count--; infomsg = TTF_RenderText_Solid(adventure_big, infomsg_str.c_str(), c_blue); apply_surface(32, 575, infomsg, screen); } std::stringstream s; s << "$: " << money; moneymsg = TTF_RenderText_Solid(adventure, s.str().c_str(), c_white); apply_surface(550, 545, moneymsg, screen); if(message_str != "" && talkmsg_str == ""){ message = TTF_RenderText_Solid(adventure, message_str.c_str(), c_black); apply_surface(pers->get_x()-32, pers->get_y()+32, message, screen); } if(shop_rooms[room] == 1){ for(int i = 0; i <= 3; i++){ shopmsg[i] = TTF_RenderText_Solid(adventure_big, shop_msg[shopstate][i].c_str(), c_blue); apply_surface(50, 60+32*i, shopmsg[i], screen); } } if(talkmsg_str != "" && human_near(pers->get_x(), pers->get_y()) != -1){ talkmsg = TTF_RenderText_Solid(adventure, talkmsg_str.c_str(), c_black); apply_surface(humans[human_near(pers->get_x(), pers->get_y())]->get_x()-16, humans[human_near(pers->get_x(), pers->get_y())]->get_y()-16, talkmsg, screen); } }else{ } //fade if(fadenr != -1){ for(int i = 0; i <= fadenr; i++){ apply_surface(i*30, 0, blackfade, screen); apply_surface(SCREEN_WIDTH-(i+1)*30, 0, blackfade, screen); } } //end if(SDL_Flip(screen) == -1){ return 1; } //game speed delay frame++; if(fps.get_ticks() < 1000 / GAME_SPEED){ SDL_Delay((1000 / GAME_SPEED) - fps.get_ticks()); } } clean_up(); return 0; }
Registered: 30 January 2007

View Users Forum Profile

Embed:


Games By This Creator

  1. The Adventure Of Hank Vansail
    The Adventur...
    By Ulrik04
    • Rating: 3.4/5 Stars.
  2. Snake Example
    Snake Example
    By Ulrik04
    • Rating: 2.5/5 Stars.
  3. Sphere Break
    Sphere Break
    By Ulrik04
    • Rating: 3.52/5 Stars.
  4. Threat Of The Nazus
    Threat Of Th...
    By Ulrik04
    • Rating: 3.11111/5 Stars.
  5. Football Engine
    Football Engine
    By Ulrik04
    • Rating: 3.22222/5 Stars.
  6. Fireblast
    Fireblast
    By Ulrik04
    • Rating: 3.33333/5 Stars.

Reviews By This Member

  • Overall Score rating rating rating rating rating rating
  • Graphics rating rating rating rating rating rating
  • Sound rating rating rating rating rating rating
  • Gameplay rating rating rating rating rating rating
  • Story rating rating rating rating rating rating
  • Interface rating rating rating rating rating rating
Ulrik04

Mingitilla
Game: Mingitilla
Added: 24 February 2008
Created by: Ulrik04

Pros: Really nice graphic, fun gameplay, nice music
Cons: my head!! gah!

1 2 3 4 ... 7

Comments By This Member

View Comment

134 days ago Ulrik04 talked about the member NT

put a T in front of NT and put it all into some fireworks O_O

View Comment

134 days ago Ulrik04 talked about the member unknown gamer

Hi UG, I'm spamming your comments O_O luckily for you, I'm too lazy to post more than one comment

View Comment

160 days ago Ulrik04 talked about the member Jolly Green Giant Moderator

hey also gz with star for you ^_^

View Comment

160 days ago Ulrik04 talked about the member NAL Moderator

heey nal gz with star :P

1 2 3 4 ... 38