• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.

Archived

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

PsYcHoPrOg

HELP!!!

5 posts in this topic

I made this little app to try and get a 32x32 bitmap to bounce around the screen, but it''s not working! I just get a blank screen! If anyone could help, I would really appreciate it! Here''s the code: #define WIN32_LEAN_AND_MEAN //include important stuff #include #include #include #include #include //#include "Blitex.h" #define Rgb16Bit565(r,g,b) ((b%32) + ((g%64) << 6) + ((r%32) << 11)) #define KEYDOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0) #define KEYUP(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1) int GameInit(); int GameMain(); int GameEnd(); //declarations struct Mover { int bitheight; int bitwidth; int locationx; int locationy; int velocityx; int velocityy; RECT mover; }MOVER; Mover Mover1; int mainloop = 0; int locx; int locy; int velx; int vely; int bh; int hw; bool LoadBMP(LPDIRECTDRAWSURFACE4 surface, LPSTR filename); HWND window_handle = NULL; HINSTANCE instance = NULL; LPDIRECTDRAW lpdd = NULL; LPDIRECTDRAW4 lpdd4 = NULL; LPDIRECTDRAWSURFACE4 pbuff = NULL; LPDIRECTDRAWSURFACE4 bbuff = NULL; LPDIRECTDRAWSURFACE4 Bitmap = NULL; DDSURFACEDESC2 ddsd; DDSCAPS2 ddscaps; HRESULT hr; DDBLTFX bltfx; LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { // this is the main message handler of the system PAINTSTRUCT ps; // used in WM_PAINT HDC hdc; // handle to a device context // what is the message switch(msg) { case WM_CREATE: { // do initialization stuff here // return success return(0); } break; case WM_PAINT: { // simply validate the window hdc = BeginPaint(hwnd,&ps); // end painting EndPaint(hwnd,&ps); // return success return(0); } break; case WM_DESTROY: { // kill the application, this sends a WM_QUIT message PostQuitMessage(0); // return success return(0); } break; default:break; } // end switch // process any messages that we didn''t take care of return (DefWindowProc(hwnd, msg, wparam, lparam)); } // end WinProc // WINMAIN //////////////////////////////////////////////// int WINAPI WinMain( HINSTANCE hinstance, HINSTANCE hprevinstance, LPSTR lpcmdline, int ncmdshow) { WNDCLASSEX winclass; // this will hold the class we create HWND hwnd; // generic window handle MSG msg; // generic message //HDC hdc; // graphics device context // first fill in the window class stucture winclass.cbSize = sizeof(WNDCLASSEX); winclass.style = CS_DBLCLKS / CS_OWNDC / CS_HREDRAW / CS_VREDRAW; winclass.lpfnWndProc = WindowProc; winclass.cbClsExtra = 0; winclass.cbWndExtra = 0; winclass.hInstance = hinstance; winclass.hIcon = LoadIcon(NULL, IDI_APPLICATION); winclass.hCursor = LoadCursor(NULL, IDC_ARROW); winclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); winclass.lpszMenuName = NULL; winclass.lpszClassName = "class"; winclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION); // save hinstance in global instance = hinstance; // register the window class if (!RegisterClassEx(&winclass)) return(0); // create the window if (!(hwnd = CreateWindowEx(NULL, // extended style "class", // class "BlitMove", // title WS_POPUP / WS_VISIBLE, 0,0, // initial x,y 640,480, // initial width, height NULL, // handle to parent NULL, // handle to menu hinstance,// instance of this application NULL))) // extra creation parms return(0); ShowCursor(FALSE); // save main window handle window_handle = hwnd; // initialize game here GameInit(); // enter main event loop while(TRUE) { // test if there is a message in queue, if so get it if (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) { // test if this is a quit if (msg.message == WM_QUIT) break; // translate any accelerator keys TranslateMessage(&msg); // send the message to the window proc DispatchMessage(&msg); } // end if // main game processing goes here GameMain(); } // end while // closedown game here GameEnd(); // return to Windows like this return(msg.wParam); } // end WinM bool LoadBMP(LPDIRECTDRAWSURFACE4 surface, LPSTR filename) { HBITMAP hbm; HDC imagedc; HDC surfacedc; DDSURFACEDESC2 ddsd2; DDSCAPS2 ddscaps2; memset(&ddsd2, 0, sizeof(ddsd2)); ddsd2.dwSize = sizeof(ddsd2); if(FAILED(surface->GetSurfaceDesc(&ddsd2))) return FALSE; memset(&ddscaps2, 0, sizeof(ddscaps2)); if(FAILED(surface->GetCaps(&ddscaps))) return FALSE; hbm = (HBITMAP)LoadImage(NULL, filename, IMAGE_BITMAP, ddsd2.dwWidth, ddsd2.dwHeight, LR_LOADFROMFILE/ LR_CREATEDIBSECTION); imagedc = CreateCompatibleDC(NULL); SelectObject(imagedc, hbm); if(FAILED(surface->GetDC(&surfacedc))) return FALSE; if(!(BitBlt(surfacedc, 0, 0, ddsd2.dwWidth, ddsd2.dwHeight, imagedc, 0, 0, SRCCOPY))) return FALSE; if(surfacedc) surface->ReleaseDC(surfacedc); if(imagedc) DeleteDC(imagedc); if(hbm) DeleteObject(hbm); return TRUE; }//end LoadBMP // int GameInit() { if(FAILED(DirectDrawCreate(NULL, &lpdd, NULL))) return(0); if(FAILED(lpdd->QueryInterface(IID_IDirectDraw4, (LPVOID *)&lpdd4))) return(0); if(FAILED(lpdd4->SetCooperativeLevel(window_handle, DDSCL_FULLSCREEN/ DDSCL_EXCLUSIVE/DDSCL_ALLOWREBOOT))) return(0); if(FAILED(lpdd4->SetDisplayMode(640, 480, 16, 0, 0))) return(0); memset(&ddsd, 0, sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); ddsd.dwFlags = DDSD_CAPS/DDSD_BACKBUFFERCOUNT; ddsd.dwBackBufferCount = 1; ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE/ DDSCAPS_COMPLEX/ DDSCAPS_FLIP; if(FAILED(lpdd4->CreateSurface(&ddsd, &pbuff, NULL))) return(0); //********************************* // You were using the ddsd instead of ddscaps // ie. ddsd.ddsCaps.dwCaps = ... // should be: // ddscaps.dwCaps = ... // The back buffer uses the ddscaps while the primary uses the ddsd memset(&ddscaps, 0, sizeof(ddscaps)); ddscaps.dwCaps = DDSCAPS_BACKBUFFER; if(FAILED(pbuff->GetAttachedSurface(&ddscaps, &bbuff))) return(0); memset(&ddsd, 0, sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); ddsd.dwFlags = DDSD_CAPS/DDSD_HEIGHT/DDSD_WIDTH; ddsd.dwWidth = 640; ddsd.dwHeight = 480; ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; if(FAILED(lpdd4->CreateSurface(&ddsd, &Bitmap, NULL))) return (0); LoadBMP(Bitmap, "image.bmp"); //***************************** // Make sure to return a value return 1; }//end GameInit() inline int CreateMover(Mover create) { create.mover.top = 200; create.mover.left = 320; create.mover.bottom = 232; create.mover.right = 352; create.velocityx = rand()%5; create.velocityy = rand()%5; return(1); } //Clear the screen for the next frame inline int CLS(LPDIRECTDRAWSURFACE4 surface) { memset(&bltfx, 0, sizeof(bltfx)); bltfx.dwSize = sizeof(bltfx); bltfx.dwFillColor = Rgb16Bit565(0, 0, 0); if(FAILED(surface->Blt(NULL, NULL, NULL, DDBLT_COLORFILL/ DDBLT_WAIT, &bltfx))) return(0); return(1); }//end CLS() int UpdateMover(LPDIRECTDRAWSURFACE4 surface,Mover update) { velx = update.velocityx; vely = update.velocityy; update.mover.top += vely; update.mover.left += velx; update.mover.bottom += vely; update.mover.right += velx; if( update.mover.right >= 640 ) { update.mover.left -= (update.mover.right - 640); update.mover.right = 640; update.velocityx = -velx; } else if( update.mover.left <= 0 ) { update.mover.right -= update.mover.left; update.mover.left = 0; update.velocityx = -velx; } if( update.mover.bottom >= 480 ) { update.mover.top -= (update.mover.bottom - 480); update.mover.bottom = 480; update.velocityy = -vely; } else if( update.mover.top <= 0 ) { update.mover.bottom -= update.mover.top; update.mover.top = 0; update.velocityy = -vely; } RECT image_rect = { 0, 0, 32, 32 }; //Blit the mover''s new location if(FAILED(surface->Blt(&update.mover,Bitmap, &image_rect,DDBLT_WAIT,NULL))) return 0; return 1; } int GameMain() { //test if user is escaping if(KEYDOWN(VK_ESCAPE)) PostMessage(window_handle, WM_CLOSE, 0, 0); //If this is the first time around, create a mover CLS(bbuff); if(mainloop == 0) { CreateMover(Mover1); UpdateMover(bbuff, Mover1); } //if it''s another time around, just update it else { UpdateMover(bbuff, Mover1); } //flip the two surfaces if(FAILED(pbuff->Flip(NULL, DDFLIP_WAIT))) return(0); //add to MainLoop mainloop++; return(1); //Wait a sec Sleep(500); } //Kill everything int GameEnd() { if (Bitmap) { Bitmap->Release(); Bitmap = NULL; } if(bbuff) { bbuff->Release(); bbuff = NULL; } if(pbuff) { pbuff->Release(); pbuff = NULL; } if(lpdd4) { lpdd4->Release(); lpdd4 = NULL; } return(1); } "Remember, I'm the monkey, and you're the cheese grater. So no fooling around." -Grand Theft Auto, London
0

