Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


The Lame Game - Lua Edition

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Tutorials -> LUA Tutorials
View previous topic :: View next topic  
Author Message
atom0s
Moderator
Reputation: 198

Joined: 25 Jan 2006
Posts: 8517
Location: 127.0.0.1

PostPosted: Mon Jul 25, 2011 12:35 pm    Post subject: The Lame Game - Lua Edition Reply with quote

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.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Tutorials -> LUA Tutorials All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites