[Tutor] Distutils Font Error

2011-04-18 Thread Greg Nielsen
Dear Fellow Python Users,

 I am currently working on a small Python 3.1.3 game on a Windows 7
machine and am attempting to freezing it using Distutils and cx_freeze so I
can share it with friends and family. Several attempts in I reached an error
that I am unable to fix and was hoping for some advice. The error is as
followes.

C:\Users\Greg\Documents\NetBeansProjects\Racing1\src\build\exe.win32-3.1>racing1
.exe
C:\Users\Greg\Documents\NetBeansProjects\Racing1\src\build\exe.win32-3.1\library
.zip\RacingLibrary.py:335: RuntimeWarning: use font: DLL load failed: %1 is
not
a valid Win32 application.
(ImportError: DLL load failed: %1 is not a valid Win32 application.)
Traceback (most recent call last):
  File "C:\Python31\lib\site-packages\cx_Freeze\initscripts\Console3.py",
line 2
7, in 
exec(code, m.__dict__)
  File "racing1.py", line 81, in 
  File "racing1.py", line 28, in main
  File
"C:\Users\Greg\Documents\NetBeansProjects\Racing1\src\RacingLibrary.py",
line 335, in __init__
self.font = pygame.font.Font("freesansbold.ttf", 20)
  File "C:\Python31\lib\site-packages\pygame\__init__.py", line 70, in
__getattr
__
raise NotImplementedError(MissingPygameModule)
NotImplementedError: font module not available
(ImportError: DLL load failed: %1 is not a valid Win32 application.)

This error occurs regardless to whether I use a freeware font and save a
copy of it in the .exe directory or if I attempt to call SysFont("None") Is
it possible that either Distutils or cx_freeze does not support .ttf? It's
the best guess I have at the moment. Hopefully someone can shed some light
into what is really going on here. Thank you to everyone who takes time to
read this and perhaps even respond with a possible solution. Mr. Nielsen
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Unbound Method Error

2011-04-25 Thread Greg Nielsen
Because of the limited Python 3 support, I've decided to attempt to push my
over 600 lines of code back to Python 2.6. Surprisingly, it worked well for
the most part, except for the following section of code.

crash = pygame.sprite.spritecollide(playerCar, computerSprites, False)
if crash:
for BlueCarSprite in crash:
redracersprites26.BlueCarSprite.collide(BlueCarSprite,
playerCar)
for GreenCarSprite in crash:
redracersprites26.GreenCarSprite.collide(GreenCarSprite,
playerCar)
for TruckSprite in crash:
redracersprites26.TruckSprite.collide(TruckSprite,
playerCar)

This is a perfectly good piece of code in Python 3.1.3 which checks to see
if a user controlled sprite collides with one or more computer controlled
sprites, then passes the data off to the proper class method to handle the
details. In Python 2.6.6, this section of code returns the following error

TypeError: unbound method collide() must be called with BlueCarSprite
instance as first argument (got GreenCarSprite instance instead)

I have several questions as to what exactly is going on and what I should
do, if you have any sort of answer to any of these questions, please
respond.

1) What exactly is an "unbound method" error? I have been programming (in
other languages) for several years on and off and have never heard of
something like this.

2) What changes between 3.1.3 and 2.6.6 that makes this section of code not
work? My best guess is that I'm missing something that lets the computer
know that BlueCarSprite is an object type, but even if that's true, I
wouldn't know what to do to fix it.

3) What would be a legit fix to my code to make it run? Sure, I guess I
could write a Collide class and use that rather than my collide method, or
perhaps a class that could act as a middle man between bits of code that I
know work, but I know that there has to be a better way to fix this.

Thank you to any and all who take the time to read this message, and
especially to those who respond with any sort of feedback

Greg
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Unbound Method Error

2011-04-25 Thread Greg Nielsen
First and foremost, thank you Steven for your quick and well written
response. It means a lot to me that you took the time out of your day to
answer my question, and it has really helped me better understand what it
going on.

