jephindavis's Profile User Rating: -----

Reputation: -1 Dishonored
Group:
Members
Active Posts:
19 (0.01 per day)
Joined:
13-November 09
Profile Views:
1,082
Last Active:
User is offline Aug 22 2012 05:08 AM
Currently:
Offline

Previous Fields

Country:
IN
OS Preference:
Windows
Favorite Browser:
FireFox
Favorite Processor:
Intel
Favorite Gaming Platform:
PC
Your Car:
Who Cares
Dream Kudos:
0

Latest Visitors

Icon   jephindavis has not set their status

Posts I've Made

  1. In Topic: Create executable file from pygame files

    Posted 8 Aug 2012

    View Postatraub, on 25 July 2012 - 08:46 PM, said:

    View Postjephindavis, on 25 July 2012 - 10:19 AM, said:

    View Postatraub, on 24 July 2012 - 09:47 PM, said:

    Have you considered distributing your application with portable python rather than as an executable?


    How do i do that? Can you explain?


    If you want a step by step guide, I'd suggest you google pygame and portable python. The basic concept is that portable python is a fully functioning install of python that can be distributed with an application. I believe it's based on 2.6, and it does come with pygame. Your users won't need to install python, they'll have it with pp! Sorry, that's the best answer you'll receive while I'm posting from my phone.

    Quote

    View Postatraub, on 24 July 2012 - 07:56 PM, said:

    You might want to try pygame2exe instead.

    Actually it looks like you used that resource, I'll take a closer look...

    EDIT:
    So it says that it's looking for the file in E:\Python27\dist\GAME STARTER.exe\background.jpg

    Does that mean that it's literally looking for a folder called "GAME STARTER.exe" and inside that directory it's looking for your background image? Try manually adding that folder and see what happens.


    Well, "GAME STARTER.exe" is the executable created, and as i said ,i have all the images kept in the same folder.
    i think the setup file has to be edited, but i have no idea how.


    I'm aware of all that, but I'm interested in what will happen, can you try my suggestion regardless? It will give me a better idea of what's going on.


    I tried that but still no use. So i changed the setup.py after going through a book by Andy Harris,Distributing Modules and Programs.
    But still my setup.py gives out error while compiling. The new setup.py is
    from distutils.core import setup
    import py2exe
    
    setup(window = ["SHADOW.py"],
          author="Jephin Davis",
          author_email="jephindavis@gmail.com",
          data_files=[('.', ["11.ttf","13.ttf","menufont.ttf"]),
                      ('frames',["Frame0.png","Frame1.png","Frame2.png",
                                 "Frame3.png","Frame4.png","Frame5.png",
                                 "Frame6.png","Frame7.png","Frame8.png",
                                 "Frame9.png","Frame10.png","Frame11.png",
                                 "Frame12.png","Frame13.png","Jump0.png",
                                 "Jump1.png","Jump2.png","Jump3.png",
                                 "Jump4.png","Jump5.png","Jump6.png",
                                 "Jump7.png","Jump8.png","Jump9.png",
                                 "Jump10.png","Jump11.png","Jump12.png",
                                 "Jump13.png","Shoot1.png","Shoot2.png",
                                 "Shoot3.png","Shoot4.png","Shoot5.png",
                                 "Shoot6.png","Shoot7.png","Shoot8.png",
                                 "Shoot9.png","Shoot10.png","Shoot11.png",
                                 "Shoot12.png","Shoot13.png","Shoot14.png",
                                 "Shoot15.png","Shoot16.png","Shoot17.png",
                                 "Shoot18.png","Shoot19.png","Shoot20.png",
                                 "Shoot21.png","Shoot22.png","Shoot23.png",
                                 "Stand1.png","Sword1.png","Sword2.png",
                                 "Sword3.png","Sword4.png","Sword5.png",
                                 "Sword6.png","Sword7.png","Sword8.png",
                                 "Sword9.png"])
                     ]
          
          )
    
    


    the error i am getting in the command prompt is

    copying 11.ttf -> E:\Python27\dist\.
    copying 13.ttf -> E:\Python27\dist\.
    copying menufont.ttf -> E:\Python27\dist\.
    creating E:\Python27\dist\frames
    error: can't copy 'Frame0.png': doesn't exist or not a regular file
  2. In Topic: importing module from another folder

    Posted 31 Jul 2012

    View PostNallo, on 31 July 2012 - 05:45 PM, said:

    Now it becomes clear:

    When you import a module the working directory is still the working directory of the main module:
    #say this file is in c:\py_progs
    import sys
    sys.path.append(r'C:\py_progs\modules')
    import my_module
    
    

    #this is my_module in c:\py_progs\modules
    import os
    print(os.getcwd)
    
    

    Even though my_module is in the modules directory and gets correctly imported, the working directory is still C:\py_progs.

    So in your program pygame.image.load() looks into the wrong directory. If you want pygame to load from the directory your imported program is in you could do it the following way:

    import os
    mypath = os.path.dirmane(__file__)
    
    #...
    pygame.image.load(os.path.join(mypath, image_name))
    
    


    Thank you very much. That solved the problem. Pardon me for not providing the details of the error before.

    View Postatraub, on 31 July 2012 - 08:58 PM, said:

    I'd like to point out how swiftly and awesomely Nallo was able to solve your problem once he was able to view your code and see the error message. The more information you give us, the more we're able to do for you.



    Yes, i am sorry that i didn't give much information at the beginning. Will be doing that from now now on. Thank you guys.
  3. In Topic: Sprite sheet and character animation

    Posted 30 Jul 2012

    View Postatraub, on 31 July 2012 - 08:23 AM, said:

    Can you show us the dirty code you have thus far? Also, it'll probably help if you upload the image too.



    import pygame,os
    from pygame import *
    import random
    
    pygame.init()
    pygame.key.set_repeat(1,1)
    
    pygame.mixer.music.load("music.ogg")
    pygame.mixer.music.play(-1)
    pygame.mixer.music.set_volume(0.3)
    class Shadow(pygame.sprite.Sprite):
          def __init__(self):
              pygame.sprite.Sprite.__init__(self)
              self.image=pygame.image.load("frames/Stand1.png")
              self.rect=self.image.get_rect()
              self.rect.x=20
              self.rect.y=510
          def update(self):
              self.image=pygame.image.load("frames/Frame0.png")
          def update0(self):
              self.image=pygame.image.load("frames/Stand1.png")
              self.rect=self.image.get_rect()
              self.rect.x=26
              self.rect.y=510
          def update1(self):
              self.image=pygame.image.load("frames/Frame1.png")
              self.rect=self.image.get_rect()
              self.rect.x=20
              self.rect.y=510
          def update2(self):
              self.image=pygame.image.load("frames/Frame2.png")  
          def update3(self):
              self.image=pygame.image.load("frames/Frame3.png")  
          def update4(self):
              self.image=pygame.image.load("frames/Frame4.png")  
          def update5(self):
              self.image=pygame.image.load("frames/Frame5.png")  
          def update6(self):
              self.image=pygame.image.load("frames/Frame6.png")  
          def update7(self):
              self.image=pygame.image.load("frames/Frame7.png")  
          def update8(self):
              self.image=pygame.image.load("frames/Frame8.png")  
          def update9(self):
              self.image=pygame.image.load("frames/Frame9.png")  
          def update10(self):
              self.image=pygame.image.load("frames/Frame10.png")  
          def update11(self):
              self.image=pygame.image.load("frames/Frame11.png")  
          def update12(self):
              self.image=pygame.image.load("frames/Frame12.png")  
          def update13(self):
              self.image=pygame.image.load("frames/Frame13.png")
    def main():
                
          background = pygame.Surface(screen.get_size())
          background=pygame.image.load("backclothwithclose.jpg")
          close=pygame.image.load("backclothwithcloseup.jpg")
          screen.blit(background,(0,0))
          clock =pygame.time.Clock()
          shadow = Shadow()
          allSprites = pygame.sprite.Group(shadow)
          keepGoing = True
          while keepGoing:
              clock.tick(30)
              x,y=pygame.mouse.get_pos()
              if x>1052 and x<1166 and y>35 and y<64:
                    screen.blit(close,(0,0))
              else:
                    screen.blit(background,(0,0))
              for event in pygame.event.get():
                  if event.type == pygame.QUIT:
                        keepGoing = False
                  elif event.type==pygame.KEYDOWN and event.key==pygame.K_ESCAPE: 
                        keepGoing = False
                  elif event.type==pygame.MOUSEBUTTONDOWN:
                        x,y=pygame.mouse.get_pos()
                        if x>1052 and x<1166 and y>35 and y<64:
                              keepGoing = False
                  
                  elif event.type==pygame.KEYDOWN and event.key==pygame.K_RIGHT :
                        allSprites.update()
                        allSprites.draw(screen)
                        pygame.display.flip()
                        pygame.time.delay(30)
                        #
                        shadow.update1()
                        allSprites.draw(screen)
                        pygame.display.flip()
                        pygame.time.delay(30)
                        #
                        shadow.update2()
                        allSprites.draw(screen)
                        pygame.display.flip()
                        pygame.time.delay(30)
                        #
                        shadow.update3()
                        allSprites.draw(screen)
                        pygame.display.flip()
                        pygame.time.delay(30)
                        #
                        shadow.update4()
                        allSprites.draw(screen)
                        pygame.display.flip()
                        pygame.time.delay(30)
                        #
                        shadow.update5()
                        allSprites.draw(screen)
                        pygame.display.flip()
                        pygame.time.delay(30)
                        #
                        shadow.update6()
                        allSprites.draw(screen)
                        pygame.display.flip()
                        pygame.time.delay(30)
                        #
                        shadow.update7()
                        allSprites.draw(screen)
                        pygame.display.flip()
                        pygame.time.delay(30)
                        #
                        shadow.update8()
                        allSprites.draw(screen)
                        pygame.display.flip()
                        pygame.time.delay(30)
                        #
                        shadow.update9()
                        allSprites.draw(screen)
                        pygame.display.flip()
                        pygame.time.delay(30)
                        #
                        shadow.update10()
                        allSprites.draw(screen)
                        pygame.display.flip()
                        pygame.time.delay(30)
                        #
                        shadow.update11()
                        allSprites.draw(screen)
                        pygame.display.flip()
                        pygame.time.delay(30)
                        #
                        shadow.update12()
                        allSprites.draw(screen)
                        pygame.display.flip()
                        pygame.time.delay(30)
                        #
                        shadow.update13()
                        allSprites.draw(screen)
                        pygame.display.flip()
                        pygame.time.delay(30)
    if __name__ == "__main__":
          main()
    
    


    The sprite image is attached
  4. In Topic: importing module from another folder

    Posted 30 Jul 2012

    this is the error i'm getting

    Traceback (most recent call last):
    File "G:\pygamer J3F\BASE.py", line 84, in <module>
    main()
    File "G:\pygamer J3F\BASE.py", line 75, in main
    l.main()
    File "G:\pygamer J3F\testfolder\level1.py", line 320, in main
    background=pygame.image.load("backclothwithclose.jpg")
    error: Couldn't open backclothwithclose.jpg


    backclothwithclose.jpg is one of the images i am using.
  5. In Topic: importing module from another folder

    Posted 30 Jul 2012

    View PostSimown, on 27 July 2012 - 03:14 PM, said:

    Which path exactly have you been using? This may be a case of having to escape backslashes in your path name. Try r'path\name\'

    The os module is your friend here, and it makes it cross platform compatible too!
    import os
    
    folder = "my-folder"
    image = "my-image.jpg"
    
    path = os.path.join(folder, image)
    
    



    If you are using custom modules (which you seem to be) I would probably prefer this method:

    Make a blank file called __init__.py in your subdirectory (this tells Python it is a module)

    So:
    your-file.py
           your-folder
                 __init__.py
                 your-module.py
    



    And then you can call the module by name:
    from your-folder import your-module
    


    Actually, the importing does work. But the problem is with the execution of the file imported.
    I have a folder/file structure like this:

    MY_FOLDER
    FILE1.PY
    MY_FOLDER2
    FILE2.PY
    <SOME IMAGES>

    I am able to import FILE2.PY into FILE1.PY, but when i try to run the main function of FILE2.PY from FILE1.PY, it gives the error that certain image cannot be found.

My Information

Member Title:
New D.I.C Head
Age:
23 years old
Birthday:
December 10, 1990
Gender:
Interests:
pygaming,c,c++, android
Full Name:
Jephin Davis
Years Programming:
5
Programming Languages:
C,C++,HTML,Java,Perl,Pygame,Sql

Contact Information

E-mail:
Click here to e-mail me

Friends

Comments

jephindavis has no profile comments yet. Why not say hello?