Click here to Skip to main content
14,332,889 members

.NET Framework

 
AnswerRe: Invoking .NET from Native C Pin
Mike Dimmick28-Feb-07 0:39
memberMike Dimmick28-Feb-07 0:39 
QuestionGetting WebBrowser cookies for HttpWebRequest Pin
jjholt27-Feb-07 12:57
memberjjholt27-Feb-07 12:57 
QuestionDateTimePicker commercial replacements ? Pin
CAE27-Feb-07 12:20
memberCAE27-Feb-07 12:20 
QuestionPlease help me Pin
Glen Liu27-Feb-07 12:09
memberGlen Liu27-Feb-07 12:09 
GeneralWPF ActiveControl Equivalent Pin
Ed.Poore26-Feb-07 22:02
memberEd.Poore26-Feb-07 22:02 
QuestionMTOM taking more time than base64 method Pin
shahzadgodil26-Feb-07 19:26
membershahzadgodil26-Feb-07 19:26 
QuestionRemoting connection problem Pin
BobishKindaGuy26-Feb-07 13:41
memberBobishKindaGuy26-Feb-07 13:41 
Questionforce feedback game graphics - please help Pin
men0aphw25-Feb-07 23:10
membermen0aphw25-Feb-07 23:10 
I've developed a visual c++ game within micrsoft visual studio.net 1.0. Basically the game involves moving a sprite around a 2d region to various targets, the game is setup such that assistive force is applied by the sidewinder 2 force feedback joystick. I'm struggling a little now with improving the graphics.

I would like to display a bitmap image as the background, another bitmap image as the targets and a transparent bitmap as the sprite. This is the code i'm using at the moment:

It draws a white background and i have a bitmap as the sprite (i would like to make it transparent and maybe even blit it to animate it) and blue circles as the targets. I also get a screen flicker problem and the game crashes out after a little while, i guess this is due to a buffer filling up?

you can see a screen shot from my game here: www.personal.leeds.ac.uk/~men0aphw/image1.jpg

Any help or ideas would be greatly appreciated!

Many thanks!!

ANDY

//variables for the bitmap
HBITMAP g_hGrid = NULL; // Grid Bitmap object
INT g_nGridW, g_nGridH; // and dimensions .................

later on......

//will do the drawing
case WM_PAINT:
currentTime = time(NULL);
timeElapsed = difftime(currentTime, startingTime)- pauseTime;
SetDlgItemText(hDlg, IDTIME_C, ctime(¤tTime));

minutes = timeElapsed / 60;
seconds = timeElapsed - minutes*60;

if(minutes<10 && seconds <10)
sprintf(timePassed_s, "0%dBlush | :O %d", minutes, seconds);
else if (minutes<10 && seconds>=10)
sprintf(timePassed_s, "0%d:%d", minutes, seconds);
else
sprintf(timePassed_s, "%d:%d", minutes, seconds);

SetDlgItemText(hDlg, IDTIME, timePassed_s);

SetDlgItemText(hDlg, IDFORCE, ffCurrentMagStr);
sprintf(numStr, "%d", joy_x);
SetDlgItemText(hDlg, IDJOYX, numStr);
sprintf(numStr, "%d", joy_y);
SetDlgItemText(hDlg, IDJOYY, numStr);
sprintf(score_s, "%d", score);
SetDlgItemText(hDlg, IDSCORE, score_s);
sprintf(numStr, "%.0lf", totalDamping);
SetDlgItemText(hDlg, IDDAMP, numStr);
sprintf(numStr, "%d", current_travel);
SetDlgItemText(hDlg, IDTRAVEX, numStr);
sprintf(numStr, "%d", travelled_total);
SetDlgItemText(hDlg, IDTOTTRAV, numStr);
OnPaint( hDlg );
//Get access to the needed device context
hWndGrid = GetDlgItem( hDlg, IDC_RENDER_WINDOW );

//Move the picture to the joystick position
MoveWindow(hWndGrid, joy_x-15, joy_y-15, 50, 50, TRUE);

// Make sure the picture window is visible.
ShowWindow(hWndGrid, SW_SHOW);

//UpdateWindow( hDlg );
return TRUE;

case WM_DESTROY:
//create a static data file
CreateStaticData(userId);
// Cleanup everything
KillTimer( hDlg, 0 );
FreeDirectInput();
return TRUE;
}

