Advertisement

When coders get bored...

Started by May 15, 2010 05:44 PM
13 comments, last by zerothrillz 14 years, 5 months ago
What happens, when you get bored, but you must stay on your PC, eg. to look after something? I had a very annoying problem with blooming, and had to look after the thread about it, here at gamedev. While I was doing this, I got very bored. I couldn't work on my engine, because I didn't want to break more, I didn't want to have problems when implementing the solution from the thread. So, I decided to make a little side project. A *very* little side project. ;) Screenshot Download WindowPong from ModDB When you ever made such a little mini game, or when you were in a similar situation, please post it here. :)
That was cool :D

Not to send this thread off topic, but how did you make this?
Is it win32, MFC? Also I knowtice that you have a window for the ball & a window for the 'bat'? are you using MDI?

I am doing win32 programming, & I tried make a pong game but it didn't go to well :P Would you feel comfortable releasing your source code?
Advertisement
I was bored in class one day, so I created a game called Ultimate Block Adventure. All you have to do is collect the small squares by controlling the big squares, before you run out of energy. I think it took about an hour to do, although most of that was spent on getting sound to play.

@-Datriot-: Cool! Can you post a Download link please? :)

@gretty: It's just made with Win32. Here is the source (Sorry, not best written, it wasn't supposed to get open source ;) )

#include <Windows.h>#include "resource.h"#include <stdlib.h>#include <malloc.h>#include <memory.h>//How hard will the game be?const int HARDNESS=10;struct Vec2{	float x;	float y;};RECT DesktopSize;HWND BallHW;UINT BallSize=20;Vec2 BallPos;Vec2 BallVel;float BallSpeed=0.5;HWND BarHW;UINT BarX=50;UINT BarSizeX=10;UINT BarSizeY=420;Vec2 BarPos;float MaxSpeed=1;#define TIME_RING_BUFFER_SIZE 10LONGLONG m_pausedTime;LONGLONG m_timeDelta;RingBuffer<LONGLONG, TIME_RING_BUFFER_SIZE> m_times;bool bWantsQuit=false;LRESULT WINAPI BallDlgProc( HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam );LRESULT WINAPI BarDlgProc( HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam );LRESULT WINAPI BallDlgProc( HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam ){	return 0;}LRESULT WINAPI BarDlgProc( HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam ){	switch(msg)	{	case WM_MOUSEWHEEL:			BallVel.x+=GET_WHEEL_DELTA_WPARAM(wParam)*0.001;			BallVel.y+=GET_WHEEL_DELTA_WPARAM(wParam)*0.001;			if(BallVel.x>MaxSpeed)			{				BallVel.x=MaxSpeed;			}			if(BallVel.y>MaxSpeed)			{				BallVel.y=MaxSpeed;			}			if(BallVel.x<-MaxSpeed)			{				BallVel.x=-MaxSpeed;			}			if(BallVel.y<-MaxSpeed)			{				BallVel.y=-MaxSpeed;			}		break;	case WM_KEYDOWN:		if(wParam==VK_ESCAPE)		{			bWantsQuit=true;		}		break;	}	return 0;}bool CheckForBallCollision(){	if(BallPos.x-BallSize > BarPos.x+BarSizeX)	{		return false;	}else if(BallPos.x-BallSize <= BarPos.x+BarSizeX && BallPos.y-BallSize>BarPos.y-(BarSizeY/2) && BallPos.y+BallSize<BarPos.y+(BarSizeY/2))	{		return true;	}	return false;}void HandleTick(){	if(BallVel.x+BallPos.x > DesktopSize.right)	{		BallVel.x=-BallVel.x;		BallPos.x=DesktopSize.right;	}else if( BallVel.x+BallPos.x < 0 )	{		BallVel.x=-BallVel.x;		BallPos.x=0;		MessageBox(NULL,L":(",L"Gaah!",MB_OK);	}		if(BallVel.y+BallPos.y > DesktopSize.bottom)	{		BallVel.y=-BallVel.y;		BallPos.y=DesktopSize.bottom;	}else if( BallVel.y+BallPos.y < 0)	{		BallVel.y=-BallVel.y;		BallPos.y=0;			}	if(CheckForBallCollision())	{		BallPos.x=BarPos.x+BarSizeX+BallSize;		BallVel.x=-BallVel.x;	}	BallPos.x+=(BallVel.x*2);	BallPos.y+=BallVel.y;	SetWindowPos(BallHW,NULL,BallPos.x-BallSize,BallPos.y-BallSize,BallSize,BallSize,SWP_NOACTIVATE);	POINT MousePos;	GetCursorPos(&MousePos);	BarPos.y=MousePos.y;	SetWindowPos(BarHW,NULL,BarX,MousePos.y-(BarSizeY/2),BarSizeX,BarSizeY,SWP_NOACTIVATE);}void DoGame(){	HandleTick();}int WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow ){	MessageBox(NULL,L"Welcome to [WuTz]!'s Window-Pong!\n\nThere is no goal in this game, just have fun. ;)\nNote that you can scale the speed of the ball by using your mousewheel.\nTo exit, just press ESC. (Make sure you have the bar-window selected)\n\n\nHave fun!",L"[WuTz]!'s Window Pong",MB_OK);	BallHW=CreateDialog(hInstance,L"IDD_Ball",NULL,(DLGPROC)BallDlgProc);	SetWindowPos(BallHW,NULL,BallPos.x-BallSize,BallPos.y-BallSize,BallSize,BallSize,NULL);	GetClientRect(GetDesktopWindow(),&DesktopSize);	BarSizeY=DesktopSize.bottom/HARDNESS;	BarHW=CreateDialog(hInstance,L"IDD_Bar",NULL,(DLGPROC)BarDlgProc);	SetWindowPos(BarHW,NULL,BarX,0,BarSizeX,BarSizeY,NULL);	BarPos.x=BarX;	BarPos.y=0;		BallPos.x=DesktopSize.right/2;	BallPos.y=DesktopSize.bottom/2;	BallVel.x=BallSpeed;	BallVel.y=BallSpeed;	MSG msg;	while(bWantsQuit==false)    {		bool bGotMsg;                bGotMsg = ( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) != 0 );        if( bGotMsg )        {                       TranslateMessage( &msg );            DispatchMessage( &msg );                    }        else        {           DoGame();        }    }}


