Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualPointer2APointer

Posted 06 October 2012 - 01:52 PM

First of all, you probably mean a VERY simple game engine, like maybe one that dictates coordinates on a cartesian plane of bounded raster images in memory in a window, and maybe input synchronization.

You can implement a super-simple engine like this, pretty much:

#include <SDL/SDL.h>
void ShowBMP(char *file, SDL_Surface *screen, int x, int y)
{
    SDL_Surface *image;
    SDL_Rect dest;
    /* Load the BMP file into a surface */
    image = SDL_LoadBMP(file);
    if ( image == NULL ) {
	    fprintf(stderr, "Couldn't load %s: %s\n", file, SDL_GetError());
	    return;
    }
    /* Blit onto the screen surface.
	   The surfaces should not be locked at this point.
	 */
    dest.x = x;
    dest.y = y;
    dest.w = image->w;
    dest.h = image->h;
    SDL_BlitSurface(image, NULL, screen, &dest);
    /* Update the changed portion of the screen */
    SDL_UpdateRects(screen, 1, &dest);
}

This is basically a skeleton source code that can be brushed up to draw images into memory.

It is reusable, and fixed now for any future readers.

#1Pointer2APointer

Posted 02 October 2012 - 01:34 PM

First of all, you probably mean a VERY simple game engine, like maybe one that dictates coordinates on a cartesian plane of bounded raster images in memory in a window, and maybe input synchronization.

You can implement a super-simple engine like this, pretty much:

// This is using SDL and C++ as an example.
#include <SDL/SDL.h>
typedef SDL_Surface * LOAD;
class GameEngine
{
public:
GameEngine() // Put whatever here for the constructor params.
{
// Here, too, for whatever you want it to initialize.
}
}
class Player : public GameEngine
{
public:
Draw_Image(short xpos, short ypos, short xheight, short yheight, const char *FILE_NAME)
{
// Render the image here, optimizations, etc.
}
private:
short x, y;
short height, width;
}

This is basically a skeleton source code that can be brushed up to draw images by passing arguments to the function Draw_Image in the Player class, which inherits from the main GameEngine class. This way you can reuse, edit, and have an image blitted to the screen of any kind as long as its position and size fits in a 16-bit short(I could have elaborated more, but I think this gives the basic idea of an engine).

This way you can also "ask" the engine for the image's position, change the position, change the image, and I could have (but neglected) to add that you can invoke a separate copy constructor to allocate objects off the heap, deallocate them to free memory, and reuse them to create character class objects that handle data within a larger class that manages all of the logic through smaller sub-systems.

PARTNERS