//-----------------------------------------------------------------------------
// Name: OnPaint()
// Desc: Handles the WM_PAINT window message
//-----------------------------------------------------------------------------
VOID OnPaint( HWND hDlg )
{
PAINTSTRUCT ps;
HDC hDC;
HPEN hpenOld;
HPEN hpenBlack;
HBRUSH hbrOld;
HBRUSH hbrBlack, hbrRed, hbrYellow, hbrBlue, hbrGreen, hbrLightBlue, hbrOrange, hbrWhite;
HRGN hrgn;

hDC = BeginPaint( hDlg, &ps );
if( NULL == hDC )
return;

// Everything is scaled to the size of the window.
hpenBlack = GetStockPen( BLACK_PEN );
hpenOld = SelectPen( hDC, hpenBlack );

// Draw force feedback bounding rect
MoveToEx( hDC, FEEDBACK_WINDOW_X, FEEDBACK_WINDOW_Y, NULL );

LineTo( hDC, FEEDBACK_WINDOW_X,
FEEDBACK_WINDOW_Y + FEEDBACK_WINDOW_HEIGHT );
LineTo( hDC, FEEDBACK_WINDOW_X + FEEDBACK_WINDOW_HEIGHT,
FEEDBACK_WINDOW_Y + FEEDBACK_WINDOW_HEIGHT );
LineTo( hDC, FEEDBACK_WINDOW_X + FEEDBACK_WINDOW_HEIGHT,
FEEDBACK_WINDOW_Y );
LineTo( hDC, FEEDBACK_WINDOW_X,
FEEDBACK_WINDOW_Y );

//create different colour brushes
hbrBlack = GetStockBrush( BLACK_BRUSH );
hbrWhite = CreateSolidBrush(RGB(255, 255, 255));
hbrRed = CreateSolidBrush(RGB(255, 0, 0));
hbrYellow = CreateSolidBrush(RGB(255, 255, 0));
hbrBlue = CreateSolidBrush(RGB(0, 0, 255));
hbrGreen = CreateSolidBrush(RGB(0, 255, 0));
hbrLightBlue = CreateSolidBrush(RGB(100, 200, 200));
hbrOrange = CreateSolidBrush(RGB(255, 150, 0));
hbrOld = SelectBrush( hDC, hbrBlack );


//colour the bounding rectangle
hrgn = CreateRectRgn(FEEDBACK_WINDOW_X+1, FEEDBACK_WINDOW_Y+1, FEEDBACK_WINDOW_X+ FEEDBACK_WINDOW_HEIGHT-1, FEEDBACK_WINDOW_Y+ FEEDBACK_WINDOW_HEIGHT-1);
FillRgn(hDC, hrgn, hbrWhite);

// my new code to try and display a background image
/////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////
//new code to erase background
// LRESULT CALLBACK WindowProc(
// HWND hwnd, // handle to window
// UINT uMsg, // WM_ERASEBKGND
// WPARAM wParam, // handle to device context (HDC)
// LPARAM lParam // not used
//);


//calculate the joystick position
joy_x = MulDiv( FEEDBACK_WINDOW_HEIGHT, g_nXForce + DI_FFNOMINALMAX,
2 * DI_FFNOMINALMAX );

joy_y = MulDiv( FEEDBACK_WINDOW_HEIGHT, g_nYForce + DI_FFNOMINALMAX,
2 * DI_FFNOMINALMAX );

joy_x += FEEDBACK_WINDOW_X;
joy_y += FEEDBACK_WINDOW_Y;

//if low vision is on draw a bigger control object
if(!lowVisionOn)
Rectangle( hDC, joy_x-10, joy_y-10, joy_x+11, joy_y+11 );
else
Rectangle( hDC, joy_x-15, joy_y-15, joy_x+16, joy_y+16 );

int x, y;

//draw the targets
int i;
for(i=0; i<targetsnum; i++)
="" {
="" x="targets_x[i];
" y="targets_y[i];

" if(i="">= currentTargetNum){
if(trajectoryOn && i!=0)
DrawTrajectory(hDC, i);

if(highlightOn && i == currentTargetNum)
SelectBrush( hDC, hbrRed );
else
SelectBrush( hDC, hbrBlack );


if(!lowVisionOn)
Ellipse( hDC, x-10, y-10, x+11, y+11 );
else
Ellipse( hDC, x-15, y-15, x+16, y+16 );
}
}

