Any one up for a practice pygame project.

Re: Any one up for a practice pygame poroject.

Postby Mekire » Sat Jun 29, 2013 5:11 am

Code: Select all
from __future__ import absolute_import

Unless you are using python 2.5 or lower I don't think you need the future import (I personally code to maintain compatibility with 2.7+ and 3.x. Anything below 2.7 is too much trouble).

One thing you do need to be careful of when using packages is the relative imports will work on python 2.x, but on python 3.x absolute imports are no longer optional.

Honestly they are a bit of a pain to work with in my experience but it ends up being worth it.
I will try to make an example project shell if anyone is interesting in seeing the setup.

-Mek
User avatar
Mekire
 
Posts: 988
Joined: Thu Feb 07, 2013 11:33 pm
Location: Amakusa, Japan

Re: Any one up for a practice pygame poroject.

Postby DrakeMagi » Sun Jun 30, 2013 4:06 am

Code: Select all
from __future__ import absolute_import

using this enforce this behavior in 2.7 which is what python 3 uses.
and the code above should have no effect in python 3.
since this option in python 2.5.0a1 and mandatory in python 3.
Linux: won't find windows here.
Linux: the choice of a GNU generation.
https://github.com/DrakeMagi
DrakeMagi
 
Posts: 112
Joined: Sun May 12, 2013 8:36 pm

Re: Any one up for a practice pygame poroject.

Postby Mekire » Mon Jul 01, 2013 2:08 am

I added some issues to the github page.
They correspond to States/Pages that our game will need (or rather that I imagine it will need).

They so far include:
Code: Select all
Splash Screen: (Coding: easy, Graphics: easy)
Title Screen: (Coding: easy, Graphics: medium/hard)
Menu Screen: (Coding: average, Graphics: average)
Game: (Coding: advanced, Graphics: Enormous amounts needed)
Highscore Screen: (Coding: average, Graphics: average)

All but the Game itself are fairly trivial to implement. However, with the exception of the Splash screen, they all have fairly significant art requirements.

More info here:
https://github.com/metulburr/Plants-VS-Zombies/issues

-Mek
User avatar
Mekire
 
Posts: 988
Joined: Thu Feb 07, 2013 11:33 pm
Location: Amakusa, Japan

Re: Any one up for a practice pygame poroject.

Postby metulburr » Mon Jul 01, 2013 2:40 am

ah, ok. See i wasn't even thinking in terms of states. I was just thinking of the actaul game programming. Should we assign each one to everyone, so we dont end up doing the same one? (for the exception of the actual game) If so, whos all in for this part to be assigned?
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1471
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: Any one up for a practice pygame poroject.

Postby Mekire » Mon Jul 01, 2013 2:49 am

If someone comments on an issue saying they would like to work on it go ahead and assign them (or state you want to do something and assign yourself). No worries. I just threw it up so that people might go, "hey, I want to work on that," and we would start moving forward.

-Mek
User avatar
Mekire
 
Posts: 988
Joined: Thu Feb 07, 2013 11:33 pm
Location: Amakusa, Japan

Re: Any one up for a practice pygame poroject.

Postby metulburr » Mon Jul 01, 2013 2:50 am

oh sweet, i also didnt know about .gitignore, i always have manually removed the files or didnt push those (of course sometimes i got lazy and jsut pushed them anyways)

I learned a bit already

I am in the process of reading through your code, docs, and attempting to follow the control around
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1471
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: Any one up for a practice pygame poroject.

Postby Mekire » Mon Jul 01, 2013 4:16 am

Basically all you need to do to add a State is add the appropriate import and modify the dictionary in the main module. If you are doing the splash screen you should be able to use the placeholder Title State as a template. Obviously the state module itself goes in the State directory.

-Mek
User avatar
Mekire
 
Posts: 988
Joined: Thu Feb 07, 2013 11:33 pm
Location: Amakusa, Japan

Re: Any one up for a practice pygame poroject.

Postby metulburr » Mon Jul 01, 2013 4:46 am

im not sure how to do like a pull request to my own repo, lol. It would be good to just show the code, but i would assume it would just update the repo. And i dont want to just push what i have cuz it could just be crap, and wanting the old back, hmm but then again, its mostly just one file that i added. i guess i will just post the code here for now.

well main.py was a no brainer
Code: Select all
...
from .states import title, splash #menu, game

def main():
    """Add states to control here."""
    RunIt = tools.Control(setup.ORIGINAL_CAPTION)
    state_dict = { 
        "SPLASH" : splash.Splash(),
        "TITLE"  : title.Title()
    }
##                  "MENU"   : menu.Menu(),
##                  "GAME"   : game.Game()}
    RunIt.setup_states(state_dict,"SPLASH")
    RunIt.main()