So the full trace back for my error is as follows:

Traceback (most recent call last):
  File "C:\Users\Greg\Documents\NetBeansProjects\Red Racer
26\src\redracer26.py", line 19, in 
main()
  File "C:\Users\Greg\Documents\NetBeansProjects\Red Racer
26\src\redracer26.py", line 16, in main
redracerstates26.game(startLives)
  File "C:\Users\Greg\Documents\NetBeansProjects\Red Racer
26\src\redracerstates26.py", line 87, in game
redracersprites26.BlueCarSprite.collide(BlueCarSprite, playerCar)
TypeError: unbound method collide() must be called with BlueCarSprite
instance as first argument (got GreenCarSprite instance instead)
After reading through your explanation of unbound methods (and wrapping my
head around the concept), I came up with a quick fix that lead to a new
issue in my code. Here is what I think should work:

crash = pygame.sprite.spritecollide(playerCar, computerSprites, False)
if crash:
for BlueCarSprite in crash:
redracersprites26.BlueCarSprite.collide(crash, playerCar)
for GreenCarSprite in crash:
redracersprites26.GreenCarSprite.collide(crash, playerCar)
for TruckSprite in crash:
redracersprites26.TruckSprite.collide(crash, playerCar)

However, the spritecollide method returns a list, which my collide method
isn't expecting. The list should only contain the name of the sprite the
player hit. In Python 3, the method would just pull the variable out of the
list and work with it, but in Python 2, it's not expecting a list, causing
an error similar to the one seen previously:

Traceback (most recent call last):
  File "C:\Users\Greg\Documents\NetBeansProjects\Red Racer
26\src\redracer26.py", line 19, in 
main()
  File "C:\Users\Greg\Documents\NetBeansProjects\Red Racer
26\src\redracer26.py", line 16, in main
redracerstates26.game(startLives)
  File "C:\Users\Greg\Documents\NetBeansProjects\Red Racer
26\src\redracerstates26.py", line 87, in game
redracersprites26.BlueCarSprite.collide(crash, playerCar)
TypeError: unbound method collide() must be called with BlueCarSprite
instance as first argument (got list instance instead)
So what really has to happen now (I think) is that the list needs to be
unpacked into just a simple variable containing the name of the sprite in
question. This way the method receives the name of the instance (self) in
the way it was expecting to receive it. In your opinion, should I unpacked
the list before passing the data into the method, or attempt to define
"self" as a list? Is the latter even possible? I would think it would have
to be because otherwise Python could pick a variable type which you don't
want or aren't expecting it to pick and need to force it to take a certain
type of input.

And thank you for pointing out the fact I could just make a CarSprite class
and have subclasses (basically just a different sprite image) work with the
details. You just removed over 150 lines of redundant code from my program.
And once again, thank you Steven for taking the time to help me better
understand the whole unbound method concept.

Greg
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Unbound Method Error

2011-04-25 Thread Greg Nielsen
Ramit,

 First, thank you for your input and insight into my problem, I believe
that the code you came up with should not only be more efficient, but also
clear up the last of my issues. I just have a quick question on the
isinstance command you called. How exactly do I get the code to recognize it
as a class I wrote sitting in an imported library file? I would guess that
it would look sort of like this:

   if crash:
   for car in crash:
if isinstance(car, redracersprites26.BlueCarSprite()):
redracersprites26.BlueCarSprite.collide(car, playerCar)

However, worded as it the follow error and call back happens:

Traceback (most recent call last):
  File "C:\Users\Greg\Documents\NetBeansProjects\Red Racer
26\src\redracer26.py", line 19, in 
main()
  File "C:\Users\Greg\Documents\NetBeansProjects\Red Racer
26\src\redracer26.py", line 16, in main
redracerstates26.game(startLives)
  File "C:\Users\Greg\Documents\NetBeansProjects\Red Racer
