473,756 Members | 3,211 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

pygame problems

51 New Member
Hi guys i have come again with more problems.This time it has to do with pygame.The following code does not give any error messages but it does not do what it is supposed to do either.the code is a bit long but it's straightforward .Please help
Expand|Select|Wrap|Line Numbers
  1. import pygame
  2. from pygame.locals import *
  3. pygame.init()
  4. screen=pygame.display.set_mode((900,900))
  5.  
  6.  
  7. class Hero(pygame.sprite.Sprite):
  8.     def __init__(self):
  9.         pygame.sprite.Sprite.__init__(self)
  10.         self.image=pygame.image.load('C:/Python24/r3.PNG')
  11.         self.image=self.image.convert()
  12.         self.rect=self.image.get_rect()
  13.         self.rect.topleft=0,500
  14.         self.a=screen.get_rect()
  15.     def forward(self):
  16.         a=1
  17.     def back(self):
  18.         a=2
  19.     def original(self):
  20.         self.a.topleft=0,500
  21.     def moveup(self):
  22.         a=3  
  23.     def movedown(self):
  24.         a=4    
  25.     def update(self):
  26.         if a==0:
  27.             self.original()
  28.         if a==1:
  29.             if self.rect.left<=self.a.right :
  30.                 self.rect.move_ip(5,0)
  31.             else:
  32.                 self.original()
  33.         if a==2:
  34.             if self.rect.left!=0:
  35.                 self.rect.move_ip(-5,0)
  36.             else:
  37.                 self.original()
  38.         if a==3:
  39.             if self.rect.top!=self.a.top:
  40.                 self.rect.move_ip(0,5)
  41.             else:
  42.                 self.rect.move_ip(0,-5)
  43.         if a==4:
  44.             if self.rect.bottom!=0:
  45.                 self.rect.move_ip(0,-5)
  46.             else:
  47.                 self.rect.move_ip(0,5)
  48. class Villian(pygame.sprite.Sprite):
  49.     def __init__(self):
  50.         pygame.sprite.Sprite.__init__(self)
  51.         self.image=pygame.image.load('C:/Python24/toba-pyweek3/toba-pyweek3/data/cards/1.PNG')
  52.         self.rect=self.image.convert()
  53.         self.rect=self.image.get_rect()
  54.         self.rect.topleft=400,500
  55.         a=0
  56.     def forward(self):
  57.         self.rect.move_ip(0,5)
  58.  
  59.     def update(self):
  60.         if self.rect.top!=900:
  61.             self.forward()
  62.         else:
  63.             self.original()
  64.     def original(self):
  65.         self.rect.topleft=400,500
  66.  
  67. imig=pygame.image.load('C:/Python24/Blue hills.GIF')
  68. background=pygame.Surface(screen.get_size())
  69. background=background.convert()
  70. background.blit(imig,(0,0))
  71. screen.blit(background,(0,0))
  72. hero=Hero()
  73. villian=Villian()
  74. allsprites=pygame.sprite.RenderPlain((hero,villian))
  75. allsprites.draw(screen)
  76. pygame.display.flip()
  77.  
  78. clock=pygame.time.Clock()
  79. while True:
  80.     clock.tick(60)
  81.     for event in pygame.event.get():
  82.         if event.type==KEYDOWN and event.key==K_UP:
  83.             hero.moveup()
  84.         if event.type==KEYDOWN and event.key==K_DOWN:
  85.             hero.movedown()
  86.         if event.type==KEYDOWN and event.key==K_RIGHT:
  87.             hero.forward()
  88.         if event.type==KEYDOWN and event.key==K_LEFT:
  89.             hero.back()
  90.         if event.type==QUIT:
  91.             pygame.quit()
  92.             raise SystemExit()
  93. allsprites.update()
  94. screen.blit(background,(0,0))
  95. allsprites.draw(screen)
  96. pygame.display.flip()
May 20 '07
11 3627
dynamo
51 New Member
Lol, you need to enter at least 20 characters in a message. Used to be 10.
Oh,lol.Thanks again.
May 31 '07 #11
bartonc
6,596 Recognized Expert Expert
Lol, you need to enter at least 20 characters in a message. Used to be 10.
Or !
May 31 '07 #12

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

Similar topics

12
16140
by: Marian Aldenhövel | last post by:
Hi, I am trying to make pygame play music on windows. This simple program: import pygame,time pygame.init() print "Mixer settings", pygame.mixer.get_init() print "Mixer channels", pygame.mixer.get_num_channels() pygame.mixer.music.set_volume(1.0) pygame.mixer.music.load('file1.mp3)
3
3720
by: Tim Knauf | last post by:
Hi everyone, I'm glad to have found this list. I've written a small script for my own use which, amongst other things, captures mouse click information from a window containing an image. I used Pygame to manage the image window, as it was the easiest way to implement the functionality I needed. The surrounding interface windows (there are two) are constructed with Tkinter. Despite their unholy union, Pygame and Tkinter seem, generally,...
2
2079
by: Brent W. Hughes | last post by:
I'm just starting to learn pygame. I write what I think is just about the simplest program that should display a window and then quit. #----------------------------------------------- import sys import time import pygame pygame.init() screen = pygame.display.set_mode((640,480)) pygame.display.set_caption("A Bug's Life")
1
3237
by: kjm | last post by:
Hi everyone, I have recently acquired a Logitech Rumble pad to use as an input device. I have been having trouble getting the event que to respond that a button or hat arrow has been pressed. This is on a system running OS 10.3.9. I have modified/written a small piece of code that initializes the joystick, and pygame does recognize it. I was wondering if someone has a small snippet of code to get me going? I have posted the code...
2
2825
by: DK | last post by:
I'm somewhat new to Python but not to programming. I just want to know if it's possible to have a SINGLE wxPython frame containing two sections where one will contain widgets and the other will host an animation done using PyGame. More specifically, I want to have a list of names of animations on the left and depending on what is selected, run the PyGame animation in the main area.
1
6825
by: liuliuliu | last post by:
hi -- sorry if this is trivial -- but how do you make a screenshot of a pygame display? i have a surface which is basically the entire visible screen -- how do you write this surface as an image file during specific events in the script execution? image format doesnt matter. thanks! christine
1
1428
by: joshuabraham | last post by:
os version =windows xp hi guys i'm having problems using pygame the following code just does not seem to work. clock=pygame.time.Clock() while True: sound1.play() clock.tick(60) pKeys = pygame.key.get_pressed() Eves=pygame.event.get() villian.face() villian.hert()
3
4423
by: globalrev | last post by:
im doing this : http://www.learningpython.com/2006/03/12/creating-a-game-in-python-using-pygame-part-one/ and when closing the program the window stays up and doesnt respond. i tried adding this: http://www.pygame.org/wiki/FrequentlyAskedQuestions bu it doesnt work, or maybe im doing it wrong. heres the code without the added tutorial exit:
11
11681
by: globalrev | last post by:
http://www.pygame.org/docs/ref/mixer.html import pygame #pygame.mixer.init(frequency=22050, size=-16, channels=2, buffer=3072) //it complained abiout words= so i guess its only the nbrs should be there// pygame.mixer.init(22050, -16, 2, 3072) pygame.mixer.music.load("example1.mp3")
0
9275
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
10034
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
9872
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...
0
9713
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8713
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...
0
6534
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
5304
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3358
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2666
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.