Skip to content

Instantly share code, notes, and snippets.

View willyandan's full-sized avatar

Willyan Antunes willyandan

View GitHub Profile
@willyandan
willyandan / .vimrc
Created August 17, 2021 01:52
my .vimrc
"1. SETS"
"1.1 visual config"
syntax on
colorscheme default
set relativenumber
set nu rnu
set mouse=a
set tabstop=4
set softtabstop=4
set autoindent
@willyandan
willyandan / docker-help.md
Created May 28, 2019 21:59 — forked from bradtraversy/docker-help.md
Docker Commands, Help & Tips

Docker Commands, Help & Tips

Show commands & management commands

$ docker

Docker version info

@willyandan
willyandan / pong.js
Created February 1, 2019 03:20
pong.js - versão final
let ctx, p1_y, p2_y, p1_points, p2_points
let ball_y_orientation, ball_x_orientation, ball_x, ball_y
let p1_key, p2_key
const h=500, w=800, p_w=20, p_h=200, p1_x = 10, p2_x = w - p_w - 10
function setup(){
const canvas = document.getElementById("canvas")
ctx = canvas.getContext("2d")
// inicializa as posições y do p1 e do p2 para metade da tela
p1_y = p2_y = (h / 2) - (p_h/2)
@willyandan
willyandan / pong.js
Created February 1, 2019 03:18
pong.js - writePoints
function writePoints(){
ctx.font = "50px monospace";
ctx.fillStyle = "#fff";
// w/4 = 1/4 da tela = metade da tela do player 1
ctx.fillText(p1_points, w/4, 50);
// 3*(w/4) = 3/4 da tela = metade da tela do player 2
ctx.fillText(p2_points, 3*(w/4), 50);
}
@willyandan
willyandan / pong.js
Created February 1, 2019 02:59
pong.js - loop verificando pontuação
function loop(){
//Verifica se a bola está colidindo com o barra do player 1
if(ball_x >= p1_x && ball_x <= p1_x + 10 && ball_y >= p1_y && ball_y <= p1_y + p_h){
ball_x_orientation = 1
}
//Verifica se a bola está colidindo com o barra do player 2
else if(ball_x >= p2_x && ball_x <= p2_x + 10 && ball_y >= p2_y && ball_y <= p2_y + p_h){
ball_x_orientation = -1
}
@willyandan
willyandan / pong.js
Created February 1, 2019 00:45
pong.js - mesclando lógica do ricochete da bolinha e movimento das barras no código
let ctx, p1_y, p2_y, p1_points, p2_points
let ball_y_orientation, ball_x_orientation, ball_x, ball_y
let p1_key, p2_key
const h=500, w=800, p_w=20, p_h=200, p1_x = 10, p2_x = w - p_w - 10
function setup(){
const canvas = document.getElementById("canvas")
ctx = canvas.getContext("2d")
// inicializa as posições y do p1 e do p2 para metade da tela
p1_y = p2_y = (h / 2) - (p_h/2)
@willyandan
willyandan / pong.js
Created February 1, 2019 00:42
pong.js - função loop com a lógica para colidir com a barra e com o teto
function loop(){
//Verifica se a bola está colidindo com o barra do player 1
if(ball_x >= p1_x && ball_x <= p1_x + 10 && ball_y >= p1_y && ball_y <= p1_y + p_h){
ball_x_orientation = 1
}
//Verifica se a bola está colidindo com o barra do player 2
else if(ball_x >= p2_x && ball_x <= p2_x + 10 && ball_y >= p2_y && ball_y <= p2_y + p_h){
ball_x_orientation = -1
}
@willyandan
willyandan / pong.js
Created February 1, 2019 00:24
pong.js - lógica para mover barras dentro do loop
function loop(){
...
if(p1_key == 87 && p1_y > 0){
p1_y -= 10
}else if(p1_key == 83 && p1_y + p_h < h){
p1_y += 10
}
if(p2_key == 38 && p2_y > 0){
p2_y -= 10
@willyandan
willyandan / pong.js
Last active February 1, 2019 00:21
pong.js - event listener
let p1_key, p2_key
document.addEventListener("keydown",function(ev){
// keyCode 87 = w, keycode 83 = s
if(ev.keyCode == 87 || ev.keyCode == 83){
p1_key = ev.keyCode
}
// keycode 38 = arrowUp, keycode 40 = arrowDown
else if(ev.keyCode== 38 || ev.keyCode==40)
p2_key = ev.keyCode
})
@willyandan
willyandan / pong.js
Created January 31, 2019 23:31
pong.js - mesclando funções drawRect e draw ao código
let ctx, p1_y, p2_y, p1_points, p2_points
let ball_y_orientation, ball_x_orientation, ball_x, ball_y
const h=500, w=800, p_w=20, p_h=200, p1_x = 10, p2_x = w - p_w - 10
function setup(){
const canvas = document.getElementById("canvas")
ctx = canvas.getContext("2d")
// inicializa as posições y do p1 e do p2 para metade da tela
p1_y = p2_y = (h / 2) - (p_h/2)