473,657 Members | 2,540 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Runtime error when starting a game.

9 New Member
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 5004
boxfish
469 Recognized Expert Contributor
Is your background solid green? Livewires may be converting the green pixels to transparent. Try this:
bg = games.load_imag e("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 New Member
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(pla yer_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 "coordinate s" doesn't work...
Mar 3 '09 #3
boxfish
469 Recognized Expert Contributor
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 New Member
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
4656
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 the others. Since updating 2 applications, I have had problems on the event log of the servers, following stopping of the aspnet_ws.exe process. Something is causing the following error in the windows application event log: The description for...
27
2605
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 to the function: example = new Array("A",2); example = new Array("Q",4); function loopIt(example);
3
15783
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 but it IS the simplest solution, believe me). The 'Select' clause of the query works fine when run alone, but, when I run the INSERT query I get a Runtime Error 3167 Record Deleted. I get the error even when I'm the only person accessing...
3
8636
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 have added 3 records to the table and ran the program but it fails with the error above. The application is supposed to create the hashtable of records as a static feature which will be permanently available to my application. To demonstrate that...
0
4888
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 http://www.microsoft.com/events/series/msdnvideodev.mspx and the corresponding binaries can be found at http://www.digipen.edu/main/Webcast/Introduction_to_2-D_Video_Game_Development.
20
20355
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 the first time, its files store on your pc. I've never had a problem untill its makers switched to Java Se (SUN Java). Normally, when you move to a new location / area in this game it brings up these words loading-please wait... and within 2 seconds...
3
1829
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 all in advance // gamble with Craps
9
2918
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 arrays objects etc.. Any way, I encountered a strange logic error and kinda put it to the side until now. This code is supposed to role the die, chose the killer and deal the cards to the players depending upon the # of player. However it only...
3
2375
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 Counter-Strike (CS) a lot, but I'm limited to 2 ½ hours a day, and a total of 4 hours a day. I have one button in my program which starts CS, and one button that "kills" CS. The Start-button starts a timer, and the Stop-button stops it. But I want to start the...
0
8326
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8845
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8743
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8522
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7355
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6177
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5647
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1973
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.