Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Apr 16th, 2018 55 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. var X = -1000, Y = 100;
  2. var Xv, Yv;
  3. var Xc, Yc;
  4. var Xt = 350, Yt = -200;
  5. var Xe = 350, Ye = 750;
  6.  
  7. var font;
  8.  
  9. var enter;
  10. var select;
  11. var selector = 0;
  12. var title;
  13. var overlay;
  14. var win, failure;
  15. var ovni;
  16. var virus;
  17. var texture_virus;
  18. var coin;
  19.  
  20. var select_pressed = 0;
  21.  
  22. var coin_sound;
  23. var start_sound;
  24. var death_sound;
  25. var select_sound;
  26. var denied_sound;
  27. var intro = 0;
  28. var intro_music;
  29. var game_music;
  30. var win_music;
  31.  
  32. var highscore = 999;
  33.  
  34. var timer=window.setInterval("Timer()",1000);
  35. var seconds = 0;
  36.  
  37. var gamemode = 0;        // 0 = Menu , 1 = En jeu, 2 = Mort, 3 = Gagné
  38. var niveau = 1;
  39.  
  40. ////////////// Initialisation //////////////
  41.  
  42. function preload() {
  43.   font = loadFont('textures/game_over.ttf')
  44.   title = loadImage('textures/title.png');
  45.   select = loadImage('textures/select.png');
  46.   enter = loadImage('textures/enter.png');
  47.   overlay = loadImage('textures/overlay.png');
  48.   win = loadImage('textures/win.png');
  49.   failure = loadImage('textures/failure.png');
  50.   ovni = loadImage('textures/ovni.png');
  51.   texture_virus = loadImage('textures/virus.png');
  52.   coin = loadImage('textures/coin.png');
  53.   soundFormats('mp3', 'ogg');
  54.   coin_sound = loadSound('sounds/coin.ogg');
  55.   start_sound = loadSound('sounds/start.ogg');
  56.   death_sound = loadSound('sounds/death.ogg');
  57.   select_sound = loadSound('sounds/select.ogg');
  58.   denied_sound = loadSound('sounds/denied.ogg');
  59.   intro_music = loadSound('sounds/intro.ogg');
  60.   game_music = loadSound('sounds/game.ogg');
  61.   win_music = loadSound('sounds/win.ogg')
  62.     }
  63.    
  64. function setup() {
  65.   createCanvas(windowWidth, windowHeight);
  66.   imageMode(CENTER);
  67.   textAlign(CENTER);
  68.   noCursor();
  69. }
  70.  
  71. function windowResized() {
  72.   resizeCanvas(windowWidth, windowHeight);
  73. }
  74.  
  75. ////////////// Draw //////////////
  76.  
  77. function draw() {
  78.   if (gamemode == 0){
  79.     mainMenu();
  80. }
  81.  
  82.   else if (gamemode == 1){
  83.   Playing();
  84. }
  85.  
  86. if (keyIsDown(13) && gamemode==2) {
  87.   niveau = 1;
  88.   gamemode = 1;
  89.   seconds = 0;
  90.   start_sound.play();
  91.   game_music.loop();
  92.   Level(1);
  93. }
  94.  
  95. if (keyIsDown(27) && gamemode==3) {
  96.   win_music.stop();
  97.   X = -1000;
  98.   Y = 100;
  99.   seconds = 0;
  100.   niveau = 1;
  101.   gamemode = 0;
  102.   start_sound.play();
  103. }
  104. }
  105.  
  106. ////////////// Classe Virus //////////////
  107.  
  108. class Virus {
  109.   constructor(virus, x, y) {
  110.       this.virus = virus;
  111.       this.x = x;
  112.       this.y = y;
  113.   }
  114. }
  115.  
  116.  
  117. ////////////// Menu //////////////
  118.  
  119. function mainMenu() {
  120.     background(0);
  121.     image(ovni, X, Y, 60, 60);
  122.     image(title, Xt, Yt, 600, 600);
  123.     image(enter, Xe, Ye, 400, 400);
  124.    
  125.  
  126.     X+=10;
  127.     if(X == 1400 && Y == 100){
  128.       X = -1000;
  129.       Y = 600;
  130.     }
  131.     if(X == 1400 && Y == 600){
  132.       X = -1000;
  133.       Y = 100;
  134.     }
  135.  
  136.  
  137.     if (Yt < 200){
  138.       Yt+=5;
  139.     }
  140.  
  141.     if (Ye > 500){
  142.       Ye-=5;
  143.     }
  144.  
  145.     if (Yt == 200 && selector == 0){
  146.       image(select, 235, 475, 150, 150);
  147.     }
  148.     if (Yt == 200 && selector == 1){
  149.       image(select, 463, 475, 150, 150);
  150.     }
  151.  
  152.     if (keyIsDown(37)) {
  153.       select_pressed = 1;
  154.       selector = 0;
  155.      }
  156.     if (keyIsDown(39)) {
  157.       select_pressed = 1;
  158.       selector = 1;
  159.     }
  160.  
  161.     //if (select_pressed == 1){
  162.     //  select_sound.play();
  163.     //  select_pressed = 0;
  164.     //}
  165.  
  166.     if (intro == 0){
  167.       intro_music.loop();
  168.       intro = 1;
  169.     }
  170.  
  171.     if (keyIsDown(13) && selector == 0) {
  172.       gamemode = 1;
  173.       intro = 0;
  174.       intro_music.stop();
  175.       start_sound.play();
  176.       game_music.loop();
  177.  
  178.     Level(1);
  179. }
  180. if (keyIsDown(13) && selector == 1) {
  181.   denied_sound.play();
  182. }
  183. }
  184.  
  185. ////////////// Lose //////////////
  186.  
  187.  function Lose() {
  188.   gamemode = 2;
  189.   background(0);
  190.   image(failure, width/2, height/2, 670, 670);
  191.  
  192.  }
  193. ////////////// Level //////////////
  194.  
  195. function Level(niveau) {
  196.   if(niveau == 1){
  197.     X = 0;
  198.     Y = 400;
  199.     let virus = new Virus(virus, 255, 255);
  200.     Xc = 135;
  201.     Yc = 82;
  202.   }
  203.   else if(niveau == 2){
  204.     X = 0;
  205.     Y = 400;
  206.     Xv = 126;
  207.     Yv = 98;
  208.     Xc = 550;
  209.     Yc = 344;
  210.   }
  211.   else if(niveau == 3){
  212.     X = 0;
  213.     Y = 400;
  214.     Xv = 126;
  215.     Yv = 98;
  216.     Xc = 550;
  217.     Yc = 344;
  218.   }
  219.   else if(niveau == 4){
  220.     X = 0;
  221.     Y = 400;
  222.     Xv = 126;
  223.     Yv = 98;
  224.     Xc = 550;
  225.     Yc = 344;
  226.   }
  227.   else if(niveau == 5){
  228.     X = 0;
  229.     Y = 400;
  230.     Xv = 126;
  231.     Yv = 98;
  232.     Xc = 550;
  233.     Yc = 344;
  234.   }
  235.   else if(niveau == 6){
  236.     X = 0;
  237.     Y = 400;
  238.     Xv = 126;
  239.     Yv = 98;
  240.     Xc = 550;
  241.     Yc = 344;
  242.   }
  243.   else if(niveau == 7){
  244.     X = 0;
  245.     Y = 400;
  246.     Xv = 126;
  247.     Yv = 98;
  248.     Xc = 550;
  249.     Yc = 344;
  250.   }
  251.   else if(niveau == 8){
  252.     X = 0;
  253.     Y = 400;
  254.     Xv = 126;
  255.     Yv = 98;
  256.     Xc = 550;
  257.     Yc = 344;
  258.   }
  259.   else if(niveau == 9){
  260.     X = 0;
  261.     Y = 400;
  262.     Xv = 126;
  263.     Yv = 98;
  264.     Xc = 550;
  265.     Yc = 344;
  266.   }
  267.   else if(niveau == 10){
  268.     X = 0;
  269.     Y = 400;
  270.     Xv = 126;
  271.     Yv = 98;
  272.     Xc = 550;
  273.     Yc = 344;
  274.   }
  275.   else if(niveau == 11){
  276.     game_music.stop();
  277.     win_music.loop();
  278.     gamemode = 3;
  279.     X = 0;
  280.     Y = 400;
  281.     Xt = 350;
  282.     Yt = -200;
  283.     Xe = 350;
  284.     Ye = 750;
  285.     background(0);
  286.     if(seconds < highscore){
  287.       highscore = seconds;
  288.     }
  289.     image(win, width/2, height/2, 670, 670);
  290.     fill(255, 255, 255);
  291.     textSize(80);
  292.     textFont(font);
  293.     text(highscore, (width/2), 520);
  294.     text(seconds, (width/2), 610);
  295.   }
  296. }
  297.  
  298. ////////////// Timer //////////////
  299.  
  300. function Timer() {
  301.   if(gamemode == 1){
  302.   seconds+=1;
  303. }
  304. }
  305.  
  306. ////////////// Playing //////////////
  307.  
  308. function Playing() {
  309.  
  310.   background(0);
  311.   noFill();
  312.  
  313. image(overlay, width/2, height/2, 670, 670);
  314.  
  315.  fill(200);
  316.  
  317.  image(ovni, X, Y, 50, 50);
  318.  image(virus, Xv, Yv, 50, 50);
  319.  image(coin, Xc, Yc, 15, 15);
  320.  
  321.  textSize(60);
  322.  textFont(font);
  323.  text("Level ", 325, 35);
  324.  text(niveau, 385, 35);
  325.  
  326.  textSize(60);
  327.  textFont(font);
  328.  text("Best Time : ", 150, 645);
  329.  text(highscore, 235, 645);
  330.  text("Time : ", 500, 645);
  331.  text(seconds, 550, 645);
  332.  
  333.   if (keyIsDown(40)) {
  334.     Y+=5;
  335.   }
  336.   if (keyIsDown(38)) {
  337.     Y-=12;
  338.   }
  339.   if (keyIsDown(39)) {
  340.     X+=5;
  341.   }
  342.   if (keyIsDown(37)) {
  343.     X-=5;
  344.   }
  345.  
  346.   if (X > width-60)
  347.    X = width-60;
  348.   if (X < 60)
  349.    X = 60;
  350.   if (Y > height-100)
  351.    Y=height-100;
  352.   if (Y < 78)
  353.    Y=78;
  354.  
  355.   if (Y < height)
  356.    Y+=3;
  357.    
  358.    if (dist(X, Y, Xv, Yv)<=40){
  359.      death_sound.play();
  360.      game_music.stop();
  361.      Lose();
  362.   }
  363.    
  364.    if (dist(X, Y, Xc, Yc)<=20){
  365.     niveau+=1;
  366.     Level(niveau);
  367.     coin_sound.play();
  368.   }
  369. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top