applying xoffset to player causing funky results

BlitzMax Forums/BlitzMax Programming/applying xoffset to player causing funky results

Matt McFarland(Posted 2006) [#1]
player.max_x = 584-player.xoffset
player.min_x = 16-player.xoffset

If MouseX()+player.xoffset < player.min_x Then MoveMouse(player.min_x,MouseY())

If MouseX()+player.xoffset > player.max_x Then MoveMouse(player.max_x,MouseY())


As you can see, I'm using mouse control... The control works fine itself. But when I have 2 playerships you're controlling, I need to add an xoffset to one of the ships so they dont overlap each other. The problem is, one of the ships will go off screen. To fix this I figured I'd apply the xoffset on the mouseX if check. But it's not working.

Symptoms:
Ship with offset applied to it still goes too far right.


Scott Shaver(Posted 2006) [#2]
the first thing I would do is apply the offset to both. The one on the left gets -(offsetx/2) and the one on the right gets (offsetx/2) this should put the mouse between them. then your movement limits become

>(MouseX-offsetx/2-shipwidth/2) and <(MouseX+offsetx/2+shipwidth/2)






Matt McFarland(Posted 2006) [#3]
Scott,

You have an interesting Idea here. The problem is that this is a quite dynamic Object. Here are some obstacles I have about this.

Everytime you collect a new ship, you're adding a new ship to your fleet at the bottom (I'll say we'll cap it at 4 max ships you can control) Of course, tlike galaga they all follow your ship.

Now if you have 4 ships spread like this:

ship1 ship2 ship3 ship4

Obviously the center location has to be configured to be inbetween all the ships? What would be the most effective way to do that?

Also, if you have just 3 ships, what to do then?

and if you have just one ship.. I suppose you focus it at the ship itself.

My problem is you're going through the playerlist and updating all of them at the same time.

So would it be better to creaqte a completely new object, called "player center" then when you go through the player list you place them all around it?

Just an idea, trying to see if it's any good or if its too much work.

Each playership has its own values, you know, like whaty weapon it's using, etc. So this is going to be like GALAGA (when you capture your ship back) but with an edge.

Any additional thoughts and input is greatly appreciated! I do love your idea and I think I'll use it with the tweaks I described above.


Scott Shaver(Posted 2006) [#4]
So I would have a method that positions them. Take the number of ships minus 1, times the number of pixels of separation, plus the width in pixels of the ship. That gives you the total width. Now start positioning them at the MouseX()-totalWidth from left to right.

totalWidth = ((shipCount-1)*sepWidth)+(shipCount*shipWidth)
for i=0 until shipCount
ships[i].x = MouseX()-(totalWidth/2)+(shipWidth/2)+(i*sepWidth)
next

something like that should do it for any number of ships 1 to n. The above assumes you are using midhandle for the ship images


Tom Darby(Posted 2006) [#5]
Instead of linking the x position of your original ship to the mouseX, you should create some simple mouse movement and positioning routines and use those to modify the position of your ship.

This is useful should you ever want to limit the speed with which your ship can move, or do other things to your ship that don't necessarily play nice with whatever the mouse is doing at a particular moment. (For example, if you wanted to have a power-down that halved the speed of the ship, you'd have a hard time implementing this while ship position was tied to the MouseX.)

Check out my code example over here. It's a good starting point:

http://blitzmax.com/Community/posts.php?topic=42355#601350


Matt McFarland(Posted 2006) [#6]
@ Tom: Actually that is great importance as you have pointed out! I'm doing exactly that actually already. the player.x speed goes + or - depending on how far away the mouse cursor is from the ship itself.. The greater the distance, the more the ships are 'swayed' in that direction..

Instead I could create the 'ship-fleet center' object that behaves like the player does and have the playerships surrounding it.

@ Scott: I am going to do just that! Thank you :) I believe I'll have this solved thanks to you. However, changing the ship image in relative to how far it is swayed may be difficult with this but I'm sure I can put that in somehow.