add control panels (blocks, steps, loop)

This commit is contained in:
nadiarvi 2025-05-01 17:40:46 +09:00
parent 4e609c171a
commit 6fe0f84f53
2 changed files with 42 additions and 20 deletions

View File

@ -28,16 +28,16 @@ export class ControlPanel {
// Label // Label
fill(colors.tertiary); fill(colors.tertiary);
noStroke(); noStroke();
rect(this.x, this.y, this.getPanelWidth(), this.getTextBoxHeight(), 5); rect(this.x, this.y, this._getPanelWidth(), this._getTextBoxHeight(), 5);
fill(colors.secondary); fill(colors.secondary);
textAlign(CENTER, CENTER); textAlign(CENTER, CENTER);
textSize(this.fontSize); textSize(this.fontSize);
text(this.name, this.x + this.getPanelWidth() / 2, this.y + this.getTextBoxHeight() /2); text(this.name, this.x + this._getPanelWidth() / 2, this.y + this._getTextBoxHeight() /2);
// White panel // White panel
fill(255); fill(255);
noStroke(); noStroke();
rect(this.x, this.y + 24 + this.gap, this.getPanelWidth(), this.boxHeight + this.boxSpacing, 6); rect(this.x, this.y + 24 + this.gap, this._getPanelWidth(), this.boxHeight + this.boxSpacing, 6);
// Boxes // Boxes
for (let i = 0; i < this.numBoxes; i++) { for (let i = 0; i < this.numBoxes; i++) {
@ -59,16 +59,20 @@ export class ControlPanel {
this.empty.draw(bx + this.boxWidth / 2 - 20, by + this.boxHeight / 2 - 20); this.empty.draw(bx + this.boxWidth / 2 - 20, by + this.boxHeight / 2 - 20);
} }
} }
} }
getPanelWidth() { setPosition(x, y){
blocks.x = x;
blocks.y = y;
}
//helper functions
_getPanelWidth() {
return this.numBoxes * (this.boxWidth + this.boxSpacing) + 12; return this.numBoxes * (this.boxWidth + this.boxSpacing) + 12;
} }
getTextBoxHeight(){ _getTextBoxHeight(){
return this.fontSize + 16; return this.fontSize + 16;
} }
} }

View File

@ -10,6 +10,8 @@ export default function GameScene() {
let cat; let cat;
let runButton; let runButton;
let blocks; let blocks;
let steps;
let loops;
this.name = "GameScene"; this.name = "GameScene";
@ -17,10 +19,10 @@ export default function GameScene() {
cat = new Cat(width / 6, height - 167.5, 150); cat = new Cat(width / 6, height - 167.5, 150);
runButton = new MyButton({ runButton = new MyButton({
x: width / 16 * 15, x: width / 32 * 28.5,
y: height / 16, y: height / 32,
text: "run >>", text: "run >>",
mode: "CENTER", mode: "CORNER",
style: buttonS, style: buttonS,
onPress: () => { onPress: () => {
console.log("Run button pressed"); console.log("Run button pressed");
@ -28,26 +30,40 @@ export default function GameScene() {
}); });
blocks = new ControlPanel({ blocks = new ControlPanel({
name: 'blocks', name: 'building blocks',
x: width / 32, x: width / 32 * 7,
y: height / 32,
numBoxes: 3
});
steps = new ControlPanel({
name: 'steps',
x: width / 32 * 12,
y: height / 32,
numBoxes: 6
});
loops = new ControlPanel({
name: 'loop',
x: width / 32 * 21,
y: height / 32, y: height / 32,
numBoxes: 4 numBoxes: 4
}); })
}; };
this.draw = () => { this.draw = () => {
background(colors.primary); background(colors.primary);
rectMode(CENTER);
fill(colors.tertiary); fill(colors.tertiary);
textSize(128); textSize(128);
stroke(colors.secondary); stroke(colors.secondary);
strokeWeight(7); strokeWeight(7);
textAlign(LEFT, TOP);
text('dan yap', width / 2, height / 2 - 100); text('lvl.3', width / 32, height /32 - 4);
// Ground // Ground
rectMode(CENTER);
fill(colors.secondary); fill(colors.secondary);
rect(width / 2, height - 100 / 2, width, 80); rect(width / 2, height - 100 / 2, width, 80);
@ -55,13 +71,15 @@ export default function GameScene() {
cat.draw(); cat.draw();
runButton.draw(); runButton.draw();
blocks.draw(); blocks.draw();
steps.draw();
loops.draw();
}; };
this.onResize = () => { this.onResize = () => {
cat.setPosition(width / 2, height - 177.5); cat.setPosition(width / 2, height - 177.5);
runButton.setPosition((width / 16) * 15, height / 16); runButton.setPosition((width / 16) * 15, height / 16);
blocks.x = width / 16 - 40; blocks.setPosition(width / 32, height / 32);
blocks.y = height / 16 + 8; steps.setPosition((width / 32) * 4, height / 32);
} }
} }