//select the current target
targetX = targets_x[currentTargetNum];
targetY = targets_y[currentTargetNum];



//if force feedback is on draw the dead zone
if(ffOn == 1){
Arc(hDC, targetX -fDeadZone, targetY-fDeadZone, targetX+fDeadZone,
targetY+fDeadZone, targetX+fDeadZone, targetY, targetX+fDeadZone, targetY);
}

//check whether the target has been hit
hrgn = CreateEllipticRgn(targetX-radius, targetY-radius, targetX+radius, targetY+radius);
//display the hit zone
FillRgn(hDC, hrgn, hbrBlue);
if(PtInRegion(hrgn, joy_x, joy_y))
{
currentTargetNum++;
score++;

//if no more targets are left display the winning message
if(currentTargetNum == targetsNum)
{
if(MessageBox( NULL, TEXT("Congratulations! ")\
TEXT("You win!")\
TEXT("Do you want to play again? "),
TEXT("End of game"),
MB_YESNO | MB_TASKMODAL) == IDYES){
start = 1;
startBack = 1;
currentTargetNum = 0;
}
EndDialog(hDlg, TRUE);
}

}

SelectBrush( hDC, hbrOld );
SelectPen( hDC, hpenOld );

EndPaint( hDlg, &ps );
//ReleaseDC(hDlg, hDC);

}




Many thanks
ANDY
QuestionHTTPS POST returning 100 Continue makes the WebClient throw protocol violation exception [modified] Pin
Corneliu Tusnea25-Feb-07 12:57
memberCorneliu Tusnea25-Feb-07 12:57 
QuestionStrongly named assemblies & 3rd-party COM/OCX Pin
Len Miller25-Feb-07 10:54
memberLen Miller25-Feb-07 10:54 
Questionintegrating visual studio.net 2003 or 2005 with autocad or 3d studio max Pin
mestkaniasa25-Feb-07 8:53
membermestkaniasa25-Feb-07 8:53 
Questionhelp on project biulding Pin
thesad25-Feb-07 3:17
memberthesad25-Feb-07 3:17 
AnswerRe: help on project biulding Pin
Colin Angus Mackay25-Feb-07 4:03
memberColin Angus Mackay25-Feb-07 4:03 
GeneralRe: help on project biulding Pin
thesad25-Feb-07 6:12
memberthesad25-Feb-07 6:12 
Question.NET Security Configuration Pin
Ian Uy24-Feb-07 16:17
memberIan Uy24-Feb-07 16:17 
AnswerRe: .NET Security Configuration Pin
Colin Angus Mackay25-Feb-07 4:02
memberColin Angus Mackay25-Feb-07 4:02 
QuestionGeneral question about object reference in .NET Framework Pin
Yanshof24-Feb-07 10:07
memberYanshof24-Feb-07 10:07 
AnswerRe: General question about object reference in .NET Framework Pin
Luc Pattyn24-Feb-07 10:59
professionalLuc Pattyn24-Feb-07 10:59 
GeneralRe: General question about object reference in .NET Framework Pin
Yanshof24-Feb-07 19:19
memberYanshof24-Feb-07 19:19 
GeneralRe: General question about object reference in .NET Framework Pin
Luc Pattyn24-Feb-07 23:20
professionalLuc Pattyn24-Feb-07 23:20 
QuestionXML inside WebBrowser control causes large delay when unloading the control Pin
Michael Wolski23-Feb-07 3:38
memberMichael Wolski23-Feb-07 3:38 
AnswerRe: XML inside WebBrowser control causes large delay when unloading the control Pin
Michael Wolski23-Feb-07 3:54
memberMichael Wolski23-Feb-07 3:54 
QuestionImplementing some broadcast udp protocol Pin
ohad_2923-Feb-07 3:31
memberohad_2923-Feb-07 3:31 
QuestionMailMessage.From vs. MailMessage.Sender in .NET 2.0 Pin
SindyatIndy22-Feb-07 6:29
memberSindyatIndy22-Feb-07 6:29 
AnswerRe: MailMessage.From vs. MailMessage.Sender in .NET 2.0 Pin
Scott Dorman22-Feb-07 18:02
professionalScott Dorman22-Feb-07 18:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.