Update level

This commit is contained in:
Miloslav Číž 2020-04-07 21:24:41 +02:00
parent 94f27afeac
commit eb53f7664b
3 changed files with 43 additions and 40 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.9 KiB

After

Width:  |  Height:  |  Size: 4.2 KiB

79
main.c
View File

@ -1086,6 +1086,44 @@ RCL_Unit SFG_floorCollisionHeightAt(int16_t x, int16_t y)
SFG_getItemCollisionMapBit(x,y) * RCL_UNITS_PER_SQUARE;
}
void SFG_getPlayerWeaponInfo(
uint8_t *ammoType, uint8_t *projectileCount, uint8_t *canShoot)
{
*ammoType = SFG_weaponAmmo(SFG_player.weapon);
*projectileCount = SFG_GET_WEAPON_PROJECTILE_COUNT(SFG_player.weapon);
#if SFG_INFINITE_AMMO
*canShoot = 1;
#else
*canShoot =
(*ammoType == SFG_AMMO_NONE ||
SFG_player.ammo[*ammoType] >= *projectileCount);
#endif
}
void SFG_playerRotateWeapon(uint8_t next)
{
RCL_Unit initialWeapon = SFG_player.weapon;
RCL_Unit increment = next ? 1 : -1;
while (1)
{
SFG_player.weapon =
RCL_wrap(SFG_player.weapon + increment,SFG_WEAPONS_TOTAL);
if (SFG_player.weapon == initialWeapon)
break;
uint8_t ammo, projectileCount, canShoot;
SFG_getPlayerWeaponInfo(&ammo,&projectileCount,&canShoot);
if (canShoot)
break;
}
}
void SFG_initPlayer()
{
RCL_initCamera(&SFG_player.camera);
@ -1118,6 +1156,9 @@ void SFG_initPlayer()
SFG_player.weapon = 2;
SFG_playerRotateWeapon(1); // this chooses weapon with ammo available
SFG_playerRotateWeapon(0);
SFG_player.weaponCooldownStartFrame = SFG_game.frame;
SFG_player.lastHurtFrame = SFG_game.frame;
SFG_player.lastItemTakenFrame = SFG_game.frame;
@ -1439,44 +1480,6 @@ void SFG_init()
#endif
}
void SFG_getPlayerWeaponInfo(
uint8_t *ammoType, uint8_t *projectileCount, uint8_t *canShoot)
{
*ammoType = SFG_weaponAmmo(SFG_player.weapon);
*projectileCount = SFG_GET_WEAPON_PROJECTILE_COUNT(SFG_player.weapon);
#if SFG_INFINITE_AMMO
*canShoot = 1;
#else
*canShoot =
(*ammoType == SFG_AMMO_NONE ||
SFG_player.ammo[*ammoType] >= *projectileCount);
#endif
}
void SFG_playerRotateWeapon(uint8_t next)
{
RCL_Unit initialWeapon = SFG_player.weapon;
RCL_Unit increment = next ? 1 : -1;
while (1)
{
SFG_player.weapon =
RCL_wrap(SFG_player.weapon + increment,SFG_WEAPONS_TOTAL);
if (SFG_player.weapon == initialWeapon)
break;
uint8_t ammo, projectileCount, canShoot;
SFG_getPlayerWeaponInfo(&ammo,&projectileCount,&canShoot);
if (canShoot)
break;
}
}
/**
Adds new projectile to the current level, return 1 if added, 0 if not (max
count reached).

View File

@ -204,12 +204,12 @@
/**
Developer cheat for having infinite ammo in all weapons.
*/
#define SFG_INFINITE_AMMO 1
#define SFG_INFINITE_AMMO 0
/**
Developer cheat for immortality.
*/
#define SFG_IMMORTAL 1
#define SFG_IMMORTAL 0
/**
Turn on for previes mode for map editing (flying, noclip, fast movement etc.).