• Advertisement

Archived

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

AAaaarggh - Extra eyes needed - HELP Please

This topic is 5832 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

Hey, I am stiil working on my breakout clone, I am cool wqith everything except getting the damn blocks in the damn gamegrid row/column order. At first I got them in a random display on the surface. Now I get one block at the top left of the screen and it looks like it is doing the loop but not moving across so it''s one block flashing non stop. I am making a bit of progress but I think it''s something stupid and simple that I''ve either messed up or missed but I cannot for the life of me see what it is. The problem lies with the Draw_Blocks() function but I have included the entire code so you can get the jist of what I''m doing because it does appear a bit odd at first. All I need is someone with more experience to look at Draw_Blocks() and see where I''m going wrong and let me know what I''ve done wrong. I dont'' want a total rewrite of the code rather just a few mods to the function or whatever is the prob. Sorry for the long post but you I''ve tried to include as much info as possible.
  
// Yaaaargh you mother fucking waste of bitch


// INCLUDES ///////////////////////////////////////////////


#define WIN32_LEAN_AND_MEAN  

#define INITGUID           // if not done elsewhere
#include <stdAfx.h>


#include <windows.h>       // include important windows stuff
#include <windowsx.h> 
#include <mmsystem.h>
#include <objbase.h>
#include <iostream.h>      // include important C/C++ stuff
#include <conio.h>
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <string.h>
#include <stdarg.h>
#include <stdio.h> 
#include <math.h>
#include <io.h>
#include <fcntl.h>


#include <ddraw.h>          // directX includes
#include <dinput.h>
#include "T3DLIB1.H"        // graphics library


// DEFINES ////////////////////////////////////////////////


// defines for windows 

#define WINDOW_CLASS_NAME "WINCLASS1"

// default screen size

#define SCREEN_WIDTH    640  // size of screen
#define SCREEN_HEIGHT   480
#define SCREEN_BPP      8    // bits per pixel


#define BITMAP_ID            0x4D42 // universal id for a bitmap
#define MAX_COLORS_PALETTE   256    // defines 8bit palette


#define NUM_BLOCK_ROWS       6      // blocks stuff
#define NUM_BLOCK_COLUMNS    8


#define BLOCK_ORIGIN_X       8
#define BLOCK_ORIGIN_Y       8
#define BLOCK_X_GAP          80
#define BLOCK_Y_GAP          32
// TYPES ///////////////////////////////////////////////////


// PROTOTYPES /////////////////////////////////////////////


// game console

int Game_Init(void *parms=NULL, int num_parms = 0);
int Game_Shutdown(void *parms=NULL, int num_parms = 0);
int Game_Main(void *parms=NULL,  int num_parms = 0);

// GLOBALS ////////////////////////////////////////////////


// windows vars

HWND      main_window_handle = NULL; // globally track main window

int       window_closed      = 0;    // tracks if window is closed

HINSTANCE main_instance      = NULL; // globally track hinstance


char buffer[80];                     // used to print text


BITMAP_IMAGE reactor;                // the background  image 

BITMAP_IMAGE blocks_bmp[4];          // the blocks images 4 types


int        index;                    // counting loop variable

int        row;
int        col;

UCHAR blockgrid[NUM_BLOCK_ROWS][NUM_BLOCK_COLUMNS];

// PROTOTYPES //////////////////////////////////////////////


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

char buffer[80];        // used to print strings


// 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	= WINDOW_CLASS_NAME;
winclass.hIconSm        = LoadIcon(NULL, IDI_APPLICATION);

// save hinstance in global

main_instance = hinstance;

// register the window class

if (!RegisterClassEx(&winclass))
	return(0);

// create the window

if (!(hwnd = CreateWindowEx(NULL,                  // extended style

                            WINDOW_CLASS_NAME,     // class

						    "Breakout Version 0.1 P.Kirkbride", // title

						    WS_POPUP | WS_VISIBLE,
					 	    0,0,	  // initial x,y

						    SCREEN_WIDTH,SCREEN_HEIGHT,  // initial width, height

						    NULL,	  // handle to parent 

						    NULL,	  // handle to menu

						    hinstance,// instance of this application

						    NULL)))	// extra creation parms

return(0);

// save main window handle

main_window_handle = hwnd;

// initialize game here

Game_Init();

// 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

       Game_Main();
       
	} // end while


// closedown game here

Game_Shutdown();

// return to Windows like this

return(msg.wParam);

} // end WinMain


///////////////////////////////////////////////////////////

//GAME FUNCTIONS

///////////////////////////////////////////////////////////


////////////////////////////////////////////////////////////


void Init_Blocks(void)
{
	for (int row=0; row < NUM_BLOCK_ROWS; row++)
		for (int col=0; col < NUM_BLOCK_COLUMNS; col++)
			blockgrid[row][col] = row*16+col*3+16;
}

/////////////////////////////////////////////////////////////



