Cavestory Mod API
WeaponShoot.cpp

An example of CSM_Weapon_ShootFunc.

Parameters
sDataThe shoot information.
iLevelThe level of the weapon, starting from 1.
void ShootBullet_MyWeapon(ShootInfo* sData, int iLevel)
{
// Don't allow more than 6 bullets on screen for this weapon.
if (sData->sClient.CountBulletNum(sData->arms_code) > 5)
return;
// Wait until they press the 'shoot' button!
if (!(sData->keyTrg & gKeyShot))
return;
// We're shooting!
if (!sData->sClient.UseArmsEnergy(1))
{
// Not enough ammo.
}
else
{
// Determine how to spawn the bullet
if (sData->ourC->up)
{
// Shoot up
if (sData->ourC->direct == CSM_DIRECT_LEFT)
{
// Shoot left
CSM_SetBullet(sData->bullet_ids[sData->arms_level], sData->ourC->x - 0x600, sData->ourC->y - 0x1400, CSM_DIRECT_UP, sData->arms_code, sData->arms_level, sData->ghostId);
// Muzzle flash
CSM_SetCaret(sData->ourC->x - 0x600, sData->ourC->y - 0x1400, 3, 0);
}
else
{
// Shoot right
CSM_SetBullet(sData->bullet_ids[sData->arms_level], sData->ourC->x + 0x600, sData->ourC->y - 0x1400, CSM_DIRECT_UP, sData->arms_code, sData->arms_level, sData->ghostId);
// Muzzle flash
CSM_SetCaret(sData->ourC->x + 0x600, sData->ourC->y - 0x1400, 3, 0);
}
}
else if (sData->ourC->down)
{
// Shoot down
if (sData->ourC->direct == CSM_DIRECT_LEFT)
{
// Shoot left
CSM_SetBullet(sData->bullet_ids[sData->arms_level], sData->ourC->x - 0x600, sData->ourC->y + 0x1400, CSM_DIRECT_DOWN, sData->arms_code, sData->arms_level, sData->ghostId);
// Muzzle flash
CSM_SetCaret(sData->ourC->x - 0x600, sData->ourC->y + 0x1400, 3, 0);
}
else
{
// Shoot right
CSM_SetBullet(sData->bullet_ids[sData->arms_level], sData->ourC->x + 0x600, sData->ourC->y + 0x1400, CSM_DIRECT_DOWN, sData->arms_code, sData->arms_level, sData->ghostId);
// Muzzle flash
CSM_SetCaret(sData->ourC->x + 0x600, sData->ourC->y + 0x1400, 3, 0);
}
}
else
{
// Shoot straight
if (sData->ourC->direct == CSM_DIRECT_LEFT)
{
// Shoot left
CSM_SetBullet(sData->bullet_ids[sData->arms_level], sData->ourC->x - 0xC00, sData->ourC->y + 0x400, CSM_DIRECT_LEFT, sData->arms_code, sData->arms_level, sData->ghostId);
// Muzzle flash
CSM_SetCaret(sData->ourC->x - 0x1800, sData->ourC->y + 0x400, 3, 0);
}
else
{
// Shoot right
CSM_SetBullet(sData->bullet_ids[sData->arms_level], sData->ourC->x + 0xC00, sData->ourC->y + 0x400, CSM_DIRECT_RIGHT, sData->arms_code, sData->arms_level, sData->ghostId);
// Muzzle flash
CSM_SetCaret(sData->ourC->x + 0x1800, sData->ourC->y + 0x400, 3, 0);
}
}
// Play the 'shoot' sound
CSM_PlaySoundObject(33, CSM_SOUND_MODE_STOP_THEN_PLAY);
}
}
int up
Is facing up?
Definition: CSMAPI_types.h:1506
int y
Y Position.
Definition: CSMAPI_types.h:1526
int x
X Position.
Definition: CSMAPI_types.h:1522
int down
Is facing down?
Definition: CSMAPI_types.h:1510
int direct
Direction.
Definition: CSMAPI_types.h:1498
bool UseArmsEnergy(int iAmount)
Use ammo from the held weapon.
Definition: CavestoryModAPI.cpp:458
void ChangeToFirstArms()
Change to this client's first weapon.
Definition: CavestoryModAPI.cpp:514
int CountBulletNum(int iBulletCode)
Get the number of active bullets w/ the given Bullet ID that this client has shot.
Definition: CavestoryModAPI.cpp:435
ShootInfo structure.
Definition: CSMAPI_types.h:1968
int keyTrg
The key-Trg input state.
Definition: CSMAPI_types.h:1983
int arms_code
Which weapon ID was shot.
Definition: CSMAPI_types.h:2003
MYCHAR * ourC
The character tied to this shoot event.
Definition: CSMAPI_types.h:1975
int arms_level
The level at which the weapon was shot at.
Definition: CSMAPI_types.h:2007
int ghostId
The shooter's Ghost ID.
Definition: CSMAPI_types.h:1995
int bullet_ids[3]
Ease-of-use: List of bullet IDs defined in CaveEditor for each weapon level.
Definition: CSMAPI_types.h:2011
SafeClientInterface sClient
A safe interface for the client who shot the gun.
Definition: CSMAPI_types.h:2015