Maison  >  Article  >  interface Web  >  HTML5 implémente les compétences du didacticiel WeChat masturbation game_html5

HTML5 implémente les compétences du didacticiel WeChat masturbation game_html5

WBOY
WBOYoriginal
2016-05-16 15:48:211665parcourir

html5 implémente le jeu de masturbation de WeChat. Utilisez ce mini-jeu pour apprendre le HTML5. C'est une direction pour développer le WEB

Copier le code .
Le code est le suivant :

// Document JavaScript
var c = document.getElementById("dotu");
var cxt = c.getContext("2d");
var img = newImg(". /assets/bg_01.jpg");
var fps;
cxt.drawImage(img,0,0,480,800);

var flivverLog = 0;
var flivver1 = newImg(". /assets/flivver.png");
var flivver2 = newImg("./assets/flivver2.png");
var flivver3 = newImg("./assets/flivver3.png");

// Utilisé pour enregistrer le temps du jeu, plus vite il passe en arrière
var time1 = 0;
var time2 = 80;

// Points
var jifen = 0;

function getSudu(){
var number = parseInt(Math.random()*10);
if(number < 5 && number > 0){
numéro de retour ;
}
renvoie 1 ;
}
//Objet avion
fonction flivverObj(hp,ewidth,eheight,eimg,esudu){
//Random X
this.x = parseInt(Math.random()*460 1);
this.y = 0;
// HP
this.hp = hp;
// Battu
this.hit = 0;
// S'il faut mourir
this.over = 0;

this.width = ewidth;
this.height = eheight;
this. img = eimg;
this.sudu = esudu;
}

//Obtenir l'avion
fonction getFlivver(type){
switch(type){
cas 1 :
return new flivverObj(100,50,30,flivver1,getSudu());
cas 2 :
return new flivverObj(500,70,90,flivver2,getSudu());
cas 3 :
return new flivverObj(1000,110,170,flivver3,getSudu());
}
>
function cartouche(x,y){
this.x = x;
this .y = y;
}

function gameover(){
window.clearTimeout(fps);
//$('#dotu').fadeOut();
$('.content').css('position','relative');
$('.content').append('');
$('#sil').html(' vous') .hide().fadeIn(1000,function(){
$(this).html('Tu merdes').hide().fadeIn(1000,function(){
$(this ).html ('Tu es de la merde
' jifen 'fen ') .hide().fadeIn();
});
});
}

(function(cxt){
var dotu = {nums:0} ;
// Utilisé pour stocker les petits avions
var flivver = new Array();
var flivverImg = newImg("./assets/flivver.png");
// Self
var me = {x:240,y:750};
var meImg = newImg('assets/me.png');
// Puces
var cartouches = new Array();
var cartoucheImg = newImg('./assets/cartridge.png');

var boo1 = newImg('./assets/boo1.png');
var over = newImg('./assets /over .png');
//
dotu.update = function(){

dotu.setTimes();
// Définir l'arrière-plan
dotu.setBg() ;
// Installer le petit avion
dotu.setFlivver();
// Dessine-toi
dotu.setMe();
// Puces
dotu.cartridge() ;


cxt.font = "italic 20px Microsoft Yahei";
cxt.StrokeText("Points :" jifen, 10, 30);

$('#fjs '). html(flivver.length);
$('#zds').html(cartridges.length);
$('#scfj').html("1000/" time2 " millisecondes") ;
}

dotu.setTimes = function(){
time1 ;
// 1 vitesse en 100 secondes
if(time1 == 1000){
time1 = 0;
heure2 = (heure2 == 20) : heure2 - 20;
}

}


/**
* Définir un arrière-plan mobile
*/
dotu .setBg = function(){
dotu.nums ;
if(dotu.nums == 800){
dotu.nums = 0;
}
// Fond de toile
cxt.drawImage(img,0,dotu.nums,480,800);
cxt.drawImage(img,0,dotu.nums - 800,480,800);
}

dotu.setFlivver = fonction ( ){
// Générer un avion
if(dotu.nums % time2 == 0){
flivverLog ;
if(flivverLog % 6 == 0){
flivver.push( getFlivver (2));
}else if(flivverLog % 13 == 0){
flivver.push(getFlivver(3));
}else{
flivver.push(getFlivver(1 ) );
}

}

pour(a dans flivver){



flivver[a].y = flivver[a] . sudu;
// S'il dépasse l'écran, supprimez le petit avion
if(flivver[a].y > 780){
flivver.splice(a, 1);
}
// Dessine le petit avion sur la toile


// Le petit avion meurt
if(flivver[a].over > 0){
flivver[a ] .over --;

if(flivver[a].over > 20){
cxt.drawImage(boo1,flivver[a].x flivver[a].width/2 - 20 , flivver[a].y flivver[a].height / 2 -10,41,39);
}else if(flivver[a].over > 2){
cxt.drawImage(over, flivver [a].x flivver[a].width/2 - 20 ,flivver[a].y flivver[a].height / 2 -10,40,43);
}else{
flivver. splice (a, 1);
}



}else{
cxt.drawImage(flivver[a].img,flivver[a].x,flivver[a ] .y,flivver[a].width,flivver[a].height);
// Déterminez si vous êtes mort
if( me.x > (flivver[a].x - flivver[a ]. largeur 20) && (me.x) <(flivver[a].x flivver[a].width - 20) && (me.y) < 20) && (me.y 72) > (flivver[a].y - 20)){
gameover();
}

if(flivver[a].hit > 0) {
cxt.drawImage(boo1,flivver[a].x flivver[a].width/2 - 20 ,flivver[a].y flivver[a].height / 2 -10,41,39) ;
//cxt.drawImage(boo1,flivver[a].x 5,flivver[a].y,41,39);
flivver[a].hit--;
}
}

}
}

// Mettre à jour sa propre distance
dotu.setMe = function(){
cxt.drawImage(meImg,me.x,me. y ,64,72);
}

// Mettre à jour la méthode bullet
dotu.cartridge = function(){
if(dotu.nums % 10 == 0){
cartouches.push(nouvelle cartouche(me.x 30,me.y));
}

for(i in cartouches){
// Supprimer OBJ lorsqu'il atteint le sommet
if(cartouches[i].y < 0){
cartouches.splice(i, 1);
continuer;
}


cartouches[i].y -= 20;
// Dessine le petit avion sur la toile
cxt.drawImage(cartridgeImg,cartridges[i].x,cartridges[i].y,7,17);

// La situation où la balle touche l'avion
for(j in flivver){
if(flivver[j].over > 0){
continue;
}
if( cartouches[ i].x > flivver[j].x && cartouches[i].x < && cartouches [i].y -flivver[j].height < flivver[j].y){

flivver[j].hit = 10;
$('#isdz'). html( 'Appuyez sur le numéro' j);

if(flivver[j].hp > 1){
flivver[j].hp -= 80;
}else{
flivver[j].over = 40;
jifen = 50000;
}
// La balle disparaît
cartouches.splice(i, 1);
break;
}
}
}
}

// Lier l'événement de la souris
c.addEventListener('mousemove', function onMouseMove(evt) {
me.x = evt.layerX - $('#dotu').offset().left - 32;
me.y = evt.layerY - 36;
$('#sbX').html(me.x);
$('#sbY').html(me.y);
});

fps = setInterval(dotu.update, 1000/100
}(cxt))


function newImg(src){
var obj = new Image();
obj.src = src;
return obj;
}

/ /setInterval(h.update, 1000/65);


Copier le code
Le code est le suivant :


http://www.w3 .org/1999/xhtml">

;
打飞机 - 多途


Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn