-
Notifications
You must be signed in to change notification settings - Fork 0
/
menu.js
68 lines (59 loc) · 2 KB
/
menu.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
var gameName,
charName;
window.onload = function(){
animate();
window.addEventListener('keyup',function(e){
if (e.keyCode == 13) {
loadNext();
}
else
switchEntry();
});
//get display default game name
switchEntry();
//generate background image
var generator = new Generator();
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
var bgImage = generator.generateBackground(canvas.width, canvas.height, 30, 0, 0.05, 50, 150);
ctx.drawImage(bgImage.getImage(),0,0);
}
window.onresize = function(){
var generator = new Generator();
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
var bgImage = generator.generateBackground(canvas.width, canvas.height, 30, 0, 0.05, 50, 150);
ctx.drawImage(bgImage.getImage(),0,0);
}
function animate(){
setInterval(function(){
if($("#cursor").css("opacity") == 0)
$("#cursor").css("opacity", 1);
else if($("#cursor").css("opacity") == 1)
$("#cursor").css("opacity", 0);
}, 500);
}
function loadNext(){
if($("#textbox").hasClass("title")){
gameName = $("#textbox").val();
$("#textbox").val("Now our hero needs a name");
$("#textbox").removeClass("title");
$("#textbox").addClass("name");
$("#textbox").select();
switchEntry();
}else if($("#textbox").hasClass("name")){
charName = $("#textbox").val();
//PASS gameName and charName to the game
//------------------------
window.location = "index.html?game=" + gameName.replace(" ", "") + "&char=" + charName.replace(" ", "");
}
}
function switchEntry(){
$("#title").empty();
$("#title").append($("#textbox").val());
document.title = $("#textbox").val();
}