[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] GSoC project proposal: Pygame on rails



On Sat, Mar 20, 2010 at 6:16 PM, Luke Paireepinart
<rabidpoobear@xxxxxxxxx> wrote:
>
>
> On Sun, Mar 7, 2010 at 2:30 PM, Evan Kroske <e.kroske@xxxxxxxxx> wrote:
>>
>> I plan to make my framework much simpler by restricting the game
>> developer's options
>>
>> I plan to make my framework much simpler by restricting the game
>> developer's options to hide complexity. Here's an idea of the type of code a
>> developer using my framework would write to create a simple platformer with
>> a single level:
>>
>> from insta.menu import *
>> from insta.platformer import *
>>
>> def startMenu():
>>
>>   titleScreen = Screen(600, 400)
>>   titleScreen.setTheme(themes.MEDIEVAL)
>>   titleScreen.setTitle("Porcupine's Tiny Adventure")
>>   titleScreen.setOptions(["Play", "Controls", "Credits"])
>>   titleScreen.getOption("Play").setAction(startGame)
>>   # More code for other menu options
>>
>> def startGame():
>>
>>   game = Game()
>>     hero = Player()
>>   hero.setSprite("standing.gif")
>>   hero.setRunningSprites(["running1.gif", "running2.gif", "running3.gif"])
>>   hero.setJumpSprite("jumping.gif")
>>   hero.setDeathSprite("gravestone.gif")
>>     hero.setMovementTriggers(constants.ARROW_KEYS)
>>   hero.setJumpTrigger(constants.SPACE_BAR)
>>     goal = Item()
>>   goal.setSprite("bigring.gif")
>>   goal.setBehavior(constants.FLOATING)
>>   goal.setAction(game.nextLevel)
>>     itemGenerator = ItemGenerator([None, goal, hero])
>>   [snip...]
>
> Personally I _HATE_ the setSomething notation you're using.  one of the
> reasons I don't use Java is so I don't have to deal with setters and
> getters.  It's an extra 4 keystrokes per function call! (if you include the
> "shift" to make the 4th letter uppercase).
> also, most of your setters/getters are just gonna be setting variables
> behind the scenes so it makes more sense to use properties and to use
> variable syntax.  Eg.
> hero.running_sprites = ["running1.gif", "running2.gif", "running3.gif"]
>
> doesn't that make a lot more sense?
>
> Also I agree that this doesn't have that much relevance to GSoC as far as
> I'm concerned, but you should still pursue the project if it is something
> you want to do!
>
> -Luke
> -Luke
>

Yeah, you're right. When I started thinking about it, I quickly
realized that the setSomething API was ridiculous. I decided to use a
event system for switching sprites; here's an example:

hero.when(hero.running).setSprites('running1.gif', 'running2.gif')

or

hero.when(hero.moving, "left").setSprite('bankingleft.gif')

I think it would be a highly intuitive method for triggering actions.

-- 
Evan Kroske
http://welcome2obscurity.blogspot.com/
The personal blog of Evan Kroske,
novice software developer.