26\src\redracerstates26.py", line 87, in game
if isinstance(car, redracersprites26.BlueCarSprite()):
TypeError: isinstance() arg 2 must be a class, type, or tuple of classes and
types
I must be using the wrong syntax in the second argument. I think I should be
able to find the documentation for this (extremely cool) method you showed
me, but if you know the proper way to cite my object, could you send me what
you think will work. This way I can have something to double check my work
against if I don't get it right first time round. Thank you again for your
time and assistance Ramit.

Greg
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Unbound Method Error

2011-04-25 Thread Greg Nielsen
And it works! Thank you once again to both Steven and Ramit for your
peerless insight into the workings of Python and for taking time out of you
day to help me work my code back to Python 2. I have learned much by talking
with both of you over the last day or so.

Greg
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Splitting a Tuple in Python 2.7

2011-12-05 Thread Greg Nielsen
The following gets returned from a function that I am calling.

(120, 400)

While I can use the Tuple as is in my program, I would like the ability to
change one or even both of the numbers depending on other events that
happen. So here is my question, is there a way to either 1) save each part
of the Tuple into a seperate variable or 2) edit just one part of the Tuple
without knowing or affecting the other number. Thanks for the help!

Greg
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Sandbox Game

2012-02-06 Thread Greg Nielsen
Nate,

 I myself am a newer programmer with most of my experience in the use
of pygame, perhaps I could help point you in the right direction. First,
there is a lot of cool stuff over at the main pygame website, and a lot of
the users will post projects with images, general overviews, and a link to
their main codebase / content. It might take some searching, but you could
definitely find something similar to what you are working on there.
 While finding something similar to what you are working on would
really help you out, something you might find even better is this book by
Andy Harris
http://www.amazon.com/Game-Programming-Line-Express-Learning/dp/0470068221/ref=sr_1_5?s=books&ie=UTF8&qid=1328564353&sr=1-5
It's
an amazing resource that takes you from installing python to creating your
own games and even a game engine. There is a good chance that your local
library has a copy. If you are serious about learning game programming in
python, this is what you need to read.
 Lastly, speaking from experience. Start small. Just like Bob said,
start with just the absolute basics and slowly add to your program. Mr.
Harris' book demonstrates this in Chapter 7 perfectly. So check out
pygame's website and check out that book from your library. I promise it
will help you get started.

Greg
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Class Nesting

2012-02-06 Thread Greg Nielsen
Hello List,

 My name is Greg, and while working on a project I've come across a
rather interesting problem. I'm trying to create a rough model of a star
cluster and all of the stars and planets contained within. Kind of a cool
project; hopefully it should work a little like this. I create a Star
Cluster object, which goes through a list of positions and decides if it
should build a Star System there. If it does, it then creates a Star System
object at that position which in turn calls upon and creates several Planet
objects to reside inside of it. All in all, about 64 positions to check, on
average 24 Star Systems, each with between 2 and 9 planets.
 So here is the problem, to create an object, you need to assign it to
a variable, and you need to know what that variable is to call upon it
later, so to have a object build a second object, it would need to somehow
create a variable name, and you would somehow have to know what name it
picked. Unless perhaps you had a Star Cluster list which had all of your
created Star System objects, each with their own list of Planets which you
could use list to call upon maybe
 I have a general grasp on the idea of nesting and calling upon objects
which you don't know the name of, but this goes far beyond my level of
understanding. Can anyone shed some light on how this would work, or
perhaps point me in the right direction of some documentation on this?
Thanks for the help, and I hope this is not too difficult of a question.

Greg
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Position issue with Pygame

2012-03-13 Thread Greg Nielsen
Hey everyone,

 Still working on that racing game project. I have come quite a far way
and will hopefully release something soon, but I wrote some bad code and
can't seem to fix it. Im most likely just missing something really silly
because I wrote this code at 2am yesterday. Here it is

def __init__(self):
pygame.sprite.Sprite.__init__(self)

"""Set the image, convert the image, and set the rect"""
self.image = pygame.image.load("NoCondition.bmp")
self.image = self.image.convert()
self.rect = self.image.get_rect()

"""Set the position of the sprite on screen"""
self.center = (100, 100)
self.rect.center = self.center

 For whatever reason, the sprite is placed at the very top of the
screen as if assigned "self.rect.topleft = (0, 0)" reguardless of what I
assign as the position. Please put me out of my misery and point out what
little thing I coded wrong. Thank you all for the help.

Greg
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Math Function and Python

2012-07-01 Thread Greg Nielsen
Hello Tutor,

 I'm having some trouble with a mathematical function in my code. I am
attempting to create a realistic acceleration in an object, slower to speed
up at its min and max speeds and fastest in the middle. To keep the math
simpl(er), I just wrote this function for a parabola, which models the
acceleration of the object. Y is the acceleration and X is the current
speed of the object.

Y = -.01X^2 * 1.45X

Before I came up with this formula, I was using a very inefficient list
method to do this. The old code is in italics. I still have it in the code
because it works (sort of). The function is commented out because it
doesn't work. It's also in bold, so you can see it easily.

if keys[pygame.K_UP] and self.dy < (15 + self.speedMod):
if self.dy <= 0:
   * self.accelPoints += self.accelList[0]*
*#self.dy += 1*
else:
*self.accelPoints += self.accelList[self.dy]*
*#self.accelPoints += ((-.1 * (self.dy * self.dy)) + (1.45
* self.dy))*
if self.accelPoints >= self.accelGoal:
self.dy += 1
self.nety = self.dy
self.accelPoints = 0

I did a test, and for some reason, it seems like the output of the function
is never saved into the self.accelPoints variable, because it always prints
out as 0. (For those who don't want to do the math, when dy = 1, the
function should output something close to 1.55) My best guess is that the
accelPoints doesn't like the fact that the function outputs a double, but
even when i make accelPoints a double (made it equal 0.01 instead of 0) it
still didn't work. If you have any thoughts on the matter, please let me
know. I most likely broke it in the most silly way imaginable. Thanks for
reading.

Greg
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Pygame and TkInter

2012-09-09 Thread Greg Nielsen
Hello Tutor,

 Quick question. Working on a new game and want to build in a GUI.
TkInter seems to fit the bill except for one small item. Both Pygame and
TkInter create windows. (Screen in Pygame, and the Root widget in TkInter)
Is there a way to combined these two so I can use all my Pygame sprites and
objects and any TkInter bars and buttons all in one screen? My best guess
would be something along this line.

screen = pygame.display.set_mode((640, 420))
root = Tk(screen)

or maybe this...

screen = Tk(pygame.display.set_mode((640, 420))

I really just need Tkinter for some easy buttons and stuff, everything else
I can do in Pygame. Any thoughts? Thanks for the assist.

Greg
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Pygame and TkInter

2012-09-09 Thread Greg Nielsen
Eryksun,

 That there is some classy code work. I actually found that same answer
and was about to try it when I saw your reply. It's going to take some time
to figure out everything you did there and how to apply it to my project,
but this is exactly what I needed. Thanks for the assist!

Greg
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Pygame and TkInter

2012-09-10 Thread Greg Nielsen
Ok kids, settle down.

Quick question to Dwight; why Blender? Im not going for "new age" like
that. (Personally when you spend that much time making a game look nice,
the core mechinics suffer.) However, it does look rather shiny and
powerful. All I really need though are some GUI components to add to my
game. I could write them myself, but if someone else already did the work,
why bother. Have any other recomendations or related info on Blender?

Greg
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Pygame and TkInter

2012-09-10 Thread Greg Nielsen
I will admit that the whole Blender project is cool, but Jerry has a point.
All I wanted to know was how to get Pygame and TkInter to work together,
and I got a solid answer about 12 hours ago. (Check out Eryksun's code,
it's beyond cool, past awsome, and close to sexy.) As such, I am
considering this post closed. Thank you all for your help.

Greg
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor