Add gun items

Revolver, Shotgun, Rifle,
Assult Rifle, Super Soaker

- Add Items script and IItems interface,
  stores and manages selected item
- Add Weapon script controls gun parameters,
  such as effective range, spread and recoil
- Weapon sprites (32x32 Firearm Pack)
- Weapon sounds (made with rFXGen)
- Move BlockPos and Facing to own files
main
copygirl 4 years ago
parent fb75edb51f
commit b803c94200
  1. 19
      CREDITS.md
  2. BIN
      gfx/guns/AK47.png
  3. 34
      gfx/guns/AK47.png.import
  4. BIN
      gfx/guns/Blunderbuss.png
  5. 34
      gfx/guns/Blunderbuss.png.import
  6. BIN
      gfx/guns/BowArrow.png
  7. 34
      gfx/guns/BowArrow.png.import
  8. BIN
      gfx/guns/ColtSingleActionArmy.png
  9. 34
      gfx/guns/ColtSingleActionArmy.png.import
  10. BIN
      gfx/guns/Derringer.png
  11. 34
      gfx/guns/Derringer.png.import
  12. BIN
      gfx/guns/DoubleBarrel.png
  13. 34
      gfx/guns/DoubleBarrel.png.import
  14. BIN
      gfx/guns/FNScar.png
  15. 34
      gfx/guns/FNScar.png.import
  16. BIN
      gfx/guns/LaserPistol.png
  17. 34
      gfx/guns/LaserPistol.png.import
  18. BIN
      gfx/guns/M1911.png
  19. 34
      gfx/guns/M1911.png.import
  20. BIN
      gfx/guns/M1Garand.png
  21. 34
      gfx/guns/M1Garand.png.import
  22. BIN
      gfx/guns/MP40.png
  23. 34
      gfx/guns/MP40.png.import
  24. BIN
      gfx/guns/MauserC96.png
  25. 34
      gfx/guns/MauserC96.png.import
  26. BIN
      gfx/guns/MoneyLauncher.png
  27. 34
      gfx/guns/MoneyLauncher.png.import
  28. BIN
      gfx/guns/P90.png
  29. 34
      gfx/guns/P90.png.import
  30. BIN
      gfx/guns/PlasmaBlaster.png
  31. 34
      gfx/guns/PlasmaBlaster.png.import
  32. BIN
      gfx/guns/RocketLauncher.png
  33. 34
      gfx/guns/RocketLauncher.png.import
  34. BIN
      gfx/guns/Sawed-OffWinchester1897.png
  35. 34
      gfx/guns/Sawed-OffWinchester1897.png.import
  36. BIN
      gfx/guns/SuperSoaker.png
  37. 34
      gfx/guns/SuperSoaker.png.import
  38. BIN
      gfx/guns/ThombsonSMG.png
  39. 34
      gfx/guns/ThombsonSMG.png.import
  40. BIN
      gfx/guns/Uzi.png
  41. 34
      gfx/guns/Uzi.png.import
  42. BIN
      gfx/guns/WaltherP38.png
  43. 34
      gfx/guns/WaltherP38.png.import
  44. BIN
      gfx/guns/Winchester1873.png
  45. 34
      gfx/guns/Winchester1873.png.import
  46. BIN
      gfx/guns/Winchester1897.png
  47. 34
      gfx/guns/Winchester1897.png.import
  48. 4
      scene/ClientScene.tscn
  49. 103
      scene/Player.tscn
  50. BIN
      sfx/assault_rifle.rfx
  51. BIN
      sfx/assault_rifle.wav
  52. 21
      sfx/assault_rifle.wav.import
  53. BIN
      sfx/revolver.rfx
  54. BIN
      sfx/revolver.wav
  55. 21
      sfx/revolver.wav.import
  56. BIN
      sfx/rifle.rfx
  57. BIN
      sfx/rifle.wav
  58. 21
      sfx/rifle.wav.import
  59. BIN
      sfx/shotgun.rfx
  60. BIN
      sfx/shotgun.wav
  61. 21
      sfx/shotgun.wav.import
  62. 2
      src/Items/CreativeBuilding.cs
  63. 61
      src/Items/Items.cs
  64. 122
      src/Items/Weapon.cs
  65. 83
      src/RadialMenu.cs
  66. 50
      src/Utility/BlockPos.cs
  67. 52
      src/Utility/Facing.cs

@ -1,3 +1,14 @@
# Tools
## rFXGen ZERO
Used to create simple retro sound effects in the game.
**URL:** https://raylibtech.itch.io/rfxgen
**Author:** raylib technologies
**License:** zlib License
# Assets
## Heartbit Font
@ -9,3 +20,11 @@
> You'll need to pay the suggested price for commercial projects.
**Notes:** Modified `1` and `V` characters.
## 32x32 Firearm Pack
**URL:** https://ma9ici4n.itch.io/ma9ici4nweaponpack
**Author:** ma9ici4n
**License:** Custom
> You can download and use this pack anywhere you want without crediting me.
> However credit is still appreciated. Do not redistribute this under your own name.

Binary file not shown.

After

Width:  |  Height:  |  Size: 313 B

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/AK47.png-b3a2177e704ef07670dcc3fbcf5fe2b5.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://gfx/guns/AK47.png"
dest_files=[ "res://.import/AK47.png-b3a2177e704ef07670dcc3fbcf5fe2b5.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=false
svg/scale=1.0

Binary file not shown.

After

Width:  |  Height:  |  Size: 241 B

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/Blunderbuss.png-f9541a9afbcc7503436ddb33d87600bd.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://gfx/guns/Blunderbuss.png"
dest_files=[ "res://.import/Blunderbuss.png-f9541a9afbcc7503436ddb33d87600bd.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=false
svg/scale=1.0

Binary file not shown.

After

Width:  |  Height:  |  Size: 338 B

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/BowArrow.png-6b5dd8d866365f0485866a478b6a0cd1.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://gfx/guns/BowArrow.png"
dest_files=[ "res://.import/BowArrow.png-6b5dd8d866365f0485866a478b6a0cd1.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=false
svg/scale=1.0

Binary file not shown.

After

Width:  |  Height:  |  Size: 255 B

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/ColtSingleActionArmy.png-4ffeb11f8b9db175b4a4529b4533c26c.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://gfx/guns/ColtSingleActionArmy.png"
dest_files=[ "res://.import/ColtSingleActionArmy.png-4ffeb11f8b9db175b4a4529b4533c26c.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=false
svg/scale=1.0

Binary file not shown.

After

Width:  |  Height:  |  Size: 168 B

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/Derringer.png-43093e7c64541e63c047f9a45f88d5c6.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://gfx/guns/Derringer.png"
dest_files=[ "res://.import/Derringer.png-43093e7c64541e63c047f9a45f88d5c6.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=false
svg/scale=1.0

Binary file not shown.

After

Width:  |  Height:  |  Size: 231 B

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/DoubleBarrel.png-0d2a0a5877ea0832296b59ab69073d32.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://gfx/guns/DoubleBarrel.png"
dest_files=[ "res://.import/DoubleBarrel.png-0d2a0a5877ea0832296b59ab69073d32.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=false
svg/scale=1.0

Binary file not shown.

After

Width:  |  Height:  |  Size: 308 B

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/FNScar.png-6b3a68f387ec6ab89122d03cf241a16f.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://gfx/guns/FNScar.png"
dest_files=[ "res://.import/FNScar.png-6b3a68f387ec6ab89122d03cf241a16f.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=false
svg/scale=1.0

Binary file not shown.

After

Width:  |  Height:  |  Size: 243 B

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/LaserPistol.png-5913c4141046557751080b5a6a4dcbb9.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://gfx/guns/LaserPistol.png"
dest_files=[ "res://.import/LaserPistol.png-5913c4141046557751080b5a6a4dcbb9.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=false
svg/scale=1.0

Binary file not shown.

After

Width:  |  Height:  |  Size: 229 B

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/M1911.png-fb90f2bf6081ebaaa4570e1f13d26084.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://gfx/guns/M1911.png"
dest_files=[ "res://.import/M1911.png-fb90f2bf6081ebaaa4570e1f13d26084.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=false
svg/scale=1.0

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/M1Garand.png-8ea72bda0579460c0ab21455199ddf51.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://gfx/guns/M1Garand.png"
dest_files=[ "res://.import/M1Garand.png-8ea72bda0579460c0ab21455199ddf51.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=false
svg/scale=1.0

Binary file not shown.

After

Width:  |  Height:  |  Size: 227 B

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/MP40.png-541ce9f02220339ddd77f7c18bfb102c.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://gfx/guns/MP40.png"
dest_files=[ "res://.import/MP40.png-541ce9f02220339ddd77f7c18bfb102c.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=false
svg/scale=1.0

Binary file not shown.

After

Width:  |  Height:  |  Size: 218 B

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/MauserC96.png-e3f26ff256559f76cbf4380e8c78de28.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://gfx/guns/MauserC96.png"
dest_files=[ "res://.import/MauserC96.png-e3f26ff256559f76cbf4380e8c78de28.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=false
svg/scale=1.0

Binary file not shown.

After

Width:  |  Height:  |  Size: 244 B

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/MoneyLauncher.png-38558cda7f759b8a828a02520ae7fa9d.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://gfx/guns/MoneyLauncher.png"
dest_files=[ "res://.import/MoneyLauncher.png-38558cda7f759b8a828a02520ae7fa9d.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=false
svg/scale=1.0

Binary file not shown.

After

Width:  |  Height:  |  Size: 249 B

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/P90.png-b84ced4c3b84daba88bcb46f3f2fb629.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://gfx/guns/P90.png"
dest_files=[ "res://.import/P90.png-b84ced4c3b84daba88bcb46f3f2fb629.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=false
svg/scale=1.0

Binary file not shown.

After

Width:  |  Height:  |  Size: 356 B

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/PlasmaBlaster.png-662106c2dd5c775f0121fd667460ead0.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://gfx/guns/PlasmaBlaster.png"
dest_files=[ "res://.import/PlasmaBlaster.png-662106c2dd5c775f0121fd667460ead0.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=false
svg/scale=1.0

Binary file not shown.

After

Width:  |  Height:  |  Size: 257 B

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/RocketLauncher.png-fa5fe47507c4a5106da9783313b29ce2.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://gfx/guns/RocketLauncher.png"
dest_files=[ "res://.import/RocketLauncher.png-fa5fe47507c4a5106da9783313b29ce2.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=false
svg/scale=1.0

Binary file not shown.

After

Width:  |  Height:  |  Size: 237 B

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/Sawed-OffWinchester1897.png-1828856c6c85c4c85f9f239d881cc72a.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://gfx/guns/Sawed-OffWinchester1897.png"
dest_files=[ "res://.import/Sawed-OffWinchester1897.png-1828856c6c85c4c85f9f239d881cc72a.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=false
svg/scale=1.0

Binary file not shown.

After

Width:  |  Height:  |  Size: 305 B

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/SuperSoaker.png-ad26a5aee73722ca7f641ac2f8616b8a.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://gfx/guns/SuperSoaker.png"
dest_files=[ "res://.import/SuperSoaker.png-ad26a5aee73722ca7f641ac2f8616b8a.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=false
svg/scale=1.0

Binary file not shown.

After

Width:  |  Height:  |  Size: 291 B

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/ThombsonSMG.png-3e71e65b4033797b49413ad61792d18e.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://gfx/guns/ThombsonSMG.png"
dest_files=[ "res://.import/ThombsonSMG.png-3e71e65b4033797b49413ad61792d18e.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=false
svg/scale=1.0

Binary file not shown.

After

Width:  |  Height:  |  Size: 233 B

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/Uzi.png-1c37865966347d689e7d0d5728dc5079.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://gfx/guns/Uzi.png"
dest_files=[ "res://.import/Uzi.png-1c37865966347d689e7d0d5728dc5079.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=false
svg/scale=1.0

Binary file not shown.

After

Width:  |  Height:  |  Size: 221 B

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/WaltherP38.png-c8185be1b2a1769c60b86322c1f29049.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://gfx/guns/WaltherP38.png"
dest_files=[ "res://.import/WaltherP38.png-c8185be1b2a1769c60b86322c1f29049.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=false
svg/scale=1.0

Binary file not shown.

After

Width:  |  Height:  |  Size: 239 B

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/Winchester1873.png-1b4ec1d71f56d7af98fb910a51fa5323.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://gfx/guns/Winchester1873.png"
dest_files=[ "res://.import/Winchester1873.png-1b4ec1d71f56d7af98fb910a51fa5323.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=false
svg/scale=1.0

Binary file not shown.

After

Width:  |  Height:  |  Size: 234 B

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/Winchester1897.png-a4adb39ab0537aef28a489a5a9e49483.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://gfx/guns/Winchester1897.png"
dest_files=[ "res://.import/Winchester1897.png-a4adb39ab0537aef28a489a5a9e49483.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=false
svg/scale=1.0

@ -47,9 +47,9 @@ anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
margin_left = -36.0
margin_left = -29.0
margin_top = -16.0
margin_right = 36.0
margin_right = 29.0
margin_bottom = 16.0
theme = ExtResource( 10 )
align = 1

@ -1,10 +1,21 @@
[gd_scene load_steps=7 format=2]
[gd_scene load_steps=18 format=2]
[ext_resource path="res://ui_theme.tres" type="Theme" id=1]
[ext_resource path="res://gfx/player.png" type="Texture" id=2]
[ext_resource path="res://src/Objects/Player.cs" type="Script" id=3]
[ext_resource path="res://src/CreativeBuilding.cs" type="Script" id=4]
[ext_resource path="res://src/Items/CreativeBuilding.cs" type="Script" id=4]
[ext_resource path="res://src/Items/Items.cs" type="Script" id=5]
[ext_resource path="res://gfx/block.png" type="Texture" id=6]
[ext_resource path="res://gfx/guns/ColtSingleActionArmy.png" type="Texture" id=7]
[ext_resource path="res://src/Items/Weapon.cs" type="Script" id=8]
[ext_resource path="res://gfx/guns/DoubleBarrel.png" type="Texture" id=9]
[ext_resource path="res://gfx/guns/SuperSoaker.png" type="Texture" id=10]
[ext_resource path="res://gfx/guns/M1Garand.png" type="Texture" id=11]
[ext_resource path="res://gfx/guns/FNScar.png" type="Texture" id=12]
[ext_resource path="res://sfx/shotgun.wav" type="AudioStream" id=13]
[ext_resource path="res://sfx/revolver.wav" type="AudioStream" id=14]
[ext_resource path="res://sfx/rifle.wav" type="AudioStream" id=15]
[ext_resource path="res://sfx/assault_rifle.wav" type="AudioStream" id=16]
[sub_resource type="CircleShape2D" id=1]
radius = 8.0
@ -40,6 +51,8 @@ z_index = -5
texture = ExtResource( 2 )
[node name="Items" type="Node2D" parent="."]
script = ExtResource( 5 )
DefaultItemPath = NodePath("Creative Building")
[node name="Creative Building" type="Node2D" parent="Items"]
visible = false
@ -48,3 +61,89 @@ script = ExtResource( 4 )
[node name="Icon" type="Sprite" parent="Items/Creative Building"]
visible = false
texture = ExtResource( 6 )
[node name="Revolver" type="Sprite" parent="Items"]
visible = false
texture = ExtResource( 7 )
offset = Vector2( 8, 0 )
script = ExtResource( 8 )
Spread = 3.0
SpreadIncrease = 1.0
RecoilMin = 3.0
RecoilMax = 5.0
RecoilRegen = 16.0
[node name="Tip" type="Node2D" parent="Items/Revolver"]
position = Vector2( 15, -2.5 )
[node name="Fire" type="AudioStreamPlayer2D" parent="Items/Revolver"]
stream = ExtResource( 14 )
attenuation = 1.0
[node name="Shotgun" type="Sprite" parent="Items"]
visible = false
texture = ExtResource( 9 )
offset = Vector2( 8, 0 )
script = ExtResource( 8 )
EffectiveRange = 240
MaximumRange = 360
Spread = 14.0
SpreadIncrease = 20.0
SpreadRegen = 16.0
RecoilMin = 6.0
RecoilMax = 12.0
RecoilRegen = 8.0
[node name="Tip" type="Node2D" parent="Items/Shotgun"]
position = Vector2( 22, -1.5 )
[node name="Fire" type="AudioStreamPlayer2D" parent="Items/Shotgun"]
stream = ExtResource( 13 )
attenuation = 1.0
[node name="Rifle" type="Sprite" parent="Items"]
visible = false
texture = ExtResource( 11 )
offset = Vector2( 8, 0 )
script = ExtResource( 8 )
EffectiveRange = 480
MaximumRange = 920
SpreadIncrease = 2.0
SpreadRegen = 2.0
RecoilMin = 8.0
RecoilMax = 8.0
RecoilRegen = 8.0
[node name="Tip" type="Node2D" parent="Items/Rifle"]
position = Vector2( 24, -1.5 )
[node name="Fire" type="AudioStreamPlayer2D" parent="Items/Rifle"]
stream = ExtResource( 15 )
attenuation = 1.0
[node name="Assault Rifle" type="Sprite" parent="Items"]
visible = false
texture = ExtResource( 12 )
offset = Vector2( 8, 0 )
script = ExtResource( 8 )
Spread = 1.0
SpreadIncrease = 1.2
SpreadRegen = 5.0
RecoilMin = 1.0
RecoilMax = 2.5
[node name="Tip" type="Node2D" parent="Items/Assault Rifle"]
position = Vector2( 22, -1.5 )
[node name="Fire" type="AudioStreamPlayer2D" parent="Items/Assault Rifle"]
stream = ExtResource( 16 )
attenuation = 1.0
[node name="Super Soaker" type="Sprite" parent="Items"]
visible = false
texture = ExtResource( 10 )
offset = Vector2( 8, 0 )
script = ExtResource( 8 )
[node name="Tip" type="Node2D" parent="Items/Super Soaker"]
position = Vector2( 17, 0.5 )

Binary file not shown.

Binary file not shown.

@ -0,0 +1,21 @@
[remap]
importer="wav"
type="AudioStreamSample"
path="res://.import/assault_rifle.wav-be55643f0ef4eee454a1d69851e40bdb.sample"
[deps]
source_file="res://sfx/assault_rifle.wav"
dest_files=[ "res://.import/assault_rifle.wav-be55643f0ef4eee454a1d69851e40bdb.sample" ]
[params]
force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=false
edit/normalize=false
edit/loop=false
compress/mode=0

Binary file not shown.

Binary file not shown.

@ -0,0 +1,21 @@
[remap]
importer="wav"
type="AudioStreamSample"
path="res://.import/revolver.wav-a193edf66acf3d5ba572c83152b952b7.sample"
[deps]
source_file="res://sfx/revolver.wav"
dest_files=[ "res://.import/revolver.wav-a193edf66acf3d5ba572c83152b952b7.sample" ]
[params]
force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=false
edit/normalize=false
edit/loop=false
compress/mode=0

Binary file not shown.

Binary file not shown.

@ -0,0 +1,21 @@
[remap]
importer="wav"
type="AudioStreamSample"
path="res://.import/rifle.wav-4d8a68001c8b651b3f0f41b64fa095a8.sample"
[deps]
source_file="res://sfx/rifle.wav"
dest_files=[ "res://.import/rifle.wav-4d8a68001c8b651b3f0f41b64fa095a8.sample" ]
[params]
force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=false
edit/normalize=false
edit/loop=false
compress/mode=0

Binary file not shown.

Binary file not shown.

@ -0,0 +1,21 @@
[remap]
importer="wav"
type="AudioStreamSample"
path="res://.import/shotgun.wav-29870054b4a67834b920542f9f1e5152.sample"
[deps]
source_file="res://sfx/shotgun.wav"
dest_files=[ "res://.import/shotgun.wav-29870054b4a67834b920542f9f1e5152.sample" ]
[params]
force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=false
edit/normalize=false
edit/loop=false
compress/mode=0

@ -35,7 +35,7 @@ public class CreativeBuilding : Node2D
public override void _UnhandledInput(InputEvent ev)
{
if (!(Player is LocalPlayer) || !Visible) return;
if (!Visible || !(Player is LocalPlayer)) return;
if (ev.IsActionPressed("interact_place")) {
GetTree().SetInputAsHandled();

@ -0,0 +1,61 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Godot;
// TODO: Add ways to add/move/remove items, including event when changed.
public interface IItems : IReadOnlyCollection<Node2D>
{
Node2D this[int index] { get; }
Node2D Current { get; set; }
}
public class Items : Node2D, IItems
{
[Export] public NodePath DefaultItemPath { get; set; }
private Node2D _current;
public int Count => GetChildCount();
public Node2D this[int index] => GetChild<Node2D>(index);
public Node2D Current { get => _current; set => SetCurrent(value, true); }
public override void _Ready()
{
foreach (var item in this) SetActive(item, false);
if (DefaultItemPath != null) SetCurrent(GetNode<Node2D>(DefaultItemPath), false);
}
private void SetCurrent(Node2D node, bool sendRpc)
{
if (node == _current) return;
if ((node != null) && (node.GetParent() != this)) throw new ArgumentException();
SetActive(_current, false);
SetActive(node, true);
_current = node;
if (sendRpc) {
if (this.GetGame() is Server) Rpc(nameof(DoSetCurrent), _current?.Name);
else RpcId(1, nameof(DoSetCurrent), _current?.Name);
}
}
[Remote]
private void DoSetCurrent(string name)
{
var node = (name != null) ? GetNode<Node2D>(name) : null;
SetCurrent(node, this.GetGame() is Server);
}
public IEnumerator<Node2D> GetEnumerator()
=> GetChildren().Cast<Node2D>().GetEnumerator();
IEnumerator IEnumerable.GetEnumerator()
=> GetEnumerator();
private static void SetActive(Node2D node, bool value) {
if (node == null) return;
node.SetProcessInput(value);
node.SetProcessUnhandledInput(value);
node.Visible = value;
}
}

@ -0,0 +1,122 @@
using Godot;
public class Weapon : Sprite
{
[Export] public int EffectiveRange { get; set; } = 320;
[Export] public int MaximumRange { get; set; } = 640;
[Export] public float Spread { get; set; } = 0.0F;
[Export] public float SpreadIncrease { get; set; } = 0.0F;
[Export] public float SpreadRegen { get; set; } = 10.0F;
[Export] public float RecoilMin { get; set; } = 0.0F;
[Export] public float RecoilMax { get; set; } = 0.0F;
[Export] public float RecoilRegen { get; set; } = 10.0F;
// TODO: Make the Regen multiplicative instead of substractive?
public Cursor Cursor { get; private set; }
public Player Player { get; private set; }
private float _currentSpreadInc = 0.0F;
private float _currentRecoil = 0.0F;
public float AimDirection { get; private set; }
public override void _Ready()
{
Cursor = this.GetClient()?.Cursor;
Player = GetParent().GetParent<Player>();
}
public override void _UnhandledInput(InputEvent ev)
{
if (!(Player is LocalPlayer)) return;
// TODO: Is not "place", is shoot!
if (ev.IsActionPressed("interact_place")) {
GetNodeOrNull<AudioStreamPlayer2D>("Fire")?.Play();
// TODO: Spawn bullet or something.
// TODO: Tell server (and other clients) we shot.
_currentSpreadInc += Mathf.Deg2Rad(SpreadIncrease);
_currentRecoil += Mathf.Deg2Rad((float)GD.RandRange(RecoilMin, RecoilMax));
}
}
public override void _Process(float delta)
{
// FIXME: Need to run _Process after switching to a weapon.
_currentSpreadInc = Mathf.Max(0, _currentSpreadInc - Mathf.Deg2Rad(SpreadRegen) * delta);
_currentRecoil = Mathf.Max(0, _currentRecoil - Mathf.Deg2Rad(RecoilRegen) * delta);
if (Visible && (Player is LocalPlayer)) {
AimDirection = Cursor.Position.AngleToPoint(Player.Position);
RpcId(1, nameof(SendAimAngle), AimDirection);
Update();
}
var angle = Mathf.PosMod(AimDirection + Mathf.Pi, Mathf.Tau) - Mathf.Pi;
angle = Mathf.Abs(Mathf.Rad2Deg(angle));
if (Scale.y > 0) { if (angle > 100.0F) Scale = new Vector2(1, -1); }
else if (angle < 80.0F) Scale = new Vector2(1, 1);
Rotation = AimDirection - _currentRecoil * ((Scale.y > 0) ? 1 : -1);
}
[Remote]
private void SendAimAngle(float value)
{
if (this.GetGame() is Server) {
if (Player.NetworkID != GetTree().GetRpcSenderId()) return;
// TODO: Verify input.
// if ((value < 0) || (value > Mathf.Tau)) return;
Rpc(nameof(SendAimAngle), value);
} else if (!(Player is LocalPlayer))
AimDirection = value;
}
public override void _Draw()
{
if (!(Player is LocalPlayer)) return;
var tip = GetNode<Node2D>("Tip").Position + new Vector2(4, 0);
var angle = Mathf.Sin((Mathf.Deg2Rad(Spread) + _currentSpreadInc) / 2);
var color = Colors.Black;
var points = new Vector2[8];
var colors = new Color[8];
colors[0] = colors[7] = new Color(color, 0.0F);
points[0] = points[7] = tip;
colors[1] = colors[6] = new Color(color, 0.15F);
points[1] = tip + new Vector2(1, angle) * 64;
points[6] = tip + new Vector2(1, -angle) * 64;
colors[2] = colors[5] = new Color(color, 0.15F);
points[2] = tip + new Vector2(1, angle) * EffectiveRange;
points[5] = tip + new Vector2(1, -angle) * EffectiveRange;
colors[3] = colors[4] = new Color(color, 0.0F);
points[3] = tip + new Vector2(1, angle) * MaximumRange;
points[4] = tip + new Vector2(1, -angle) * MaximumRange;
var st = new SurfaceTool();
st.Begin(Mesh.PrimitiveType.TriangleStrip);
st.AddColor(colors[0]);
st.AddVertex(To3(points[0]));
st.AddColor(colors[1]);
st.AddVertex(To3(points[1]));
st.AddVertex(To3(points[6]));
st.AddColor(colors[2]);
st.AddVertex(To3(points[2]));
st.AddVertex(To3(points[5]));
st.AddColor(colors[3]);
st.AddVertex(To3(points[3]));
st.AddVertex(To3(points[4]));
st.Index();
DrawMesh(st.Commit(), null);
DrawPolylineColors(points, colors, antialiased: true);
}
private static Vector3 To3(Vector2 vec)
=> new Vector3(vec.x, vec.y, 0);
}

@ -12,8 +12,7 @@ public class RadialMenu : Node2D
public Label ActiveName { get; private set; }
private float _startAngle;
public Node2D Selected { get; private set; } = null;
public int? SelectedIndex => (Selected != null) ? Selected.GetIndex() : (int?)null;
private Node2D _selected;
public override void _Ready()
{
@ -23,36 +22,20 @@ public class RadialMenu : Node2D
ActiveName = GetNode<Label>("ActiveName");
}
public Node GetItems()
=> this.GetClient().LocalPlayer?.GetNode<Node2D>("Items");
public void Select(Node2D node)
{
if (node == Selected) return;
if ((node != null) && (node.GetParent() != GetItems())) throw new ArgumentException();
ActiveName.Text = node?.Name ?? "";
if (Visible)
Update();
else {
SetActive(Selected, false);
SetActive(node, true);
}
Selected = node;
}
private static void SetActive(Node2D node, bool value) {
if (node == null) return;
node.SetProcessInput(value);
node.SetProcessUnhandledInput(value);
node.Visible = value;
}
public IItems GetItems()
=> this.GetClient().LocalPlayer?.GetNode<IItems>("Items");
public override void _UnhandledInput(InputEvent ev)
{
if (ev.IsActionPressed("interact_select")) {
Position = this.GetClient().Cursor.ScreenPosition.Round();
Visible = true;
SetActive(Selected, false);
var items = GetItems();
_selected = items.Current;
items.Current = null;
ActiveName.Text = _selected?.Name ?? "";
Update();
}
// TODO: Add scrollwheel support.
@ -61,54 +44,62 @@ public class RadialMenu : Node2D
public override void _Process(float delta)
{
if (!Visible) return;
var items = GetItems();
var cursorPos = ToLocal(this.GetClient().Cursor.ScreenPosition);
var angle = cursorPos.Angle() - _startAngle;
var index = (int)((angle / Mathf.Tau + 1) % 1 * MinElements);
var items = GetItems();
if ((cursorPos.Length() > InnerRadius) && (index < items.GetChildCount()))
Select(items.GetChild<Node2D>(index));
if ((cursorPos.Length() > InnerRadius) && (index < items.Count) && (items[index] != _selected)) {
_selected = items[index];
ActiveName.Text = _selected?.Name ?? "";
Update();
}
if (!Input.IsActionPressed("interact_select")) {
Visible = false;
SetActive(Selected, true);
items.Current = _selected;
Update();
}
}
public override void _Draw()
{
var items = GetItems();
var vertices = new Vector2[5];
var colors = new Color[5];
for (var i = 0; i < MinElements; i++) {
var angle1 = _startAngle + Mathf.Tau * ( i / (float)MinElements);
var angle3 = _startAngle + Mathf.Tau * ((i + 1) / (float)MinElements);
var numElements = Math.Max(MinElements, items.Count);
for (var i = 0; i < numElements; i++) {
var angle1 = _startAngle + Mathf.Tau * ( i / (float)numElements);
var angle3 = _startAngle + Mathf.Tau * ((i + 1) / (float)numElements);
var angle2 = (angle1 + angle3) / 2;
var sep1 = new Vector2(Mathf.Cos(angle1 + Mathf.Tau / 4), Mathf.Sin(angle1 + Mathf.Tau / 4)) * Separation;
var sep2 = new Vector2(Mathf.Cos(angle3 - Mathf.Tau / 4), Mathf.Sin(angle3 - Mathf.Tau / 4)) * Separation;
var sep1 = Mathf.Polar2Cartesian(Separation, angle1 + Mathf.Tau / 4);
var sep2 = Mathf.Polar2Cartesian(Separation, angle3 - Mathf.Tau / 4);
var isSelected = i == SelectedIndex;
var isSelected = (i < items.Count) && (_selected == items[i]);
var innerRadius = InnerRadius + (isSelected ? 5 : 0);
var outerRadius = OuterRadius + (isSelected ? 5 : 0);
vertices[0] = new Vector2(Mathf.Cos(angle1), Mathf.Sin(angle1)) * innerRadius + sep1;
vertices[1] = new Vector2(Mathf.Cos(angle1), Mathf.Sin(angle1)) * outerRadius + sep1;
vertices[2] = new Vector2(Mathf.Cos(angle2), Mathf.Sin(angle2)) * (outerRadius + Separation);
vertices[3] = new Vector2(Mathf.Cos(angle3), Mathf.Sin(angle3)) * outerRadius + sep2;
vertices[4] = new Vector2(Mathf.Cos(angle3), Mathf.Sin(angle3)) * innerRadius + sep2;
vertices[0] = Mathf.Polar2Cartesian(innerRadius , angle1) + sep1;
vertices[1] = Mathf.Polar2Cartesian(outerRadius , angle1) + sep1;
vertices[2] = Mathf.Polar2Cartesian(outerRadius + Separation, angle2);
vertices[3] = Mathf.Polar2Cartesian(outerRadius , angle3) + sep2;
vertices[4] = Mathf.Polar2Cartesian(innerRadius , angle3) + sep2;
var color = new Color(0.1F, 0.1F, 0.1F, isSelected ? 0.7F : 0.4F);
for (var j = 0; j < colors.Length; j++) colors[j] = color;
DrawPolygon(vertices, colors, antialiased: true);
var items = GetItems();
if ((i < items.GetChildCount()) && (items.GetChild(i)?.GetNodeOrNull("Icon") is Sprite sprite)) {
var pos = new Vector2(Mathf.Cos(angle2), Mathf.Sin(angle2)) * (innerRadius + outerRadius) / 2;
if (sprite.Centered) pos -= sprite.Texture.GetSize() / 2;
DrawTexture(sprite.Texture, sprite.Offset + pos, sprite.Modulate);
if (i < items.Count) {
var sprite = (items[i].GetNodeOrNull("Icon") as Sprite) ?? (items[i] as Sprite);
if (sprite != null) {
var pos = Mathf.Polar2Cartesian((innerRadius + outerRadius) / 2, angle2);
if (sprite.Centered) pos -= sprite.Texture.GetSize() / 2;
DrawTexture(sprite.Texture, pos, sprite.Modulate);
}
}
}
}

@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using Godot;
public readonly struct BlockPos : IEquatable<BlockPos>
@ -48,52 +47,3 @@ public readonly struct BlockPos : IEquatable<BlockPos>
public static BlockPos operator /(BlockPos left, int right)
=> new BlockPos(left.X / right, left.Y / right);
}
public enum Facing
{
Left,
Right,
Up,
Down,
}
public static class Facings
{
public static readonly IReadOnlyCollection<Facing> All = new []{ Facing.Left, Facing.Right, Facing.Up, Facing.Down };
public static readonly IReadOnlyCollection<Facing> Horizontal = new []{ Facing.Left, Facing.Right };
public static readonly IReadOnlyCollection<Facing> Vertical = new []{ Facing.Up, Facing.Down };
public static BlockPos ToBlockPos(this Facing facing)
{
switch (facing) {
case Facing.Left: return BlockPos.Left;
case Facing.Right: return BlockPos.Right;
case Facing.Up: return BlockPos.Up;
case Facing.Down: return BlockPos.Down;
default: throw new ArgumentException();
}
}
public static Vector2 ToVector(this Facing facing)
=> facing.ToBlockPos().ToVector();
public static Facing FromAngle(float radians)
{
radians = ((radians % (Mathf.Pi*2)) + Mathf.Pi*2) % (Mathf.Pi*2);
if (radians < Mathf.Pi / 4) return Facing.Right;
else if (radians < Mathf.Pi / 4 * 3) return Facing.Down;
else if (radians < Mathf.Pi / 4 * 5) return Facing.Left;
else if (radians < Mathf.Pi / 4 * 7) return Facing.Up;
else return Facing.Right;
}
public static float ToAngle(this Facing facing)
{
switch (facing) {
case Facing.Right: return 0;
case Facing.Down: return Mathf.Pi / 2;
case Facing.Left: return Mathf.Pi;
case Facing.Up: return Mathf.Pi / 2 * 3;
default: throw new ArgumentException();
}
}
}

@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using Godot;
public enum Facing
{
Left,
Right,
Up,
Down,
}
public static class Facings
{
public static readonly IReadOnlyCollection<Facing> All = new []{ Facing.Left, Facing.Right, Facing.Up, Facing.Down };
public static readonly IReadOnlyCollection<Facing> Horizontal = new []{ Facing.Left, Facing.Right };
public static readonly IReadOnlyCollection<Facing> Vertical = new []{ Facing.Up, Facing.Down };
public static BlockPos ToBlockPos(this Facing facing)
{
switch (facing) {
case Facing.Left: return BlockPos.Left;
case Facing.Right: return BlockPos.Right;
case Facing.Up: return BlockPos.Up;
case Facing.Down: return BlockPos.Down;
default: throw new ArgumentException();
}
}
public static Vector2 ToVector(this Facing facing)
=> facing.ToBlockPos().ToVector();
public static Facing FromAngle(float radians)
{
radians = Mathf.PosMod(radians, Mathf.Tau);
if (radians < Mathf.Pi / 4) return Facing.Right;
else if (radians < Mathf.Pi / 4 * 3) return Facing.Down;
else if (radians < Mathf.Pi / 4 * 5) return Facing.Left;
else if (radians < Mathf.Pi / 4 * 7) return Facing.Up;
else return Facing.Right;
}
public static float ToAngle(this Facing facing)
{
switch (facing) {
case Facing.Right: return 0;
case Facing.Down: return Mathf.Pi / 2;
case Facing.Left: return Mathf.Pi;
case Facing.Up: return Mathf.Pi / 2 * 3;
default: throw new ArgumentException();
}
}
}
Loading…
Cancel
Save