Options
All
  • Public
  • Public/Protected
  • All
Menu

The weapon that is show for the user's player

Hierarchy

  • Weapon

Index

Constructors

constructor

  • new Weapon(imgPath: string, shootImgPaths: string[], width: number, height: number, semiAutomatic: boolean, shootDuration?: number, muzzFlashCol?: string, testingImage2DClass?: any): Weapon
  • Parameters

    • imgPath: string

      Path to the idle weapon image

    • shootImgPaths: string[]
    • width: number

      Width in px of the weapon images

    • height: number

      Height in px of the weapon images

    • semiAutomatic: boolean

      Is non automatic eg. pistol, revolver, etc

    • Optional shootDuration: number

      How long a shot lasts in second

    • Optional muzzFlashCol: string

      Color of the muzzle flash (#RRGGBB)

    • Optional testingImage2DClass: any

      Mocking class of Image2D for testing purposes

    Returns Weapon

Properties

Private currentShootImage

currentShootImage: number

Index for this.shootImages

Private idleImage

idleImage: Image2D

Image shown when the gun's not being shot (idle)

Private muzzleFlashColor

muzzleFlashColor: string

Color (#RRGGBB) of the gunshot flash color

Private muzzleFlashOngoing

muzzleFlashOngoing: boolean

Is the muzzle flash currently going on? If yes, the renderer will render a bright flash.

Private semiAutomatic

semiAutomatic: boolean

Determines if the weapon is semi-automatic. If false, it's automatic. The idea when a weapon is semi-automatic is that you have to click for each shot (as opposed to an automatic weapon where you can just hold down the button and keep shooting).

Private shootAnimDuration

shootAnimDuration: number

How long one weapon animation frame lasts in seconds. It's a fraction of this.shootDuration

Private shootDuration

shootDuration: number

Determines how long the shooting animation lasts in seconds.

Private shootImages

shootImages: Image2D[]

Image set used to animate when the gun is shot

Private timeSinceLastShootImg

timeSinceLastShootImg: number

Time elapsed since the last shooting animation image in seconds. Used as an animation timekeeping variable. So if a certain time has passed (this.shootAnimDuration), then we swap to the next weapon animation image.

Private weaponState

weaponState: WeaponState

In which state the weapon animation is

Static Readonly DEFAULT_MUZZLE_FLASH_COLOR

DEFAULT_MUZZLE_FLASH_COLOR: "#baba82" = '#baba82'

Color of the muzzle flash that's going to be rendered on the floor near color gradient.

Static Private Readonly DEFAULT_SHOOT_DURATION

DEFAULT_SHOOT_DURATION: 0.4 = 0.4

Also corresponds with shoot frequency. Determines after which timespan a shot can be fired.

Static Readonly WEAPON_BOB_SPEED

WEAPON_BOB_SPEED: 3 = 3

How fast the weapon bobs. A faster factor here may be used to animate faster walking speeds

Static Readonly WEAPON_BOB_SWAY

WEAPON_BOB_SWAY: 20 = 20

A factor used in the renderer to animate the weapon swaying (bobbing) from left to right. This effectively sets the "radius", kind of like a stride length.

Static Readonly WEAPON_ZOOM

WEAPON_ZOOM: 0.5 = 0.5

magnification of weapon images on the screen

Accessors

getCurrentImage2D

getMuzzleFlashColor

  • get getMuzzleFlashColor(): string

getWeaponState

isMuzzleFlashOngoing

  • get isMuzzleFlashOngoing(): boolean
  • Returns boolean

    whether or not the muzzle flash should be animated or not

isSemiautomatic

  • get isSemiautomatic(): boolean

Methods

shoot

  • shoot(): void
    • Set weapon state to SHOOT if not already shooting
    • Play shooting sound
    • Enable muzzle flash

    Returns void

update

  • update(time: number): void
  • Timekeeping method to cycle the weapon shoot animation and set muzzle flash status.

    Parameters

    • time: number

      Time passed in seconds (probably taken from the gameloop)

    Returns void

Generated using TypeDoc