Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

SSJCORY

How come my rectangle extends the bounds if moved to the far right?

This topic is 5558 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

This is like a start to learning to program character movement... For the bottom left and top it will show the square until it cant move any higher left or lower... But on the right for some reason i get a halfish square... Actually they are rect. Here''s the source:
#include<windows.h>
#include<stdio.h>
bool paintred = false;
bool paintblue = false;
bool down = false;
bool up = false;
bool left = false;
bool right = false;
#define WIN_WIDTH 640
#define WIN_HEIGHT 480
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hprev,PSTR szCmdLine, int iCmdShow){
	HWND hwnd;
	MSG msg;
	WNDCLASSEX flash;
	flash.cbSize = sizeof(flash);
	flash.lpfnWndProc = WndProc;
	flash.hInstance = hInstance;
	flash.hIcon = LoadIcon(NULL,IDI_WINLOGO);
	flash.hIconSm = LoadIcon(NULL,IDI_WINLOGO);
	flash.hCursor = LoadCursor(NULL,IDC_ARROW);
	flash.lpszClassName = "Cory Class";
	flash.lpszMenuName = 0;
	flash.cbClsExtra = 0;
	flash.cbWndExtra = 0;
	flash.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
	flash.style = CS_HREDRAW | CS_VREDRAW;

	RegisterClassEx(&flash);
	hwnd = CreateWindow("Cory Class", "Cory''s Window", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 
		CW_USEDEFAULT, WIN_WIDTH, WIN_HEIGHT, NULL, NULL, hInstance, NULL);
	HDC hdc = GetDC(hwnd);
	ShowWindow(hwnd, iCmdShow);
	UpdateWindow(hwnd);
	RECT rect = {0,0,50,50};
	RECT killold = {0,0,50,50};

	HBRUSH RED = CreateSolidBrush(COLORREF RGB(255,0,0));
	HBRUSH BLUE = CreateSolidBrush(COLORREF RGB(0,0,255));
	while(GetMessage(&msg,NULL,0,0)){
		TranslateMessage(&msg);
		DispatchMessage(&msg);
		FillRect(hdc,&rect,RED);
		if(down == true && (rect.bottom + 50) < WIN_HEIGHT){
			rect.bottom += 100;
			rect.top += 100;
			FillRect(hdc,&killold,WHITE_BRUSH);
			killold.bottom += 100;
			killold.top += 100;
		}
		if(up == true && (rect.top - 50) > 0){
			rect.bottom -= 100;
			rect.top -= 100;
			FillRect(hdc,&killold,WHITE_BRUSH);
			killold.top -= 100;
			killold.bottom -= 100;
		}
		if(left == true && (rect.left - 50) > 0){
			rect.left -= 100;
			rect.right -= 100;
			FillRect(hdc,&killold,WHITE_BRUSH);
			killold.left -= 100;
			killold.right -= 100;
		}
		if(right == true && (rect.right + 50) < WIN_WIDTH){
			rect.left += 100;
			rect.right += 100;
			FillRect(hdc,&killold,WHITE_BRUSH);
			killold.right += 100;
			killold.left += 100;
		}

		up = false;
		down = false;
		left = false;
		right = false;
	}
	ReleaseDC(hwnd,hdc);
	UnregisterClass("Cory Class", hInstance);
	return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam){
	switch(iMsg){
	case WM_DESTROY:
		{
			PostQuitMessage(0);
			break;
		}
	case WM_CHAR:
		{
			TCHAR INPUT = (TCHAR)wParam;
			if(INPUT == ''8''){
				up = true;
			}
			if(INPUT == ''2''){
				down = true;
			}
			if(INPUT == ''4''){
				left = true;
			}
			if(INPUT == ''6''){
				right = true;
			}
		}
	}
	return DefWindowProc(hwnd, iMsg, wParam, lParam);
}
Thnx in advance
Favorite Quotes:Gandalf: You shall not pass!|Gollum: My Precious!|Smeagol: My little hobbitses.|

Share this post


Link to post
Share on other sites
Advertisement

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!