Share this post


Link to post
Share on other sites
I notice you''re using a forward slash instead of a pipe in GameInit() and maybe another place.. I don''t have time to study it all, but you may want to check that out... otherwise it looked fine as I perused it...
0

Share this post


Link to post
Share on other sites
That''s simply a problem in the GameDev Forums. Look, I''ll put five pipes right here: /////

Anyway, It doesn''t seem to work! I don''t know why!

"Remember, I'm the monkey, and you're the cheese grater. So no fooling around."
-Grand Theft Auto, London
0

Share this post


Link to post
Share on other sites
There are 2 things that could go wrong - either the bitmap was not loaded (and you are blitting a black square) or the blit is not right. Did you check what kind of error values you are getting back from the LoadBitmap and the Blt function? These might indicate what is going on. Don''t just return a zero - you might want to quit on an error and then put up a messagebox saying what the error value was. It could be something as simple as not finding "image.bmp" (Visual C++ will stick the .exe in a different directory than the code - try hard coding a path) and you would never know without checking the error values.

You might also want to temporarily comment out the extra stuff (BMP movement, page flipping) until you can just get a bitmap on the screen.

Otherwise, it looks good homeslice! (I love LaMothe''s books!)


---
Grandpa Simpson - "I never thought I could shoot down a German plane, but last year I proved myself wrong!"
0

Share this post


Link to post
Share on other sites
I've used the same exact fuction in another app to simply load a bitmap onto a surface and it worked in the other app. So I'm positive that it works. However, I don't know why the code itself doesn't work here! I'm going to go C r AzY!!!

"Remember, I'm the monkey, and you're the cheese grater. So no fooling around."
-Grand Theft Auto, London

Edited by - PsYcHoPrOg on 3/3/00 3:03:39 PM
0

Share this post


Link to post
Share on other sites
Someone replied to your other post about this problem that you need to pass your Mover struct "by reference" to the CreateMover and UpdateMover functions. Have you tried that yet?
0

Share this post


Link to post
Share on other sites