게시판 즐겨찾기
편집
드래그 앤 드롭으로
즐겨찾기 아이콘 위치 수정이 가능합니다.
vs2015 c++로 갤러그를 만드는 중인데요 너무 어렵네요..
게시물ID : programmer_16989짧은주소 복사하기
작성자 : 윗집사는그녀
추천 : 0
조회수 : 815회
댓글수 : 2개
등록시간 : 2016/04/29 01:37:46
옵션
  • 본인삭제금지
다보여드리면 안읽으실거 같아서 부분만 올려봅니다

Bullet *pB = new Bullet[50];
int pos = 0;

if (whatkey(VK_SPACE))
{
pB[pos].user_shoot(); // pos번째 유저슛 함수를 부름  user_bullet이란 char형 변수에 총알 i를 넣음.

pB[pos].set_userbullety(-1); // pos번째 총알y좌표를 -1함(총알이 위로올라가죠)
gotoxy(user.set_nowx(0) + 2, pB[pos].get_userbullety()); // 비행기의 x좌표와 pos번째 총알의 y좌표로 이동
cout << pB[pos].get_userbullet(); //pos번째 총알i를 출력
Sleep(20); //약간의 텀
gotoxy(user.set_nowx(0) + 2, pB[pos].get_userbullety()); //같은위치로 커서이동
cout << " "; //총알의 흔적을 지움
RemoveCursor();
pos++;
}

일단 이 부분이 구현이 안되고 있습니다
메모리 부분은 문제가 없을줄 알았는데 메모리 부분도 문제가 있는것같고..
무엇도다 안에서 포문으로 돌릴수가 없어서 총알 y좌표값을 계속 -1 시키면서 총알을 위로 날려야하는데.. 너무 어려워요 ㅠㅠ

while (-1)
{
if (count % 5 == 0) 
{
if (whatkey(VK_LEFT))
{ 왼쪽방향키 눌렀을때 비행기 왼쪽이동}

if (whatkey(VK_RIGHT))
{ 비행기 오른쪽 이동 }
}

if (whatkey(VK_SPACE))
{
.....위 소스 그대로
}
count++;
}

이런식으로 count 를 이용해 돌리기때문에 안에서 포문을 쓸수가 없습니다 ㅠㅠ 
더 공부하고 만들고 싶지만 프로젝트발표가 코앞이라 일단 뭐가 됐든 만들어야하는데 여기가 너무 어려워요
조언부탁드립니다



전체 소스도 올려볼게요
============================================================


// 맵 크기 36x36
#include <iostream>
#include <Windows.h>
#include <conio.h>
using namespace std;
//#define LEFT 75 // 좌측방향키
//#define RIGHT 77 // 우측방향키
//#define UP 72 // 위쪽방향키
//#define DOWN 80 // 아래방향키
//#define SPACEBAR 32 // 스페이스바

void gotoxy(int x, int y)
{
COORD Cur;
Cur.X = x;
Cur.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), Cur);
}

void RemoveCursor() {
CONSOLE_CURSOR_INFO curinfo;
GetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &curinfo);
curinfo.bVisible = 0;
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &curinfo);
}

BOOL whatkey(int Key)
{
return ((GetAsyncKeyState(Key) & 0x8000) != 0);
}


class Airplane
{
protected:
int hp; // user, enemy 모두 100으로 고정
int power; // 공격력
int nowx = 36; // 유저 현재 좌표
int nowy = 36;
int oldx = nowx; // 유저 이전 좌표
int oldy = nowy;
public:
Airplane() {}//없애자
Airplane(int h, int p) : hp(h), power(p) {}
int set_nowx(int n)
{
nowx += n;
return nowx;
}
int set_nowy(int m)
{
nowy += m;
return nowy;
}
int get_oldx(int n)
{
oldx = nowx;
return oldx;
}
int get_oldy(int m)
{
oldy = nowy;
return oldy;
}
};

class Bullet
{
private:
char user_bullet = NULL;
int user_bulletx = 36;
int user_bullety = 36;
public:
friend class User;
Bullet b() {}
void set_userbulletx(int n)
{
user_bulletx += n;
}
void set_userbullety(int n)
{
user_bullety += n;
}
int get_userbulletx()
{
return user_bulletx;
}
int get_userbullety()
{
return user_bullety;
}
char get_userbullet()
{
return user_bullet;
}
void user_shoot()
{
user_bullet = 'i';
}
};

//void init()
//{
// pB = NULL;
//}


class User : public Airplane
{
private:
char user_unit[2][7] = { "  ψ  ","∈※∋" };
int cnt = 0;
public:
User() {}//없애자
User(int h, int p) : Airplane(h, p) {}
void user_airplane(int x, int y)
{
gotoxy(x, y);
cout << user_unit[0] << endl;
gotoxy(x, y + 1);
cout << user_unit[1] << endl;
RemoveCursor();
}
void clear_user() //유저흔적지우기 (값 나중에 다시 주기)
{
gotoxy(set_nowx(0) + 5, set_nowy(0));
cout << " ";
gotoxy(set_nowx(0) + 3, set_nowy(0) + 1);
cout << " ";
}
/*void del_bullet()
{
delete[] pB;
}*/
};

//class Enemy : public Airplane
//{
//private:
// char enemy_unit[2][7] = { "◁▩▷", "  Π  " };
//public:
// Enemy(int h, int p, char b) : Airplane(h, p, b) {}
// void enemy_airplane(int x, int y) //좌표를 매개변수로
// {
// gotoxy(x, y);
// cout << enemy_unit[0] << endl;
// gotoxy(x, y + 1);
// cout << enemy_unit[1] << endl;
// }
//};

int main()
{
//Bullet *pB = new Bullet[20];
// init();
int count = 0;
Airplane a();
User user(100, 50);
Bullet *pB = new Bullet[20];
//Bullet b;
int pos = 0;
//User user(100, 50);
user.user_airplane(user.set_nowx(0), user.set_nowy(0));


while (-1)
{
if (count % 5 == 0)
{
if (whatkey(VK_LEFT))
{
if (user.set_nowx(0) > 0)
{
user.set_nowx(-1);
user.clear_user();
user.user_airplane(user.set_nowx(0), user.set_nowy(0));
}
}

if (whatkey(VK_RIGHT))
{
if (user.set_nowx(0) < 36)
{
user.set_nowx(1);
user.clear_user();
user.user_airplane(user.set_nowx(0), user.set_nowy(0));
}
}
}

if (whatkey(VK_SPACE))
{
for (int i = 0; i < 36; i++)
{
pB[pos].user_shoot(); // pB[pos] = i

pB[pos].set_userbullety(-1);
gotoxy(user.set_nowx(0) + 2, pB[pos].get_userbullety());
cout << pB[pos].get_userbullet();
Sleep(20);
gotoxy(user.set_nowx(0) + 2, pB[pos].get_userbullety());
cout << " ";
RemoveCursor();
pos++;
}
}

/*if (pB[pos].get_userbullety() <= 0)
{
pB[pos].del_bullet();
}*/
count++;
Sleep(10);
}
return 0;
}

전체 추천리스트 보기
새로운 댓글이 없습니다.
새로운 댓글 확인하기
글쓰기
◀뒤로가기
PC버전
맨위로▲
공지 운영 자료창고 청소년보호