//Draw_Main.cpp
#include"DxLib.h"
#include"Player_Map.h"
#define WIDTH 21//マップの横の長さ
#define HEIGHT 16//マップの縦の長さ
#define SCREENW 640//スクリーンの横の大きさ
#define SCREENH 480//スクリーンの縦の大きさ
#define SIZE 16 //画像一つあたりの一辺の大きさ
static int rose[HEIGHT][WIDTH] = {
{ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,4 },
{ 2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4 },
{ 2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4 },
{ 2,0,0,0,0,0,20,20,20,20,20,20,20,20,20,0,0,0,0,0,4 },
{ 2,0,0,0,0,0,20,0,0,0,0,0,0,0,20,0,0,0,0,0,4 },
{ 2,0,0,0,0,0,20,0,0,0,0,0,0,0,20,0,0,0,0,0,4 },
{ 2,0,0,0,0,0,20,0,0,0,0,0,0,0,20,0,0,0,0,0,4 },
{ 2,0,0,0,0,0,20,20,20,0,0,0,20,20,20,0,0,0,0,0,4 },
{ 2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4 },
{ 2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4 },
{ 2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4 },
{ 2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4 },
{ 2,0,0,0,0,0,0,0,0,15,6,17,0,0,0,0,0,0,0,0,4 },
{ 2,0,0,0,0,0,0,0,0,18,0,18,0,0,0,0,0,0,0,0,4 },
{ 2,0,0,0,0,0,0,0,0,19,0,19,0,0,0,0,0,0,0,0,4 },
{ 2,3,3,3,3,3,3,3,3,10,0,10,3,3,3,3,3,3,3,3,3 },
};
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) {
DxLib_Init(), SetDrawScreen(DX_SCREEN_BACK), ChangeWindowMode(FALSE);
int image[8];
int image1[72];
int image2[24];
int Move = 0;//プレイヤーが移動中→1、停止中→0
int PlayerX = 2, PlayerY = 2;
LoadDivGraph("0.png", 8, 4, 2, 16, 16, image);
LoadDivGraph("rose.png", 72, 8, 9, 16, 16, image1);
LoadDivGraph("garden.png", 24, 8, 3, 16, 16, image2);
while (ScreenFlip() == 0 && ClearDrawScreen()==0&& ProcessMessage() == 0&&CheckHitKey(KEY_INPUT_ESCAPE)==0) {
Player_Map(PlayerX,PlayerY,Move,image,image1,image2,rose);
}
DxLib_End();
}
//Player_Map.cpp
#include"DxLib.h"
#include"Draw_Map.h"
#define SIZE 16
#define WIDTH 21
#define HEIGHT 16
#define SCREENW 640
#define SCREENH 480
static int Movecounter;//プレイヤーが移動し始めてから何フレーム経過したか
static int MoveX, MoveY;//プレイヤーの進行距離
static int Key;//キーの入力状態
static int ScrollX, ScrollY;//マップがどのくらいスクロールするか
void Player_Map(int PlayerX,int PlayerY,int Move,int *image,int *image1,int *image2,int rose[][21]) {
int Xnum = SCREENW / SIZE;
int Ynum = SCREENH / SIZE;
if (Move == 0) { //キー入力
Key=GetJoypadInputState(DX_INPUT_KEY_PAD1);
if (Key&PAD_INPUT_RIGHT){
Move = 1;
MoveX = 1;
MoveY = 0;
}
if (Key & PAD_INPUT_LEFT) {
Move = 1;
MoveX = -1;
MoveY = 0;
}
if (Key & PAD_INPUT_UP) {
Move = 1;
MoveX = 0;
MoveY = -1;
}
if (Key & PAD_INPUT_DOWN) {
Move = 1;
MoveX = 0;
MoveY = 1;
}
if (Move == 1) {
if (rose[PlayerY + MoveY][PlayerX + MoveX] != 0) {
Move = 0;
} //マップの0以外のところにはプレイヤーは侵入できない
else {
Movecounter = 0;
}
}
ScrollX = 0;
ScrollY = 0;
}
if (Move == 1) {
Movecounter++;//キーを一回押してから何フレーム経過したか
if (Movecounter == 32) {
ScrollX = 0;
ScrollY = 0;
Movecounter = 0;
Move = 0;
PlayerX += MoveX;//32フレーム経過するとプレイヤーの座標が変化
PlayerY += MoveY;
}else{
ScrollX = -MoveX * SIZE*Movecounter / 32;//プレイヤーが1マス動くのに32フレームかかる
ScrollY = -MoveY * SIZE*Movecounter / 32;
}
}
Draw_Map(ScrollX, ScrollY, PlayerX, PlayerY, rose, image, image1, image2);
DrawBox(Xnum/2*SIZE,Ynum/2*SIZE,(Xnum/2+1)*SIZE,(Ynum/2+1)*SIZE,GetColor(255,0,0),TRUE);//プレイヤーは常に画面の中心にいる
}
//Draw_Map.cpp
#include<DxLib.h>
#define WIDTH 21
#define HEIGHT 16
#define SCREENW 640
#define SCREENH 480
#define SIZE 16
static int Xnum, Ynum;//画面上に映ることのできる縦横各一列における画像総数
static int PointX, PointY;//マップの左上端を原点と考えたときの画面左上端の座標
static int i, j;
void Draw_Map(int ScrollX,int ScrollY,int PlayerX,int PlayerY,int rose[][21],int *image,int *image1,int *image2) {
Xnum = SCREENW / SIZE;
Ynum = SCREENH / SIZE;
PointX = PlayerX - Xnum / 2;
PointY = PlayerY - Ynum / 2;
for (i = 0; i < Ynum; i++) {
for (j = 0; j < Xnum; j++) {
if (j + PointX < 0 || i + PointY < 0 || j + PointX >= WIDTH || i + PointY >= HEIGHT) {//画面内のマップのみを描写するように限定する
continue;
}
if (rose[i + PointY][j + PointX] == 0) {
DrawGraph(j*SIZE + ScrollX, i*SIZE + ScrollY , image[0], TRUE);//
}
if (rose[i + PointY][j + PointX] == 1) {
DrawGraph(j *SIZE + ScrollX , i*SIZE + ScrollY , image1[0], TRUE);
}
if (rose[i + PointY][j + PointX] == 2) {
DrawGraph(j*SIZE + ScrollX , i*SIZE+ ScrollY , image1[1], TRUE);
}
if (rose[i + PointY][j + PointX] == 3) {
DrawGraph(j*SIZE + ScrollX , i *SIZE + ScrollY , image1[2], TRUE);
}
if (rose[i + PointY][j + PointX] == 4) {
DrawGraph(j*SIZE + ScrollX , i*SIZE + ScrollY , image1[3], TRUE);
}
if (rose[i + PointY][j + PointX] == 6) {
DrawGraph(j*SIZE + ScrollX , i*SIZE + ScrollY , image1[25], TRUE);
}
if (rose[i + PointY][j + PointX] == 10) {
DrawGraph(j *SIZE + ScrollX , i*SIZE + ScrollY , image1[64], TRUE);
}
if (rose[i + PointY][j + PointX] == 15) {
DrawGraph(j *SIZE + ScrollX , i *SIZE + ScrollY , image1[24], TRUE);
}
if (rose[i + PointY][j + PointX] == 17) {
DrawGraph(j *SIZE + ScrollX , i*SIZE + ScrollY , image1[26], TRUE);
}
if (rose[i + PointY][j + PointX] == 18) {
DrawGraph(j *SIZE + ScrollX , i *SIZE + ScrollY , image1[48], TRUE);
}
if (rose[i + PointY][j + PointX] == 19) {
DrawGraph(j*SIZE + ScrollX , i*SIZE + ScrollY , image1[56], TRUE);
}
if (rose[i + PointY][j + PointX] == 20) {
DrawGraph(j*SIZE + ScrollX , i *SIZE + ScrollY , image2[11], TRUE);
}
}
}
}
//Draw_Map.h
void Draw_Map(int ScrollX, int ScrollY, int PlayerX, int PlayerY, int rose[][21], int *image, int *image1, int *image2);