|
Post by aurel on Apr 10, 2020 13:01:11 GMT -6
Hello boys
I made game in C..yeah..is not a game it is a just demo when i play with some GDI windows example
written in pure c + win32 api
|
|
|
Post by aurel on Apr 11, 2020 7:50:25 GMT -6
If you not ..or can not believe here is a code and sh i#define WIN32_LEAN_AND_MEAN
#define TIMER_VELOCITY 1
#define TIMER_ANIMATE 2
#include <windows.h>
#include <stdlib.h>
//#include "resource.h"
HICON hMyIcon;
HBITMAP graphics[4];
HBITMAP g_hbmMask = NULL;
HDC hdcBuffer;
HBITMAP hbmBuffer;
int spriteX = 320, spriteY = 400;
typedef struct SpriteAnimation
{
int xpos;
int ypos;
int frames;
int x_velocity;
int counter;
int direction;
}SAKURA;
SAKURA g_spriteInfo;
HBITMAP CreateBitmapMask( HBITMAP hbmColour, COLORREF crTransparent )
{
HDC hdcMem, hdcMem2;
HBITMAP hbmMask;
BITMAP bm;
GetObject( hbmColour, sizeof( BITMAP ), &bm );
hbmMask = CreateBitmap( bm.bmWidth, bm.bmHeight, 1, 1, NULL );
hdcMem = CreateCompatibleDC( 0 );
hdcMem2 = CreateCompatibleDC( 0 );
SelectObject( hdcMem, hbmColour );
SelectObject( hdcMem2, hbmMask );
SetBkColor( hdcMem, crTransparent );
BitBlt( hdcMem2, 0, 0, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY );
BitBlt( hdcMem, 0, 0, bm.bmWidth, bm.bmHeight, hdcMem2, 0, 0, SRCINVERT );
DeleteDC( hdcMem );
DeleteDC( hdcMem2 );
return hbmMask;
}
void DrawScene( HDC hdc, RECT* prc )
{
HDC hdcBuffer = CreateCompatibleDC( hdc );
HBITMAP hbmBuffer = CreateCompatibleBitmap( hdc, prc->right, prc->bottom );
HBITMAP hbmOldBuffer = (HBITMAP)SelectObject( hdcBuffer, hbmBuffer );
HDC hdcMem = CreateCompatibleDC( hdc );
BitBlt(hdcBuffer, g_spriteInfo.xpos, g_spriteInfo.ypos, 32, 32, hdcMem, 4*(g_spriteInfo.frames%1), 0, SRCAND); //the sprite G
// BitBlt(hdcBuffer, spriteX, spriteY, 32, 32, hdcMem, 1, 0, SRCAND); //the sprite ship
SelectObject(hdcMem,graphics[1]); // sprG
BitBlt(hdcBuffer, g_spriteInfo.xpos, g_spriteInfo.ypos, 32, 32, hdcMem, 4*(g_spriteInfo.frames%1), 0, SRCPAINT); //spr G
SelectObject(hdcMem,graphics[3]); // ship
BitBlt(hdcBuffer, spriteX, spriteY, 32, 32, hdcMem, 0, 0, SRCPAINT); //ship
SelectObject(hdcMem,graphics[1]);
BitBlt( hdc, 0, 0, prc->right, prc->bottom, hdcBuffer, 0, 0, SRCCOPY );
// SelectObject(hdcMem,graphics[3]); //ship
//BitBlt( hdc, spriteX, spriteY, 32, 32 , hdcBuffer, 0, 0, SRCCOPY ); //ship
SelectObject( hdcMem, hbmBuffer );
DeleteDC( hdcMem );
SelectObject( hdcBuffer, hbmOldBuffer );
DeleteDC( hdcBuffer );
DeleteObject( hbmBuffer );
}
void AnimateSprite( RECT* prc )
{
g_spriteInfo.frames+=TIMER_ANIMATE;
}
void UpdateSpritePosition( RECT* prc )
{
g_spriteInfo.ypos += TIMER_VELOCITY;
g_spriteInfo.counter++;
if(g_spriteInfo.counter == 8)
{
if(g_spriteInfo.direction == 0 )
{
g_spriteInfo.x_velocity = 2;
g_spriteInfo.direction = 1;
}
else if (g_spriteInfo.direction == 1)
{
g_spriteInfo.x_velocity = -2;
g_spriteInfo.direction = 0;
}
g_spriteInfo.counter = 0;
}
g_spriteInfo.xpos += g_spriteInfo.x_velocity;
if ( g_spriteInfo.ypos > 460 ) //when the sprite goes beyond the bottom of the window
{
g_spriteInfo.ypos = -7; //re-set the position of the sprite to be above the top of the window
g_spriteInfo.xpos = abs(rand()*400/RAND_MAX); //randomize the x position of the sprite
}
if (spriteX > 640) // if out pf window
{
spriteX == 0;
}
}
LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
switch ( msg )
{
case WM_CREATE:
{
BITMAP bm;
SelectObject(hdcBuffer, hbmBuffer);
graphics[1] = LoadImageA( 0, "C:\\man.bmp", 0, 32,32,16 );
graphics[3] = LoadImageA( 0, "C:\\ship.bmp", 0, 32,32,16 );
graphics[0] = CreateBitmapMask( graphics[1], RGB( 0, 0, 0 ) );
graphics[2] = CreateBitmapMask( graphics[3], RGB( 0, 0, 0 ) );
GetObject( graphics, sizeof( bm ), &bm );
ZeroMemory( &g_spriteInfo, sizeof( g_spriteInfo ) );
g_spriteInfo.xpos = abs(rand()*405/RAND_MAX+10); //randomize starting x position
g_spriteInfo.direction = 0;
SetTimer( hwnd, TIMER_VELOCITY, 1, NULL );
SetTimer( hwnd, TIMER_ANIMATE, 2, NULL );
}
return 0;
case WM_KEYDOWN:
{
// SHOULD REALLY USE GetAsyncKeyState for game, but simplified here
switch (wParam)
{
case VK_LEFT :
spriteX=spriteX-4;
// MessageBox( hwnd, "KEY LEFT PRESSED!", "KEY_LEFT", MB_OK | MB_ICONEXCLAMATION );
break;
case VK_RIGHT:
spriteX=spriteX+4;
break;
case VK_UP:
spriteY=spriteY-4;
break;
case VK_DOWN:
spriteY=spriteY+4;
break;
}
return 0;//--------------------------------------------------------
}
case WM_CLOSE:
DestroyWindow( hwnd );
return 0;
case WM_PAINT:
{
RECT rcClient;
PAINTSTRUCT ps;
HDC hdc = BeginPaint( hwnd, &ps );
GetClientRect( hwnd, &rcClient );
DrawScene( hdc, &rcClient );
EndPaint( hwnd, &ps );
}
return 0;
//--------------------------------------------------------------------------
case WM_TIMER:
{
RECT rcClient;
GetClientRect( hwnd, &rcClient );
switch(wParam)
{
case TIMER_VELOCITY:
UpdateSpritePosition( &rcClient );
//spriteX = spriteX+1;
break;
case TIMER_ANIMATE:
AnimateSprite( &rcClient );
break;
}
InvalidateRect( hwnd, NULL, 0 );
}
return 0;
case WM_ERASEBKGND:
return 1;
case WM_DESTROY:
KillTimer( hwnd, TIMER_VELOCITY );
KillTimer( hwnd, TIMER_ANIMATE );
DeleteObject( graphics );
DeleteObject( g_hbmMask );
PostQuitMessage( 0 );
return 0;
}
return DefWindowProc( hwnd, msg, wParam, lParam );
}
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
{
hMyIcon = LoadIconW( hInstance, "\myicon.ico");
WNDCLASSEX wc = {0};
HWND hwnd;
MSG Msg;
wc.cbSize = sizeof( WNDCLASSEX );
wc.style = 0;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = hMyIcon;
wc.hIconSm = NULL;
wc.hCursor = LoadCursor( NULL, IDC_ARROW );
wc.hbrBackground = (HBRUSH)( COLOR_WINDOW + 1 );
wc.lpszMenuName = NULL;
wc.lpszClassName = TEXT( "Buttons" );
RegisterClassEx( &wc );
hwnd = CreateWindowEx( 0, TEXT("Buttons"), "Movin Ghost",
WS_OVERLAPPED | WS_SYSMENU |WS_VISIBLE |WS_CLIPCHILDREN, CW_USEDEFAULT, CW_USEDEFAULT, 640, 480, NULL, NULL, hInstance, NULL );
ShowWindow( hwnd, nCmdShow );
UpdateWindow( hwnd );
while ( GetMessage( &Msg, NULL, 0, 0 ) > 0 )
{
TranslateMessage( &Msg );
DispatchMessage( &Msg );
}
return Msg.wParam;
}nsert code here
|
|
|
Post by kennn on Apr 11, 2020 8:02:16 GMT -6
But why not use RCBasic to write the game? RCBasic is more versatile.
|
|
|
Post by tbird on Apr 11, 2020 8:27:06 GMT -6
Awesome aurel, and looks complicated lol, you must really like tinkering in the lower level stuff eh?
|
|
|
Post by aurel on Apr 11, 2020 9:04:27 GMT -6
I use C because i found it on gemedev forum and just modify it ,it is pure GDI win32api so i can easily translate it to o2 where code will be much smaller using my own include file,but with same speed of execution.
|
|
|
Post by Tomaaz on Apr 11, 2020 10:38:17 GMT -6
So, translate it and then post it here. Together with a link to the place you've found the original C code. And I agree - creating this kind of retro game in C doesn't really make sense when you could use RCBasic or NaaLaa. I was playing with C and Raylib recently (mainly because I wanted to gain some experience with C) and can say that it's much easier to use Raylib with other languages (especially Go and Ruby). Is it possible to call C libraries from Oxygen Basic? It would be something If you could create Raylib bindings for O2. Here is the list of already existing bindings - github.com/raysan5/raylib/blob/master/BINDINGS.md . At the moment, the only BASIC there is FreeBASIC. I was thinking about trying to make bindings for NewLisp, but it looks like NewLisp kinda died last year.
|
|
|
Post by aurel on Apr 11, 2020 11:57:02 GMT -6
Hey tomek
Yes of course that can,and not only that ,it can use dirctly windows.h include from C compiler.
o2 already have bindings to openGL,SDL..
For raylib i think that not have ,by the way i doub't that anyone there( on Oygen basic forum )have interest.
I don't have interest in raylib because i prefer GDI,GDI+...
I even don't have any interest in SDL,openGL and that i am author of o2 i would go with DirectX on windows
simply because have best performance in any games on windows.
|
|
|
Post by aurel on Apr 11, 2020 12:05:48 GMT -6
WOW i just look into the list ..it is really impresive even my old friend Fayed add binding to his Ring language..nice
|
|
|
Post by kennn on Apr 11, 2020 12:48:36 GMT -6
At the moment, the only BASIC there is FreeBASIC. Blitzmax syntaxbomb.com/index.php/topic,7600.0.html (Add www.) Blitzmax may be better than FreeBASIC in game development. The community looks more experienced in game making. If a developer encounters a problem, it may be easier to obtain a solution. syntaxbomb.com/index.php/board,19.0.html (Add www.)
|
|
|
Post by aurel on Apr 11, 2020 12:59:32 GMT -6
|
|
|
Post by kennn on Apr 12, 2020 1:25:31 GMT -6
i found something more interesting for me win32GDI graphic engine Is win32GDI equal to DirectX?
|
|
|
Post by aurel on Apr 12, 2020 7:29:17 GMT -6
No ken is not same ,GDI and GDI+ is a set of drawing functions built in Windows OS and DirectX is hardware based set of 2D/3D functions which comes with your graphic card driver.
|
|
|
Post by Tomaaz on Apr 12, 2020 13:28:24 GMT -6
Sorry, I missed BlitzMax. That list is getting bigger and bigger every time I visit. BTW The new Luajit bindings for Raylib 3.0 are fantastic. Just two executable files - one is an interpreter, the other can glue your script to the interpreter and produce a standalone executable. No compiling. No dependencies. Just one file that is created instantly and ready for distribution in less than a second. Plus, of course, for your programs you've got the speed of Luajit and the simplicity of Lua. Grab it from github.com/TSnake41/raylib-lua/releases/tag/v3.0a . Binaries for Windows and Linux are ready to download, as well as the source code.
|
|
|
Post by aurel on Apr 13, 2020 4:56:24 GMT -6
sorry tomek but lua is just another glue language which heavily depend on ext libs and i really doubt that anyone here is interested for that.
|
|
|
Post by Tomaaz on Apr 13, 2020 8:17:30 GMT -6
What I'm trying to explain you is that this is not a library for Lua. This is a single executable that already contains Luajit and Raylib glued together. THERE ARE NO EXTERNAL DEPENDENCIES. You don't need any headers or .dll files. Also, you can glue your script with that executable. What you'll get is another single executable that will run on any Windows machine and won't need any dependencies. You don't have to provide Raylib libraries with your program. There are already included in the .exe file you've created gluing your script with raylua.
For me the most important thing about it is that it works the same way on Linux. All dependencies are included in a single executable file. To run this file other Linux members don't have to install anything. Remember EGSL? It was possible to glue your script with the interpreter and make an executable, but to run this executable on another machine you had to have specific SDL libraries installed. I believe (sorry, if I'm wrong) RCBasic works the same way.
|
|