클래스 팩맨 |
|||||
---|---|---|---|---|---|
작성자 | 김용남 | 등록일 | 21.07.28 | 조회수 | 149 |
Packman myPackman1; Packman myPackman2; Packman myPackman3;
void setup(){ size(640, 480); myPackman1 = new Packman(color(255, 0, 0), 0, 100, 50, 1, 1); myPackman2 = new Packman(color(0, 255, 0), 0, 200, 50, 2, 2); myPackman3 = new Packman(color(0, 0, 255), 0, 300, 50, 3, 3); }
void draw(){ background(0); myPackman1.display(); myPackman1.move(); myPackman2.display(); myPackman2.move(); myPackman3.display(); myPackman3.move(); }
class Packman { color c; float x; float y; float size; float xspeed; float yspeed;
Packman(color tempC, float tempX, float tempY, float tempS, float tempXs, float tempYs){ c = tempC; x = tempX; y = tempY; size = tempS; xspeed = tempXs; yspeed = tempYs; }
void display(){ noStroke(); fill(c); if(frameCount % 20 < 10){ arc(x, y, size, size, 0.5, 5.78); } else { arc(x, y, size, size, 0.1, 6.18); } }
void move(){ x = x + xspeed; y = y + yspeed;
if(x < 0 || x > width){ xspeed= -xspeed; } if(y < 0 || y > height){ yspeed = -yspeed; } } } |
이전글 | 2022.4.11. 팩맨 움직이기 프로세싱 코드 |
---|---|
다음글 | 팩맨 |