aboutsummaryrefslogtreecommitdiff
path: root/src/player.moon
diff options
context:
space:
mode:
Diffstat (limited to 'src/player.moon')
-rw-r--r--src/player.moon49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/player.moon b/src/player.moon
new file mode 100644
index 0000000..076f9bb
--- /dev/null
+++ b/src/player.moon
@@ -0,0 +1,49 @@
+char = require "char"
+util = require "util"
+main = require "main"
+bp = require "broadphase"
+import KeyInput from char
+import Vec2 from util
+
+mod = ...
+--[[A player that we receive information about]]
+class RemotePlayer extends char.Character
+ new: (uname, data, charclass) =>
+ super(uname, data, charclass)
+
+class LocalPlayer extends char.Character
+ new:(uname, data, charclass) =>
+ super(uname, data, charclass)
+
+ draw: (...) =>
+ super(...)
+ healthnode = am.group() ^ {am.translate(-main.width/2,main.height/2) ^ am.text(string.format("Health:%d", @health), vec4(255,255,255,255), "left","top")\tag "health text"}
+ @node\append(healthnode)
+
+ take_damage: (_from, ammt) =>
+ if am.current_time! - @last_dammage > 1
+ @health -= ammt
+ @last_dammage = am.current_time!
+ (@node)("health text").text = string.format("Health:%d",@health)
+ if @health == 0
+ @\die!
+
+ filter: (other) =>
+ if other.canfall
+ return "cross"
+ if other.hurtbox
+ if other.owner ~= @
+ @take_damage(other,1)
+ return "cross"
+ else
+ return "slide"
+ die: (...) =>
+ --[[When the player dies, wait 100 ms, load the level, and drop them on the spawnpoint]]
+
+ super(...)
+
+
+
+mod["RemotePlayer"] = RemotePlayer
+mod["LocalPlayer"] = LocalPlayer
+mod