Comutare navigație
pbInfo.ro
Probleme
Probleme - clasa a IX-a
Probleme - clasa a X-a
Probleme - clasa a XI-a
Probleme din concursuri
Căutare problemă
Exerciții
Programează cu Blockly
Desenează cu Processing
Exersează SQL
Soluţii
Resurse
Resurse pentru clasa a IX-a
Resurse pentru clasa a X-a
Resurse pentru clasa a XI-a
Subiecte bacalaureat
Ajutor
Autentificare
Înregistrare
×
Autentificare
Utilizator sau email
Parola
Acest site foloseşte cookies. Navigând în continuare, vă exprimaţi acordul asupra folosirii cookie-urilor.
Îti place pbInfo? Atunci acceptă-l cu totul! Dezactivează modulul de blocare a reclamelor!
×
Lista scripturi
Script Nou
Ajutor
"Pong" - Processing
ID
Autor
Duplicat din
Ultima modificare
#1687
Lazar Ionut Radu (LazarIonutRadu)
-
Marti, 13 feb 2018, 11:28
Click pt start. Controale : UP_ARROW ,
DOWN
_ARROW , ‘W’ , ‘S’ ;
//Made by Lazar Ionut Radu var x1, y1, x2, y2, L, l, color, speed1, ballX, ballY, size, speedX, speedY; var score1, score2, start; function setup() { createCanvas(400, 400); background(70); x1 = 0; x2 = 390; y1 = 0; y2 = 0; L = 80; l = 10; color = 190; speed = 7.5; ballX = 200; ballY = 200; size = 20; speedX = 2.5; speedY = 2.5; score1 = 0; score2 = 0; start = 0; } function draw() { background(70); player1_draw(); player2_draw(); ball_draw(); score_draw(); if( start == 1 ) { player1_movement(); player2_movement(); ball_movement(); score_update(); } } function player1_draw() { fill(190); stroke(10); rect(x1, y1, l, L); } function player2_draw() { fill(190); rect(x2, y2, l ,L); } function player1_movement() { if ( keyIsDown(83) && y1
0 ) y1 -= speed; } function player2_movement() { if ( keyIsDown(DOWN_ARROW) && y2
0 ) // 87 = 'W' y2 -= speed; } function ball_draw() { fill(190); stroke(10); ellipse(ballX, ballY, size, size); } function ball_movement() { ballX += speedX; ballY += speedY; if( ballY>=400 || ballY<=0 ) speedY = -speedY; if( ballX > 440 || ballX < -40 ) { ballX = 200; ballY = 200; } if( ballY >= y2 && ballY <= y2+L && ballX == 400-l-size/2 || ballY >= y1 && ballY <= y1+L && ballX == l+size/2) { speedX = -speedX; } if( ballX >= 400-l-size/2 && ( ballY+size/2 == y2 || ballY-size/2 == y2+L) ) { speedY = -speedY; } if( ballX <= l+size/2 && ( ballY+size/2 == y1|| ballY-size/2 == y1+L) ) { speedY = -speedY; } } function score_draw() { textAlign(CENTER); textSize(20); text(score1 +" : "+ score2, 200, 30); } function score_update() { if( ballX >= 440 ) { score1++; } if( ballX <= -40 ) { score2++; } } function mousePressed() { if(start == 0) { start = 1; Loop(); } }
Duplicare
Executare
Cod
×
Cod HTML
<iframe sandbox="allow-scripts" src="/p5js/index.php?id=1687" style="width:408px; height:408px;border:solid 1px gray; overflow: scroll;"></iframe>
×
Duplicare script
Denumirea noului script
Du-te sus!