Fixed xrel, yrel having the wrong value

This commit is contained in:
2023-01-28 02:31:40 +00:00
parent 194a52394d
commit b755920100
3 changed files with 21 additions and 19 deletions

View File

@@ -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 + ")";
}

View File

@@ -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) {

View File

@@ -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);