Neat little program...


...just another snipet of my RPG. It's a module that allows easy display of a character's dialogue with little effort.

You just take the main code, add where and what color you want the text to be. Along with whatever else. Then you just simple do a little function call whenever you want the dialogue displayed.

(Toggle Plain Text) import pygame pygame.init() screen = pygame.display.set_mode((800, 700)) pygame.mouse.set_visible(1) def dialogue(name, speech): #constant variables most likely to be changed: text_boxX = 150 text_boxY = 150 speed = 100 color = (255, 255, 255) #/end constants pygame.font.init() background = pygame.Surface(screen.get_size()) background = background.convert() background.fill((0, 0, 0)) font = pygame.font.Font(None, 17) text = font.render(name + ":", 2, (255, 255, 255)) textpos = (text_boxX, text_boxY) background.blit(text, textpos) screen.blit(background, (0, 0)) pygame.display.flip() clock = pygame.time.Clock() font = pygame.font.Font(None, 14) for letter in range(0, len(speech)): clock.tick(-(speed-200)) texta = speech[letter] text = font.render(texta, 2, color) textpos = ( text_boxX+8*(len (name) )+5+(letter*8), (text_boxY+2) ) background.blit(text, textpos) screen.blit(background, (0, 0)) pygame.display.flip() import pygame pygame.init() screen = pygame.display.set_mode((800, 700)) pygame.mouse.set_visible(1) def dialogue(name, speech): #constant variables most likely to be changed: text_boxX = 150 text_boxY = 150 speed = 100 color = (255, 255, 255) #/end constants pygame.font.init() background = pygame.Surface(screen.get_size()) background = background.convert() background.fill((0, 0, 0)) font = pygame.font.Font(None, 17) text = font.render(name + ":", 2, (255, 255, 255)) textpos = (text_boxX, text_boxY) background.blit(text, textpos) screen.blit(background, (0, 0)) pygame.display.flip() clock = pygame.time.Clock() font = pygame.font.Font(None, 14) for letter in range(0, len(speech)): clock.tick(-(speed-200)) texta = speech[letter] text = font.render(texta, 2, color) textpos = ( text_boxX+8*(len (name) )+5+(letter*8), (text_boxY+2) ) background.blit(text, textpos) screen.blit(background, (0, 0)) pygame.display.flip()
Posted On: Friday 28th of December 2012 05:27:18 AM Total Views:  208
View Complete with Replies

RELATED TOPICS OF Python Programming PROGRAMMING LANGUAGE




How would I go about checking if a authentication login actuallyexists.

Okay, I've written this script to check if a password works right, but how do I know if an authentication actually exists
VIEWS ON THIS POST

131

Posted on:

Monday 5th November 2012
View Replies!

import mysteries

I'm pretty comfortable with Python, but recently I'm constantly finding mysterious issues with import. For example, looking at http://genshi.edgewall.org/browser/t...s/transform.py the examples use the symbol 'HTML' but it's not defined locally, it's not explicitly imported, and there's no import *. Yet doctest will test this module and it passes with flying colors. It turns out HTML is defined in genshi.input. How do I know that I grepped for it. How does it become available to this module Another example: I was recently working on some code that did an import from inside a class method. That import was failing. I moved the import to the top of the file (at module scope) and it succeeded. I'm fairly sure that nobody was monkeying around with sys.path in that case. Can anyone think of a likely explanation TIA, -- Dave Abrahams Boost Consulting http://www.boost-consulting.com The Astoria Seminar ==> http://www.astoriaseminar.com
VIEWS ON THIS POST

148

Posted on:

Monday 5th November 2012
View Replies!

Re: ten small Python programs

--- Steven Bethard wrote: > Steve Howell wrote: > > --- Steven Bethard > wrote: > >> I think I would rewrite the current unit-testing > >> example to use the > >> standard library unittest module:: > >> > >> # Let's write reusable code, and unit test > it. > >> def add_money(amounts): > >> # do arithmetic in pennies so as not to > >> accumulate float errors > >> pennies = sum([round(int(amount * 100)) > for > >> amount in amounts]) > >> return float(pennies / 100.0) > >> import unittest > >> class TestAddMoney(unittest.TestCase): > >> def test_float_errors(self): > >> > self.failUnlessEqual(add_money([0.13, > >> 0.02]), 0.15) > >> > self.failUnlessEqual(add_money([100.01, > >> 99.99]), 200) > >> self.failUnlessEqual(add_money([0, > >> -13.00, 13.00]), 0) > >> if __name__ == '__main__': > >> unittest.main() > >> > > > > Just a minor quibble, but wouldn't you want the > import > > and test class to only get executed in the > ___main__ > > context > > That would be fine too. In the real world, I'd put > the tests in a > different module. > Maybe this is the first good example that motivates a hyperlink to alternatives. Would you accept the idea that we keep my original example on the SimplePrograms page, but we link to a UnitTestingPhilosophies page, and we show your alternative there Or vice versa, show your example on the first page, but then show mine on the hyperlinked page I am in 100% agreement with you that most unit tests would be completely outside the module, although I often follow the practice that my modules have a little "if __main__" section that runs a few simple unit tests, as sort of a bit of self-documentation. ____________________________________________________________________________________Building a website is a piece of cake. Yahoo! Small Business gives you all the tools to get online. http://smallbusiness.yahoo.com/webhosting
VIEWS ON THIS POST

