"wobble," my little 2D platformer

Anything related in any way to game development as a whole is welcome here. Tell us about your game, grace us with your project, show us your new YouTube video, etc.

Moderator: PC Supremacists

Post Reply
User avatar
BugInTheSYS
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 88
Joined: Mon Feb 07, 2011 4:16 pm
Current Project: Vintage Roads
Favorite Gaming Platforms: PC
Programming Language of Choice: C++, Delphi
Location: Pinneberg, Germany
Contact:

"wobble," my little 2D platformer

Post by BugInTheSYS »

I felt like starting my own thread now, since I see I've been working on this thing (with long breaks and recommencements) for a year, but never actually finished it. I hope this will help me keep at it this time.
In retrospect, all started a year a go in a CS lesson where we got the assignment to make a game of any kind - in Visual Basic .net - in one month. System.Drawing aka GDI+ didn't really work as fast as I would have liked, so I abandoned that project and made a (in my opinion) small poker game. Still got the best grade... teacher said it was almost over the top, but anyway, I had this girl in my group, a really talented artist, and we originally had that idea for "wobble" which I couldn't complete. Instead of switching to xna or OpenGL or to any other framework than .net, I tried to come up with a solution to the speed problem and failed sort of. That was my second try, not too glorious.
Some days ago I rethought that whole program, started over again and that was when C# came into play, because of the nice features concerning pointers. I wrote a small library and figured accessing GDI+ through pointers had potential, so I optimized the shit out of that code and came up with something like a .net graphics framework that could render ~150fps in contrast to the previous 12-15fps, with exactly the same content and resolution. I was able to reduce the CPU operations/pixel to a value around 42.
I started writing a level editor first (lol yeah, first level editor and then engine does not seem that usual, but w/e) and it works quite well up to this point. I hope that I'll be able to add things like event triggers, manual collision for tile-independence (so that one can use his own artwork instead of tiles for the foreground and set collision point arrays), and background music in the next time, and after having that inside, I'm going to start working on the actual game. Which then actually is not going to be too much more than a loader for the compiled levels and worlds (= level collections) I created with the editor, which should on a later stage be able to create such worlds.
And now for a little screenshot of what I made.
Screenshot
Screenshot
tärfenschiefe_ftw.png (99.82 KiB) Viewed 1926 times
The artwork is original, except for the tiles obviously (I do have a version with an own foreground, but you get the point). I know there's no reason to call it wobble as for what you have seen now, but I'm just retaining the protagonist for one of the posts I'm going to make in the future.
Also I'm going to ask the girl in my group if she wants to make more stuff because it's partly her creation. Gotta see how I'll move on if she says no, but I'm going to convince her...^^
Feel free to comment :)
Someday, everything will go to /dev/null. - Bug's prophecy 13:37
User avatar
Light-Dark
Dreamcast Developer
Dreamcast Developer
Posts: 307
Joined: Sun Mar 13, 2011 7:57 pm
Current Project: 2D RPG & NES Platformer
Favorite Gaming Platforms: NES,SNES,N64,Genesis,Dreamcast,PC,Xbox360
Programming Language of Choice: C/++
Location: Canada

Re: "wobble," my little 2D platformer

Post by Light-Dark »

Hahaha man thats sweet great job, lol you started with a level editor nonethless great job man can't wait to see more!
<tpw_rules> LightDark: java is a consequence of inverse moore's law: every 18 months, the average program will be twice as slow. therefore, computers always run at the same percevied speed. java's invention was a monumental step
Image
Inlinevoid
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 54
Joined: Thu Oct 20, 2011 2:53 pm

Re: "wobble," my little 2D platformer

Post by Inlinevoid »

.
Last edited by Inlinevoid on Sat Feb 27, 2016 2:23 am, edited 1 time in total.
User avatar
BugInTheSYS
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 88
Joined: Mon Feb 07, 2011 4:16 pm
Current Project: Vintage Roads
Favorite Gaming Platforms: PC
Programming Language of Choice: C++, Delphi
Location: Pinneberg, Germany
Contact:

Re: "wobble," my little 2D platformer

Post by BugInTheSYS »

Inlinevoid wrote:Very nice looking editor. From what I can tell, that is a Windows 8 gui, correct? (sorry if that fact is stated in the description, I only skimmed)

