I am writing programming in the dx library to the specifications shown in the image, but I am not sure that pressing this space key changes the coordinate criteria.
My goal is to press the space once and the center coordinate will be in the upper left coordinate, and then press the space again to go back. How should I write it in this case?
What I don't understand is //Replace coordinate criteria??
of the source code.
This is my first question, and I'm afraid I'm short of words, but I appreciate your cooperation
specifications
Current source code
#include "DxLib.h"
# include <stdlib.h>
const char TITLE[] = "K0: Title";
constint WIN_WIDTH = 600; // Window Width
constint WIN_HEIGHT=400;// Window width
int WINAPI WinMain(_In_HINSTANCE hInstance,_In_opt_HINSTANCE hPrevInstance,_In_LPSTR lpCmdLine,_In_intnCmdShow)
{
ChangeWindowMode (TRUE); // Set to window mode
// To prevent manually changing the window size and scaling to fit the window size
SetWindowSizeChangeEnableFlag(FALSE,FALSE);
SetMainWindowText (TITLE); // Change Title
SetGraphMode(WIN_WIDTH,WIN_HEIGHT,32); // Set the maximum screen size, number of color bits (to match monitor resolution)
SetWindowSizeExtendRate (1.0); // Set screen size (set in ratio to resolution)
SetBackgroundColor (0x00, 0x00, 0xFF); // Set the background color of the screen
// Initialize Dx Library
if(DxLib_Init()==-1) {return-1;}
// (Double Buffer) Drawing destination graphic area designates the back side
SetDrawScreen(DX_SCREEN_BACK);
// Variable declaration and loading of resource data such as images
// Declare variables to use in game loops
char keys [256] = {0}; // For latest keyboard information
char oldkeys [256] = {0}; // Keyboard information before loop (frame)
intposX;// center coordinates of the rectangle to be described
int posY;//
intradius;// square radius
radius = 60;
posX=300;
posY = 200;
int ClickX, ClickY, Button, LogType; // Square Move
int DrawFlag, DrawX, DrawY, DrawColor;
int spaceFlag = 0;
inttx=posX;
intty=posY;
int MouseX;
int MouseY;
DrawFlag=FALSE;
DrawX = 0;
DrawY=0; DrawColor=0;
// game loop
while(1)
{
// Save the latest keyboard information as one frame ago
// Get the latest keyboard information
GetHitKeyStateAll(keys);
// Clear Screen
ClearDrawScreen();
//--------- Describe the program here -------------------------
// Update Processing
// Zoom in and out of squares
if(keys[KEY_INPUT_UP] == 1)
{
radius=radius+3;
}
if(keys[KEY_INPUT_DOWN] == 1)
{
radius=radius-3;
}
// Move quadrilateral with mouse
if (GetMouseInputLog2(&Button,&ClickX,&ClickY,&LogType,TRUE) == 0)
{
if(Button&MOUSE_INPUT_LEFT)!=0)
{
DrawFlag = TRUE;
posX=ClickX;
posY = ClickY;
}
}
if(DrawFlag==TRUE)
{
DrawBox(posX-radius, posY-radius, posX+radius, posY+radius, DrawColor, TRUE);
}
// Replace coordinate criteria??
if(keys[KEY_INPUT_SPACE] == 1)
{
spaceFlag = 1;
}
inttx=posX;
intty=posY;
if(spaceFlag==1){
tx+=radius;
ty+=radius;
spaceFlag = 0;
}
spaceFlag = 0;
DrawBox(tx-radius, ty-radius, tx+radius, ty+radius, GetColor (255, 255, 255), TRUE);
// Get mouse coordinate position
GetMousePoint (&MouseX, & MouseY);
// Drawing processing
DrawFormatString(0,15,GetColor(200,50,130), "Square x coordinates, Square y coordinates(%d, %d), posX, posY);
DrawFormatString(0,30, GetColor(200,50,130), "Mouse coordinates x, Mouse coordinates y(%d,%d), MouseX, MouseY);
//--------- So far, I've written a program -------------//
ScreenFlip(); // (double buffer) back
// 20 ms wait (pseudo 60 FPS)
WaitTimer (20);
// process information coming from a Windows system
if(ProcessMessage()==-1)
{
break;
}
// ESC key presses out of loop
if(CheckHitKey(KEY_INPUT_ESCAPE)==1)
{
break;
}
}
// Dx library shutdown process
DxLib_End();
return 0;
}
It's written in a complicated way.
In this case, I think spaceFlag works without it.
If you press the space key, the program moves the program.
Pressing the right of the cross key does not change what Mario is doing (but I don't know why you add values to both x and y...)
Also, when refactoring, it looks like the following.What do you think? Do you think you can imagine?
//Replace coordinate criteria??
inttx=posX;
intty=posY;
if(keys[KEY_INPUT_SPACE] == 1)
{
tx+=radius;
ty+=radius;
}
DrawBox(tx-radius, ty-radius, tx+radius, ty+radius, GetColor (255, 255, 255), TRUE);
© 2024 OneMinuteCode. All rights reserved.