and threw in some images:
Code: Select all
metulburr@ubuntu:~/repos/github/Pants VS Zombies/data/images$ ls
pygame_powered.jpeg  python_powered.jpeg
pygame_powered.png   python_powered.png
metulburr@ubuntu:~/repos/github/Pants VS Zombies/data/images$

all of which i opened in GIMP and attempted a background convert to (255,0,255) or ff00ff. which i beleive is done well.

and now i am still in the progress of splash.py in states: ( which i did just copy your title as a template
Code: Select all

import pygame as pg
from .. import setup as su,tools
import os



class Splash(tools._State):
    """This State is updated while our game shows the splash screen."""
    def __init__(self):
        tools._State.__init__(self)
        #self.title = self.render_font("Fixedsys500c",40,"Splash Screen Place Holder")
        #self.title_rect = self.title.get_rect(center=(su.SCREEN_RECT.centerx,75))
       # self.ne_key = self.render_font("Fixedsys500c",20,"[Press Any Key]",(255,255,0))
       # self.ne_key_rect = self.ne_key.get_rect(center=(su.SCREEN_RECT.centerx,500))
        self.blink = False
        self.timer = 0.0
       
        thisdir = os.path.dirname(os.path.realpath(__file__))
        image_path = os.path.join(os.path.split(thisdir)[0], 'images')
        #self.images = tools.load_all_gfx(os.path.join(image_path))#, 'python_powered.jpeg'))
        self.python_image = pg.image.load(os.path.join(image_path, 'python_powered.png')).convert()
        self.python_image_rect = self.python_image.get_rect(center=(su.SCREEN_RECT.centerx,75))
        self.python_image.set_colorkey((255,0,255))
        self.pygame_image = pg.image.load(os.path.join(image_path, 'pygame_powered.png')).convert()
        self.pygame_image_rect = self.pygame_image.get_rect(center=(su.SCREEN_RECT.centerx,200))
        self.pygame_image.set_colorkey((255,0,255))
    def render_font(self,font,size,msg,color=(255,255,255)):
        """Takes the name of a loaded font, the size, and the color and returns
        a rendered surface of the msg given."""
        RenderFont = pg.font.Font(su.FONTS[font],size)
        return RenderFont.render(msg,1,color)

    def update(self,Surf,keys,mouse):
        """Updates the title screen."""
        Surf.fill((50,50,50))
        #Surf.blit(self.title,self.title_rect)
        Surf.blit(self.python_image, self.python_image_rect)
        Surf.blit(self.pygame_image, self.pygame_image_rect)
        if pg.time.get_ticks() - self.timer > 1000/5.0:
            self.blink = not self.blink
            self.timer = pg.time.get_ticks()
        #if self.blink:
        #    Surf.blit(self.ne_key,self.ne_key_rect)

    def get_event(self,event):
        """Get events from Control.  Currently changes to next state on any key
        press."""
        if event.type == pg.KEYDOWN:
            self.next = "TITLE"
            self.done = True


a couple questions though:
your loading functions AKA
Code: Select all
def load_all_gfx(directory,colorkey=(255,0,255),accept=(".png",".jpg",".bmp")):

i couldnt find where you loaded all the images to? i also assumed at first the directory would be hard coded in that function, otherwise i had to put it splash independently. i loaded them separetly, because i wasnt sure, your function laods all the images and it seemed moot to load all images on every state, so i just put a temp independent load image in.

But now i was expecting the background (hot pink) of those images to be transparent, but they show up hot pink. Obviously i missed something.

oh and uh yeah, i know it looks like a lawn mower hit it, but that is why i didnt want to push it
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1471
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: Any one up for a practice pygame poroject.

Postby Mekire » Mon Jul 01, 2013 4:50 am

they are in setup

so if you use:
Code: Select all
from .. import setup as su
then the graphics are in the dict:
Code: Select all
su.GFX
dictionary keys are the names of the images minus the extension. So for example if you put an image "myimage.png" in the graphics resource folder, you would access it with:
Code: Select all
su.GFX["myimage"]

-Mek

Edit: In the future it might be necessary to change the resource loading so that the states pass the resources around. It depends how deep our directory structure gets. We don't want to have to start doing things like:
Code: Select all
from .... import setup as su

Also my other repo showed an example multistate project using this setup if you need a further resource.
https://bitbucket.org/Mekire/sample_pygame_project_organization/overview
I will try to add more detailed documentation if/when it becomes clear that the current is insufficient.
User avatar
Mekire
 
Posts: 988
Joined: Thu Feb 07, 2013 11:33 pm
Location: Amakusa, Japan

Re: Any one up for a practice pygame poroject.

Postby metulburr » Mon Jul 01, 2013 4:58 am

oh, duh
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1471
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: Any one up for a practice pygame poroject.

Postby metulburr » Mon Jul 01, 2013 5:03 am

wait, why are there two graohics paths now?
Code: Select all
metulburr@ubuntu:~/repos/github/Pants VS Zombies/data/images$ ls
pygame_powered__.jpeg  python_powered__.jpeg
pygame_powered.png     python_powered.png
metulburr@ubuntu:~/repos/github/Pants VS Zombies/data/images$


Code: Select all
metulburr@ubuntu:~/repos/github/Pants VS Zombies/resources/graphics$ ls
placeholder.txt
metulburr@ubuntu:~/repos/github/Pants VS Zombies/resources/graphics$
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1471
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: Any one up for a practice pygame poroject.

Postby Mekire » Mon Jul 01, 2013 5:07 am

Huh? No clue. Mine is resources/graphics.

-Mek
User avatar
Mekire
 
Posts: 988
Joined: Thu Feb 07, 2013 11:33 pm
Location: Amakusa, Japan

Re: Any one up for a practice pygame poroject.

Postby metulburr » Mon Jul 01, 2013 5:32 am

oh ok, the images one is the one i made as a placeholder on initial commit, gotta remove that
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1471
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: Any one up for a practice pygame poroject.

Postby metulburr » Mon Jul 01, 2013 7:03 am

i pushed a basic splash page, havent gotten to fading in. The only problem i had with it, is it needs not only x number of seconds, but it appears to also need input. I am not sure why though. (at this point)
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1471
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: Any one up for a practice pygame poroject.

Postby Mekire » Mon Jul 01, 2013 7:36 am

Again, my fault for not providing enough documentation. All States have an attribute self.start_time which is initialized to the current time every time we switch to that state, so no need for a new timer in this case. Also you don't need the self.next_state flag. Since the splash can only go to one other state, set self.next in the init, then just set self.done to True when it needs to be.

Code: Select all
import pygame as pg
from .. import setup as su,tools

class Splash(tools._State):
    """This State is updated while our game shows the splash screen."""
    def __init__(self):
        tools._State.__init__(self)
        self.next = "TITLE"
        self.timeout = 4

        self.python_image = su.GFX['python_powered']
        self.python_image_rect = self.python_image.get_rect(center=(su.SCREEN_RECT.centerx,75))

        self.pygame_image = su.GFX['pygame_powered']
        self.pygame_image_rect = self.pygame_image.get_rect(center=(su.SCREEN_RECT.centerx,200))

    def update(self,Surf,keys,mouse):
        """Updates the title screen."""
        Surf.fill((255,255,255))
        Surf.blit(self.python_image, self.python_image_rect)
        Surf.blit(self.pygame_image, self.pygame_image_rect)
        if pg.time.get_ticks()-self.start_time > 1000.0*self.timeout:
            self.done = True

    def get_event(self,event):
        """Get events from Control. Currently changes to next state on any key
        press."""
        if event.type == pg.KEYDOWN:
            self.done = True

-Mek
User avatar
Mekire
 
Posts: 988
Joined: Thu Feb 07, 2013 11:33 pm
Location: Amakusa, Japan

Re: Any one up for a practice pygame poroject.

Postby metulburr » Mon Jul 01, 2013 2:46 pm

ah ok


should we merge all the splash images into one? It seems kind of overdoing it with multiple images, and text. the only good thing is switching out images, for example, i put the python-forum.org logo in there, but that is not necessarily our logo though.
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1471
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: Any one up for a practice pygame poroject.

Postby Mekire » Mon Jul 01, 2013 3:18 pm

Yeah you could rearrange those all into one image. We can move them around later if we'd like. I just pushed a minor change to yours. The time out needed to go within the update function. Things in the get_event function will only run IF control has an event to pass down.

-Mek
User avatar
Mekire
 
Posts: 988
Joined: Thu Feb 07, 2013 11:33 pm
Location: Amakusa, Japan

Re: Any one up for a practice pygame poroject.

Postby metulburr » Mon Jul 01, 2013 5:07 pm

is there a purpose in the splash page? wouldnt that normally be mixzed in with the title page?
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1471
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: Any one up for a practice pygame poroject.

Postby Mekire » Mon Jul 01, 2013 11:33 pm

Just makes things look professional. Most games have a company logo screen that appears first before the actual title screen of their game. Strictly speaking, no, it isn't necessary; but strictly speaking, most things aren't. I think a quick fade in title screen with (eventually) some sort of accompanying soundeffect/music gives a strong impression (and later if it can be used to hide resource loading time, so much the better).

-Mek
User avatar
Mekire
 
Posts: 988
Joined: Thu Feb 07, 2013 11:33 pm
Location: Amakusa, Japan

Re: Any one up for a practice pygame poroject.

Postby metulburr » Tue Jul 02, 2013 2:30 am

Ok next step. I hope we are not fully mimicing the game, as that would be boring artwise, plus restricting us to use certain things?
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1471
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

PreviousNext

Return to Game Development

Who is online

Users browsing this forum: No registered users and 2 guests

cron