BlueGit

blue-star speeltuin

Files

speeltuin / src / game.js

game.js

Menu component
timfa Nick Hiert · pushed by timfa · 4 years ago
f555b1c2 History
game.js 7.5 KiB Download Raw
1console.log("Game started!");
2var game = new Game();
3game.chaoImages = [];
4
5window.onload = function ()
6{
7
8 game.preloadImagesThenStart(
9 [
10 { name: "arrow", url: "images/arrow.png", subImgTotal: 4, perRow: 2 },
11 { name: "gem", url: "images/gems.png", subImgTotal: 72, perRow: 6 },
12 { name: "ball", url: "images/ball.png", subImgTotal: 4, perRow: 4 },
13 { name: "grass_dark", url: "images/grass_dark.png" },
14 { name: "grass_light", url: "images/grass_light.png" },
15 { name: "frog_basic", url: "images/character/frog/frog_basic.png", subImgTotal: 4, perRow: 4 },
16 { name: "frog_tongue_base", url: "images/character/frog/frog_tongue_base.png" },
17 { name: "frog_tongue_tip", url: "images/character/frog/frog_tongue_tip.png" },
18 { name: "chao_default", url: "images/character/chao/default.png", subImgTotal: 67, perRow: 9 },
19 { name: "chao_blue", url: "images/character/chao/blue.png", subImgTotal: 67, perRow: 9 },
20 { name: "chao_cyan", url: "images/character/chao/cyan.png", subImgTotal: 67, perRow: 9 },
21 { name: "chao_dark", url: "images/character/chao/dark.png", subImgTotal: 67, perRow: 9 },
22 { name: "chao_darkgreen", url: "images/character/chao/darkgreen.png", subImgTotal: 67, perRow: 9 },
23 { name: "chao_green", url: "images/character/chao/green.png", subImgTotal: 67, perRow: 9 },
24 { name: "chao_lightgreen", url: "images/character/chao/lightgreen.png", subImgTotal: 67, perRow: 9 },
25 { name: "chao_hero", url: "images/character/chao/hero.png", subImgTotal: 67, perRow: 9 },
26 { name: "chao_orange", url: "images/character/chao/orange.png", subImgTotal: 67, perRow: 9 },
27 { name: "chao_pink", url: "images/character/chao/pink.png", subImgTotal: 67, perRow: 9 },
28 { name: "chao_purple", url: "images/character/chao/purple.png", subImgTotal: 67, perRow: 9 },
29 { name: "chao_red", url: "images/character/chao/red.png", subImgTotal: 67, perRow: 9 },
30 { name: "chao_white", url: "images/character/chao/white.png", subImgTotal: 67, perRow: 9 },
31 { name: "chao_yellow", url: "images/character/chao/yellow.png", subImgTotal: 67, perRow: 9 },
32 { name: "tile_floor_brown", url: "images/tile/tile_floor_brown.png" },
33 { name: "tile_floor_explosion", url: "images/tile/tile_floor_explosion_anim.png", subImgTotal: 10, perRow: 5 },
34 { name: "fruit", url: "images/object/fruit.png", subImgTotal: 15, perRow: 8 },
35 { name: "spacebar", url: "images/spacebar.png" },
36
37 { name: "menuButton", url: "images/buttons/menubutton.png", subImgTotal: 1, perRow: 1 },
38 { name: "btnFruit", url: "images/buttons/menubutton_fruit.png", subImgTotal: 1, perRow: 1 },
39 { name: "btnToys", url: "images/buttons/menubutton_toys.png", subImgTotal: 1, perRow: 1 },
40 { name: "btnGames", url: "images/buttons/menubutton_games.png", subImgTotal: 1, perRow: 1 },
41 { name: "btnPlants", url: "images/buttons/menubutton_plants.png", subImgTotal: 1, perRow: 1 },
42 { name: "btnFrog", url: "images/buttons/menubutton_frog.png" },
43 { name: "closeButton", url: "images/buttons/closeMenuBtn.png", subImgTotal: 1, perRow: 1 },
44 { name: "fruitInventory", url: "images/buttons/fruitInventory.png", subImgTotal: 1, perRow: 1 }
45 ]
46 , function ()
47 {
48 game.images.frog_basic.addAnimationCycle("walk", [0, 1, 2, 1], true);
49 game.images.tile_floor_explosion.addAnimationCycle("destroy", [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], false);
50 this.setupChaoAnimations(game.images.chao_default);
51 this.setupChaoAnimations(game.images.chao_blue);
52 this.setupChaoAnimations(game.images.chao_cyan);
53 this.setupChaoAnimations(game.images.chao_dark);
54 this.setupChaoAnimations(game.images.chao_darkgreen);
55 this.setupChaoAnimations(game.images.chao_green);
56 this.setupChaoAnimations(game.images.chao_lightgreen);
57 this.setupChaoAnimations(game.images.chao_hero);
58 this.setupChaoAnimations(game.images.chao_orange);
59 this.setupChaoAnimations(game.images.chao_pink);
60 this.setupChaoAnimations(game.images.chao_purple);
61 this.setupChaoAnimations(game.images.chao_red);
62 this.setupChaoAnimations(game.images.chao_white);
63 this.setupChaoAnimations(game.images.chao_yellow);
64
65 this.createMainScene(game);
66 });
67};
68
69function setupChaoAnimations (image)
70{
71 game.chaoImages.push(image);
72 image.addAnimationCycle("walkDown", [0, 1, 0, 2], true);
73 image.addAnimationCycle("walkLeft", [3, 4, 3, 5], true);
74 image.addAnimationCycle("walkUp", [6, 7, 6, 8], true);
75
76 image.addAnimationCycle("standDown", [0]);
77 image.addAnimationCycle("standLeft", [3]);
78 image.addAnimationCycle("standUp", [6]);
79
80 image.addAnimationCycle("flyDown", [9, 10, 11, 10], true);
81 image.addAnimationCycle("flyLeft", [12, 13, 14, 13], true);
82 image.addAnimationCycle("flyUp", [15, 16, 17, 16], true);
83
84 image.addAnimationCycle("tripDown", [18, 19, 20]);
85 image.addAnimationCycle("tripLeft", [21, 22, 23]);
86 image.addAnimationCycle("tripUp", [24, 25, 26]);
87
88 image.addAnimationCycle("sitDown", [27]);
89 image.addAnimationCycle("sitLeft", [28]);
90
91 image.addAnimationCycle("tantrum", [29, 30, 29, 31, 32, 33, 33], false, "standDownAngry");
92 image.addAnimationCycle("standDownAngry", [29], true);
93
94 image.addAnimationCycle("swimStruggle", [34, 35], true);
95 image.addAnimationCycle("eatStart", [36, 37, 38], false, "eat");
96 image.addAnimationCycle("eat", [37, 38], true);
97
98 image.addAnimationCycle("cheer", [39, 40, 39, 40, 39, 40, 39, 40, 39, 40], false, "standDown");
99 image.addAnimationCycle("wave", [41, 42, 42, 42, 42], false, "standDown");
100
101 image.addAnimationCycle("hungry", [43, 44, 43, 44, 43, 44, 43, 44], false, "standDown");
102
103 image.addAnimationCycle("no", [45, 46, 45, 47, 45, 46, 45, 47], false, "standDownBored");
104 image.addAnimationCycle("standDownBored", [45], false);
105
106 image.addAnimationCycle("think", [48, 48, 48, 48, 48], false, "standDown");
107 image.addAnimationCycle("happy", [49, 50, 49, 51], true);
108 image.addAnimationCycle("standDownSad", [52], false);
109 image.addAnimationCycle("sleep", [53, 54], true);
110 image.addAnimationCycle("eureka", [60, 60, 60, 60, 60, 60, 60, 60, 60, 66, 66, 66, 66, 66, 66, 48, 48, 48], false, "wave");
111
112 image.addAnimationCycle("swim", [55, 56, 57], true);
113 image.addAnimationCycle("eatBig", [58, 59], true);
114 image.addAnimationCycle("sneeze", [60, 61, 62, 63], false, "standDown");
115 image.addAnimationCycle("cry", [64, 65, 64, 65, 64, 65, 64, 65, 64, 65], false, "standDownSad");
116 image.addAnimationCycle("think2", [66, 66, 66, 66, 66, 66], false, "standDown");
117}
118
119createMainScene = function (game)
120{
121 var background = new BackgroundScene(0, 0, 704, 640, Scene.DisplayModes.absolute);
122 var scene = new Scene(0, 0, 704, 640, Scene.DisplayModes.absolute);
123 scene.renderBackground = false;
124
125 game.loadScene(background);
126 game.loadScene(scene);
127
128 background.addObject(new GrassTiler(50, 50, game.images.arrow, 0));
129 chao = new Chao(Math.randomRange(0, 704), Math.randomRange(0, 640), game.images.chao_default, 0);
130 scene.addObject(chao);
131
132 menu = new MainMenu(0, 50, 60, 50, game.images.menuButton, 5, true);
133
134 scene.addObject(menu);
135 scene.addObject(new SimpleImagesRenderTween(-100, -100, game.images.arrow, 1));
136
137 WorldObjectTracker.Load(scene);
138};