atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Mon Jul 25, 2011 12:35 pm Post subject: The Lame Game - Lua Edition |
|
|
If you know about the easter egg in Cheat Engine called (TLG - The Lame Game) you'll understand what this is. This is a similar game written using the Lua engine in CE. I used a label rather then the stick figure image due to not wanting to require extra files to run the script. It's fairly basic and pointless but figured I'd post it anyway.
| Code: |
--[[
TLG: The Lame Game - Lua Edition
coded by: Wiccaan
]]--
local lame_game =
{
-- Form Variables
form_width = 490,
form_height = 375,
-- Game Variables
score = 0,
pos_x = 0,
pos_y = 0,
canclick = false,
-- Control Objects
_formobj = nil,
_timerobj = nil,
_scoreobj = nil,
_entityobj = nil,
};
------------------------------------------------------------------------
-- func: math.clamp
-- desc: Keeps the given input value within the low/high values.
------------------------------------------------------------------------
function math.clamp( input, low, high )
if ( input > high ) then input = high; end
if ( input < low ) then input = low; end
return input;
end
------------------------------------------------------------------------
-- func: lame_game:start
-- desc: Initializes the game information.
------------------------------------------------------------------------
function lame_game:start( )
-- Setup form..
self._formobj = createForm();
form_centerScreen( self._formobj );
control_setSize( self._formobj, self.form_width, self.form_height );
control_setCaption( self._formobj, 'TLG: The Lame Game - Lua Edition' );
-- Prepare score label..
self._scoreobj = createLabel( self._formobj );
control_setCaption( self._scoreobj, string.format( 'Current Score: %d', self.score ) );
-- Prepare entity object..
self._entityobj = createLabel( self._formobj );
control_setCaption( self._entityobj, '[ CLICK ]' );
control_onClick( self._entityobj, function( ) self:onClick() end );
-- Prepare timer..
self._timerobj = createTimer( self._formobj, false );
timer_setInterval( self._timerobj, 1000 );
timer_onTimer( self._timerobj, function( ) self:onTimer() end );
timer_setEnabled( self._timerobj, true );
end
------------------------------------------------------------------------
-- func: lame_game:onTimer
-- desc: Timer callback that is called each interval.
------------------------------------------------------------------------
function lame_game:onTimer( )
-- Allow new clicks..
self.canclick = true;
-- Move entity randomly..
self.pos_x = math.clamp( math.random( 1, self.form_width ), 1, self.form_width - 50 );
self.pos_y = math.clamp( math.random( 1, self.form_height ), 1, self.form_height - 15 );
control_setPosition( self._entityobj, self.pos_x, self.pos_y );
-- Update score..
control_setCaption( self._scoreobj, string.format( 'Current Score: %d', self.score ) );
end
------------------------------------------------------------------------
-- func: lame_game:onClick
-- desc: Control callback to handle click events.
------------------------------------------------------------------------
function lame_game:onClick( )
if self.canclick == false then
return;
end
-- User clicked, update score and disable clicks.
self.score = self.score + 1;
self.canclick = false;
control_setCaption( self._scoreobj, string.format( 'Current Score: %d', self.score ) );
end
lame_game:start( );
|
_________________
- Retired. |
|