Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var ovr=new Image();
- ovr.src = "overlay.png"
- //YOUR PLAYER COORDINATES
- var myX = 640, myY = 580;
- //BACKGROUND
- let BackGroundX = 0, BackGroundY = 0;
- //CYCLE VARIABLES
- var x, i, y;
- //BULET COORDINATES
- var MyBulletsX = [], MyBulletsY = [], broiPatroni=0;
- //LIVES & POINTS
- var lives = 1;
- var points=0;
- //ENEMY COORDINATES
- var vragX = [], vragY = [];
- //"TO BE CONTINUED" IMAGE & SOUND
- //sound
- var jojo;
- jojo = new sound("jojo.mp3");
- jojo.loop =false;
- //image
- var tbc = new Image();
- tbc.src = "tbc.png"
- //ENEMY IMAGE & SOUND
- var dank;
- dank = new sound("dank.mp3");
- //sound
- dank.loop = false;
- //image
- var vrag = new Image();
- vrag.src = "vrag.png";
- //BULLET IMAGE
- var bullet = new Image();
- bullet.src = "bullet.png"
- //BACKGROUND IMAGE
- var backgroundImage = new Image();
- backgroundImage.src = "da3.png";
- //PLAYER IMAGE
- var kartinageroi = new Image();
- kartinageroi.src = "player.png";
- for(x = 0; x < 10; x ++){
- vragX[x] = Math.random()*1280 - 50;
- vragY[x] = Math.random()*(-450) - 150;
- }
- //SOUND FUNCTION
- function sound(src) {
- this.sound = document.createElement("audio");
- this.sound.src = src;
- this.sound.setAttribute("preload", "auto");
- this.sound.setAttribute("controls", "none");
- this.sound.style.display = "none";
- document.body.appendChild(this.sound);
- this.play = function(){
- this.sound.play();
- }
- this.stop = function(){
- this.sound.pause();
- }
- }
- //end
- function update() {
- //WHEN POINTS BECOME 10
- //LIVES BECOME +1
- if(points==10){
- lives++
- points=0
- }
- if(lives > 0){
- jojo.stop();
- for(i=0;i<broiPatroni;i++){
- MyBulletsY[i] = MyBulletsY[i] - 5;
- if(MyBulletsY[i]<0){
- MyBulletsX.splice(i,1);
- MyBulletsY.splice(i,1);
- i--;
- broiPatroni--;
- }
- }
- if(isKeyPressed[68]){
- myX = myX + 8;
- }
- if(isKeyPressed[65]){
- myX = myX - 8;
- }
- if(isKeyPressed[83]){
- myY = myY + 8;
- }
- if(isKeyPressed[87]){
- myY = myY - 8;
- }
- if(myX >= 1250){
- myX = 1250;
- }
- if(myX <= 0){
- myX = 0;
- }
- if(myY >=570){
- myY = 570
- }
- if(myY <= 0){
- myY = 0;
- }
- for(x = 0; x < 10; x ++){
- vragY[x] = vragY[x] + 2;
- if(vragY[x] >= 600) {
- vragX[x] = Math.random()*1100 - 50;
- vragY[x] = Math.random()*(-20) -40;
- }
- }
- for(x = 0; x < 10; x ++){
- for(y = 0; y < broiPatroni; y ++){
- if(areColliding(MyBulletsX[y], MyBulletsY[y], 15, 25, vragX[x], vragY[x], 40, 40)){
- vragX[x] = Math.random()*1100 - 50;
- vragY[x] = Math.random()*(-20) -40;
- dank.play();
- MyBulletsX.splice(i,1);
- MyBulletsY.splice(i,1);
- i--;
- broiPatroni--;
- points++
- }
- }
- }
- for(x = 0; x < 10; x ++){
- if(areColliding(myX, myY, 55, 70, vragX[x], vragY[x], 30, 30)){
- lives --;
- vragX[x] = Math.random()*1100 - 50;
- vragY[x] = Math.random()*(-20) -40;
- }
- }
- }else{
- if(lives<=0){
- jojo.play();
- }else{
- jojo.stop();
- }
- }
- }
- function draw() {
- context.drawImage(backgroundImage, BackGroundX, BackGroundY, 1280, 660);
- context.drawImage(kartinageroi, myX, myY, 55, 70);
- for(x = 0; x < 10; x ++){
- context.drawImage(vrag, vragX[x], vragY[x], 40, 40)
- }
- if(lives>0)
- { for(i=0;i<broiPatroni;i++){
- context.drawImage(bullet, MyBulletsX[i], MyBulletsY[i], 15, 25)
- }}
- if(lives <= 0){
- context.drawImage(tbc, 930, 538, 350, 100);
- context.drawImage(ovr, 0, 0, 8000, 6000);
- }
- context.font = "20px Comic Sans MS";
- context.fillText(points, 40, 40);
- context.fillText(lives, 40, 60);
- };
- function keyup(key) {
- // Show the pressed keycode in the console
- console.log("Pressed", key);
- if(key == 32){
- MyBulletsX[broiPatroni]=myX+10;
- MyBulletsY[broiPatroni]=myY+50;
- broiPatroni++;
- }
- };
- function mouseup() {
- // Show coordinates of mouse on click
- console.log("Mouse clicked at", mouseX, mouseY);
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement