To get a clear view of what I'm trying to explain, check the game-demo "Blockz".
This part of code checks, when dragging 'myobject' to the right, if an object called 'oBlockb' is at a certain coordinate [and therefor being in it's way].
If so, 'myobject' [the dragged object] shouldn't move.
It also should let the dragged object only move right when it's X <=360.
Problems:
* If I drag the object really quick it drags through oBlockb instead of being blocked by it.
* If I drag the object really quick it drags through the <=360 boundary.
* If I drag the object slowly it stops because of "myobject.X+120==oBlockb.X", but then I also can't drag it to the left...
So, how to solve these problems...
And: is there maybe a better way to check if objects are blocking the to-be-dragged "myobject'?
Code: ags
Regards,
Arj0n.
This part of code checks, when dragging 'myobject' to the right, if an object called 'oBlockb' is at a certain coordinate [and therefor being in it's way].
If so, 'myobject' [the dragged object] shouldn't move.
It also should let the dragged object only move right when it's X <=360.
Problems:
* If I drag the object really quick it drags through oBlockb instead of being blocked by it.
* If I drag the object really quick it drags through the <=360 boundary.
* If I drag the object slowly it stops because of "myobject.X+120==oBlockb.X", but then I also can't drag it to the left...
So, how to solve these problems...
And: is there maybe a better way to check if objects are blocking the to-be-dragged "myobject'?
Object* myobject = Object.GetAtScreenXY(mouse.x, mouse.y);
if (mouse.IsButtonDown(eMouseLeft)) {
if (button_pressed==0) {
button_pressed = 1;
ob = Object.GetAtScreenXY(mouse.x, mouse.y);
}
}
else {
button_pressed=0;
if (ob!=null) {
//ob.Baseline = 0;
ob=null;
}
}
if ((ob != null) && (Game.SpriteWidth[myobject.Graphic]==120) &&
(myobject.X+120==oBlockb.X && myobject.Y-60==oBlockb.Y-60 && myobject.X <=360)){
int width = Game.SpriteWidth[ob.Graphic];
int height = Game.SpriteHeight[ob.Graphic];
ob.SetPosition(ob.X, ob.Y);}
else if ((ob != null) && (Game.SpriteWidth[myobject.Graphic]==120) &&
(myobject.X+120==oBlockb.X && myobject.Y-60==oBlockb.Y-120 && myobject.X <=360)) {
int width = Game.SpriteWidth[ob.Graphic];
int height = Game.SpriteHeight[ob.Graphic];
ob.SetPosition(ob.X, ob.Y);}
else if (ob != null){
int width = Game.SpriteWidth[ob.Graphic];
int height = Game.SpriteHeight[ob.Graphic];
ob.SetPosition(mouse.x-width/2, ob.Y);
Regards,
Arj0n.