From 3b32ebf46ba2b807b0c4d7003a3c68c70a7482e2 Mon Sep 17 00:00:00 2001 From: Alexander Weld/hanoix Date: Mon, 28 Sep 2009 00:51:09 +0200 Subject: [PATCH] Added potion. reverted inventory lala --- Inventory.cpp | 8 ++++---- Object.cpp | 6 +++--- Player.cpp | 17 ++++++++++++----- Player.h | 2 ++ Robot.cpp | 10 +--------- luafuncs.cpp | 20 ++++++++++++++++++++ luafuncs.h | 1 + map.lua | 11 ++++++----- objects.lua | 14 +++++++++++++- objects.png | Bin 1010 -> 1249 bytes 10 files changed, 62 insertions(+), 27 deletions(-) rewrite objects.png (86%) diff --git a/Inventory.cpp b/Inventory.cpp index 4f6ad35..af08036 100644 --- a/Inventory.cpp +++ b/Inventory.cpp @@ -12,10 +12,10 @@ namespace botor { // assert( o->getLocation() == Object::LOC_FREE ); - if( hasItem( o->getID() ) ) + /*if( hasItem( o->getID() ) ) { - } + }*/ invent_t temp; temp.obj = o; @@ -56,7 +56,7 @@ namespace botor } } - invent_t *Inventory::hasItem( std::string id ) + /*invent_t *Inventory::hasItem( std::string id ) { if(!invent.empty()) { @@ -67,7 +67,7 @@ namespace botor } } return NULL; - } + }*/ } diff --git a/Object.cpp b/Object.cpp index 6ae5295..fc203d8 100644 --- a/Object.cpp +++ b/Object.cpp @@ -82,15 +82,15 @@ namespace botor p->Pickup( this ); } - bool Object::checkID( std::string id ) +/* bool Object::checkID( std::string id ) { return oclass->id == id; } - std::string &getID( ) + std::string & Object::getID( ) { return oclass->id; - } + }*/ } diff --git a/Player.cpp b/Player.cpp index 6a90d12..5593a8e 100644 --- a/Player.cpp +++ b/Player.cpp @@ -88,7 +88,7 @@ namespace botor Die(); } - if( Object *o = Game::getMap()->getObject( mapX, mapY ) ) + while( Object *o = Game::getMap()->getObject( mapX, mapY ) ) { o->OnPlayerOnTile( this ); } @@ -127,6 +127,9 @@ namespace botor else Use( 0 ); break; + case SDLK_d: + Drop( 0 ); + break; //case SDLK_a: // Game::getMap()->Acid( mapX, mapY ); // break; @@ -187,9 +190,8 @@ namespace botor { if( Object *obj = inv.removeObject() ) { + obj->OnDrop( this ); Game::getMap()->insertObject( obj, mapX, mapY ); - - o->OnDrop( this ); } } @@ -207,9 +209,8 @@ namespace botor } else if( obj->getNUse() == ObjectClass::NUseDrop ) { - Game::getMap()->insertObject( obj, mapX, mapY ); - obj->OnDrop( this ); + Game::getMap()->insertObject( obj, mapX, mapY ); } else { @@ -234,5 +235,11 @@ namespace botor p_ani_walking = &ani_walking; } } + + + void Player::addLives( int i ) + { + lives += i; + } } diff --git a/Player.h b/Player.h index 7e2d206..3e0af17 100644 --- a/Player.h +++ b/Player.h @@ -77,6 +77,8 @@ class Player : public LivingMapObject unsigned int getLives(); + void addLives( int i = 1 ); + }; diff --git a/Robot.cpp b/Robot.cpp index 3e6dd83..8a3bcd2 100644 --- a/Robot.cpp +++ b/Robot.cpp @@ -84,15 +84,7 @@ namespace botor if( mapX == Game::getPlayer()->getMapX() && mapY == Game::getPlayer()->getMapY() ) { - if( Game::getPlayer()->Walking() ) - { -// if( rand()%3 ) -// { - Game::getPlayer()->Die(); -// } - } - else - Game::getPlayer()->Die(); + Game::getPlayer()->Die(); if( rand()%4 == 0 ) Die(); diff --git a/luafuncs.cpp b/luafuncs.cpp index 4feb5d8..d4e02b3 100644 --- a/luafuncs.cpp +++ b/luafuncs.cpp @@ -105,6 +105,25 @@ namespace botor return 0; } + LUA_FUNC( LuaFuncs::Player_AddLives ) + { + int largc = lua_gettop( L ); + if( largc == 0 ) + { + Game::getPlayer()->addLives( ); + } + else if( largc == 1 ) + { + Game::getPlayer()->addLives( (int)luaL_checkinteger( L, 1 ) ); + } + else + return luaL_error( L, "Got %d arguments, needed 0 or 1!", largc ); + + return 0; + + + } + LUA_FUNC( LuaFuncs::Player_Pickup ) { return 0; } LUA_FUNC( LuaFuncs::Player_Drop ) { return 0; } @@ -119,6 +138,7 @@ namespace botor const luaL_Reg LuaFuncs::lPlayerFuncs[] = { { "getPosition", Player_GetPosition }, { "setImmune", Player_SetImmune }, + { "addLives", Player_AddLives }, { "teleport", Player_Teleport }, { "pickup", Player_Pickup }, { "drop", Player_Drop }, diff --git a/luafuncs.h b/luafuncs.h index c6804ee..47f659e 100644 --- a/luafuncs.h +++ b/luafuncs.h @@ -31,6 +31,7 @@ namespace botor static LUA_FUNC( Player_Teleport ); static LUA_FUNC( Player_Pickup ); static LUA_FUNC( Player_Drop ); + static LUA_FUNC( Player_AddLives ); static const luaL_Reg lPlayerFuncs[]; }; diff --git a/map.lua b/map.lua index 4352ad3..959e43a 100644 --- a/map.lua +++ b/map.lua @@ -1,10 +1,10 @@ for i = 0,10,1 do - map.CreateRobot( i+5, 12 ) + for y = 0,3,1 do + map.CreateRobot( i+5, y+12 ) + end end -map.CreateRobot( 19, 14 ) - for i = 0,10,1 do for y = 0,2,1 do map.CreateObject( "acid", i+6, y+1 ) @@ -12,7 +12,8 @@ for i = 0,10,1 do end map.CreateObject( "blueman", 5, 6 ) -map.CreateObject( "hihi", 6, 6 ) +map.CreateObject( "potion", 6, 6 ) + +player.teleport( 1, 1 ) -player.teleport( 4, 4 ) diff --git a/objects.lua b/objects.lua index 8b785eb..6469d57 100644 --- a/objects.lua +++ b/objects.lua @@ -14,6 +14,12 @@ objects["blueman"] = } +objects["potion"] = +{ + tile = 2, + nuse = "Once" +} + objects["hihi"] = { tile = 1, @@ -39,6 +45,12 @@ function objects.blueman.Drop() player.setImmune( 0 ); end +-- POTION + +function objects.potion.Activation() + player.addLives( ); +end + --HIHI FUNCTIONS function objects.hihi.Activation() @@ -46,4 +58,4 @@ function objects.hihi.Activation() for i = pos.x+1,pos.x+10,1 do map.CreateObject( "acid", i, pos.y ) end -end \ No newline at end of file +end diff --git a/objects.png b/objects.png dissimilarity index 86% index c8decbbcf3d507b27dfadac81c3142ddad3a2e4f..4b95176165d56b09d39705829931964a64febda3 100644 GIT binary patch delta 1000 zcwPbM0~h@A2jK~jU^>6_5m}bC-Iv(X)e&2|I@&fL z53XE;Z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