From b7559201007b440403077111687422b41fb0cfe4 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Sat, 28 Jan 2023 02:31:40 +0000 Subject: [PATCH] Fixed xrel, yrel having the wrong value --- assets/scripts/entity.toy | 34 ++++++++++++++++++---------------- assets/scripts/root.toy | 2 +- box/box_engine.c | 4 ++-- 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/assets/scripts/entity.toy b/assets/scripts/entity.toy index 86d7ae2..82a13d8 100644 --- a/assets/scripts/entity.toy +++ b/assets/scripts/entity.toy @@ -5,19 +5,21 @@ var SPEED: int const = 10; //variables var parent: opaque = null; -var x: int = 50; -var y: int = 50; +var posX: int = 50; +var posY: int = 50; +var WIDTH: int const = 100; +var HEIGHT: int const = 100; var xspeed: int = 0; var yspeed: int = 0; //accessors - variables are private, functions are public fn getX(node: opaque) { - return x; + return posX; } fn getY(node: opaque) { - return y; + return posY; } //lifecycle functions @@ -29,8 +31,8 @@ fn onInit(node: opaque) { } fn onStep(node: opaque) { - x += xspeed; - y += yspeed; + posX += xspeed; + posY += yspeed; } fn onFree(node: opaque) { @@ -53,7 +55,7 @@ fn onDraw(node: opaque) { py = 0; } - node.drawNode(x + px, y + py, 100, 100); + node.drawNode(posX + px, posY + py, WIDTH, HEIGHT); } //event functions @@ -102,22 +104,22 @@ fn onKeyUp(node: opaque, event: string) { } fn onMouseMotion(node: opaque, x: int, y: int, xrel: int, yrel: int) { - print "entity.toy:onMouseMotion()"; - //TODO: mouse motion + // print "entity.toy:onMouseMotion(" + string x + ", " + string y + ", " + string xrel + ", " + string yrel + ")"; } fn onMouseButtonDown(node: opaque, x: int, y: int, button: string) { - print "entity.toy:onMouseButtonDown()"; - //TODO: mouse button down + // print "entity.toy:onMouseButtonDown(" + string x + ", " + string y + ", " + button + ")"; + + //jump to pos + posX = x - WIDTH / 2; + posY = y - HEIGHT / 2; } fn onMouseButtonUp(node: opaque, x: int, y: int, button: string) { - print "entity.toy:onMouseButtonUp()"; - //TODO: mouse button up + // print "entity.toy:onMouseButtonUp(" + string x + ", " + string y + ", " + button + ")"; } -fn onMouseWheel(node: opaque, x: int, y: int) { - print "entity.toy:onMouseWheel()"; - //TODO: mouse wheel +fn onMouseWheel(node: opaque, xrel: int, yrel: int) { + // print "entity.toy:onMouseWheel(" + string xrel + ", " + string yrel + ")"; } diff --git a/assets/scripts/root.toy b/assets/scripts/root.toy index eaa53c2..fe8b6c7 100644 --- a/assets/scripts/root.toy +++ b/assets/scripts/root.toy @@ -17,7 +17,7 @@ fn onInit(node: opaque) { node.makeChild("scripts:/entity.toy"); //give the child a child - node.getNodeChild(0).makeChild("scripts:/entity.toy"); + // node.getNodeChild(0).makeChild("scripts:/entity.toy"); } fn onStep(node: opaque) { diff --git a/box/box_engine.c b/box/box_engine.c index 6d5f148..80838b1 100644 --- a/box/box_engine.c +++ b/box/box_engine.c @@ -176,8 +176,8 @@ static void execEvents() { case SDL_MOUSEMOTION: { Toy_Literal mouseX = TOY_TO_INTEGER_LITERAL( (int)(event.motion.x) ); Toy_Literal mouseY = TOY_TO_INTEGER_LITERAL( (int)(event.motion.y) ); - Toy_Literal mouseXRel = TOY_TO_INTEGER_LITERAL( (int)(event.motion.x) ); - Toy_Literal mouseYRel = TOY_TO_INTEGER_LITERAL( (int)(event.motion.y) ); + Toy_Literal mouseXRel = TOY_TO_INTEGER_LITERAL( (int)(event.motion.xrel) ); + Toy_Literal mouseYRel = TOY_TO_INTEGER_LITERAL( (int)(event.motion.yrel) ); Toy_pushLiteralArray(&args, mouseX); Toy_pushLiteralArray(&args, mouseY);