GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Pong-JavaScript/sketch.js at main · Wanderverissimo/Pong-JavaScript

Expand file tree

/

sketch.js

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
110 lines (97 loc) · 2.33 KB
/

sketch.js

Copy path

File metadata and controls

110 lines (97 loc) · 2.33 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// variáveis Bolinha
let xBolinha = 300;
let yBolinha = 200;
let diametro = 20;
let raio = diametro / 2;
let velocidadex = 6;
let velocidadey = 6;
let colide = false;
//variáveis minha raquete
let xRaquete = 5;
let yRaquete = 150;
let comprimentoRaq = 10;
let larguraRaq = 100;
//Raquete do Oponente
let xRaqueteOponente = 585;
let yRaqueteOponente = 150;
let velocidadeOponente;
let meusPontos = 0;
let PontosOponente = 0;
function setup() {
createCanvas(600, 400);
}
function draw() {
background(0, 100, 0);
mostraBolinha();
movimentaBolinha();
colideBorda();
mostraRaquete(xRaqueteOponente, yRaqueteOponente);
mostraRaquete(xRaquete, yRaquete);
placar();
Pontos();
movimentaMinhaRaquete();
colideRaquete(xRaquete, yRaquete);
colideRaquete(xRaqueteOponente, yRaqueteOponente);
movimentoRaqueteOponente();
function colideBorda() {
if (xBolinha + raio > width || xBolinha - raio < 0)
velocidadex = velocidadex * -1;
if (yBolinha + raio > height || yBolinha - raio < 0)
velocidadey = velocidadey * -1;
}
function mostraBolinha() {
circle(xBolinha, yBolinha, diametro);
}
function movimentaBolinha() {
xBolinha = xBolinha + velocidadex;
yBolinha = yBolinha + velocidadey;
}
function mostraRaquete(x, y) {
rect(x, y, comprimentoRaq, larguraRaq);
}
function movimentaMinhaRaquete() {
if (keyIsDown(UP_ARROW)) {
yRaquete = yRaquete - 10;
}
if (keyIsDown(DOWN_ARROW)) {
yRaquete = yRaquete + 10;
}
}
function colideRaquete(xRaquete, yRaquete) {
colide = collideRectCircle(
xRaquete,
yRaquete,
comprimentoRaq,
larguraRaq,
xBolinha,
yBolinha,
diametro
);
if (colide) {velocidadex = velocidadex * -1;}
}
}
function movimentoRaqueteOponente() {
velocidadeOponente = yBolinha - yRaqueteOponente - comprimentoRaq / 2 + 90;
yRaqueteOponente = yRaqueteOponente + velocidadeOponente;
}
if (
xBolinha - raio < xRaquete + comprimentoRaq &&
yBolinha + raio > yRaquete &&
yBolinha - raio < yRaquete + larguraRaq
) {
velocidadex *= -1;
}
function placar() {
fill(255);
textSize(30);
text(meusPontos, 100, 30);
text(PontosOponente, 500, 30);
}
function Pontos() {
if (xBolinha - raio < 0) {
PontosOponente = PontosOponente + 1;
}
if (xBolinha + raio > 600) {
meusPontos = meusPontos + 1;
}
}
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.