-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketch.js
141 lines (109 loc) · 3.44 KB
/
sketch.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// initialise some game world references
var gameChar_x;
var gameChar_y;
var floorPos_y;
var scrollPos;
var gameChar_world_x;
// scenery
var bg_trees;
var collectables;
var clouds;
var mountainSmall;
var mountainBig;
var canyons;
// character movements
var isLeft;
var isRight;
var isFalling;
var isPlummeting;
var isDead;
//game peripherals and level complete detection
var game_score;
var flagpole;
var lives = 3;
// background gradient colours
var c1;
var c2;
// fire animation
var flames = [];
var sideFlames = [];
// arrays for mountain constructor functions
var bigMountains = [];
var smallMountains = [];
//game sound effects
var jumpSound;
var canyonSound;
var prettyFunSound;
var lastLifeSound;
var backgroundSound;
var superSaiyanSound;
var transformed;
function preload()
{
soundFormats('mp3','wav');
//load your sounds here
jumpSound = loadSound('assets/jump.wav');
jumpSound.setVolume(0.05);
canyonSound = loadSound('assets/canyonFall.wav');
canyonSound.setVolume(0.1);
prettyFunSound = loadSound('assets/prettyFun.wav');
prettyFunSound.setVolume(0.2);
lastLifeSound = loadSound('assets/lastLife.wav');
lastLifeSound.setVolume(0.3);
backgroundSound = loadSound('assets/background.mp3');
backgroundSound.setVolume(0.1);
superSaiyanSound = loadSound('assets/superSaiyanAura.wav');
superSaiyanSound.setVolume(0.1);
}
function setup()
{
startGame();
backgroundMusic();
}
function draw()
{
// draw the sky gradient
setGradient(0, 0, width, height, c1, c2);
// draw the ground
noStroke();
fill(25, 130, 102);
rect(0, floorPos_y, width, height/4); // draw the ground
// create a scrolling background
push();
translate(scrollPos,0);
// run all game drawing functions and game mechanics
drawMountains();
moveClouds();
drawTrees(); // background trees to fill out scenery
advancedTrees(-550,280);
advancedTrees(0,300);
advancedTrees(340,300);
advancedTrees(590,320);// dynamic trees with x & y pos parameters
advancedTrees(1200,280);
advancedTrees(1700,280);
advancedTrees(2100,280);
drawAndCheckCanyon(); // canyon with collision detection
drawAndCollectCollectible(); // also changes player score
namekShip();// draw spaceship at flagpole location
pop(); // end of translated "fixed" scenery objects
drawDynamicChar(); // draws transforming Goku
// display player lives and score to screen and check number of lives
drawPlayerLives();
lifeCounter();
// prevents bug of instant game restart if spacebar still held at flagpole
keyReset();
// checks level complete, locks player x_position, awaits restart command
levelComplete();
// game mechanics
mechanics();
// checks if player died, if lives > 0, resets character
checkPlayerDie();
// plays sound for falling down canyon
canyonFall();
// stops the player from moving infinately to the right past flagpole
stopPlayerRight();
// create burning embers blowing in the wind with y and alpha parameters
sideFire(random(2, 20), 255);
// vegeta warning sound on game over
lastLife();
}