-
알카노이드 게임Processing 2020. 11. 11. 18:37
아래의 소스를 분석하기 전에 아래의 글을 참고하는 것도 나쁘지 않다.
아래는 API를 이용해서 구현해본 것인데, 프로세싱과 API가 좌표계가 같다.
화면 창을 기준으로 좌측 상단이 원점이다.
아래쪽으로 이동할수록 y값이 커지고 오른쪽으로 이동할수록 x값이 커진다.
designatedroom87.tistory.com/132?category=887656
소스 코드
더보기int xpos, ypos; int xdir, ydir; int padx, padWidth; int pady, padHeight; void setup(){ size(800,600); xpos = ypos = 400; xdir = ydir = 3; padWidth = 150 ; padHeight = 30; stroke(color(#D324CB)); strokeWeight(3); fill(color(#FFDC0F)); line(0,50,width,50); } void draw(){ background(200); line(0,height-100,width,height-100); ellipse(xpos, ypos, 20, 20); ellipse(xpos, ypos, 1, 1); xpos += xdir; ypos += ydir; padx = mouseX; if( mouseY > height-100) pady = mouseY; if( mouseY < height-100) pady = height-100; rect( padx-padWidth/2, pady-padHeight/2, padWidth, padHeight,10); //bounce check if( xpos < 0 || xpos > width) xdir *= -1; if( ypos < 0 || ypos > height) ydir *= -1; if( mouseY > height-100 && xpos >= padx-padWidth/2 && xpos <= padx + padWidth/2 && ypos > mouseY-padHeight/2 ) ydir *= -1; if( mouseY < height-100 && xpos >= padx-padWidth/2 && xpos <= padx + padWidth/2 && ypos > height-100-padHeight/2) ydir *= -1; println("xpos ypos :"); println(xpos," ",ypos); //block check }
'Processing' 카테고리의 다른 글
마우스 클릭으로 선을 그리고 지우기 (0) 2020.11.11 아두이노(송신)와 프로세싱(수신)에서의 데이터 처리하기 - 하 (0) 2020.11.11 아두이노(송신)와 프로세싱(수신)에서의 데이터 처리하기 - 상 (0) 2020.11.10 아두이노에서 프로세싱에 데이터를 전송하고 그래프로 표현하기 (0) 2020.11.10 프로세싱을 활용해서 도형(원, 선) 그리기 (0) 2020.11.10