Skip to content

Commit

Permalink
wtfpl public license
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmytro Lytovchenko committed Oct 1, 2011
1 parent 4c53809 commit cf03aca
Show file tree
Hide file tree
Showing 18 changed files with 1,129 additions and 1,011 deletions.
6 changes: 6 additions & 0 deletions CMakeLists.txt
Expand Up @@ -3,6 +3,12 @@
# This is minimal game skeleton in HGE based on HGE_TUTORIAL 06 # This is minimal game skeleton in HGE based on HGE_TUTORIAL 06
# to adapt this to your new game, search and replace HGESKEL with your project name # to adapt this to your new game, search and replace HGESKEL with your project name
# #
# This program is free software. It comes without any warranty, to
# the extent permitted by applicable law. You can redistribute it
# and/or modify it under the terms of the Do What The Fuck You Want
# To Public License, Version 2, as published by Sam Hocevar. See
# http://sam.zoy.org/wtfpl/COPYING for more details.
#
#----------------------------------------------------------------------- #-----------------------------------------------------------------------
project( HGESKEL ) project( HGESKEL )
cmake_minimum_required( VERSION 2.8 ) cmake_minimum_required( VERSION 2.8 )
Expand Down
16 changes: 16 additions & 0 deletions LICENSE.txt
@@ -0,0 +1,16 @@
http://sam.zoy.org/wtfpl/COPYING

DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004

Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>

Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.

DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

0. You just DO WHAT THE FUCK YOU WANT TO.

50 changes: 28 additions & 22 deletions src/creature.cpp
@@ -1,3 +1,9 @@
/* This program is free software. It comes without any warranty, to
* the extent permitted by applicable law. You can redistribute it
* and/or modify it under the terms of the Do What The Fuck You Want
* To Public License, Version 2, as published by Sam Hocevar. See
* http://sam.zoy.org/wtfpl/COPYING for more details.
*/
// base Creature class // base Creature class
// represents a walking or stationary creature which is able to kill player // represents a walking or stationary creature which is able to kill player
// on touch. // on touch.
Expand All @@ -9,44 +15,44 @@


WorldObject::WorldObject( World * owner, float x, float y ): m_world(owner) WorldObject::WorldObject( World * owner, float x, float y ): m_world(owner)
{ {
m_box.Set( x, y, x + World::CELL_BOX_SIZE - 1.0f, y + World::CELL_BOX_SIZE - 1.0f ); m_box.Set( x, y, x + World::CELL_BOX_SIZE - 1.0f, y + World::CELL_BOX_SIZE - 1.0f );
} }


void WorldObject::Render() void WorldObject::Render()
{ {
hgeSprite * spr = GetSprite(); hgeSprite * spr = GetSprite();
if( ! spr ) return; // can't draw a NULL sprite if( ! spr ) return; // can't draw a NULL sprite


hgeRect box( m_box.x1 - m_world->m_camera_pos.x, hgeRect box( m_box.x1 - m_world->m_camera_pos.x,
m_box.y1 - m_world->m_camera_pos.y, m_box.y1 - m_world->m_camera_pos.y,
m_box.x2 - m_world->m_camera_pos.x, m_box.x2 - m_world->m_camera_pos.x,
m_box.y2 - m_world->m_camera_pos.y ); m_box.y2 - m_world->m_camera_pos.y );


spr->Render4V( box.x1, box.y1, spr->Render4V( box.x1, box.y1,
box.x2, box.y1, box.x2, box.y1,
box.x2, box.y2, box.x2, box.y2,
box.x1, box.y2 ); box.x1, box.y2 );
} }


WorldObject_Money::WorldObject_Money( World * owner, float x, float y ) : WorldObject( owner, x, y ) WorldObject_Money::WorldObject_Money( World * owner, float x, float y ) : WorldObject( owner, x, y )
{ {
m_sprite[0] = owner->m_sprite_manager.GetSprite( "textures/coin1.png" ); m_sprite[0] = owner->m_sprite_manager.GetSprite( "textures/coin1.png" );
m_sprite[1] = owner->m_sprite_manager.GetSprite( "textures/coin2.png" ); m_sprite[1] = owner->m_sprite_manager.GetSprite( "textures/coin2.png" );
} }




WorldObject_Money::~WorldObject_Money() WorldObject_Money::~WorldObject_Money()
{ {
delete m_sprite[0]; delete m_sprite[0];
delete m_sprite[1]; delete m_sprite[1];
} }


hgeSprite * WorldObject_Money::GetSprite() hgeSprite * WorldObject_Money::GetSprite()
{ {
uint32_t milliseconds = GetTickCount(); uint32_t milliseconds = GetTickCount();
// we want frames to change every 250 msec from 0 to 1 // we want frames to change every 250 msec from 0 to 1
// total of 2 frames, hence the modulo of 2 // total of 2 frames, hence the modulo of 2
uint32_t f = (milliseconds / 250) % 2; uint32_t f = (milliseconds / 250) % 2;


return m_sprite[f]; return m_sprite[f];
} }
26 changes: 16 additions & 10 deletions src/creature.h
@@ -1,3 +1,9 @@
/* This program is free software. It comes without any warranty, to
* the extent permitted by applicable law. You can redistribute it
* and/or modify it under the terms of the Do What The Fuck You Want
* To Public License, Version 2, as published by Sam Hocevar. See
* http://sam.zoy.org/wtfpl/COPYING for more details.
*/
// to prevent multiple compiling of this header // to prevent multiple compiling of this header
#pragma once #pragma once


