M src/codebox.js => src/codebox.js +5 -7
@@ 5,9 5,6 @@ const systemDefinitions = {
keyboard: {
outputs: ['c'],
},
- mouse: {
- outputs: ['p'],
- },
log: {
inputs: {
t: ({ value }) => {
@@ 16,8 13,9 @@ const systemDefinitions = {
}
},
screen: {
- width: 20,
- height: 20,
+ width: 15,
+ height: 12,
+ outputs: ['m'],
inputs: {
p: ({ value, box }) => {
const screen = box.screen;
@@ 30,7 28,7 @@ const systemDefinitions = {
screen.beginFill(hsv(0, 1, 1));
const wrappedPixel = new Vec(
Math.floor((pixel.x + width / 2).mod(width)) * pixelSize,
- Math.floor((pixel.y + height / 2 - headerSpace).mod(height - headerSpace) + headerSpace) * pixelSize,
+ Math.floor((pixel.y + height / 2).mod(height - headerSpace)) * pixelSize,
)
screen.drawRect(wrappedPixel.x, wrappedPixel.y, pixelSize, pixelSize);
},
@@ 45,7 43,7 @@ const systemDefinitions = {
screen.beginFill(hsv(0, 0, 0));
const wrappedPixel = new Vec(
Math.floor((pixel.x + width / 2).mod(width)) * pixelSize,
- Math.floor((pixel.y + height / 2 - headerSpace).mod(height - headerSpace) + headerSpace) * pixelSize,
+ Math.floor((pixel.y + height / 2).mod(height - headerSpace)) * pixelSize,
)
screen.drawRect(wrappedPixel.x, wrappedPixel.y, pixelSize, pixelSize);
},
M src/game.js => src/game.js +26 -8
@@ 107,7 107,8 @@ export function drawBox(box) {
box.screen.beginFill(hsv(0, 0, 0));
// REL: screen-dimentions
const headerSpace = TILE_SIZE * 2.5;
- box.screen.drawRect(0, 0 + headerSpace, box.width * TILE_SIZE, box.height * TILE_SIZE - headerSpace)
+ box.screen.y = headerSpace;
+ box.screen.drawRect(0, 0, box.width * TILE_SIZE, box.height * TILE_SIZE - headerSpace)
boxG.addChild(box.screen);
}
@@ 245,19 246,36 @@ export function evaluateNewPieces (newKey, gameData, gs) {
const keyBoxes = codeBoxes.filter(box => box.type === 'keyboard');
newPieces = newPieces.concat(keyBoxes.flatMap(box => emit(newKey, box)));
}
- if (gameData.mouseMoved) {
- const mouseBoxes = codeBoxes.filter(box => box.type === 'mouse');
- newPieces = newPieces.concat(mouseBoxes.flatMap(
- box => emit(gameData.mouse.mul(1 / TILE_SIZE).round(), box)
- ));
- }
const tickRate = TICK_RATE / gameData.gameSpeed;
- if (gameData.i.mod(Math.ceil(tickRate)) === 0) {
+ const tickTriggered = gameData.i.mod(Math.ceil(tickRate)) === 0;
+ if (tickTriggered) {
const tickBoxes = codeBoxes.filter(box => box.type === 'tick');
newPieces = newPieces.concat(tickBoxes.flatMap(
box => emit(null, box)
));
}
+ if (gameData.mouseMoved && tickTriggered) {
+ gameData.mouseMoved = false;
+ const screenBoxes = codeBoxes.filter(box => box.type === 'screen');
+ newPieces = newPieces.concat(screenBoxes.flatMap(
+ box => {
+ const headerSpace = TILE_SIZE * 2.5;
+ const point = (
+ gameData.mouse.sub(box.pos.mul(TILE_SIZE))
+ .sub(new Vec(box.width, box.height).mul(.5 * TILE_SIZE).add(new Vec(0, headerSpace)))
+ )
+ const inRange = (
+ Math.abs(point.x) < box.width * TILE_SIZE / 2
+ && Math.abs(point.y) < box.height * TILE_SIZE / 2
+ );
+ if (!inRange) {
+ return [];
+ }
+ const pixelSize = 3;
+ return emit(point.mul(1 / pixelSize).round(), box)
+ }
+ ));
+ }
// Just evaluate all boxes every frame for now
newPieces = newPieces.concat(codeBoxes.flatMap(box => {
const clicked = box.clicked;
M src/main.js => src/main.js +1 -3
@@ 76,7 76,7 @@ app.renderer.backgroundColor = hsv(.6, .1, .9)
$('.canvas').appendChild(app.view)
//Start the game loop
-setInterval(() => gameLoop(1), 30)
+setInterval(() => gameLoop(1), 50)
// app.ticker.add(delta => gameLoop(delta))
window.app = app
@@ 132,8 132,6 @@ function play (delta) {
}
});
gameData.dataPieces = gameData.dataPieces.filter(piece => !piece.consumedBy);
-
- gameData.mouseMoved = false;
}
function save () {