Skip to content

Instantly share code, notes, and snippets.

@dinarname
Last active October 17, 2018 12:41
Show Gist options
  • Save dinarname/3d0539f6c63db77eb9e84b054dd5bfb4 to your computer and use it in GitHub Desktop.
Save dinarname/3d0539f6c63db77eb9e84b054dd5bfb4 to your computer and use it in GitHub Desktop.
processing. car in motion
void setup(){
size(600, 400);
}
int x = 20, y = 250;
PImage explosion;
void draw() {
// Делаем заливку экрана, чтобы удалить предыдущее изображение
background(#ABE8C6);
// основание
fill(127);
rect(x, y, 80, 20);
// верхняя часть
fill(200);
rect(x + 10, y - 20, 60, 20);
// окна
fill(255);
rect(x + 15, y - 15, 20, 10);
rect(x + 45, y - 15, 20, 10);
// колеса
fill(0);
ellipse(x + 15, y + 20, 10, 10);
ellipse(x + 65, y + 20, 10, 10);
fill(80);
ellipse(x + 15, y + 20, 8, 8);
ellipse(x + 65, y + 20, 8, 8);
// Стена
fill(#FCC045);
rect(width - 50, 50, 25, height - 100);
// Движение до стены
if (x + 60 < width - 30){
x = x + 1;
}
// Обнуление координат
if (mousePressed) {
x = 20;
}
// Взрыв при столкновении со стеной
if (x + 60 > width - 50) {
explosion = loadImage("explosion-color.png");
explosion.resize(100, 100);
image(explosion, x, y - 50);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment