Re: [pygame] Float precision

2008-07-05 Thread Greg Ewing

OsKaR wrote:
If you try to move forward and left or right it would made a perfect 
circle isn't?


Accumulation of errors will cause this to happen, even
when there aren't any bugs, because you're moving in
discrete steps.

The error can be reduced by taking smaller steps. Or
by using a more sophisticated numerical integration
technique, although that's probably overkill for a
tank game.

--
Greg


Re: [pygame] Float precision

2008-07-05 Thread Ian Mallett
Python really should have a function for that.  I looked around for
one and couldn't find it.

I usually define a function rndint() which essentially is
int(round(num)), like Marcel's first method.

That second method, Marcel, is interesting--I hadn't thought of it.

Ian


Re: [pygame] Float precision

2008-07-04 Thread Marcel Rodrigues
Hi. If you still have problens with precision, you may want to use round()
before converting to integer:

   self.rect.centerx = int(round(self.xx))
   self.rect.centery = int(round(self.yy))

or just (with same results):

   self.rect.centerx = int(self.xx + 0.5)
   self.rect.centery = int(self.yy + 0.5)

  Marcel


2008/7/4 OsKaR <[EMAIL PROTECTED]>:

> Thanks John I will use this till I find a new solution
>
> 2008/7/4 John Leach <[EMAIL PROTECTED]>:
>
> Yes I see this.
>> I think most of the problem is here
>> self.rect.centerx += dx
>>self.rect.centery += dy
>> maybe centerx and centery need to be integers?
>> I had better luck when I changed it to like this
>>self.xx += dx
>>self.yy += dy
>>self.rect.centerx = int(self.xx)
>>self.rect.centery = int(self.yy)
>> where self.xx and self.yy are floats.
>> It was still not perfect but much better than before.
>> John
>>
>


Re: [pygame] Float precision

2008-07-04 Thread OsKaR
Thanks John I will use this till I find a new solution

2008/7/4 John Leach <[EMAIL PROTECTED]>:

