473,387 Members | 3,820 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Runtime error when starting a game.

9
All i wanna do at this point is to test the (soon to be) game and see that the correct sprites are were they are supposed to be.

When i run the game the background is black instead of the green color of my field.png, no other sprites are visible and after a while i get a Runtime error and the game crashes.

Any ideas?

Expand|Select|Wrap|Line Numbers
  1. import pygame, math, sys
  2. from pygame.locals import *
  3. from livewires import games
  4.  
  5. # FPS
  6. clock = pygame.time.Clock()
  7. FRAMES_PER_SECOND = 30
  8. deltat = clock.tick(FRAMES_PER_SECOND)
  9.  
  10. class Endzone(pygame.sprite.Sprite):
  11.     endzone_no_td = pygame.image.load('endzone.png')
  12.     endzone_td = pygame.image.load('endzone_td.png')
  13.  
  14.     def __init__(self, position):
  15.         pygame.sprite.Sprite.__init__(self)
  16.         self.rect = pygame.Rect(self.endzone_no_td.get_rect())
  17.         self.rect.center = position
  18.  
  19. class Player(pygame.sprite.Sprite):
  20.     player_image = pygame.image.load('49er.gif')
  21.     def __init__(self,position,team,pos_in_team):
  22.  
  23.         if team == 'offense':
  24.             player_image = pygame.image.load('49er.gif')
  25.         else:
  26.             player_image = pygame.image.load('defense.gif')
  27.  
  28.         """ if pos_in_team... """
  29.  
  30.         pygame.sprite.Sprite.__init__(self)
  31.         self.rect = pygame.Rect(self.player_image.get_rect())
  32.         self.rect.center = position
  33.  
  34. def game():
  35.     my_screen = games.Screen (width=1024, height=768)
  36.     bg = games.load_image("field.png")
  37.     my_screen.set_background(bg)
  38.     def_safety = Player((400,400),'defense','safety')
  39.     off_tight_end = Player((500,500),'offense','tigth_end')
  40.     my_screen.mainloop()
  41.  
  42. game()
  43.  
Mar 2 '09 #1
4 4986
boxfish
469 Expert 256MB
Is your background solid green? Livewires may be converting the green pixels to transparent. Try this:
bg = games.load_image("field.png", transparent = False)
If that works, we'll have to work on your sprites next. I don't think loading the player images with pygame is a good idea. If you're going to be using livewires, you might as well let it do that stuff for you. Or you could just use pygame without livewires.
Good luck with the game.
Mar 2 '09 #2
GKRAFT
9
Thanks for the tip, it took care of the runtime error.
I've played around a bit more and now i have another problem.

I get the following error:

Traceback (most recent call last):
File "...", line 54, in <module>
game()
File "...", line 47, in game
def_safety = Player('defense',(40, 40))
File "...", line 36, in __init__
screen.blit(player_image, self.position)
TypeError: invalid destination position for blit



And here is the code:
Expand|Select|Wrap|Line Numbers
  1. import pygame, math, sys
  2. from pygame.locals import *
  3. from livewires import games
  4.  
  5. # FPS
  6. clock = pygame.time.Clock()
  7. FRAMES_PER_SECOND = 30
  8. deltat = clock.tick(FRAMES_PER_SECOND)
  9.  
  10. screen = pygame.display.set_mode((1024, 768))
  11.  
  12.  
  13. class Player(pygame.sprite.Sprite):
  14.     player_image = pygame.image.load('49er.gif')
  15.     def __init__(self,team,position):
  16.         self.team = None
  17.         self.position = None
  18.  
  19.         if self.team == 'offense':
  20.             player_image = pygame.image.load('49er.gif')
  21.         else:
  22.             player_image = pygame.image.load('defense.gif')
  23.  
  24.         screen.blit(player_image, self.position)
  25.  
  26. def game():
  27.     bg = pygame.image.load("field.png")
  28.     screen.blit(bg, (0,0))
  29.  
  30.     #DEFENSE
  31.     def_safety = Player('defense',(40, 40))
  32.     def_safety.__init__()
  33.  
  34.     # OFFENSE
  35.     off_tight_end = Player('offense',(100, 100))
  36.     def_safety.__init()
  37.  
  38. game()
  39.  
I have no idea why the "coordinates" doesn't work...
Mar 3 '09 #3
boxfish
469 Expert 256MB
Your init function does nothing with the arguments you pass it, and assigns the members to None. It should be
Expand|Select|Wrap|Line Numbers
  1.     def __init__(self,team,position):
  2.         self.team = team
  3.         self.position = position
I hope this helps.
Mar 3 '09 #4
GKRAFT
9
Ah, that was kinda obvious :)
Thanks alot!
Mar 3 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: VinnieT | last post by:
I have a load balanced system that consists of 3 production servers. There are about 20 different applications that are used on these boxes. One of my applications in particular is used more than...
27
by: Mike P | last post by:
I will be passing my function a two dimensional array of varying length. Within that array is one data point, and the number of times it should loop through. So, for example, I might pass this...
3
by: bill_hounslow | last post by:
I'm trying to transfer data from one Sql Server into a table on another, using a simple INSERT query in an Access database with links to tables on both servers (the reasons for this are complicated...
3
by: Oberon | last post by:
How do I deal with this? I am getting an error for each get in the Game class (see code below). In the simplified example below I have reduced this to just 3 fields, one which can be NULL. I...
0
by: acb | last post by:
Hi, I have concluded an on-demand series of webcasts forming part of a series titled "Introduction to 2-D Video Game Development" that took place in 2005. The URL is at...
20
by: NeedJavaHelp | last post by:
Hello everyone, first time poster here, bear with me. RuneScape is an online multiplayer game run by Java www.runescape.com. The game itself is run on the website and when you play the game for...
3
by: whitehatmiracle | last post by:
SOS When i comile this program, im getting 13 errors all saying "prompt_for_bet and get_bet are not memebers of class Player" Where am i going wrong? Can anyone plzz enlighten me? Thnking u...
9
xpun
by: xpun | last post by:
hey all So I decided to be a little ambitious over the summer and create the game of clue in c. I figured it would give my self a GOOD refresher of the language and further understand functions...
3
by: Saser | last post by:
Hi all bytes out there. I have a few little problems in my program. The program is supposed to help me to not spend too much time of my day at the computer ;) I play a game called...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.