Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <curses.h>
- #include <vector>
- #include <ctime>
- #include <cstdlib>
- #include <string>
- #include <iostream>
- #define O 0
- #define N 1
- #define S 2
- #define W 3
- #define E 4
- #define NW 5
- #define SW 6
- #define NE 7
- #define SE 8
- #define U 9
- #define D 10
- using namespace std;
- const int map_y = 200;
- const int map_x = 200;
- const int map_z = 1;
- short int map_g[map_y][map_x][map_z];
- struct creature
- {
- int y;
- int x;
- int z;
- string name;
- int min_dmg;
- int max_dmg;
- int mhp;
- int hp;
- int fov;
- char symbol;
- bool hostile;
- bool dead;
- bool mv(short dir);
- };
- vector <creature> creatures;
- creature blank
- {
- 0,
- 0,
- 0,
- "BLANK",
- 0,
- 0,
- 0,
- 0,
- 0,
- '?',
- 0,
- 0
- };
- creature human
- {
- 100,
- 100,
- 1,
- "Human",
- 20,
- 30,
- 100,
- 100,
- 10,
- '@',
- 0,
- 0
- };
- //vector <item> item_v;
- creature *player;
- #include "bresenham.h"
- int creature_on_tile(int y, int x, int z)
- {
- int i = -1;
- for(int ct = 0 ; ct < creatures.size() ; ct++)
- {
- if(creatures[ct].y == y && creatures[ct].x == x && creatures[ct].z == z)
- {
- i = ct;
- }
- }
- return i;
- }
- bool creature::mv(short dir)
- {
- switch(dir)
- {
- case N:
- if(creature_on_tile(y - 1, x , z) != -1 || dead == 1)
- {
- return false;
- }
- else
- {
- if(map_g[y - 1][x][z] != 2)
- {
- y--;
- }
- else
- {
- return false;
- }
- }
- break;
- case S:
- if(creature_on_tile(y + 1, x , z) != -1 || dead == 1)
- {
- return false;
- }
- else
- {
- if(map_g[y + 1][x][z] != 2)
- {
- y++;
- }
- else
- {
- return false;
- }
- }
- break;
- case W:
- if(creature_on_tile(y, x - 1, z) != -1 || dead == 1)
- {
- return false;
- }
- else
- {
- if(map_g[y][x - 1][z] != 2)
- {
- x--;
- }
- else
- {
- return false;
- }
- }
- break;
- case E:
- if(creature_on_tile(y, x + 1, z) != -1 || dead == 1)
- {
- return false;
- }
- else
- {
- if(map_g[y][x + 1][z] != 2)
- {
- x++;
- }
- else
- {
- return false;
- }
- }
- break;
- }
- }
- void render_map()
- {
- int cr;
- for(int yt = player->y - player->fov ; yt < player->y + player->fov ; yt++)
- {
- for(int xt = player->x - player->fov ; xt < player->x + player->fov ; xt++)
- {
- cr = creature_on_tile(yt , xt , player->z);
- if(line(yt, xt, player->y, player->x, player->z))
- {
- if(cr != -1)
- {
- printw("%c", creatures[cr].symbol);
- }
- else
- {
- switch(map_g[yt][xt][player->z])
- {
- case 0:
- printw("*");
- break;
- case 1:
- printw("+");
- break;
- case 2:
- printw("#");
- break;
- default:
- printw("?");
- break;
- }
- }
- }
- else
- {
- printw(" ");
- }
- }
- printw("\n");
- }
- }
- void gen_map()
- {
- for(int yt = 0; yt < map_y; yt++)
- {
- for(int xt = 0; xt < map_x; xt++)
- {
- map_g[yt][xt][1] = 1;
- }
- }
- }
- void play(char ch)
- {
- switch(ch)
- {
- case 'w':
- player->mv(N);
- break;
- case 's':
- player->mv(S);
- break;
- case 'a':
- player->mv(W);
- break;
- case 'd':
- player->mv(E);
- break;
- case 'r':
- map_g[player->y][player->x][player->z] = 2;
- break;
- }
- }
- int main()
- {
- creatures.push_back(blank);
- creatures.push_back(human);
- player = &creatures[1];
- initscr();
- resize_term(50, 100);
- char ch;
- gen_map();
- map_g[player->y + 2][player->x - 1][1] = 2;
- printw("%d", creatures.size());
- refresh();
- while(player->dead == 0 && ch != 'q')
- {
- render_map();
- printw("\n");
- refresh();
- printw("%d", player->y);
- printw("\n");
- printw("%d", player->x);
- printw("\n");
- printw("%d", player->z);
- printw("\n");
- printw("\n");
- refresh();
- ch = getch();
- play(ch);
- clear();
- }
- endwin();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement