first Prototype
This commit is contained in:
parent
e11825c698
commit
35ce267482
481 changed files with 17315 additions and 1 deletions
110
scripts/player/player.gd
Normal file
110
scripts/player/player.gd
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
class_name Player extends Node
|
||||
|
||||
var gameName: String = ""
|
||||
|
||||
# -- HEALTH --
|
||||
const maxHealth: int = 3
|
||||
const minHealth: int = 0
|
||||
var health := maxHealth
|
||||
# -- HEALTH --
|
||||
|
||||
# -- Item --
|
||||
var itemInventory: Array[Item] = []
|
||||
# -- Item --
|
||||
|
||||
var gun: Gun
|
||||
var selectedPlayer: Player = self
|
||||
|
||||
var character: Character
|
||||
|
||||
var bot: bool = false
|
||||
|
||||
signal dead(player: Player)
|
||||
signal hit(player: Player)
|
||||
signal missed()
|
||||
signal hurt()
|
||||
|
||||
func _init(_name: String, _gun: Gun, _character: Character) -> void:
|
||||
gameName = _name
|
||||
gun = _gun
|
||||
character = _character
|
||||
gun.setOwner(self)
|
||||
|
||||
# -- HEALTH --
|
||||
func damage(amount: int) -> void:
|
||||
print("Hit")
|
||||
if health - amount < minHealth:
|
||||
kill()
|
||||
health = minHealth
|
||||
else:
|
||||
health -= amount
|
||||
for i in range(0,amount):
|
||||
character.removeShot()
|
||||
|
||||
func heal(amount: int) -> void:
|
||||
if health + amount > maxHealth:
|
||||
health = maxHealth
|
||||
else:
|
||||
health += amount
|
||||
|
||||
func getHealth () -> int:
|
||||
return health
|
||||
|
||||
func kill():
|
||||
dead.emit(self)
|
||||
# -- HEALTH --
|
||||
|
||||
|
||||
# -- Item --
|
||||
func addItem(_item: Item) -> void:
|
||||
itemInventory.append(_item)
|
||||
|
||||
func removeItem(_item: Item) -> void:
|
||||
itemInventory.erase(_item)
|
||||
|
||||
func getItems() -> Array[Item]:
|
||||
return itemInventory
|
||||
# -- Item --
|
||||
|
||||
|
||||
# -- Gun --
|
||||
func giveGun(_gun: Gun):
|
||||
gun = _gun
|
||||
|
||||
func takeGun():
|
||||
gun = null
|
||||
|
||||
func useItem(_item: Item):
|
||||
if _item is Bullet:
|
||||
loadBullet(_item)
|
||||
else:
|
||||
print("no bullet")
|
||||
|
||||
func loadBullet(_bullet: Bullet):
|
||||
gun.loadBullet(_bullet)
|
||||
itemInventory.erase(_bullet)
|
||||
|
||||
func shootAtSelectedPlayer():
|
||||
var randomBullet = gun.getRandomBullet()
|
||||
if randomBullet is StandardBullet or randomBullet is LuckyBullet:
|
||||
var bulletDamage = randomBullet.getDamage()
|
||||
if bulletDamage > 0:
|
||||
selectedPlayer.damage(bulletDamage)
|
||||
else:
|
||||
print("Missed")
|
||||
else:
|
||||
print("Empty")
|
||||
|
||||
# -- Gun --
|
||||
|
||||
func selectPlayer(_player: Player) -> void:
|
||||
selectedPlayer = _player
|
||||
|
||||
func getGameName() -> String:
|
||||
return gameName
|
||||
|
||||
func setCharacter(_character: Character) -> void:
|
||||
character = _character
|
||||
|
||||
func getItemAmount() -> int:
|
||||
return itemInventory.size()
|
||||
1
scripts/player/player.gd.uid
Normal file
1
scripts/player/player.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://fkhkxtks5vaw
|
||||
Loading…
Add table
Add a link
Reference in a new issue