DXらいぶらり エラー
Posted: 2014年8月15日(金) 16:36
DXライブラリでゲームを作り始めようとして、クラス化しようとしたんですが以下のようなエラーが出ました
ほどんどいじったことがないのでよくわかりません。ご指摘おねがいします.
エラー 1 error LNK2005: "public: void __thiscall MyChar::jump(void)" (?jump@MyChar@@QAEXXZ) は既に main.obj で定義されています。
エラー 2 error LNK2005: "int __cdecl onLand(int)" (?onLand@@YAHH@Z) は既に main.obj で定義されています。
エラー 3 error LNK1169: 1 つ以上の複数回定義されているシンボルが見つかりました。
ソースファイルは下です。
//main.cpp
#include "DxLib.h"
#include "MyChar.cpp"
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
ChangeWindowMode(TRUE);
if (DxLib_Init() == -1)
{
return -1;//エラーが起きたら直ちに終了
}
SetDrawScreen(DX_SCREEN_BACK);
MyChar p;
while (ProcessMessage() == 0 && CheckHitKey(KEY_INPUT_ESCAPE) == 0)
{
ClearDrawScreen();
//ジャンプと移動の処理
p.jump();
DrawGraph(p.x, p.y, p.img, TRUE);
ScreenFlip();
}
DxLib_End();
return 0;
}
//MyChar.cpp
#include "DxLib.h"
int onLand(int);
class MyChar{
public:
int img = LoadGraph("player.png");
int x=0, y=480-32;
int isJump=0;
int ay=0;
int isThrow;
int g = 1;
void jump();
int onland(int);
};
void MyChar::jump(){
int key;
key = GetJoypadInputState(DX_INPUT_KEY_PAD1);
if (key & PAD_INPUT_RIGHT) x += 10;
if (key & PAD_INPUT_LEFT) x -= 10;
int StartTime = 0;
if (isJump != 2){
if (key & PAD_INPUT_10 && 200 <= GetNowCount() - StartTime){
StartTime = GetNowCount();
ay = -17;
isJump++;
}
}
if (isJump >= 1){
ay += g;
y += ay;
if (onLand(y)){
isJump = 0;
y = 480 - 32;
StartTime = 0;
}
}
}
int onLand(int y){
if (y > 480 - 32)
return 1;
else
return 0;
}
ほどんどいじったことがないのでよくわかりません。ご指摘おねがいします.
エラー 1 error LNK2005: "public: void __thiscall MyChar::jump(void)" (?jump@MyChar@@QAEXXZ) は既に main.obj で定義されています。
エラー 2 error LNK2005: "int __cdecl onLand(int)" (?onLand@@YAHH@Z) は既に main.obj で定義されています。
エラー 3 error LNK1169: 1 つ以上の複数回定義されているシンボルが見つかりました。
ソースファイルは下です。
//main.cpp
#include "DxLib.h"
#include "MyChar.cpp"
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
ChangeWindowMode(TRUE);
if (DxLib_Init() == -1)
{
return -1;//エラーが起きたら直ちに終了
}
SetDrawScreen(DX_SCREEN_BACK);
MyChar p;
while (ProcessMessage() == 0 && CheckHitKey(KEY_INPUT_ESCAPE) == 0)
{
ClearDrawScreen();
//ジャンプと移動の処理
p.jump();
DrawGraph(p.x, p.y, p.img, TRUE);
ScreenFlip();
}
DxLib_End();
return 0;
}
//MyChar.cpp
#include "DxLib.h"
int onLand(int);
class MyChar{
public:
int img = LoadGraph("player.png");
int x=0, y=480-32;
int isJump=0;
int ay=0;
int isThrow;
int g = 1;
void jump();
int onland(int);
};
void MyChar::jump(){
int key;
key = GetJoypadInputState(DX_INPUT_KEY_PAD1);
if (key & PAD_INPUT_RIGHT) x += 10;
if (key & PAD_INPUT_LEFT) x -= 10;
int StartTime = 0;
if (isJump != 2){
if (key & PAD_INPUT_10 && 200 <= GetNowCount() - StartTime){
StartTime = GetNowCount();
ay = -17;
isJump++;
}
}
if (isJump >= 1){
ay += g;
y += ay;
if (onLand(y)){
isJump = 0;
y = 480 - 32;
StartTime = 0;
}
}
}
int onLand(int y){
if (y > 480 - 32)
return 1;
else
return 0;
}