Skip to content

Commit 2d2a05d

Browse files
committed
health regain fix
1 parent 9dd7ad6 commit 2d2a05d

File tree

4 files changed

+38
-9
lines changed

4 files changed

+38
-9
lines changed

game/classes/player.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ class Player {
3535
this.animationFrame = 0;
3636
this.animationType = ""; // Name of current animation
3737

38+
39+
this.regenTimer = 0;
40+
this.regenInterval = 3
41+
3842
this.attackingOBJ = {}
3943
}
4044

game/classes/statblock.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const BASE_STATS = [
33
"name": "gnome",
44
"hp": 100,
55
"mhp": 100,
6-
"regen": 2,
6+
"regen": .2,
77
"attack": 2,
88
"magic": 1,
99
"mp": 100,
@@ -22,7 +22,7 @@ const BASE_STATS = [
2222
"name": "aylah",
2323
"hp": 100,
2424
"mhp": 100,
25-
"regen": 1,
25+
"regen": .1,
2626
"attack": 1,
2727
"magic": 5,
2828
"mp": 150,
@@ -41,7 +41,7 @@ const BASE_STATS = [
4141
"name": "skizzard",
4242
"hp": 100,
4343
"mhp": 100,
44-
"regen": 10,
44+
"regen": .5,
4545
"attack": 1,
4646
"magic": 1,
4747
"mp": 100,

game/sketch.js

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const races = BASE_STATS.map(item => item.name);
1010
var camera = {};
1111
var dirtBagUI = {};
1212
var Debuging = false;
13-
//console.log("Race names:", races);
13+
1414

1515
function setup() {
1616
// Create a responsive canvas
@@ -111,6 +111,34 @@ function windowResized() {
111111
updateResponsiveDesign();
112112
}
113113

114+
function updatePlayerRegen(player) {
115+
// Increase timer
116+
player.regenTimer += 0.05;
117+
118+
// Only tick on interval
119+
if (player.regenTimer >= player.regenInterval) {
120+
// --- HP Regen ---
121+
let mhp = player.statBlock.stats.mhp || 100;
122+
if (player.statBlock.stats.hp < mhp) {
123+
let regenAmount = (player.statBlock.stats.regen || 0) ;
124+
player.statBlock.stats.hp = Math.min(player.statBlock.stats.hp + regenAmount, mhp);
125+
}
126+
127+
// --- MP Regen ---
128+
let mmp = player.statBlock.stats.mmp || 100;
129+
if (player.statBlock.stats.mp < mmp) {
130+
let mpRegen = (player.statBlock.stats.magic || 0) / 5;
131+
player.statBlock.stats.mp = Math.min(player.statBlock.stats.mp + mpRegen, mmp);
132+
}
133+
134+
// Reset timer and interval (randomize 4-5s)
135+
player.regenTimer = 0;
136+
player.regenInterval = random(4, 5);
137+
}
138+
}
139+
140+
141+
114142
function draw() {
115143
// image as background
116144

@@ -171,10 +199,9 @@ function draw() {
171199
}
172200

173201
//regen mana and health over time
174-
if(curPlayer.statBlock.stats.mp < curPlayer.statBlock.stats.mmp) curPlayer.statBlock.stats.mp += 0.01;
175-
if(curPlayer.statBlock.stats.hp < curPlayer.statBlock.stats.mhp) curPlayer.statBlock.heal(0.01);
202+
updatePlayerRegen(curPlayer,1)
176203

177-
//little interact key above the thing you can interact with
204+
//little interact key above the thing you can interact with f rendered
178205
let mouseVec = createVector(mouseX + camera.pos.x - (width / 2), mouseY + camera.pos.y - (height / 2));
179206
let chunkPos = testMap.globalToChunk(mouseVec.x,mouseVec.y);
180207
let chunk = testMap.chunks[chunkPos.x + "," + chunkPos.y];

game/ui.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@ let markeeText = [
7272
"Remember V the Media Lies",
7373
"If the government could be trusted Jesus would have died of natural causes",
7474
"The Simpson's did it !",
75-
76-
7775
]
7876
// Function to render buttons instead of links
7977
function renderLinks() {

0 commit comments

Comments
 (0)