Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
#include <ncurses.h>
#include <stdlib.h>
using namespace std;
int screenSetup()
{
initscr();
mvprintw(0, 28,"Map");
noecho();
refresh();
return 0;
}
typedef struct Player
{
int xPosition;
int yPosition;
} Player;
typedef struct Enemy
{
int xPosition;
int yPosition;
} Enemy;
int mapConfig()
{
mvprintw(12, 12, "----------");
mvprintw(13, 12, "|........|");
mvprintw(14, 12, "|........|");
mvprintw(15, 12, "|........|");
mvprintw(16, 12, "|........|");
mvprintw(17, 12, "----------");
mvprintw(2, 35, "------------");
mvprintw(3, 35, "|..........|");
mvprintw(4, 35, "|..........|");
mvprintw(5, 35, "|..........|");
mvprintw(6, 35, "|..........|");
mvprintw(7, 35, "------------");
mvprintw(14, 35, "---------------");
mvprintw(15, 35, "|.............|");
mvprintw(16, 35, "|.............|");
mvprintw(17, 35, "|.............|");
mvprintw(18, 35, "|.............|");
mvprintw(19, 35, "|.............|");
mvprintw(20, 35, "|.............|");
mvprintw(21, 35, "|.............|");
mvprintw(22, 35, "|.............|");
mvprintw(23, 35, "---------------");
}
Player*playerSetup()
{
Player * newPlayer;
newPlayer = (Player*)malloc(sizeof(Player));
newPlayer -> xPosition = 15;
newPlayer -> yPosition = 16;
mvprintw(newPlayer->yPosition, newPlayer->xPosition, "@" );
move(newPlayer->yPosition, newPlayer->xPosition);
return newPlayer;
}
Enemy*enemySetup()
{
Enemy * newEnemy;
Enemy * newEnemy1;
Enemy * newEnemy2;
Enemy * newEnemy3;
newEnemy = (Enemy*)malloc(sizeof(Enemy));
newEnemy1 = (Enemy*)malloc(sizeof(Enemy));
newEnemy2 = (Enemy*)malloc(sizeof(Enemy));
newEnemy3 = (Enemy*)malloc(sizeof(Enemy));
newEnemy -> xPosition = 15;
newEnemy -> yPosition = 13;
newEnemy -> xPosition = 14;
newEnemy -> yPosition = 15;
newEnemy2 -> xPosition = 37;
newEnemy2 -> yPosition = 5;
newEnemy3 -> xPosition = 38;
newEnemy3 -> yPosition = 3;
mvprintw(newEnemy->yPosition, newEnemy->xPosition, "X" );
move(newEnemy->yPosition, newEnemy->xPosition);
mvprintw(newEnemy1->yPosition, newEnemy1->xPosition, "X" );
move(newEnemy1->yPosition, newEnemy1->xPosition);
mvprintw(newEnemy2->yPosition, newEnemy2->xPosition, "X" );
move(newEnemy2->yPosition, newEnemy2->xPosition);
mvprintw(newEnemy3->yPosition, newEnemy2->xPosition, "X" );
move(newEnemy3->yPosition, newEnemy3->xPosition);
return newEnemy, newEnemy1, newEnemy2, newEnemy3;
}
int playerMovement(int y, int x, Player * user)
{
mvprintw(user->yPosition, user->xPosition, ".");
user->yPosition = y;
user->xPosition = x;
mvprintw(user->yPosition, user->xPosition, "@");
move(user->yPosition, user->xPosition);
}
int collisionDetection(int newYposition, int newXposition, Player * user)
{
int space;
switch(mvinch(newYposition, newXposition))
{
case '.':
playerMovement(newYposition, newXposition, user);
break;
default:
move(user->yPosition, user->xPosition);
break;
}
}
int inputFunction(int input, Player * user)
{
int newYposition;
int newXposition;
switch(input)
{
case 'w':
case 'W':
newYposition = user->yPosition - 1;
newXposition = user->xPosition;
break;
case 's':
case 'S':
newYposition = user->yPosition + 1;
newXposition = user->xPosition;
break;
case 'a':
case 'A':
newYposition = user->yPosition;
newXposition = user->xPosition - 1;
break;
case 'd':
case 'D':
newYposition = user->yPosition;
newXposition = user->xPosition + 1;
break;
default:
break;
}
collisionDetection(newYposition, newXposition, user);
}
int main(int argc, char ** argv)
{
Player * user;
int ch;
screenSetup();
mapConfig();
user = playerSetup();
enemySetup();
while((ch = getch()) != '1')
{
inputFunction(ch, user);
}
endwin();
return 0;
}