xxxxxxxxxx
112
/*
trying spatial hash mapping (using this awesome implementation for reference https://github.com/simondevyoutube/Tutorial_SpatialHashGrid_Optimized/blob/main/src/spatial-grid.js)
TODO
- [x] figure out how the spatial hashmap works
- [x] add mana to the hashmap, around the player just out of sight
- [x] 'query' the hashmap with the players position and pickup-range to get any mana within pickup range
- [x] remove picked up manas and add them to player exp
- [ ] develop a magnet effect that attracts mana
- [ ] make a way to increase/multiply pickuprange (wonder, is that square or circle?)
- [x] add an xp modifier slider and make it work lol
- [ ] figure out a better nonlinear growth for leveling whatever that is called
*/
const dimensions = [50, 50]; // size of a square in the hashmap
const boundaries = [[0,0], [400,400]];
let random_stuff = [];
let xpslider;
function setup() {
createCanvas(400, 400);
xpslider = createSlider(1, 30, 15);
xpslider.position(10, 120);
xpslider.style('width', '80px');
doom_button = createButton('doom');
doom_button.position(10, 370);
doom_button.mousePressed(testOfDoom);
color_button = createButton('color');
color_button.position(10, 340);
color_button.mousePressed(colorChange);
player = new Player(xpslider);
world = new SpatialHashMap(boundaries, dimensions);
manastore = new ManaStorage(world, player);
hud = new HUD(player, manastore, xpslider)
}
function testOfDoom(){
for (var i=0; i<100000; i++){
var posx = random(400);
var posy= random(400);
var pos = [posx,posy];
var dim = [1,1];
world.NewClient(pos, dim);
manastore.manaSpawnCount++;
}
}
function colorChange(){
console.log("unimplemented");
//random_stuff.push(new LingeringDiv('nott implemented',300), );
}
function tickDivs(){
for(var i = random_stuff.length-1; i > -1;i--){
var div = random_stuff[i];
if (!div.isalive){
random_stuff.splice(i, 1);
//delete div;
} else {
div.tick();
}
}
}
function draw() {
background(220);
manastore.tick();
player.tick();
manastore.render();
player.render();
hud.render();
tickDivs();
}
class LingeringDiv{
constructor(msg, t){
this.d = createDiv(msg);
this.d.position(mouseX, mouseY);
this.d.style('font-size', 25 + 'px');
this.t=t;
this.isalive=true;
}
tick (){
this.t -=1;
this.d.html(this.d.html + this.t);
if (this.t <= 0 && this.isalive){
this.isalive=false;
this.d.remove();
console.log('div died')
}
}
}