Skip to content

Commit

Permalink
change rendering algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
CaseyNelson314 authored Mar 17, 2022
1 parent a056787 commit e4c0eef
Show file tree
Hide file tree
Showing 5 changed files with 319 additions and 122 deletions.
99 changes: 99 additions & 0 deletions othelo_prosessing/bottonManager.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*ボタンの当たり判定を作成するクラス*/

class Botton {
private int bottonMode = CORNER;
private float x, y, _x, _y;
private float left_x, left_y, right_x, right_y;

private boolean lastClick;

void botton(float x, float y, float _x, float _y) {
this.x = x;
this.y = y;
this._x = _x;
this._y = _y;
bottonMode(bottonMode);
}

void bottonMode(int mode) {
bottonMode = mode;
switch(mode) {
case CORNER:
left_x = x;
left_y = y;
right_x = x + _x;
right_y = y + _y;
break;
case CORNERS:
left_x = x;
left_y = y;
right_x = _x;
right_y = _y;
break;
case CENTER:
left_x = x - _x/2;
left_y = y - _y/2;
right_x = x + _x/2;
right_y = y + _y/2;
break;
case RADIUS:
left_x = x - _x;
left_y = y - _y;
right_x = left_x + _x*2;
right_y = left_y + _y*2;
break;
}
}

boolean hover() {
if (left_x <= mouseX && mouseX <=right_x && left_y <= mouseY && mouseY <=right_y)
return true;
return false;
}

boolean click() {
if (left_x <= mouseX && mouseX <=right_x && left_y <= mouseY && mouseY <=right_y
&& mousePressed && lastClick==false) {
lastClick = true;
return true;
}
lastClick = mousePressed;
return false;
}

boolean press() {
if (left_x <= mouseX && mouseX <=right_x && left_y <= mouseY && mouseY <=right_y
&& mousePressed)
return true;
return false;
}

float x() {
return x;
}
float y() {
return y;
}
float _x() {
return _x;
}
float _y() {
return _y;
}

void drawBotton() {
if (hover())
fill(150);
else
noFill();
rectMode(CORNERS);
stroke(0);
rect(left_x, left_y, right_x, right_y);
rectMode(CORNER);

fill(0);
textSize(10);
textAlign(LEFT, TOP);
text("botton", left_x, left_y);
}
};
152 changes: 69 additions & 83 deletions othelo_prosessing/drawFunction.pde
Original file line number Diff line number Diff line change
@@ -1,134 +1,120 @@
void turnAI() { //<>//
void turnAI() { //<>// //<>//
if (AImode==false)return;

turn^=true;
}

void drawTurn(int x, int y, int boardSize) { //ターン表示用バー
noStroke();
rectMode(CENTER);
fill(#eeeeee);
if (!turn && mode==1)
rect(x - boardSize/4, y - boardSize*0.533, boardSize*0.4, boardSize*0.03, 10);
if (turn && mode==1)
rect(x + boardSize/4, y - boardSize*0.533, boardSize*0.4, boardSize*0.03, 10);
}

boolean AImode;
boolean isHintMode;
boolean isSettingMode;

void botton(int bottonType) {
switch(bottonType) {
case 0: //hit button
isHintMode^=true;
break;
case 1: //reset botton
void optionBotton() {


option[0].botton(win.x(0), win.y(botton_height), win.width(333), win.height(100));
option[1].botton(win.x(333), win.y(botton_height), win.width(333), win.height(100));
option[2].botton(win.x(666), win.y(botton_height), win.width(333), win.height(100));

stroke(0);
strokeWeight(1);
//HINT
fill(#51bd50);
rectMode(CORNER);
isHintMode^=option[0].click();
if (option[0].hover()||isHintMode)fill(#b6e9a1);
rect(win.x(0), win.y(botton_height), win.width(333), win.height(100));
if (isHintMode)showHint();
//RESET,SORT
fill(#51bd50);
if (option[1].click()) {
AImode = false;
isHintMode = false;
if (mode==2) {
boardSort();
mode++;
} else
boardReset();
break;
case 2:
AImode^=true;
}
}
void optionBotton(int x, int y, int boardSize) { //下部ボタン表示
float blockSize = boardSize/3; //ブロック1辺
float corner_x = x - boardSize*0.498;
float corner_y = y + boardSize*0.55;
stroke(0);
strokeWeight(1);
rectMode(CORNER);
for (int i=0; i<3; i++) { //マウス当たり判定
if ((mouseX > corner_x + blockSize*i) && (corner_x + blockSize*(i+1) > mouseX)
&& (mouseY > corner_y) && (corner_y + boardSize*0.1 > mouseY)) {
fill(#b6e9a1);
if (mouseClick())
botton(i);
} else
fill(#51bd50);
if (isHintMode&&i==0) //ヒントモード時ハイライト
fill(#b6e9a1);
if (AImode&&i==2)
fill(#b6e9a1);
rect(corner_x + boardSize/3*i, corner_y, boardSize/3, boardSize*0.1);
}
if (isHintMode) showHint();

if (option[1].hover())fill(#b6e9a1);
rect(win.x(333), win.y(botton_height), win.width(333), win.height(100));
//AUTO
fill(#51bd50);
AImode^=option[2].click();
if (option[2].hover()||AImode)fill(#b6e9a1);
if (isHintMode) showHint();
rect(win.x(666), win.y(botton_height), win.width(333), win.height(100));
//ボタン枠
noFill();
strokeWeight(1.5);
rect(corner_x, corner_y, blockSize*3, boardSize*0.1);

rect(win.x(0), win.y(botton_height), win.width(1000), win.height(100));
//文字
fill(255);
textAlign(CENTER);
textSize(boardSize/20);

text("HINT", corner_x + blockSize/2*1, corner_y + boardSize*0.07);

textAlign(CENTER, CENTER);
textSize(win.width(60));
text("HINT", win.x(167), win.y(botton_height+40));
if (mode!=2)
text("RESET", corner_x + blockSize/2*3, corner_y + boardSize*0.07);
text("RESET", win.x(500), win.y(botton_height+40));
else
text("SORT", corner_x + blockSize/2*3, corner_y + boardSize*0.07);

text("AUTO", corner_x + blockSize/2*5, corner_y + boardSize*0.07);
text("SORT", win.x(500), win.y(botton_height+40));
text("AUTO", win.x(833), win.y(botton_height+40));
}

void drawScore(int x, int y, int boardSize) { //スコアボード
int score_black = getScore_black();
int score_white = getScore_white();

void drawScore() { //スコアボード
final int score_height = 100;
noStroke();
rectMode(CENTER);
fill(#b6e9a1);
if (!turn && mode==1)
rect(win.x(250), win.y(score_height), win.width(440), win.height(220), 20);
if (turn && mode==1)
rect(win.x(750), win.y(score_height), win.width(440), win.height(220), 20);

noStroke();
rectMode(CENTER);
fill(#eeeeee);
rect(x - boardSize/4, y - boardSize*0.67, boardSize*0.4, boardSize*0.2, 10);
rect(win.x(250), win.y(score_height), win.width(400), win.height(180), 10);
fill(#0d1117);
rect(x + boardSize/4, y - boardSize*0.67, boardSize*0.4, boardSize*0.2, 10);
rect(win.x(750), win.y(score_height), win.width(400), win.height(180), 10);

fill(#0d1117);
textAlign(CENTER);
textSize(boardSize/10);
textAlign(CENTER, CENTER);
textSize(win.width(80));
fill(#0d1117);
text(score_white, x - boardSize/4, y - boardSize * 0.63);
text(getScore_black(), win.x(250), win.y(score_height-10));
fill(#eeeeee);
text(score_black, x + boardSize/4, y - boardSize * 0.63);
text(getScore_white(), win.x(750), win.y(score_height-10));
}


void drawBoard(int x, int y, int boardSize) { //ボード表示

float blockSize = boardSize/8; //ブロック1辺

void drawBoard() { //ボード表示
/*ホバー&ボード*/
stroke(0);
strokeWeight(1);
rectMode(CORNER);
for (int i=0; i<8; i++)
for (int j=0; j<8; j++) {
fill(#009100);
if (highlight[i][j])
fill(#b6e9a1);
else
fill(#009100);
rect(x + blockSize*-4 + blockSize*i, y + blockSize*-4 + blockSize*j, blockSize, blockSize);
rect(win.x(i*125), win.y(board_height+j*125), win.width(125), win.height(125));
}

/*外枠*/
stroke(0);
noFill();
strokeWeight(1.5);
rectMode(CENTER);
rect(x, y, blockSize*8, blockSize*8);
rectMode(CORNER);
rect(win.x(0), win.y(board_height), win.width(1000), win.height(1000));

/*ドット*/
int dotSize = boardSize / 70;
fill(0);
noStroke();
ellipseMode(CENTER);
ellipse(x + blockSize*-2, y + blockSize *-2, dotSize, dotSize);
ellipse(x + blockSize*-2, y + blockSize * 2, dotSize, dotSize);
ellipse(x + blockSize* 2, y + blockSize *-2, dotSize, dotSize);
ellipse(x + blockSize* 2, y + blockSize * 2, dotSize, dotSize);
ellipse(win.x(250), win.y(board_height+250), win.width(10), win.width(10));
ellipse(win.x(250), win.y(board_height+750), win.width(10), win.width(10));
ellipse(win.x(750), win.y(board_height+250), win.width(10), win.width(10));
ellipse(win.x(750), win.y(board_height+750), win.width(10), win.width(10));

/**/
noStroke();
Expand All @@ -141,18 +127,18 @@ void drawBoard(int x, int y, int boardSize) { //ボード表示
fill(255);
else
continue;
ellipse(x + blockSize*-4 + blockSize*0.5 + blockSize*i, y + blockSize*-4 + blockSize*0.5 + blockSize*j, blockSize*0.7, blockSize*0.7);
ellipse(win.x(63+i*125), win.y(board_height+63+j*125), win.width(80), win.width(80));
}

/*マウスに駒表示*/
}

void drawCursor(int boardSize) {
if (mode!=1 || isSettingMode==true)return;
void drawCursor() {
if (mode!=1)return;
int mouseGlow=abs(millis()/10%200-100)+155;
if (turn)
fill(0, mouseGlow);
else
fill(255, mouseGlow);
ellipse(mouseX, mouseY, boardSize*0.09, boardSize*0.09);
}
ellipse(mouseX, mouseY, win.width(80), win.width(80));
}
47 changes: 28 additions & 19 deletions othelo_prosessing/othelo_prosessing.pde
Original file line number Diff line number Diff line change
Expand Up @@ -13,44 +13,53 @@ boolean turn; //true:black,false:white

int mode;

final int board_height = 300;
final int botton_height = 1350;

Window win = new Window();
Botton option[] = new Botton[3];
Botton board[][] = new Botton[8][8];

void setup() {
frameRate(240);
surface.setResizable(true);
surface.setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
for (int i=0; i<3; i++)option[i] = new Botton();
for (int i=0; i<8; i++)for (int j=0; j<8; j++)board[i][j] = new Botton();
frameRate(1000);
win.setWindow(WINDOW_WIDTH, WINDOW_HEIGHT, 1000, 1500);
win.margin(20);
}
void draw() {
background(#e5b26a);
print((int)frameRate);
println("fps");
int boardSize = getBoradSize()/2;

//win.drawWindow();

switch(mode) {
case 0: //初期化
boardReset();
mode++;
case 1: //メイン処理
mouseCD(width/2, height/2, boardSize);
optionBotton(width/2, height/2, boardSize);
drawScore(width/2, height/2, boardSize);
drawTurn(width/2, height/2, boardSize);
drawBoard(width/2, height/2, boardSize);
drawCursor(boardSize);
mouseCD();
optionBotton();
drawScore();
drawBoard();
drawCursor();
break;
case 2: //ソート待機
isHintMode=false;
AImode=false;
clearHighlight();
optionBotton(width/2, height/2, boardSize);
drawScore(width/2, height/2, boardSize);
drawBoard(width/2, height/2, boardSize);
drawCursor(boardSize);
optionBotton();
drawScore();
drawBoard();
drawCursor();
case 3:
isHintMode=false;
AImode=false;
clearHighlight();
optionBotton(width/2, height/2, boardSize);
drawScore(width/2, height/2, boardSize);
drawBoard(width/2, height/2, boardSize);
drawCursor(boardSize);
optionBotton();
drawScore();
drawBoard();
drawCursor();
}
}
}
Loading

0 comments on commit e4c0eef

Please sign in to comment.