I'm using a joystick in a side shooter game; the joystick logic comes from CodeMonkey's joystick project. In CodeMonkey's project, the actor that is being controlled by the joystick can be moved off the screen in any direction. In my game, I am trying to prevent the actor from being able to be moved off the screen.
I've set up four rules and applied them to the movable actor, and am wondering if there is a better way to do this or not. Here's the logic behind my movable actor:
*RULE 1: Stop moving RIGHT at 440 pixels* When Attribute self.Position.X < 440 Move: Direction 0. Speed: 300
*RULE 2: Stop moving LEFT at 40 pixels* When Attribute self.PositionX > 40 Move: Direction: 180. Speed: 300
*RULE 3: Stop moving UP at 290 pixels* When Attribute self.Position.Y < 290 Move: Direction: 90. Speed: 300
*RULE 4: Stop moving DWON at 30 pixels* When Attribute self.Position.Y > 30 Move: Direction: 270. Speed: 300
*CONSTRAIN ATTRIBUTE* Constrain Attribute: self.Rotation To: game.Angle2
*RULE* Rule for firing
*CONTROL CAMERA* -------------------------
To the many experts on the forums, does this look like good code, or is there a better way? Sometimes in my fiddling around with different things (using the above code) my actor will slip beyond the boundaries or it will bounce back and forth madly against them if the joystick isn't at just the right angle.
Any feedback / suggestions are greatly appreciated.
Comments
I've set up four rules and applied them to the movable actor, and am wondering if there is a better way to do this or not. Here's the logic behind my movable actor:
-------------------------
*MOVE*
Direction: game.Angle
Speed: 300*game.DistanceFromCenter/game.BaseRadius
*RULE 1: Stop moving RIGHT at 440 pixels*
When Attribute self.Position.X < 440
Move: Direction 0. Speed: 300
*RULE 2: Stop moving LEFT at 40 pixels*
When Attribute self.PositionX > 40
Move: Direction: 180. Speed: 300
*RULE 3: Stop moving UP at 290 pixels*
When Attribute self.Position.Y < 290
Move: Direction: 90. Speed: 300
*RULE 4: Stop moving DWON at 30 pixels*
When Attribute self.Position.Y > 30
Move: Direction: 270. Speed: 300
*CONSTRAIN ATTRIBUTE*
Constrain Attribute: self.Rotation To: game.Angle2
*RULE*
Rule for firing
*CONTROL CAMERA*
-------------------------
To the many experts on the forums, does this look like good code, or is there a better way? Sometimes in my fiddling around with different things (using the above code) my actor will slip beyond the boundaries or it will bounce back and forth madly against them if the joystick isn't at just the right angle.
Any feedback / suggestions are greatly appreciated.