// Actually puts the loaded block bitmaps onto the surface

void Draw_Blocks(void)
{
	int x1 = BLOCK_ORIGIN_X,
		y1 = BLOCK_ORIGIN_Y;

	for (row=0; row<NUM_BLOCK_ROWS; row++)
	{
		x1 = BLOCK_ORIGIN_X;

		for (col=0; col<NUM_BLOCK_COLUMNS; col++)
		{
				int block = rand()%4;
				Draw_Bitmap(&blocks_bmp[block], reactor.buffer, reactor.width,1);
			}
		x1+=BLOCK_X_GAP;
	}
	y1+=BLOCK_Y_GAP;
}


////////////////////////////////////////////////////////////


// GAME PROGRAMMING CONSOLE FUNCTIONS ////////////////


int Game_Init(void *parms,  int num_parms)
{
// this function is where you do all the initialization 

// for your game


int index;         // looping var

char filename[80]; // used to build up files names


// initialize directdraw

DDraw_Init(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP);

///////////////////////////////////////////////////////////////

Load_Bitmap_File(&bitmap8bit, "MUSH.BMP"); // Load blocks

Set_Palette(bitmap8bit.palette);           // Set to block palette


for (index=0; index < 4; index++)          // load in 4 types of block

{
	Create_Bitmap(&blocks_bmp[index],0,0,32,32);
	Load_Image_Bitmap(&blocks_bmp[index],&bitmap8bit,index,0,BITMAP_EXTRACT_MODE_CELL);
} // end of 4 type block template load


Unload_Bitmap_File(&bitmap8bit); // unload and restore resources



////////////////////////////////////////////////////////////////


RECT screen_rect = {0,0,screen_width,screen_height}; // Set clipper

lpddclipper = DDraw_Attach_Clipper(lpddsback,1,&screen_rect);

// load the background

Create_Bitmap(&reactor,0,0,SCREEN_WIDTH,SCREEN_HEIGHT);
reactor.attr |=BITMAP_ATTR_LOADED;

Load_Bitmap_File(&bitmap8bit, "grass.BMP");
Load_Image_Bitmap(&reactor,&bitmap8bit,0,0,BITMAP_EXTRACT_MODE_ABS);
Unload_Bitmap_File(&bitmap8bit);

Init_Blocks();    // Initilize the block field

//Draw_Blocks();    // Puts the bitmap image blocks onto the screen


// return success

return(1);

} // end Game_Init


///////////////////////////////////////////////////////////


int Game_Shutdown(void *parms,  int num_parms)
{
// this function is where you shutdown your game and

// release all resources that you allocated


// kill the reactor

Destroy_Bitmap(&reactor); // Get rid of background image


// shutdonw directdraw

DDraw_Shutdown();

// return success

return(1);
} // end Game_Shutdown


///////////////////////////////////////////////////////////////


int Game_Main(void *parms, int num_parms)
{
// this is the workhorse of your game it will be called

// continuously in real-time this is like main() in C

// all the calls for you game go here!


// check of user is trying to exit

if (KEY_DOWN(VK_ESCAPE) || KEY_DOWN(VK_SPACE))
    PostMessage(main_window_handle, WM_DESTROY,0,0);

// clear the drawing surface

DDraw_Fill_Surface(lpddsback, 0);

// lock the back buffer

DDraw_Lock_Back_Surface();

// draw the background reactor image

Draw_Bitmap(&reactor, back_buffer, back_lpitch, 0);

// unlock the back buffer

DDraw_Unlock_Back_Surface();

// draw some text

Draw_Text_GDI("USE ARROW KEYS TO MOVE, <ESC> TO EXIT.",0,0,RGB(32,32,32),lpddsback);

Draw_Blocks();

// flip the surfaces

DDraw_Flip();

// return success

return(1);

} // end Game_Main


//////////////////////////////////////////////////////////

  

Share this post


Link to post
Share on other sites
Advertisement
In your Draw_Blocks() function, presumably x1 and y1 are supposed to store the x and y coordinates of the current block you are drawing. If this is the case, you might want to consider passing that data to your Draw_Bitmap function.

Share this post


Link to post
Share on other sites
ARGHWOOOOGA! ARGHWOOOOGA! ARGHWOOGA!
Extra wide code warning!
ARGHWOOOOGA! ARGHWOOOOGA! ARGHWOOGA!

Yeah ditto, Sandman is dead right.


Good luck with the rest of the game,
zipless

Share this post


Link to post
Share on other sites
Hey,

What I''ve tried doing is adding the variables x1, y1 to the DrawBitmap() function and then stick them on the end of the DrawBitmap() function in the Draw_Blocks function but still won''t work, is this what you mean??????????????????????????

The Xtra long source was unfortunate LOL

Share this post


