Bullet

(extends Object)

Overview

Bullets are the most important part of any attack, and as such, they can be complicated to set up. This section will first explain creating generic bullets without making new files for them, then detail how to extend them.

Note

By default, all bullets have a scale of 2, and an origin of 0.5, 0.5. This means its collider, sprite, and any other children will be relative to the topleft of the bullet’s width and height, which are automatically set to the dimensions of its sprite if the bullet is initiated with a path specified (in other words, making all children relative to the topleft of the bullet’s sprite). When making any bullet’s collider, remember that it will be scaled 2x because of this.

Class Members

(see Object for inherited members)

Useful Functions

Overridable Functions

Internal / Class Overrides

  • Bullet:update() (from Object:update())

  • Bullet:draw() (from Object:draw())

Variables

Class Reference

class Bullet(x, y, texture)

Creates a new instance of the Bullet class.

Parameters
  • x,y (numbers) – The position of the bullet.

  • texture (string) – The path to the bullet’s texture.

setSprite(texture[, speed, loop, on_finished])

Sets the sprite of the bullet to the specified path, and changes the bullet’s width and height variables to the dimensions of the sprite. speed, loop, and on_finished will be passed into the sprite’s play() function.

Parameters
  • texture (string) – The path to the bullet’s texture.

  • speed (number) – The animation delay between frames.

  • loop (boolean) – Whether the animation should loop.

  • on_finished (function) – A function to call when the animation finishes.

isBullet(id)

Returns whether the bullet is the bullet with the specified ID, or extends it.

Parameters

id (string) – The id of the bullet.

Returns

result (boolean)

getTarget()

Returns the target of the attacker (if any), or ANY.

Returns

target (string or PartyBattler)

getDamage()

Returns the damage of the bullet. If damage is nil, will calculate damage based on the enemy’s attack.

Returns

damage (number)

test()

This is a test function.

Parameters
  • arg1 (string) – The first argument.

  • arg2 (number) – The second argument.

Returns

  • result (number)

  • result2 (string)

onDamage(soul)

Called when the player collides with the bullet without invincibility frames. By default, damages the player and sets their invincibility frames.

Parameters

soul (Soul) – The Soul that the bullet collided with.

onCollide(soul)

Called when the player collides with the bullet, regardless of invincibility frames. By default, calls Bullet:onDamage(soul) if the player does not have active invincibility frames, and removes the bullet if destroy_on_hit is true.

Parameters

soul (Soul) – The Soul that the bullet collided with.

onWaveSpawn(wave)

Called when the bullet is spawned by a wave, via Wave:spawnBullet(). By default, does nothing.

Parameters

wave (Wave) – The Wave that spawned the bullet.

sprite

The Sprite of the bullet, set by Bullet:setSprite.

wave

A reference to the current Wave that is active. Gets defined after init(), but only if spawned through Wave:spawnBullet(); otherwise, it is never defined.

attacker

A reference to the EnemyBattler associated with the bullet. Gets defined after init(), but only if spawned through Wave:spawnBullet(); otherwise, it is never defined.

damage

Amount of damage the bullet does. If not provided, the game will calculate damage based on the enemy’s attack.

destroy_on_hit

Whether the bullet will be removed when it collides with the player. true by default.

remove_offscreen

Whether the bullet will be removed when it goes offscreen. true by default.

tp

The amount of TP (in percentage) the player gains from grazing the bullet. Defaults to 1.6 (1/10th of a defend).

time_bonus

The number of frames, based on 30fps, that the wave’s length will be reduced by when grazing the bullet. Apparently this is a mechanic in Deltarune.

grazed

(Internal) Whether the bullet has already been grazed. (reduces graze rewards)