I've gone through the process of starting on a level editor and THEN the game a few times in the past. It never worked out for me in the slightest but maybe you'll have better luck.
You're right, it's running on Windows 8 in this screenshot, but nonetheless it works on Windows 7 and other systems with the .net framework 4 as well.
Actually about the only thing I fear right now is collision detection, but it's Christmas time so it's not unprobable for me to get a book about it :)
And thanks Light-Dark :)
Someday, everything will go to /dev/null. - Bug's prophecy 13:37
User avatar
BugInTheSYS
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 88
Joined: Mon Feb 07, 2011 4:16 pm
Current Project: Vintage Roads
Favorite Gaming Platforms: PC
Programming Language of Choice: C++, Delphi
Location: Pinneberg, Germany
Contact:

Re: "wobble," my little 2D platformer

Post by BugInTheSYS »

Okay, today I worked on several additions to the editor. Among these:
* Point array based shapes (Still wondering how I'm going to handle the collision, I would be grateful for tutorials or even book recommendations)
* Extension of my project file format, to support tile-independent collision shapes, which I can save but not load right now, hehe
* Choice between tile-independent and tile-bound collision objects
So with these additions it is possible to design levels without tiles, but just with a layer of a parallactic factor of 1.0 ("moves as fast as the player") and the custom shape(s). These features are not really stable right now, so they're going to take about a day worth of cleanup and bug fixing. Nevertheless, I'm glad I could add it this fast, maybe I'm going to add a tile tracing algorithm that converts the tiles to somewhat smarter collision shapes, so that something like this:

Code: Select all

0:stone.png,rigid,0,0,15,15
1:stone.png,rigid,16,0,15,15
would become

Code: Select all

0:stone_composed.png,rigid,0,0,31,15
which would save a bit (really just a tiny bit) of calculation work within the game itself - but although I'm using .net and you might find it stupid for performance reasons, every cpu cycle counts on this level of development, and optimization is necessary in all corners of what's being done.
What I'm really looking forward to now is implementing event triggers and developing some sort of scripting system which would be necessary--
But first things first.
Yeah, I've been writing some seriously weird code, that's why I had some as weird issues with malfunctioning vector additions. But that wasn't the only flaw I saw in my code, now....spot the mistake!! :)
fbhcgdhd.png
fbhcgdhd.png (10.59 KiB) Viewed 1877 times
Someday, everything will go to /dev/null. - Bug's prophecy 13:37
User avatar
BugInTheSYS
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 88
Joined: Mon Feb 07, 2011 4:16 pm
Current Project: Vintage Roads
Favorite Gaming Platforms: PC
Programming Language of Choice: C++, Delphi
Location: Pinneberg, Germany
Contact:

Re: "wobble," my little 2D platformer

Post by BugInTheSYS »

Today I had an excursion to unmanaged code since as I thought I could improve my performance. I did significantly, but there's a whole lot of thinking behind that.
So I struggled with a memory leak after translating my C# function I had to render my bitmap stack to C++, as GDI+ doesn't seem to care about disposing their resources, not even with the delete keyword. So what I ended up doing is wondering for about 3 hours about the same bug, trying to fix it but nothing ever worked. So I closed that project, marked it as failed and even deleted the VS Solution. Later in the night I had the idea of a small hackup that would take me about 10 to 20 minutes, but a short delineation of the problem might be rather appropriate first of all.
As I wanted to display the Bitmap in a Picture Box on a .net control, I decided to return a HBITMAP from a Gdiplus::Bitmap using Gdiplus::Bitmap::GetHBITMAP() and load it in .net using System.Drawing.Bitmap.FromHbitmap(). All I did in the C++ function is to create the bitmap, to lock its bits, to write the bits over and over, to unlock the bitmap, to get its HBITMAP, to delete the original bitmap and to then return the HBITMAP. Worked at first, but that was where I had that huge memory leak. I calculated my way through and saw that it must have been the bitmaps I used in the c++ function that were causing it, just from the allocation size and the number of GDI objects listed in the task manager.
That was what I had going on, now about 1.5 hours wiser I thought I would Lock and Unlock in the C# code, and just pass the address the LockBits Method would return (myea it isnt a simple address, it's called Scan0, and with it there come also stride, width and height, but you get the basic idea) because in C#, the garbage collector would collect the stuff, but the math would stay inside C++'s scope
And it turned out to work great. I haven't yet implemented it in the editor - havent had any time - but I made a small demo and created the same composition of layers in the editor, and compared. The outcome is as follows:
.net Editor (C#/VB) - 160 fps peak
Demo (C#/C++ via P/Invoke) - 420 fps peak.
I'm feeling so nice right now. :mrgreen:
Someday, everything will go to /dev/null. - Bug's prophecy 13:37
User avatar
BugInTheSYS
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 88
Joined: Mon Feb 07, 2011 4:16 pm
Current Project: Vintage Roads
Favorite Gaming Platforms: PC
Programming Language of Choice: C++, Delphi
Location: Pinneberg, Germany
Contact:

Re: "wobble," my little 2D platformer

Post by BugInTheSYS »

I have to add
C#/C++ x64: 600 fps
to the comparison. As this is for two layers only, the next stage would be a whole level of five layers. I'm getting around 250 fps with the x64 release build (C#/C++), whereas in VB/C#, I get 100 fps with the same configuration.
Just thought I would make you happy with a screenshot.
C++_aided.png
C++_aided.png (77.43 KiB) Viewed 1830 times
The dll itself can be used only with images, but I made it as "basic" as I could (no complex language constructs, just bare data types that should be representable in every language out there). You can take a look on the header if you're interested. It's not complete though. It's on a working stage. I'm probably going to release the whole DLL project later on.

Code: Select all

/**************************************************************
//
// CompGX
// Graphics library for fast 2D Graphics with GDI+
// written by Fabian Schmidt
// released under the GNU GPL
//
//************************************************************/

#ifndef GX_COMPGX_H
#define GX_COMPGX_H

#include "Include.h"
//the only relevant definitions within Include.h are the following:
typedef unsigned char byte;
#define GX_DLL extern "C" _declspec( dllexport )
#define GX_CALL __stdcall

/*
====================
gxInit

  Initializes the library.
====================
*/
GX_DLL
void
GX_CALL
gxInit( void );

/*
====================
gxDispose

  Disposes all resources.
====================
*/
GX_DLL
void
GX_CALL
gxDispose( void );

/*
====================
gxImageLoadFile

  Loads an image from a file using GDI+.
  Returns the image index of the loaded image.
====================
*/
GX_DLL
int
GX_CALL
gxImageLoadFile( wchar_t *Filename );

/*
====================
gxImageLoadLock

  Loads an image from a bitmap locked with GDI+ using the Pixel
  formats 32bpp Argb or 32bpp PArgb.
  Returns the image index of the loaded image.
====================
*/
GX_DLL
int
GX_CALL
gxImageLoadLock( byte *Scan0, int Stride, int width, int height );

/*
====================
gxImageDispose

  Unloads an image from the image stack.
====================
*/
GX_DLL
void
GX_CALL
gxImageDispose( int ImageIndex );

/*
====================
gxClear

  Clears the render stack. Should be called before rendering
  each frame.
====================
*/
GX_DLL
void
GX_CALL
gxClear( void );

/*
====================
gxAdd

  Adds a specified image index to the render stack.
====================
*/
GX_DLL
int
GX_CALL
gxAdd( int ImageIndex );

/*
====================
gxRender

  Renders the render stack to a specified Bitmap locked with
  GDI+ using the Pixel formats 32bpp Argb or 32bpp PArgb.
  Once unlocked, the bitmap will provide the rendered image.
====================
*/
GX_DLL
void
GX_CALL
gxRender( byte *Scan0, int Stride, int width, int height );

/*
====================
gxImage

  Selects the image provided from the index list for modifi-
  cations.
====================
*/
GX_DLL
void
GX_CALL
gxImage( int ImageIndex );

/*
====================
gxStack

  Selects the image provided from the image stack for modifi-
  cations inside the stack.
====================
*/
GX_DLL
void
GX_CALL
gxStack( int Index );

/*
====================
gxOffset

  Sets the offset for the current stack image.
====================
*/
GX_DLL
void
GX_CALL
gxOffset( int x, int y );

#endif
Someday, everything will go to /dev/null. - Bug's prophecy 13:37
Post Reply