> Yes I see this.
> I think most of the problem is here
> self.rect.centerx += dx
>self.rect.centery += dy
> maybe centerx and centery need to be integers?
> I had better luck when I changed it to like this
>self.xx += dx
>self.yy += dy
>self.rect.centerx = int(self.xx)
>self.rect.centery = int(self.yy)
> where self.xx and self.yy are floats.
> It was still not perfect but much better than before.
> John
>
>
>
>
> On Thu, 2008-07-03 at 19:36 +0200, OsKaR wrote:
> > If you try to move forward and left or right it would made a perfect
> > circle isn't?
> > Well, if I do this the tank moves like a spring, it doesn't do a
> > circle
> >
> > 2008/7/3 PyMike <[EMAIL PROTECTED]>:
> > You forgot to include the images, but I made some mockups
> > instead. I didn't see anything wrong with it though. Moved and
> > rotated nice and smoothly.
> >
> >
> >
> > On Thu, Jul 3, 2008 at 11:52 AM, OsKaR
> > <[EMAIL PROTECTED]> wrote:
> > Ok It's upload on mediafire
> > Here is the link:
> > http://www.mediafire.com/?222n1oyn1my
> >
> > Sorry for the poor or inexistent documentation :( I'm
> > working on it too
> >
> >
> > 2008/7/3 PyMike <[EMAIL PROTECTED]>:
> >
> >
> > Hello,
> >
> > If the game's not too big, can you upload it
> > on mediafire.com or stuffr.net? I can try to
> > fix it up :-)
> >
> >
> >
> > On Thu, Jul 3, 2008 at 11:12 AM, OsKaR
> > <[EMAIL PROTECTED]> wrote:
> > I've tried both things and it still
> > working bad. I don't know what to do,
> > any more ideas?
> >
> > 2008/7/3 Ian Mallett
> > <[EMAIL PROTECTED]>:
> >
> > P.S., you may want to convert
> > your angles to radians with
> > math's handy radians()
> > function.
> >
> >
> >
> >
> >
> > --
> > - pymike (http://pymike.pyedpypers.org/)
> >
> >
> >
> >
> > --
> > - pymike (http://pymike.pyedpypers.org/)
> >
>


Re: [pygame] Float precision

2008-07-03 Thread John Leach
Yes I see this.
I think most of the problem is here
self.rect.centerx += dx
self.rect.centery += dy
maybe centerx and centery need to be integers?
I had better luck when I changed it to like this
self.xx += dx
self.yy += dy
self.rect.centerx = int(self.xx)
self.rect.centery = int(self.yy)
where self.xx and self.yy are floats.
It was still not perfect but much better than before.
John




On Thu, 2008-07-03 at 19:36 +0200, OsKaR wrote:
> If you try to move forward and left or right it would made a perfect
> circle isn't?
> Well, if I do this the tank moves like a spring, it doesn't do a
> circle
> 
> 2008/7/3 PyMike <[EMAIL PROTECTED]>:
> You forgot to include the images, but I made some mockups
> instead. I didn't see anything wrong with it though. Moved and
> rotated nice and smoothly.
> 
> 
> 
> On Thu, Jul 3, 2008 at 11:52 AM, OsKaR
> <[EMAIL PROTECTED]> wrote:
> Ok It's upload on mediafire
> Here is the link:
> http://www.mediafire.com/?222n1oyn1my
> 
> Sorry for the poor or inexistent documentation :( I'm
> working on it too
> 
> 
> 2008/7/3 PyMike <[EMAIL PROTECTED]>:
> 
> 
> Hello,
> 
> If the game's not too big, can you upload it
> on mediafire.com or stuffr.net? I can try to
> fix it up :-)
> 
> 
> 
> On Thu, Jul 3, 2008 at 11:12 AM, OsKaR
> <[EMAIL PROTECTED]> wrote:
> I've tried both things and it still
> working bad. I don't know what to do,
> any more ideas? 
> 
> 2008/7/3 Ian Mallett
> <[EMAIL PROTECTED]>:
> 
> P.S., you may want to convert
> your angles to radians with
> math's handy radians()
> function.
> 
> 
> 
> 
> 
> -- 
> - pymike (http://pymike.pyedpypers.org/)
> 
> 
> 
> 
> -- 
> - pymike (http://pymike.pyedpypers.org/)
> 


Re: [pygame] Float precision

2008-07-03 Thread OsKaR
If you try to move forward and left or right it would made a perfect circle
isn't?
Well, if I do this the tank moves like a spring, it doesn't do a circle

2008/7/3 PyMike <[EMAIL PROTECTED]>:

> You forgot to include the images, but I made some mockups instead. I didn't
> see anything wrong with it though. Moved and rotated nice and smoothly.
>
>
> On Thu, Jul 3, 2008 at 11:52 AM, OsKaR <[EMAIL PROTECTED]> wrote:
>
>> Ok It's upload on mediafire
>> Here is the link: http://www.mediafire.com/?222n1oyn1my
>>
>> Sorry for the poor or inexistent documentation :( I'm working on it too
>>
>>
>> 2008/7/3 PyMike <[EMAIL PROTECTED]>:
>>
>> Hello,
>>>
>>> If the game's not too big, can you upload it on mediafire.com or
>>> stuffr.net? I can try to fix it up :-)
>>>
>>>
>>> On Thu, Jul 3, 2008 at 11:12 AM, OsKaR <[EMAIL PROTECTED]> wrote:
>>>
 I've tried both things and it still working bad. I don't know what to
 do, any more ideas?

 2008/7/3 Ian Mallett <[EMAIL PROTECTED]>:

> P.S., you may want to convert your angles to radians with math's handy
> radians() function.
>


>>>
>>>
>>> --
>>> - pymike (http://pymike.pyedpypers.org/)
>>
>>
>>
>
>
> --
> - pymike (http://pymike.pyedpypers.org/)
>


Re: [pygame] Float precision

2008-07-03 Thread PyMike
You forgot to include the images, but I made some mockups instead. I didn't
see anything wrong with it though. Moved and rotated nice and smoothly.

On Thu, Jul 3, 2008 at 11:52 AM, OsKaR <[EMAIL PROTECTED]> wrote:

> Ok It's upload on mediafire
> Here is the link: http://www.mediafire.com/?222n1oyn1my
>
> Sorry for the poor or inexistent documentation :( I'm working on it too
>
>
> 2008/7/3 PyMike <[EMAIL PROTECTED]>:
>
> Hello,
>>
>> If the game's not too big, can you upload it on mediafire.com or
>> stuffr.net? I can try to fix it up :-)
>>
>>
>> On Thu, Jul 3, 2008 at 11:12 AM, OsKaR <[EMAIL PROTECTED]> wrote:
>>
>>> I've tried both things and it still working bad. I don't know what to do,
>>> any more ideas?
>>>
>>> 2008/7/3 Ian Mallett <[EMAIL PROTECTED]>:
>>>
 P.S., you may want to convert your angles to radians with math's handy
 radians() function.

>>>
>>>
>>
>>
>> --
>> - pymike (http://pymike.pyedpypers.org/)
>
>
>


-- 
- pymike (http://pymike.pyedpypers.org/)


Re: [pygame] Float precision

2008-07-03 Thread OsKaR
Ok It's upload on mediafire
Here is the link: http://www.mediafire.com/?222n1oyn1my

Sorry for the poor or inexistent documentation :( I'm working on it too


2008/7/3 PyMike <[EMAIL PROTECTED]>:

> Hello,
>
> If the game's not too big, can you upload it on mediafire.com or
> stuffr.net? I can try to fix it up :-)
>
>
> On Thu, Jul 3, 2008 at 11:12 AM, OsKaR <[EMAIL PROTECTED]> wrote:
>
>> I've tried both things and it still working bad. I don't know what to do,
>> any more ideas?
>>
>> 2008/7/3 Ian Mallett <[EMAIL PROTECTED]>:
>>
>>> P.S., you may want to convert your angles to radians with math's handy
>>> radians() function.
>>>
>>
>>
>
>
> --
> - pymike (http://pymike.pyedpypers.org/)


Re: [pygame] Float precision

2008-07-03 Thread PyMike
Hello,

If the game's not too big, can you upload it on mediafire.com or stuffr.net?
I can try to fix it up :-)

On Thu, Jul 3, 2008 at 11:12 AM, OsKaR <[EMAIL PROTECTED]> wrote:

> I've tried both things and it still working bad. I don't know what to do,
> any more ideas?
>
> 2008/7/3 Ian Mallett <[EMAIL PROTECTED]>:
>
>> P.S., you may want to convert your angles to radians with math's handy
>> radians() function.
>>
>
>


-- 
- pymike (http://pymike.pyedpypers.org/)


Re: [pygame] Float precision

2008-07-03 Thread OsKaR
I've tried both things and it still working bad. I don't know what to do,
any more ideas?

2008/7/3 Ian Mallett <[EMAIL PROTECTED]>:

> P.S., you may want to convert your angles to radians with math's handy
> radians() function.
>


Re: [pygame] Float precision

2008-07-02 Thread Ian Mallett
P.S., you may want to convert your angles to radians with math's handy
radians() function.


Re: [pygame] Float precision

2008-07-02 Thread Ian Mallett
Try reversing the sin and cos.  Cosine resolves x direction and Sine
resolves y.  You have it backwards.  Also, if you want to flip the screen
coordinates, the y must be negative.

You also might want to try working with the movements one at a time to
isolate problems.

Ian