164

Posted on:

Monday 5th November 2012
View Replies!

FlightFeather Social Networking Platform 0.3.1

FlightFeather's goal is "social networking for ". This means that *anyone* should have a chance to run a *popular* social networking site -- on minimal hardware, and without wasting bandwidth. Release 0.3.1 is the current development release. It adds a safe shutdown feature to the FlightFeather server, eliminating the need for the two-step shutdown procedure described in "QuickStart.txt". The new feature also allows you to stop the server remotely, from a list of trusted IP addresses (set to just 127.0.0.1 by default). The current beta release of FlightFeather is 0.2.8. You can download these releases (free/open source under the GPL) from the "BoSStats" site, which runs on FlightFeather. http://www.bosstats.com/flightfeather.html You are always welcome to participate in the discussion on the "BoSStats" site; the topic covered (what makes a good boss, office politics, etc.) is valuable in and of itself. Please, however, refrain from posting test comments, as the site is live. A Brief Overview of FlightFeather and BoSStats ---------------------------------------------- FlightFeather is in its early stages, but it is functional. You can see the system in action on the BoSStats site. BoSStats is dedicated to improving the world of work: you can discuss what makes a good boss, or share your experiences of office politics. You can also comment and vote on the posts made by others. The application does not set cookies, and no registration is required for anything except voting. http://www.bosstats.com/ BoSStats is a good testbed for FlightFeather, and has value of its own, since meaningful advice about work-related problems is very hard to find. A "Wisdom of Crowds" solution -- particularly with strong privacy protection (see below) -- is a necessary addition to this field. FlightFeather's most important feature is that all write requests generate (or modify) HTML files. In consequence, a pure read (the most common operation) merely serves static pages. The major design focus for FlightFeather are responsiveness and performance; the system should eventually support very high traffic volumes. In addition, FlightFeather allows for a great deal of user privacy -- a critical, rapidly emerging problem in the social networking realm.
VIEWS ON THIS POST

95

Posted on:

Monday 5th November 2012
View Replies!

patch barracks

patch barracks http://crack.cracksofts.com
VIEWS ON THIS POST

76

Posted on:

Wednesday 7th November 2012
View Replies!

in-client web server

I am working on a thick-client application that serves a lot of content as locally generated and modified web pages. I'm beginning to look at serving (and updating, via AJAX) these pages from a web server running within the client (mostly to provide a more natural and powerful way of interacting with the browser control). For a first cut I imagine just starting a web server within the client and serving the pages from localhost:. I have a couple questions for anyone with experience with this sort of architecture: * First, are there any existing open source libraries that exemplify this approach I have a vague recollection that TurboGears started out based on a project with this kind of architecture, but I haven't been able to find anything so far. * Second, are there any gotchas you would point out In particular I'm wondering if even this localhost connection will be a problem with many users' firewalls. In case it matters, the application is being developed in python 2.5.x with wxPython 2.8.x, aimed first at a Windows platform, but intended to be portable to Linux and Mac ASAP.
VIEWS ON THIS POST

84

Posted on:

Wednesday 7th November 2012
View Replies!

Is LOAD_GLOBAL really that slow?

It seems a common opinion that global access is much slower than local variable access. However, my benchmarks show a relatively small difference: ../python -m timeit -r 10 -v -s 'x = [None] * 10000 def foo(): for i in x: list; list; list; list; list; list; list; list; list; list' 'foo()' 10 loops -> 0.0989 secs100 loops -> 0.991 secs raw times: 0.999 0.985 0.987 0.985 0.985 0.982 0.982 0.982 0.981 0.985 100 loops, best of 10: 9.81 msec per loop ../python -m timeit -r 10 -v -s 'x = [None] * 10000 def foo(): mylist = list for i in x: mylist; mylist; mylist; mylist; mylist; mylist; mylist; mylist; mylist; mylist' 'foo()' 10 loops -> 0.0617 secs 100 loops -> 0.61 secs raw times: 0.603 0.582 0.582 0.583 0.581 0.583 0.58 0.583 0.584 0.582 100 loops, best of 10: 5.8 msec per loop So global access is about 70% slower than local variable access. To put that in perspective, two local variable accesses will take longer than a single global variable access. This is a very extreme benchmark though. In practice, other overheads will probably drop the difference to a few percent at most. Not that important in my book. So my question: does somebody have a globals benchmark that shows a really significant slowdown vs local variables -- Adam Olsen, aka Rhamphoryncus
VIEWS ON THIS POST

146

Posted on:

Wednesday 7th November 2012
View Replies!

using user input to find information in a Mysql database

hi, I have recently started a project that will involve a user inputing a barcode manually into a python program. the python program will then take this barcode and look for it in a mysql database, if the barcode matches that of one in the database it will then display the product that corresponds to that barcode. for the moment the user will enter the barcode amnually, but in the future i will use a barcode scaner. the program will run on my laptop, but in the future the program will be used in a domestic appliance. can anyone give me some tips, because I am not really sure how to go about it.
VIEWS ON THIS POST

41

Posted on:

Tuesday 27th November 2012
View Replies!