1 (edited by Ciryus 2013-03-06 12:23:21)

Topic: Adding new Pickable entities

trying to add an ammo crate to the game I am facing a problem and can't figure out how to solve this. I added the crate into the code

##network.py
Powerups = ["HEALTH", "ARMOR", "WEAPON", "NINJA","AMMO"]

......................


##content.py
[...]
container.pickups.Add(Pickup("ammo"))
[...]
container.sprites.Add(Sprite("pickup_armor", set_game, 12,2,2,2))

.................

/************Pickup.cpp*************/

case POWERUP_AMMO:
                if(pChr->IncreaseAmmo(3))
                {
                    GameServer()->CreateSound(m_Pos, SOUND_WEAPON_SWITCH);
                    RespawnTime = g_pData->m_aPickups[m_Type].m_Respawntime;
                }
                break;
.................

 

But I just can't see where in the game it has been put, I don't even think it handles my ammo crate.
So has someone ever created a new pickable entity and used it?
If yes a description the method would be welcome ^^
Thanks.

2 (edited by BeaR 2013-03-06 13:05:58)

Re: Adding new Pickable entities

Well you have to create a new pickup in the source and then render it also..

For the first take a look in the gamecontroller and search for OnEntity(),
for rendering the pickup look at the method RenderPickup and add your sprite to the list
(should be enough imho)

3 (edited by Ciryus 2013-03-12 13:49:55)

Re: Adding new Pickable entities

Thx for your answer BeaR.
I didn't post all my code cause I thought it would be a waiste of time but I already did what you told me:

/*******gamecontroller.cpp********
OnEntity()
{
[...]
 if(Index == ENTITY_AMMO_1)
            Type = POWERUP_AMMO;
[...]
}
/**************items.cpp*******/
RenderPickup()
{
[...]
    const int c[] = {
            SPRITE_PICKUP_HEALTH,
            SPRITE_PICKUP_ARMOR,
            SPRITE_PICKUP_WEAPON,
            SPRITE_PICKUP_NINJA,
            SPRITE_PICKUP_AMMO
            };
        RenderTools()->SelectSprite(c[pCurrent->m_Type]);
[...]

But still nothing, no way to find an ammo crate in the game.. Is there something I am missing?




----EDIT-----
OKay, I was missing the fact that you have to change entities.png in the editor folder,
the position in the png file must be the same as the enum position, i.e. inserting ENTITY_MY_NEW_PICKUP in the enum of the src/game/mapitems.h will define the position of you new pickup, so if you put it just right after the ENTITY_WEAPON_RIFLE be sure to fill the empty tile just after the rifle tile in your entity tiles (entities.png).
Then you will have to create a new map in the editor (best tuto https://www.teeworlds.com/forum/viewtopic.php?id=7644) and test it on your own server (https://www.teeworlds.com/forum/viewtopic.php?id=7955)
Hope it will help somebody.