#4
by keito94 » 8年前
ソースコードの全体を上げてみた。どこかおかしな点があったら教えてください。
Main.h
コード:
#pragma once
#include "DxLib.h"
class CPlayer;
class CGameMain {
int Time;
public:
int PlayerGh;
int MapGraph;
CGameMain();
~CGameMain();
void ErrMes(LPCSTR str, ...);
int MapLoad(const char* mapdata,const char* mapchip);
void Run();
};
const float GRAVMAX = 10.0f;
const float GRAV = 0.5F;
extern CGameMain *Game;
Main.cpp
コード:
#include "Main.h"
#include "Mapping.h"
#include "Stage.h"
#include "Player.h"
CFmfMap MapObj;
CGameMain *Game;
CPlayer *Player;
CStage *Stage;
int BitCount;
CGameMain::CGameMain() {
ChangeWindowMode(TRUE); SetGraphMode(320, 240, 32);
DxLib_Init();
SetDrawScreen(DX_SCREEN_BACK);
PlayerGh = LoadGraph("テスト用.png");
MapLoad("テスト用.fmf", "マップチップ.bmp");
Player = new CPlayer(160.0F, 215.0F);
}
void CGameMain::Run() {
Player->Move();
Stage->Draw();
Player->Draw();
}
int CGameMain::MapLoad(const char* mapdata, const char* mapchip) {
if (!MapObj.Open(mapdata)) {
ErrMes("Error Code 30: MapData is Not Loading.");
return -1;
}
BYTE* layer = (BYTE*)MapObj.GetLayerAddr(0);
if (layer == NULL) {
ErrMes("Error Code 31: Null Layer.");
MapObj.Close();
return -1;
}
if ((MapGraph = LoadGraph(mapchip)) == -1) {
ErrMes("Error Code 41: MapChip is Not Loading.");
return -1;
}
MapGraph = LoadGraph(mapchip);
BitCount = MapObj.GetLayerBitCount() == 8 ? 16 : 256;
}
void CGameMain::ErrMes(LPCSTR str, ...) {
char buf[1024];
wsprintf(buf, str, (char*)(&str + 1));
MessageBox(NULL, buf, "Error!!", MB_OK);
}
CGameMain::~CGameMain() {
DxLib_End();
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPervInstance, LPSTR lpCmdLine, int nCmdShow) {
Game = new CGameMain;
while(ScreenFlip()==0&&ProcessMessage()==0&&ClearDrawScreen()==0) {
Game->Run();
}
delete Game;
}
Mover.h
コード:
#pragma once
class CMover {
public:
float X, Y, L, T, R, B;
float VX, VY;
CMover(float x, float y, float l, float t, float r, float b);
};
Mover.cpp
コード:
#include "Mover.h"
CMover::CMover(float x, float y, float l, float t, float r, float b)
:X(x), Y(y), L(l), T(t), R(r), B(b), VX(0.0F), VY(0.0F) {
}
Player.h
コード:
#pragma once
#include "Mover.h"
class CCollision;
class CPlayer : public CMover {
protected:
CCollision* ColObj;
int JumpCount;
float Grav;
int Dir;
bool GroundFlag;
public:
CPlayer(float x, float y);
bool Move();
void Draw();
};
Player.cpp
コード:
#include "Main.h"
#include "Player.h"
#include "JoyPad.h"
#include "Collision.h"
CJoyPad JoyPad;
CPlayer::CPlayer(float x, float y)
:CMover(x, y, -8, -8, 8, 8),Dir(FALSE),JumpCount(0),GroundFlag(false),Grav(0.5F) {
POINT pt[] = {
{ (LONG)L, (LONG)T },//左上
{ 0, (LONG)T },//上真ん中
{ (LONG)R, (LONG)T },//右上
{ (LONG)L, 0 },//左真ん中
{ (LONG)R, 0 },//右真ん中
{ (LONG)L, (LONG)B },//左下
{ 0, (LONG)B },//下真ん中
{ (LONG)R, (LONG)B },//右下
};
ColObj = new CCollision(pt, 0, 0, 0, 0, 0);
}
bool CPlayer::Move() {
JoyPad.Update();
if (JoyPad.Get(PAD_INPUT_RIGHT)) {
Dir = FALSE;
VX = 3.0F;
}
else if (JoyPad.Get(PAD_INPUT_LEFT)){
Dir = TRUE;
VX = -3.0F;
}
else {
VX = 0;
}
if (JoyPad.Get(PAD_INPUT_1) > 0 && JumpCount < 5) {
if (JumpCount < 1 && GroundFlag) {
JumpCount++;
VY = -9.0F;
}
}
ColObj->GetMove(&X, &Y, &VX, &VY, &JumpCount, &GroundFlag);
return true;
}
void CPlayer::Draw() {
DrawRotaGraph((int)X, (int)Y, 1.0, 0.0, Game->PlayerGh, FALSE, Dir);
}
ソースコードの全体を上げてみた。どこかおかしな点があったら教えてください。
Main.h
[code]
#pragma once
#include "DxLib.h"
class CPlayer;
class CGameMain {
int Time;
public:
int PlayerGh;
int MapGraph;
CGameMain();
~CGameMain();
void ErrMes(LPCSTR str, ...);
int MapLoad(const char* mapdata,const char* mapchip);
void Run();
};
const float GRAVMAX = 10.0f;
const float GRAV = 0.5F;
extern CGameMain *Game;
[/code]
Main.cpp
[code]
#include "Main.h"
#include "Mapping.h"
#include "Stage.h"
#include "Player.h"
CFmfMap MapObj;
CGameMain *Game;
CPlayer *Player;
CStage *Stage;
int BitCount;
CGameMain::CGameMain() {
ChangeWindowMode(TRUE); SetGraphMode(320, 240, 32);
DxLib_Init();
SetDrawScreen(DX_SCREEN_BACK);
PlayerGh = LoadGraph("テスト用.png");
MapLoad("テスト用.fmf", "マップチップ.bmp");
Player = new CPlayer(160.0F, 215.0F);
}
void CGameMain::Run() {
Player->Move();
Stage->Draw();
Player->Draw();
}
int CGameMain::MapLoad(const char* mapdata, const char* mapchip) {
if (!MapObj.Open(mapdata)) {
ErrMes("Error Code 30: MapData is Not Loading.");
return -1;
}
BYTE* layer = (BYTE*)MapObj.GetLayerAddr(0);
if (layer == NULL) {
ErrMes("Error Code 31: Null Layer.");
MapObj.Close();
return -1;
}
if ((MapGraph = LoadGraph(mapchip)) == -1) {
ErrMes("Error Code 41: MapChip is Not Loading.");
return -1;
}
MapGraph = LoadGraph(mapchip);
BitCount = MapObj.GetLayerBitCount() == 8 ? 16 : 256;
}
void CGameMain::ErrMes(LPCSTR str, ...) {
char buf[1024];
wsprintf(buf, str, (char*)(&str + 1));
MessageBox(NULL, buf, "Error!!", MB_OK);
}
CGameMain::~CGameMain() {
DxLib_End();
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPervInstance, LPSTR lpCmdLine, int nCmdShow) {
Game = new CGameMain;
while(ScreenFlip()==0&&ProcessMessage()==0&&ClearDrawScreen()==0) {
Game->Run();
}
delete Game;
}
[/code]
Mover.h
[code]
#pragma once
class CMover {
public:
float X, Y, L, T, R, B;
float VX, VY;
CMover(float x, float y, float l, float t, float r, float b);
};
[/code]
Mover.cpp
[code]
#include "Mover.h"
CMover::CMover(float x, float y, float l, float t, float r, float b)
:X(x), Y(y), L(l), T(t), R(r), B(b), VX(0.0F), VY(0.0F) {
}
[/code]
Player.h
[code]
#pragma once
#include "Mover.h"
class CCollision;
class CPlayer : public CMover {
protected:
CCollision* ColObj;
int JumpCount;
float Grav;
int Dir;
bool GroundFlag;
public:
CPlayer(float x, float y);
bool Move();
void Draw();
};
[/code]
Player.cpp
[code]
#include "Main.h"
#include "Player.h"
#include "JoyPad.h"
#include "Collision.h"
CJoyPad JoyPad;
CPlayer::CPlayer(float x, float y)
:CMover(x, y, -8, -8, 8, 8),Dir(FALSE),JumpCount(0),GroundFlag(false),Grav(0.5F) {
POINT pt[] = {
{ (LONG)L, (LONG)T },//左上
{ 0, (LONG)T },//上真ん中
{ (LONG)R, (LONG)T },//右上
{ (LONG)L, 0 },//左真ん中
{ (LONG)R, 0 },//右真ん中
{ (LONG)L, (LONG)B },//左下
{ 0, (LONG)B },//下真ん中
{ (LONG)R, (LONG)B },//右下
};
ColObj = new CCollision(pt, 0, 0, 0, 0, 0);
}
bool CPlayer::Move() {
JoyPad.Update();
if (JoyPad.Get(PAD_INPUT_RIGHT)) {
Dir = FALSE;
VX = 3.0F;
}
else if (JoyPad.Get(PAD_INPUT_LEFT)){
Dir = TRUE;
VX = -3.0F;
}
else {
VX = 0;
}
if (JoyPad.Get(PAD_INPUT_1) > 0 && JumpCount < 5) {
if (JumpCount < 1 && GroundFlag) {
JumpCount++;
VY = -9.0F;
}
}
ColObj->GetMove(&X, &Y, &VX, &VY, &JumpCount, &GroundFlag);
return true;
}
void CPlayer::Draw() {
DrawRotaGraph((int)X, (int)Y, 1.0, 0.0, Game->PlayerGh, FALSE, Dir);
}
[/code]