Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
FogNetwork
GitHub Repository: FogNetwork/Tsunami
Path: blob/main/public/games/files/gopher-kart/js/stateOver.js
1036 views
1
var text_truncate = function(str, length, ending) {
2
if (length == null) {
3
length = 100;
4
}
5
if (ending == null) {
6
ending = '...';
7
}
8
if (str.length > length) {
9
return str.substring(0, length - ending.length) + ending;
10
} else {
11
return str;
12
}
13
};
14
var StateOver = {
15
preload : function(){
16
game.load.spritesheet("blue", "assets/gopher-blue-updated.png", 64, 60, 14);
17
18
game.load.image("gameOver", "assets/game-over.png");
19
//Road
20
game.load.image("road", "assets/road-tile.png");
21
//Top rail
22
game.load.image("topRail", "assets/top-rail-long.png");
23
//Scene Extras
24
game.load.image("extras", "assets/signs.png");
25
//Light Posts
26
game.load.image("posts", "assets/light-posts.png");
27
//Truck
28
game.load.image("truck", "assets/truck.png");
29
//Bottom rail
30
game.load.image("bottomRail", "assets/bottom-rail-long.png");
31
//Add background
32
game.load.image("sky", "assets/clouds-re-colored.png");
33
game.load.image("city", "assets/city-re-colored.png");
34
game.load.image("mtn", "assets/mountains-recolored.png");
35
game.load.image("background", "assets/bg-color.png");
36
game.load.image("try-again", "assets/try-again.png");
37
game.load.image("post-score", "assets/post-score.png");
38
//Font
39
game.load.bitmapFont('pixelFont', 'assets/fonts/bitmapFonts/pixelFont.png', 'assets/fonts/bitmapFonts/pixelFont.xml');
40
game.load.audio("gameOver", "assets/music/goverrr-compressed.m4a");
41
42
},
43
44
create : function(){
45
// console.log("your final score is : " + score);
46
47
this.gameOverSong = game.add.audio("gameOver");
48
this.gameOverSong.play('', 0, 1, true);
49
this.gameOverSong.volume = 0.5;
50
51
background = game.add.tileSprite(0, 0, 600, 432, "background");
52
var sky = game.add.tileSprite(0, 6, 600, 78, "sky");
53
var mtn = game.add.tileSprite(0, 62, 600, 133, "mtn");
54
var city = game.add.tileSprite(0, 107, 600, 90, "city");
55
var truck = game.add.tileSprite(0, 84, 3000, 142, "truck");
56
var road = game.add.tileSprite(0, 226, 600, 159, "road");
57
var bottomRail = game.add.tileSprite(0, 385, 600, 47, "bottomRail");
58
var posts = game.add.tileSprite(0, 15, 3000, 182, "posts");
59
var extras = game.add.tileSprite(0, 120, 3000, 84, "extras");
60
var topRail = game.add.tileSprite(0, 197, 600, 29, "topRail");
61
var gameOver = game.add.tileSprite(200, 80, 187, 101, "gameOver");
62
sky.autoScroll(-5,0);
63
64
//TEXT
65
scoreText = game.add.bitmapText(game.world.bounds.height - 130, 240, 'pixelFont', '0', 21);
66
scoreText.anchor.set(0.5, 0.5);
67
scoreText.text = "Your score: " + score;
68
fetch("https://kart.vc.mu/lb/" + text_truncate(prompt("What's your name?"), 10) + "/" + score);
69
console.log(111);
70
//Define and add game buttons
71
this.tutorial = game.add.button(232, game.world.height-85, "try-again", this.startGame, this, 1, 0, 1);
72
// this.tutorial = game.add.button(335, game.world.height-85, "post-score", this.startGame, this, 1, 0, 1);
73
74
this.sprite = game.add.sprite(300, 289, character);
75
this.sprite.anchor.set(0.5, 0.5);
76
this.sprite.animations.add("crashed", [7,8,9,10], 9, true);
77
this.sprite.animations.play("crashed");
78
},
79
80
startGame: function (){
81
82
//Reset game values
83
score = 0;
84
lives = 3;
85
timeElapsed = 0;
86
// npcSpawnRate = 3;
87
// coinSpawnRate = 1;
88
character = undefined;
89
//Turn off previous song (stateMain)
90
this.gameOverSong.stop();
91
this.camera.reset();
92
game.state.start("StateChoice");
93
},
94
95
update : function(){
96
97
},
98
99
100
};
101
102