Expand All @@ -16,29 +22,29 @@ class World;
class WorldObject class WorldObject
{ {
protected: protected:
World * m_world; World * m_world;


public: public:
hgeRect m_box; hgeRect m_box;


WorldObject( World * owner, float x, float y ); WorldObject( World * owner, float x, float y );
virtual ~WorldObject() {} virtual ~WorldObject() {}


virtual hgeSprite * GetSprite() { return NULL; } virtual hgeSprite * GetSprite() { return NULL; }
void Render(); void Render();
}; };




class WorldObject_Money: public virtual WorldObject class WorldObject_Money: public virtual WorldObject
{ {
protected: protected:
hgeSprite * m_sprite[2]; hgeSprite * m_sprite[2];


public: public:
WorldObject_Money(World * owner, float x, float y ); WorldObject_Money(World * owner, float x, float y );
virtual ~WorldObject_Money(); virtual ~WorldObject_Money();


virtual hgeSprite * GetSprite(); virtual hgeSprite * GetSprite();
}; };




Expand Down
154 changes: 80 additions & 74 deletions src/game.cpp
@@ -1,3 +1,9 @@
/* This program is free software. It comes without any warranty, to
* the extent permitted by applicable law. You can redistribute it
* and/or modify it under the terms of the Do What The Fuck You Want
* To Public License, Version 2, as published by Sam Hocevar. See
* http://sam.zoy.org/wtfpl/COPYING for more details.
*/
/* /*
** Based on: hge_tut06 - Creating menus ** Based on: hge_tut06 - Creating menus
** Haaf's Game Engine 1.8 -- Copyright (C) 2003-2007, Relish Games http://hge.relishgames.com ** Haaf's Game Engine 1.8 -- Copyright (C) 2003-2007, Relish Games http://hge.relishgames.com
Expand All @@ -18,60 +24,60 @@ MyGame * MyGame::m_game = NULL;




MyGame::MyGame() MyGame::MyGame()
: m_hge(NULL), m_font(NULL), m_mouse_cursor_sprite(NULL), m_state(NULL) : m_hge(NULL), m_font(NULL), m_mouse_cursor_sprite(NULL), m_state(NULL)
, m_sound_enabled(true) , m_sound_enabled(true)
{ {
// remember pointer to 'this' in globally visible variable so that everyone // remember pointer to 'this' in globally visible variable so that everyone
// else can reach it (not very good example of software design, but this simplifies a lot) // else can reach it (not very good example of software design, but this simplifies a lot)
m_game = this; m_game = this;


// do nothing else here, unless it can run before HGE is started // do nothing else here, unless it can run before HGE is started
} }




bool MyGame::FrameFunc() bool MyGame::FrameFunc()
{ {
// passing control to the current game state, so that game reacts to events // passing control to the current game state, so that game reacts to events
// differently in different states // differently in different states
return m_game->m_state->Think( m_game ); return m_game->m_state->Think( m_game );
// do not add more code here, all the action happens in GameState's child classes // do not add more code here, all the action happens in GameState's child classes
} }




bool MyGame::RenderFunc() bool MyGame::RenderFunc()
{ {
// letting the current game state to take care of rendering (different render for // letting the current game state to take care of rendering (different render for
// main menu, for game, and for game over screen) // main menu, for game, and for game over screen)
m_game->m_hge->Gfx_BeginScene(); m_game->m_hge->Gfx_BeginScene();


m_game->m_state->Render( m_game ); m_game->m_state->Render( m_game );


// Draw framerate and time since previous frame // Draw framerate and time since previous frame
char fps_text[64]; // some safer length so FPS text will fit char fps_text[64]; // some safer length so FPS text will fit
_snprintf( fps_text, sizeof(fps_text)-1, _snprintf( fps_text, sizeof(fps_text)-1,
"dt:%.3f\nFPS:%d", "dt:%.3f\nFPS:%d",
m_game->m_hge->Timer_GetDelta(), m_game->m_hge->Timer_GetFPS() m_game->m_hge->Timer_GetDelta(), m_game->m_hge->Timer_GetFPS()
); );


// print with black shadow // print with black shadow
m_game->m_font->SetColor(ARGB(255,0,0,0)); // black m_game->m_font->SetColor(ARGB(255,0,0,0)); // black
m_game->m_font->printf( 7, 7, HGETEXT_LEFT, fps_text ); m_game->m_font->printf( 7, 7, HGETEXT_LEFT, fps_text );
m_game->m_font->SetColor(ARGB(255,255,255,255)); // white m_game->m_font->SetColor(ARGB(255,255,255,255)); // white
m_game->m_font->printf( 5, 5, HGETEXT_LEFT, fps_text ); m_game->m_font->printf( 5, 5, HGETEXT_LEFT, fps_text );


m_game->m_hge->Gfx_EndScene(); m_game->m_hge->Gfx_EndScene();


// do not add more code here, all the action happens in GameState's child classes // do not add more code here, all the action happens in GameState's child classes
return false; return false;
} }




bool MyGame::Startup() bool MyGame::Startup()
{ {
m_hge = hgeCreate(HGE_VERSION); m_hge = hgeCreate(HGE_VERSION);


m_hge->System_SetState(HGE_SHOWSPLASH, false); m_hge->System_SetState(HGE_SHOWSPLASH, false);
m_hge->System_SetState(HGE_FPS, 60); m_hge->System_SetState(HGE_FPS, 60);


m_hge->System_SetState(HGE_LOGFILE, "hgeskel.log"); m_hge->System_SetState(HGE_LOGFILE, "hgeskel.log");
m_hge->System_SetState(HGE_FRAMEFUNC, FrameFunc); m_hge->System_SetState(HGE_FRAMEFUNC, FrameFunc);
Expand Down Expand Up @@ -110,85 +116,85 @@ bool MyGame::Startup()
m_background_quad.v[i].col=ARGB(0xFF, 0xFF, 0xFF, 0xFF); m_background_quad.v[i].col=ARGB(0xFF, 0xFF, 0xFF, 0xFF);
} }


m_background_quad.v[0].x=0; m_background_quad.v[0].x=0;
m_background_quad.v[0].y=0; m_background_quad.v[0].y=0;


m_background_quad.v[1].x=800; m_background_quad.v[1].x=800;
m_background_quad.v[1].y=0; m_background_quad.v[1].y=0;


m_background_quad.v[2].x=800; m_background_quad.v[2].x=800;
m_background_quad.v[2].y=600; m_background_quad.v[2].y=600;


m_background_quad.v[3].x=0; m_background_quad.v[3].x=0;
m_background_quad.v[3].y=600; m_background_quad.v[3].y=600;




// Load the font, create the cursor sprite // Load the font, create the cursor sprite
m_font = new hgeFont("font1.fnt"); m_font = new hgeFont("font1.fnt");
m_mouse_cursor_sprite = new hgeSprite(m_mouse_cursor_tex,0,0,32,32); m_mouse_cursor_sprite = new hgeSprite(m_mouse_cursor_tex,0,0,32,32);


m_state_options = new GameState_Options( this ); m_state_options = new GameState_Options( this );
m_state_mainmenu = new GameState_MainMenu( this ); m_state_mainmenu = new GameState_MainMenu( this );
m_state_instructions = new GameState_Instructions( this ); m_state_instructions = new GameState_Instructions( this );
m_state_credits = new GameState_Credits( this ); m_state_credits = new GameState_Credits( this );
m_state_play = new GameState_Play(); m_state_play = new GameState_Play();


ShowMainMenuScreen(); ShowMainMenuScreen();


return true; // all is fine return true; // all is fine
} }




void MyGame::Shutdown() void MyGame::Shutdown()
{ {
delete m_state_options; delete m_state_options;
delete m_state_mainmenu; delete m_state_mainmenu;
delete m_state_instructions; delete m_state_instructions;
delete m_state_credits; delete m_state_credits;
delete m_state_play; delete m_state_play;


// Delete created objects and free loaded resources // Delete created objects and free loaded resources
delete m_font; delete m_font;
delete m_mouse_cursor_sprite; delete m_mouse_cursor_sprite;


m_hge->Effect_Free(m_click_sound); m_hge->Effect_Free(m_click_sound);
m_hge->Texture_Free(m_mouse_cursor_tex); m_hge->Texture_Free(m_mouse_cursor_tex);
m_hge->Texture_Free(m_background_quad.tex); m_hge->Texture_Free(m_background_quad.tex);


// Clean up and shutdown // Clean up and shutdown
m_hge->System_Shutdown(); m_hge->System_Shutdown();
m_hge->Release(); m_hge->Release();
} }




void MyGame::ShowMainMenuScreen() void MyGame::ShowMainMenuScreen()
{ {
m_state = m_state_mainmenu; m_state = m_state_mainmenu;
} }




void MyGame::ShowOptionsScreen() void MyGame::ShowOptionsScreen()
{ {
m_state = m_state_options; m_state = m_state_options;
} }




void MyGame::ShowInstructionsScreen() void MyGame::ShowInstructionsScreen()
{ {
m_state = m_state_instructions; m_state = m_state_instructions;
} }




void MyGame::ShowCreditsScreen() void MyGame::ShowCreditsScreen()
{ {
m_state = m_state_credits; m_state = m_state_credits;
} }




void MyGame::ShowPlayScreen() void MyGame::ShowPlayScreen()
{ {
m_state = m_state_play; m_state = m_state_play;
m_state_play->OnEnterState( this ); m_state_play->OnEnterState( this );
} }




Expand Down

0 comments on commit cf03aca

Please sign in to comment.