|
|
|
@ -9,14 +9,18 @@ var tilesColor = [water,beach,grass] |
|
|
|
|
var board_numbers = []; |
|
|
|
|
|
|
|
|
|
var cycle = 50; |
|
|
|
|
var tile_width=16; |
|
|
|
|
var tile_height=16; |
|
|
|
|
var width = Math.floor(1600 / tile_width); |
|
|
|
|
var height = Math.floor(800 / tile_height); |
|
|
|
|
var tile_width=32; |
|
|
|
|
var tile_height=32; |
|
|
|
|
var width = Math.floor(640 / tile_width); |
|
|
|
|
var height = Math.floor(640 / tile_height); |
|
|
|
|
var current_noise = []; |
|
|
|
|
var currentBoardArray = []; |
|
|
|
|
var clickCounter = 0; |
|
|
|
|
|
|
|
|
|
var startx = 0; |
|
|
|
|
var starty = 0; |
|
|
|
|
var endx = 0; |
|
|
|
|
var endy = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function findHeighestNumber(array){ |
|
|
|
@ -100,7 +104,7 @@ function createBoard(height, width, array){ |
|
|
|
|
var board = document.getElementById("can"); |
|
|
|
|
var context = board.getContext("2d"); |
|
|
|
|
|
|
|
|
|
console.log(array); |
|
|
|
|
////console.log(array);
|
|
|
|
|
|
|
|
|
|
for(var i = 0; i < height; i++){ |
|
|
|
|
for(var j = 0; j < width; j++){ |
|
|
|
@ -137,7 +141,7 @@ function generate_perlin_noise(rounds,height,width){ |
|
|
|
|
|
|
|
|
|
for(var r = 0; r < rounds; r++){ |
|
|
|
|
var tmp_array = []; |
|
|
|
|
//console.log("------------------ Step "+r+" --------------");
|
|
|
|
|
////console.log("------------------ Step "+r+" --------------");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -148,11 +152,11 @@ function generate_perlin_noise(rounds,height,width){ |
|
|
|
|
var startValue = Math.random() * (maxValue - minValue) + minValue; //Stupid, but i always forgot, how to set the boundries
|
|
|
|
|
var counter = 0; |
|
|
|
|
for(var j = 0; j < width; j++){ |
|
|
|
|
//console.log(counter);
|
|
|
|
|
//console.log("Step "+i+"+"+j+":");
|
|
|
|
|
//console.log("counter: "+counter);
|
|
|
|
|
////console.log(counter);
|
|
|
|
|
////console.log("Step "+i+"+"+j+":");
|
|
|
|
|
////console.log("counter: "+counter);
|
|
|
|
|
if (j % (points_width - 1) === 0 && !(j === 0) || j === (width - 1)){ |
|
|
|
|
//console.log(counter);
|
|
|
|
|
////console.log(counter);
|
|
|
|
|
let endValue = Math.random() * (maxValue - minValue) + minValue; //Stupid, but i always forgot, how to set the boundries
|
|
|
|
|
interpolate(startValue, endValue, counter); |
|
|
|
|
row = row.concat(interpolate(startValue, endValue, counter)); |
|
|
|
@ -162,7 +166,7 @@ function generate_perlin_noise(rounds,height,width){ |
|
|
|
|
counter++; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
//console.log(row);
|
|
|
|
|
////console.log(row);
|
|
|
|
|
tmp_array.push(row); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -192,7 +196,7 @@ function generate_perlin_noise(rounds,height,width){ |
|
|
|
|
points_width = Math.floor(points_width / 2)+1; |
|
|
|
|
points_height = Math.floor(points_height / 2)+1; |
|
|
|
|
} |
|
|
|
|
console.log(result); |
|
|
|
|
//console.log(result);
|
|
|
|
|
//return result;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -206,8 +210,8 @@ function generate_perlin_noise(rounds,height,width){ |
|
|
|
|
combi.push(rows); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
console.log("------------- Ergebnisse ----------- Ergebnisse -------------"); |
|
|
|
|
console.log(combi); |
|
|
|
|
//console.log("------------- Ergebnisse ----------- Ergebnisse -------------");
|
|
|
|
|
//console.log(combi);
|
|
|
|
|
|
|
|
|
|
// adding all array to one array
|
|
|
|
|
for(var r = 0; r < rounds; r++){ |
|
|
|
@ -230,8 +234,8 @@ function generate_perlin_noise(rounds,height,width){ |
|
|
|
|
|
|
|
|
|
// ???? Anomalie ????
|
|
|
|
|
|
|
|
|
|
console.log(result); |
|
|
|
|
console.log(combi); |
|
|
|
|
//console.log(result);
|
|
|
|
|
//console.log(combi);
|
|
|
|
|
|
|
|
|
|
return combi; |
|
|
|
|
} |
|
|
|
@ -242,11 +246,12 @@ function generate_perlin_noise(rounds,height,width){ |
|
|
|
|
* */ |
|
|
|
|
function run_perlin_noise(){ |
|
|
|
|
var noise_array = generate_perlin_noise(cycle,width,height); |
|
|
|
|
console.log(noise_array); |
|
|
|
|
//console.log(noise_array);
|
|
|
|
|
current_noise = noise_array; |
|
|
|
|
currentBoardArray = createBoardArray(current_noise, height, width); |
|
|
|
|
createBoard(height,width,currentBoardArray); |
|
|
|
|
|
|
|
|
|
//currentBoardArray = createBoardArray(current_noise, height, width);
|
|
|
|
|
//dijkstra(currentBoardArray,startx,15,15,30,30);
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -283,16 +288,26 @@ function moveShip(canvas, e){ |
|
|
|
|
var y = Math.floor(e.clientY - rect.top); |
|
|
|
|
var ship = new Ship(x,y,5); |
|
|
|
|
ship.draw(canvas.getContext("2d")); |
|
|
|
|
console.log("x: "+x+" y: "+y); |
|
|
|
|
//console.log("x: "+x+" y: "+y);
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
window.onload = (function(){ |
|
|
|
|
var can = document.getElementById("can"); |
|
|
|
|
can.addEventListener('mousedown', function(e){ |
|
|
|
|
var can = document.getElementById("can"); |
|
|
|
|
rect = can.getBoundingClientRect(); |
|
|
|
|
can.addEventListener('mousedown', function(e){ |
|
|
|
|
var x = Math.floor((e.clientX - rect.left)/tile_width); |
|
|
|
|
var y = Math.floor((e.clientY - rect.top )/tile_height); |
|
|
|
|
if(clickCounter === 2){ |
|
|
|
|
clickcounter = 1; |
|
|
|
|
endx = x; |
|
|
|
|
endy = y; |
|
|
|
|
console.log(startx+" "+starty+" : "+endx+" "+endy);
|
|
|
|
|
currentBoardArray = createBoardArray(current_noise, height, width); |
|
|
|
|
dijkstra(currentBoardArray, startx, starty,endx,endy); |
|
|
|
|
} else { |
|
|
|
|
clickCounter++; |
|
|
|
|
startx = x; |
|
|
|
|
starty = y; |
|
|
|
|
} |
|
|
|
|
createBoard(height,width,currentBoardArray); |
|
|
|
|
moveShip(can, e); |
|
|
|
|