I also create the windows from a resource file as dialogs. :P
To lazy to use CreateWindow with all its parameters (:
I wrote this little game one day when I was bored. Control the green square with the mouse, avoid the ever increasing stream of red squares. If you've ever played any "bullet hell" type games you should feel right at home. Zip includes Windows binary and source; the binary should run on just about any 32 och 64 bit Windows with an OpenGL-capable driver since it's got everything, including the kitchen sink, statically linked in. To build it you'll need GHC (only tested with 6.10,) and the Haskell bindings for GLFW and OpenGL.
import Graphics.UI.GLFW as GLFWimport Graphics.Rendering.OpenGL as GLimport Data.IORefimport System.Randomimport System.Exittype Time   = Doubletype Vector = (Double, Double)type Graphic = Vector -> IO ()data Obj = Obj {    pos :: Vector,    vel :: Vector,    gfx :: Graphic  }-- Starting values for enemiesminSpd = 0.2maxSpd = 0.6spawnThreshold = 0.05-- | Generic box graphicbox :: Graphicbox (x, y) = do  vertex $ Vertex2 (x-0.02) (y+0.02)  vertex $ Vertex2 (x+0.02) (y+0.02)  vertex $ Vertex2 (x+0.02) (y-0.02)  vertex $ Vertex2 (x-0.02) (y-0.02)-- | Evil guy graphicenemy :: Graphicenemy p = do  color $ Color3 (1 :: Float) 0 0  box p-- | Player graphicplayer :: Graphicplayer p = do  color $ Color3 0 (1 :: Float) 0  box p-- | Move an object based on its velocity and the time passedmove :: Time -> Obj -> Objmove t (Obj (x, y) v@(xv, yv) g)  = Obj (x+xv*t, y+yv*t) v g-- | Callback for mouse movement; converts mouse coords into world coordsmouse :: IORef Vector -> MousePosCallbackmouse r (Position mx my) =  writeIORef r (2*fromIntegral (mx-320)/640,  	        0-2*fromIntegral (my-240)/480)-- | Game entry pointmain :: IO ()main = do  GLFW.initialize  GLFW.openWindow (Size 640 480)  		  [DisplayRGBBits 8 8 8, DisplayAlphaBits 8]		  Window  r <- newIORef (0, 0)  windowCloseCallback $= exitSuccess  mousePosCallback    $= (mouse r)  get time >>= gameLoop r []  GLFW.terminate-- | Main loopgameLoop :: IORef Vector -> [Obj] -> Time -> IO ()gameLoop mouse objs t = go objs t t spawnThreshold where  go objs t t2 spawnT = do    pollEvents    t' <- get time    -- Spawn a new object if enough time has passed    (t'', objs') <- if t'-t > spawnT      then spawnObject >>= \o -> return (t', o:objs)      else return (t, objs)    -- Move all objects and remove the ones outside the board    let objs'' = map (move (t' - t2)) $ (filter onTheBoard) objs'    (px, py) <- readIORef mouse    render $ (Obj (px, py) (0,0) player):objs''    -- Check if the player got hit    case filter (hitPlayer (px, py)) objs'' of      -- If he wasn't, loop with a slightly lower spawn threshold      [] -> go objs'' t'' t' (spawnT - 0.001 * t')      _  -> return ()  -- | Generate a new object flying at a random velocity  spawnObject = do    vx <- randomRIO (0, maxSpd)     ; vy <- randomRIO (0, maxSpd)    negx <- randomRIO (True, False) ; negy <- randomRIO (True, False)    let vx' = if negx then 0-vx else vx    let vy' = if negy then 0-vy else vy    if sqrt (vx'^2+vy'^2) < minSpd      then spawnObject      else return $ Obj (0,0) (vx', vy') enemy  -- | Is the object still on the board?  onTheBoard (Obj (x, y) _ _) = x < 1 && y < 1 && x > -1 && y > -1  -- | Has the object hit the player?  hitPlayer (px, py) (Obj (ox, oy) _ _) =     ox > px - 0.02 && ox < px + 0.02 && oy > py - 0.02 && oy < py + 0.02-- | Render all objects in listrender :: [Obj] -> IO ()render objs = do  clear [ColorBuffer, DepthBuffer]  mapM_ (\(Obj p _ g) -> renderPrimitive Quads (g p)) objs  swapBuffers


I also wrote this somewhat bigger (as in, three days of boredom) boredom project; an EDSL for creating visual novel games along with a tiny example game. I ended up turning it in as my final project in a course on functional programming focusing, conveniently enough, on embedded languages.

Windows binary + source of the example game (to give a feel for the syntax of the EDSL) can be found here. The complete original source is a bit of a mess, since I sort of had to scramble for the project deadline, but I'll post it if requested.

[Edited by - Valderman on May 16, 2010 11:21:17 AM]
Nice! But sadly your first link is broken. :(
Advertisement
Quote: Original post by mind in a box
Nice! But sadly your first link is broken. :(
Oops! Fixed it now.
I am confused about what the OP program actually does. I'm guessing it's some sort of pong game, but I can't see it.
Quote: Original post by mind in a box
@-Datriot-: Cool! Can you post a Download link please? :)

Sure, you can download it here. I can't remember if I made a decent game loop though, so it may run way too fast, making it unplayable.

Quote: Original post by Valderman
I wrote this little game one day when I was bored. Control the green square with the mouse, avoid the ever increasing stream of red squares. If you've ever played any "bullet hell" type games you should feel right at home.

Haha, I actually found myself timing how long I could last. :P I've been meaning to play some bullet hell games, but I've just never got around to it.
Quote:
I am confused about what the OP program actually does. I'm guessing it's some sort of pong game, but I can't see it.


Try it, and you will see! :P It is just 10kb and should work on any PC around here. :)
You control the bar on the left with your mouse, and this very little window is the ball. (Take a *close* look at the picture, it is at the bottom/right under my desktop icons) A bit hard to see, if it isn't moving ;)

This topic is closed to new replies.

Advertisement