PyWeek - FamilyGuys2

Warning: Failed opening 'includes/python/skillz.php3' for inclusion (include_path='.:/py/week') in /concord/california/public_html/location.php3 on line 42
This is a team entry consisting of cfadam, jjinux.

screenshot
Ratings (show detail)
Fun: 2.9
Production: 2.8
Innovation: 1.6
6% of respondents wished to disqualify the entry.
Respondents: 42
Files: Uploader Date
hellacopy-1.2.zip — final 884.61 Kbytes 2007/09/10 16:58
hellacopy final
screenshot.png 10.60 Kbytes 2007/09/08 20:39
screenshot
hellacopy-1.1.zip — final 261.25 Kbytes 2007/09/08 20:33
PyWeek 4 Submission
hellacopy-1.0.zip — final 54.30 Kbytes 2007/09/08 15:17
PyWeek 4 Submission

Thursday 06 September, 2007

[ jjinux @ 07:43 ] Python: Useful Utility for PGU's leveledit

I'm using PGU. If you're not using PGU, you can skip this post.

If you're like me, you sometimes get confused about when you're editing the tiles and when you're editing the background. My buddy drew an entire level, and the tiles and background were totally messed up. Rather than redo the entire level, I wrote a little utility to force all the tiles into the background. It's quick-and-dirty, but quite useful when you need it:

#!/usr/bin/env python
#
# Copyright 2007 Adam Ulvi, Shannon Behrens
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

"""Take a TGA file, and force any tiles onto the background.

This is to make up for UI interface "difficulties" in PGU's leveledit.

"""

import os
import sys

import pygame

__docformat__ = "restructuredtext"


try:
    if (not len(sys.argv) == 3 or 
        not os.path.isfile(sys.argv[1])):
        raise ValueError
except:  # Catch all exceptions, not just ValueErrors.
    print >> sys.stderr, "usage: force_background.py INPUT.tga OUTPUT.tga"
    sys.exit(2)

in_f, out_f = sys.argv[1], sys.argv[2]
in_img = pygame.image.load(in_f)
out_img = in_img.copy()
w, h = in_img.get_width(), in_img.get_height()
for y in range(h):
    for x in range(w):
        (tile, bg, code, alpha) = in_img.get_at((x, y))
        if tile:
            bg, tile = tile, 0
        out_img.set_at((x, y), (tile, bg, code, alpha))
pygame.image.save(out_img, out_f)