Link to post
Share on other sites
I think you might have to post your Draw_Bitmaps function as well. Just sticking some extra parameters isn''t going to help - you have to actually *use* those parameters. In other words, your Draw_Bitmaps function should take the X and Y coordinates, convert them into screen coordinates and then draw the bitmap at those coordinates.

Share this post


Link to post
Share on other sites
Hey,

I think I know what your getting at but I don''t have a clue how to implement it. Here''s the DrawBitmap function: -

  
int Draw_Bitmap(BITMAP_IMAGE_PTR source_bitmap,UCHAR *dest_buffer, int lpitch, int transparent)
{
// this function draws the bitmap onto the destination memory surface

// if transparent is 1 then color 0 will be transparent

// note this function does NOT clip, so be carefull!!!


UCHAR *dest_addr, // starting address of bitmap in destination

*source_addr; // starting adddress of bitmap data in source


UCHAR pixel; // used to hold pixel value


int index, // looping vars

pixel_x;

// test if this bitmap is loaded


if (source_bitmap->attr & BITMAP_ATTR_LOADED)
{
// compute starting destination address

dest_addr = dest_buffer + source_bitmap->y*lpitch + source_bitmap->x;

// compute the starting source address

source_addr = source_bitmap->buffer;

// is this bitmap transparent

if (transparent)
{
// copy each line of bitmap into destination with transparency

for (index=0; index<source_bitmap->height; index++)
{
// copy the memory

for (pixel_x=0; pixel_x<source_bitmap->width; pixel_x++)
{
if ((pixel = source_addr[pixel_x])!=0)
dest_addr[pixel_x] = pixel;

} // end if


// advance all the pointers

dest_addr += lpitch;
source_addr += source_bitmap->width;

} // end for index

} // end if

else
{
// non-transparent version

// copy each line of bitmap into destination


for (index=0; index<source_bitmap->height; index++)
{
// copy the memory

memcpy(dest_addr, source_addr, source_bitmap->width);

// advance all the pointers

dest_addr += lpitch;
source_addr += source_bitmap->width;

} // end for index


} // end else


// return success

return(1);

} // end if

else
return(0);

} // end Draw_Bitmap

Share this post


Link to post
Share on other sites
OK, change your draw_blocks function to this

    
void Draw_Blocks(void)
{
int x1 = BLOCK_ORIGIN_X,
y1 = BLOCK_ORIGIN_Y;
for (row=0; row<NUM_BLOCK_ROWS; row++)
{
x1 = BLOCK_ORIGIN_X;
for (col=0; col<NUM_BLOCK_COLUMNS; col++)
{
int block = rand()%4;
blocks_bmp[block].x = x1;
blocks_bmp[block].y = y1;
Draw_Bitmap(&blocks_bmp[block],reactor.buffer, reactor.width,1);
}
x1+=BLOCK_X_GAP;
y1+=BLOCK_Y_GAP;
}
}


Edited by - Sandman on February 4, 2002 11:15:00 AM

Share this post


Link to post
Share on other sites
Hey,

I now have 1 column of single block bitmaps but no rows. Still its a better effort than mine. Any ideas, and thanks for all the help its been doing my nut for a few days now.

Pk

Share this post


Link to post
Share on other sites
The increase for x1 is in the wrong spot.

Try this:
  
for (row=0; row<NUM_BLOCK_ROWS; row++) {
x1 = BLOCK_ORIGIN_X;
for (col=0; col<NUM_BLOCK_COLUMNS; col++) {
int block = rand()%4;
blocks_bmp[block].x = x1;
blocks_bmp[block].y = y1;
Draw_Bitmap(&blocks_bmp[block],reactor.buffer, reactor.width,1);
x1+=BLOCK_X_GAP; //this was in the wrong spot

}
y1+=BLOCK_Y_GAP;
}


---
Make it work.
Make it fast.

"Commmmpuuuuterrrr.." --Scotty Star Trek IV:The Voyage Home

Share this post


Link to post
Share on other sites
Sorry - my bad. I cocked up the braces when I reformatted after the cutnpaste

    
void Draw_Blocks(void)
{
int x1 = BLOCK_ORIGIN_X,
y1 = BLOCK_ORIGIN_Y;
for (row=0; row<NUM_BLOCK_ROWS; row++)
{
x1 = BLOCK_ORIGIN_X;
for (col=0; col<NUM_BLOCK_COLUMNS; col++)
{
int block = rand()%4;
blocks_bmp[block].x = x1;
blocks_bmp[block].y = y1;
Draw_Bitmap(&blocks_bmp[block],reactor.buffer, reactor.width,1);
x1+=BLOCK_X_GAP;
}
y1+=BLOCK_Y_GAP;
}
}


I think that should fix it.


Edited by - Sandman on February 4, 2002 12:37:00 PM

Share this post


Link to post
Share on other sites
beat me to it by about a minute, must be getting slow in my old age...

Yeah, that should be you sorted now.

zipless

Share this post


Link to post
Share on other sites

  • Advertisement