Python - A quick look

This forum is currently in read-only mode.
From the Asset Store
A challenging game that needs quick responses!
  • Darn, I've been learning Ruby. One of these days I should give Python a second glance... I'm kinda busy on my Ruby project, though.

    Which begs a question - how does Construct implement Python? Would it be possible to support another language, such as Ruby or LUA?

  • Looks like you might be able to make a joystick controller via pygame.

    import pygame
    pygame.init()
    pygame.joystick.init()
    count = pygame.joystick.get_count()
    
    if count > 0:
        j = pygame.joystick.Joystick(0)
        j.init()
        num_axes = j.get_numaxes()
        num_buttons = j.get_numbuttons()
        last_axes = [j.get_axis(i) for i in xrange(num_axes)]
    Text.text = num_buttons[/code:2tq20idp]
  • Looks like you might be able to make a joystick controller via pygame.

    import pygame
    pygame.init()
    pygame.joystick.init()
    count = pygame.joystick.get_count()
    
    if count > 0:
        j = pygame.joystick.Joystick(0)
        j.init()
        num_axes = j.get_numaxes()
        num_buttons = j.get_numbuttons()
        last_axes = [j.get_axis(i) for i in xrange(num_axes)]
    Text.text = num_buttons[/code:18ersfhj]
    

    This. Is so awesome. I never thought of it before.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • #!/usr/bin/env python
    background_image_filename = 'arrow.png'
    mouse_image_filename = 'redcube.png'
    import pygame
    from pygame.locals import *
    from sys import exit
    pygame.init()
    screen = pygame.display.set_mode((640, 480), 0, 32)
    pygame.display.set_caption("Hello, World!")
    background = pygame.image.load(background_image_filename).convert()
    mouse_cursor = pygame.image.load(mouse_image_filename).convert_alpha()
    while True:
    	for event in pygame.event.get():
    		if event.type == QUIT:
    			exit()
    	screen.blit(background, (0,0))
    	x, y = pygame.mouse.get_pos()
    	x-= mouse_cursor.get_width() / 2
    	y-= mouse_cursor.get_height() / 2
    	screen.blit(mouse_cursor, (x, y))
    
    	pygame.display.update()[/code:2cmpbzwh]
     , This works in works construct too.
    I am going to a start using python lot more.
  • Yeah you can create a window with Python. Matter of fact the window doesn't have to be directx.

    Useful for some things, but I don't think it can get the same speed as the Construct window.

  • Is there any way to distribute PyGame to a player who an user who would like to play an exe that uses python with pygame?

    I've been reading, and Python libraries in general seems to suffer from "dll hell", in the form of dependencies and mismatching incompatible versions.

  • Is there any way to distribute PyGame to a player who an user who would like to play an exe that uses python with pygame?

    I've been reading, and Python libraries in general seems to suffer from "dll hell", in the form of dependencies and mismatching incompatible versions.

    or just automatically install python, when you select "Create Installer" when exporting?...or does it already do that?

  • I really think installing python to play a game is overkill for any user.

    I know I have ignored games that required me to do that before, it's almost like requiring to install visual studio.

    I would not use python in my games if this was the case.

    EDIT:

    Also, they might have another version installed. Ick.

  • Uh, I'm probably asking a really stupid question but can't you just drop the .dll you need into the folder that your game is in and zip it up?

    I mean, MMF games need that CNC32.DLL or whatever it's called, if you don't have MMF installed.

  • Uh, I'm probably asking a really stupid question but can't you just drop the .dll you need into the folder that your game is in and zip it up?

    I mean, MMF games need that CNC32.DLL or whatever it's called, if you don't have MMF installed.

    Yes you can. I was going to write that you you can do this.

  • Uh, I'm probably asking a really stupid question but can't you just drop the .dll you need into the folder that your game is in and zip it up?

    Yeah but for PyGame (and other Python dependencies) it's not so easy, it would seem.

  • > Uh, I'm probably asking a really stupid question but can't you just drop the .dll you need into the folder that your game is in and zip it up?

    >

    > I mean, MMF games need that CNC32.DLL or whatever it's called, if you don't have MMF installed.

    >

    Yes you can. I was going to write that you you can do this.

    Unfortunately, it doesn't work like that. Not all Python external libraries have nicely packaged Dlls that you can include with your game. They are usually distributed with the assumption that Python is installed on the system. I'm not an expert on Py2exe but it does during compile/build time is cosntruct an exe with known library dependencies. It will include any external libraries as modules in a "dist" directory or bundle straight into the executable. I have made pygame games with Py2Exe with only the executable and it had lots of other external dependencies, so it is very much in the realm of possibility. However, this really needs to be done during compile/build time and not some kind of hack where we copy over dependencies after the fact.

    I'd like to see Python working correctly though first without external libraries, like Pygame, before that support is added. I haven't been able to get even a simple Hello World example working without a hack (copying over .pyc files) and error messages. This is no slam on developers as Python would be insanely awesome with this support.

  • And now a cool chain/snake example for python

    Tomorrow I will explain how it works.

    And you never did...

    Seriously, though, thanks for the awesome example - just what I needed for a certain effect. I did a small test cap using this (and some extras):

    http://dl.dropbox.com/u/1328856/Plasma%20Worm%20Saga%20-%20The%20Bull.cap

    Latest unstable version - so 99.82 and it does a not too necessary PS2.0 effect on the layer so in case your graphics card doesn't like it - that's the reason.

    And the main question now is - how to make instances? Like several plasma worms? Give them unique Variables and do a For Each based on that or something? Can't figure it out...

  • And the main question now is - how to make instances? Like several plasma worms? Give them unique Variables and do a For Each based on that or something? Can't figure it out...

    theres more than one way to do it, especially if you dont mind destroying and recreating all the sprites each tick.

    but one simple way without doing that would be to use the pyfix plugin and do exactly what you said

    private variables indexing each snake

    do a private variable compare and then use the pyfix plugin to loop thru the picked sprites

  • Hmm, plugins and mass destruction... I was more like hoping for something nice and easy, like Construct itself mostly is.

    Well, can always limit the number of worms to one, but that's no fun...

    Will try to figure it out anyway.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)