CodeDump
Add
Browse
Sign up
Sign in
Select language
ActionScript
Ajax
Android
AngularJS
Apache Configuration
AppleScript
ASP.NET (C#)
AutoHotkey
Bash
Brainfuck
C
C#
C++
CoffeeScript
CSS
CSS Extras
Dart
Eiffel
Erlang
F#
Fortran
Gherkin
Git
Go
Groovy
Haml
Handlebars
Haskell
HTML
HTTP
Ini
iOS
Jade
Java
Javascript
jQuery
JSON
Julia
Keyman
LaTeX
Linux
Less
LOLCODE
Makefile
Markdown
MATLAB
MySQL
NASM
Node.js
NSIS
Objective-C
Pascal
Perl
PHP
PHP Extras
PowerShell
Python
R
React JSX
reST (reStructuredText)
Rip
Ruby
Rust
SAS
Sass (Sass)
Sass (Scss)
Scala
Scheme
Smalltalk
Smarty
SQL
Stylus
Swift
Twig
TypeScript
Vb.net
VHDL
Wiki markup
YAML
Other
Search
You're not signedin! You can't edit or track the code you're going to add. If you want to maintain and track your code, you need to
signin
or
signup
.
We improved our code engine! From now on you can add more then just one peace of code! Use the "
Add more code
" button to add more code".
Add Codedump
Description (Markdown supported)
Title or filename
Language
Choose language
ActionScript
Ajax
Android
AngularJS
Apache Configuration
AppleScript
ASP.NET (C#)
AutoHotkey
Bash
Brainfuck
C
C#
C++
CoffeeScript
CSS
CSS Extras
Dart
Eiffel
Erlang
F#
Fortran
Gherkin
Git
Go
Groovy
Haml
Handlebars
Haskell
HTML
HTTP
Ini
iOS
Jade
Java
Javascript
jQuery
JSON
Julia
Keyman
LaTeX
Linux
Less
LOLCODE
Makefile
Markdown
MATLAB
MySQL
NASM
Node.js
NSIS
Objective-C
Pascal
Perl
PHP
PHP Extras
PowerShell
Python
R
React JSX
reST (reStructuredText)
Rip
Ruby
Rust
SAS
Sass (Sass)
Sass (Scss)
Scala
Scheme
Smalltalk
Smarty
SQL
Stylus
Swift
Twig
TypeScript
Vb.net
VHDL
Wiki markup
YAML
Other
Code
class Player { float health; float currentHealth; float healthRegeneration; float attack; float armor; init () { this.initHealth(); } initHealth() { /** * Sets `currentHealth` to the players `health` stat. * This way, we can track the players `health` without modifying his stats. */ this.currentHealth = health; } heal(float value) { float netHeal = value; if (this.currentHealth + netHeal >= this.health) { /** * if the heal would bring the players `currentHealth` over his `health` stat, we want to reduce this amount so the `netHeal` is the difference * ex: Player has 80/100 health. An incoming heal of 40 would be reduced to a `netHeal` of 20. */ netHeal = this.health - this.currentHealth; } // applies the heal this.currentHealth += netHeal; } damage(float value) { float netDamage = value; // reduces the `netDamage` by any `armor` present netDamage -= armor; if (this.currentHealth - netDamage <= 0) { /** * if the damage would bring the players `currentHealth` below 0, we want to reduce this amount so the `netDamage` is the difference * ex: Player has 30/100 health. An incoming damage of 40 would be reduced to a `netDamage` of 10. */ netDamage = netDamage - this.currentHealth; } // applies the damage this.currentHealth -= netDamage; } /** * Happens once per frame. */ update() { this.doHealthRegeneration(); } doHealthRegeneration() { // attempts to heal the player for their `healthRegeneration` stat amount based on the time of the last frame. this.heal(this.healthRegeneration * Time.deltaTime); } }
Access
Everyone
Just me
Create