Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var X = -1000, Y = 100;
- var Xv, Yv;
- var Xc, Yc;
- var Xt = 350, Yt = -200;
- var Xe = 350, Ye = 750;
- var font;
- var enter;
- var select;
- var selector = 0;
- var title;
- var overlay;
- var win, failure;
- var ovni;
- var virus;
- var texture_virus;
- var coin;
- var select_pressed = 0;
- var coin_sound;
- var start_sound;
- var death_sound;
- var select_sound;
- var denied_sound;
- var intro = 0;
- var intro_music;
- var game_music;
- var win_music;
- var highscore = 999;
- var timer=window.setInterval("Timer()",1000);
- var seconds = 0;
- var gamemode = 0; // 0 = Menu , 1 = En jeu, 2 = Mort, 3 = Gagné
- var niveau = 1;
- ////////////// Initialisation //////////////
- function preload() {
- font = loadFont('textures/game_over.ttf')
- title = loadImage('textures/title.png');
- select = loadImage('textures/select.png');
- enter = loadImage('textures/enter.png');
- overlay = loadImage('textures/overlay.png');
- win = loadImage('textures/win.png');
- failure = loadImage('textures/failure.png');
- ovni = loadImage('textures/ovni.png');
- texture_virus = loadImage('textures/virus.png');
- coin = loadImage('textures/coin.png');
- soundFormats('mp3', 'ogg');
- coin_sound = loadSound('sounds/coin.ogg');
- start_sound = loadSound('sounds/start.ogg');
- death_sound = loadSound('sounds/death.ogg');
- select_sound = loadSound('sounds/select.ogg');
- denied_sound = loadSound('sounds/denied.ogg');
- intro_music = loadSound('sounds/intro.ogg');
- game_music = loadSound('sounds/game.ogg');
- win_music = loadSound('sounds/win.ogg')
- }
- function setup() {
- createCanvas(windowWidth, windowHeight);
- imageMode(CENTER);
- textAlign(CENTER);
- noCursor();
- }
- function windowResized() {
- resizeCanvas(windowWidth, windowHeight);
- }
- ////////////// Draw //////////////
- function draw() {
- if (gamemode == 0){
- mainMenu();
- }
- else if (gamemode == 1){
- Playing();
- }
- if (keyIsDown(13) && gamemode==2) {
- niveau = 1;
- gamemode = 1;
- seconds = 0;
- start_sound.play();
- game_music.loop();
- Level(1);
- }
- if (keyIsDown(27) && gamemode==3) {
- win_music.stop();
- X = -1000;
- Y = 100;
- seconds = 0;
- niveau = 1;
- gamemode = 0;
- start_sound.play();
- }
- }
- ////////////// Classe Virus //////////////
- class Virus {
- constructor(virus, x, y) {
- this.virus = virus;
- this.x = x;
- this.y = y;
- }
- }
- ////////////// Menu //////////////
- function mainMenu() {
- background(0);
- image(ovni, X, Y, 60, 60);
- image(title, Xt, Yt, 600, 600);
- image(enter, Xe, Ye, 400, 400);
- X+=10;
- if(X == 1400 && Y == 100){
- X = -1000;
- Y = 600;
- }
- if(X == 1400 && Y == 600){
- X = -1000;
- Y = 100;
- }
- if (Yt < 200){
- Yt+=5;
- }
- if (Ye > 500){
- Ye-=5;
- }
- if (Yt == 200 && selector == 0){
- image(select, 235, 475, 150, 150);
- }
- if (Yt == 200 && selector == 1){
- image(select, 463, 475, 150, 150);
- }
- if (keyIsDown(37)) {
- select_pressed = 1;
- selector = 0;
- }
- if (keyIsDown(39)) {
- select_pressed = 1;
- selector = 1;
- }
- //if (select_pressed == 1){
- // select_sound.play();
- // select_pressed = 0;
- //}
- if (intro == 0){
- intro_music.loop();
- intro = 1;
- }
- if (keyIsDown(13) && selector == 0) {
- gamemode = 1;
- intro = 0;
- intro_music.stop();
- start_sound.play();
- game_music.loop();
- Level(1);
- }
- if (keyIsDown(13) && selector == 1) {
- denied_sound.play();
- }
- }
- ////////////// Lose //////////////
- function Lose() {
- gamemode = 2;
- background(0);
- image(failure, width/2, height/2, 670, 670);
- }
- ////////////// Level //////////////
- function Level(niveau) {
- if(niveau == 1){
- X = 0;
- Y = 400;
- let virus = new Virus(virus, 255, 255);
- Xc = 135;
- Yc = 82;
- }
- else if(niveau == 2){
- X = 0;
- Y = 400;
- Xv = 126;
- Yv = 98;
- Xc = 550;
- Yc = 344;
- }
- else if(niveau == 3){
- X = 0;
- Y = 400;
- Xv = 126;
- Yv = 98;
- Xc = 550;
- Yc = 344;
- }
- else if(niveau == 4){
- X = 0;
- Y = 400;
- Xv = 126;
- Yv = 98;
- Xc = 550;
- Yc = 344;
- }
- else if(niveau == 5){
- X = 0;
- Y = 400;
- Xv = 126;
- Yv = 98;
- Xc = 550;
- Yc = 344;
- }
- else if(niveau == 6){
- X = 0;
- Y = 400;
- Xv = 126;
- Yv = 98;
- Xc = 550;
- Yc = 344;
- }
- else if(niveau == 7){
- X = 0;
- Y = 400;
- Xv = 126;
- Yv = 98;
- Xc = 550;
- Yc = 344;
- }
- else if(niveau == 8){
- X = 0;
- Y = 400;
- Xv = 126;
- Yv = 98;
- Xc = 550;
- Yc = 344;
- }
- else if(niveau == 9){
- X = 0;
- Y = 400;
- Xv = 126;
- Yv = 98;
- Xc = 550;
- Yc = 344;
- }
- else if(niveau == 10){
- X = 0;
- Y = 400;
- Xv = 126;
- Yv = 98;
- Xc = 550;
- Yc = 344;
- }
- else if(niveau == 11){
- game_music.stop();
- win_music.loop();
- gamemode = 3;
- X = 0;
- Y = 400;
- Xt = 350;
- Yt = -200;
- Xe = 350;
- Ye = 750;
- background(0);
- if(seconds < highscore){
- highscore = seconds;
- }
- image(win, width/2, height/2, 670, 670);
- fill(255, 255, 255);
- textSize(80);
- textFont(font);
- text(highscore, (width/2), 520);
- text(seconds, (width/2), 610);
- }
- }
- ////////////// Timer //////////////
- function Timer() {
- if(gamemode == 1){
- seconds+=1;
- }
- }
- ////////////// Playing //////////////
- function Playing() {
- background(0);
- noFill();
- image(overlay, width/2, height/2, 670, 670);
- fill(200);
- image(ovni, X, Y, 50, 50);
- image(virus, Xv, Yv, 50, 50);
- image(coin, Xc, Yc, 15, 15);
- textSize(60);
- textFont(font);
- text("Level ", 325, 35);
- text(niveau, 385, 35);
- textSize(60);
- textFont(font);
- text("Best Time : ", 150, 645);
- text(highscore, 235, 645);
- text("Time : ", 500, 645);
- text(seconds, 550, 645);
- if (keyIsDown(40)) {
- Y+=5;
- }
- if (keyIsDown(38)) {
- Y-=12;
- }
- if (keyIsDown(39)) {
- X+=5;
- }
- if (keyIsDown(37)) {
- X-=5;
- }
- if (X > width-60)
- X = width-60;
- if (X < 60)
- X = 60;
- if (Y > height-100)
- Y=height-100;
- if (Y < 78)
- Y=78;
- if (Y < height)
- Y+=3;
- if (dist(X, Y, Xv, Yv)<=40){
- death_sound.play();
- game_music.stop();
- Lose();
- }
- if (dist(X, Y, Xc, Yc)<=20){
- niveau+=1;
- Level(niveau);
- coin_sound.play();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement