Fixed xrel, yrel having the wrong value
This commit is contained in:
@@ -5,19 +5,21 @@ var SPEED: int const = 10;
|
|||||||
|
|
||||||
//variables
|
//variables
|
||||||
var parent: opaque = null;
|
var parent: opaque = null;
|
||||||
var x: int = 50;
|
var posX: int = 50;
|
||||||
var y: int = 50;
|
var posY: int = 50;
|
||||||
|
var WIDTH: int const = 100;
|
||||||
|
var HEIGHT: int const = 100;
|
||||||
|
|
||||||
var xspeed: int = 0;
|
var xspeed: int = 0;
|
||||||
var yspeed: int = 0;
|
var yspeed: int = 0;
|
||||||
|
|
||||||
//accessors - variables are private, functions are public
|
//accessors - variables are private, functions are public
|
||||||
fn getX(node: opaque) {
|
fn getX(node: opaque) {
|
||||||
return x;
|
return posX;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn getY(node: opaque) {
|
fn getY(node: opaque) {
|
||||||
return y;
|
return posY;
|
||||||
}
|
}
|
||||||
|
|
||||||
//lifecycle functions
|
//lifecycle functions
|
||||||
@@ -29,8 +31,8 @@ fn onInit(node: opaque) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn onStep(node: opaque) {
|
fn onStep(node: opaque) {
|
||||||
x += xspeed;
|
posX += xspeed;
|
||||||
y += yspeed;
|
posY += yspeed;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn onFree(node: opaque) {
|
fn onFree(node: opaque) {
|
||||||
@@ -53,7 +55,7 @@ fn onDraw(node: opaque) {
|
|||||||
py = 0;
|
py = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
node.drawNode(x + px, y + py, 100, 100);
|
node.drawNode(posX + px, posY + py, WIDTH, HEIGHT);
|
||||||
}
|
}
|
||||||
|
|
||||||
//event functions
|
//event functions
|
||||||
@@ -102,22 +104,22 @@ fn onKeyUp(node: opaque, event: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn onMouseMotion(node: opaque, x: int, y: int, xrel: int, yrel: int) {
|
fn onMouseMotion(node: opaque, x: int, y: int, xrel: int, yrel: int) {
|
||||||
print "entity.toy:onMouseMotion()";
|
// print "entity.toy:onMouseMotion(" + string x + ", " + string y + ", " + string xrel + ", " + string yrel + ")";
|
||||||
//TODO: mouse motion
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn onMouseButtonDown(node: opaque, x: int, y: int, button: string) {
|
fn onMouseButtonDown(node: opaque, x: int, y: int, button: string) {
|
||||||
print "entity.toy:onMouseButtonDown()";
|
// print "entity.toy:onMouseButtonDown(" + string x + ", " + string y + ", " + button + ")";
|
||||||
//TODO: mouse button down
|
|
||||||
|
//jump to pos
|
||||||
|
posX = x - WIDTH / 2;
|
||||||
|
posY = y - HEIGHT / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn onMouseButtonUp(node: opaque, x: int, y: int, button: string) {
|
fn onMouseButtonUp(node: opaque, x: int, y: int, button: string) {
|
||||||
print "entity.toy:onMouseButtonUp()";
|
// print "entity.toy:onMouseButtonUp(" + string x + ", " + string y + ", " + button + ")";
|
||||||
//TODO: mouse button up
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn onMouseWheel(node: opaque, x: int, y: int) {
|
fn onMouseWheel(node: opaque, xrel: int, yrel: int) {
|
||||||
print "entity.toy:onMouseWheel()";
|
// print "entity.toy:onMouseWheel(" + string xrel + ", " + string yrel + ")";
|
||||||
//TODO: mouse wheel
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ fn onInit(node: opaque) {
|
|||||||
node.makeChild("scripts:/entity.toy");
|
node.makeChild("scripts:/entity.toy");
|
||||||
|
|
||||||
//give the child a child
|
//give the child a child
|
||||||
node.getNodeChild(0).makeChild("scripts:/entity.toy");
|
// node.getNodeChild(0).makeChild("scripts:/entity.toy");
|
||||||
}
|
}
|
||||||
|
|
||||||
fn onStep(node: opaque) {
|
fn onStep(node: opaque) {
|
||||||
|
|||||||
@@ -176,8 +176,8 @@ static void execEvents() {
|
|||||||
case SDL_MOUSEMOTION: {
|
case SDL_MOUSEMOTION: {
|
||||||
Toy_Literal mouseX = TOY_TO_INTEGER_LITERAL( (int)(event.motion.x) );
|
Toy_Literal mouseX = TOY_TO_INTEGER_LITERAL( (int)(event.motion.x) );
|
||||||
Toy_Literal mouseY = TOY_TO_INTEGER_LITERAL( (int)(event.motion.y) );
|
Toy_Literal mouseY = TOY_TO_INTEGER_LITERAL( (int)(event.motion.y) );
|
||||||
Toy_Literal mouseXRel = TOY_TO_INTEGER_LITERAL( (int)(event.motion.x) );
|
Toy_Literal mouseXRel = TOY_TO_INTEGER_LITERAL( (int)(event.motion.xrel) );
|
||||||
Toy_Literal mouseYRel = TOY_TO_INTEGER_LITERAL( (int)(event.motion.y) );
|
Toy_Literal mouseYRel = TOY_TO_INTEGER_LITERAL( (int)(event.motion.yrel) );
|
||||||
|
|
||||||
Toy_pushLiteralArray(&args, mouseX);
|
Toy_pushLiteralArray(&args, mouseX);
|
||||||
Toy_pushLiteralArray(&args, mouseY);
|
Toy_pushLiteralArray(&args, mouseY);
|
||||||
|
|||||||
Reference in New Issue
Block a user