Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


ScoreX

Member Since 24 Dec 2010
Offline Last Active Jun 20 2014 06:22 PM

Posts I've Made

In Topic: python collision recursion issue

18 May 2014 - 05:11 AM

I'm struggling to see how you got a KeyError for this, unless you're doing something exotic ( in which case I'll need more code ).

 

Anyway, instead looping through a list and remove elements in the for loop, you should instead try one of the below:

  • Loop through a copy of the list of bubbles, removing from them from the original list ( for bubble1 in bubbles[:]: )
  • Loop through the list using an iterator ( for bubble1 in iter(bubbles): )

 

Also, you don't need to set bubble_old = bubble1. When you remove old_bubble from the list, you still hold the reference to it ( old_bubble is referenced to bubble1 ).

def touching(self, bubble, bubbles):
    for bubble1 in bubbles[:]:
        if self.color == bubble_old.color and dist(bubble.pos, bubble1.pos) <= 2 * BUBBLE_RADIUS:
            bubbles.remove(bubble1)
            self.touching(bubble1, bubbles)

In Topic: JMenu, Listeners, and drawing

10 May 2014 - 03:16 AM

In the actionPerformed method of the ImageListener class, you are comparing the text of the event source to the JMenuItem object, instead of the text of the object.

 

Instead of

if(imageName.getText().equals(image1))
{
    outputTextArea.replaceRange(descriptions[0], 0, outputTextArea.getText().length());
    pictureLabel.setIcon(new ImageIcon("images/" + pictures[0]));
}

Try

if(imageName.getText().equals(image1.getText()))
{
    outputTextArea.replaceRange(descriptions[0], 0, outputTextArea.getText().length());
    pictureLabel.setIcon(new ImageIcon("images/" + pictures[0]));
}

In Topic: playing sounds in python 3

19 March 2014 - 04:56 PM

http://pygame.info/downloads/ lists downloads for 3.2 and 3.3

 

Are you sure you've setup the right interpreter in pycharm? It's easy to forget if you've got multiple virtualenvs on the go.


In Topic: Turn based VS Real time strategy games and Total War series

06 March 2014 - 07:28 AM

The main difference is in the name... One takes place in real time, while the other takes place in turns.

 

In terms of programming, the difference is that for RTS you will need to be constantly updating/drawing. For TBS, you only need to update when something occurs e.g player hits end turn, so now we calculate the next AI players moves.

 

Have you played a Total War game? It's pretty obvious how they make use of both systems. The turn-based portion takes place on a large world map, where you move your armies and create castles/cities and the real-time bit is for battles where you fight on a smaller map with 2 or more armies.


In Topic: The Pygrid Engine (Pygame)

01 March 2014 - 04:02 PM

Looks like a good start smile.png

 

Just some feedback on your code style:

  • For modules, classes, methods and functions you might want to use python docstrings instead of using '#'. A docstring is much more useful as any decent IDE can show it to you without you needing to visit the file to read the comment.
  • It's generally not good python style to use import *. Better to import exactly what you need so there is no ambiguity. ( e.g, the "init" function in main.py, where is that defined? Is it pygame, random or pygrid? ( I know it's pygame in this script, but as your codebase grows bigger, you might want to provide your own init()  ) )
  • I know it's only a demo script, but all the "global" code in main.py would look a lot nicer grouped into a function ( or an if __name__ == "__main__" ), just to make it more readable. As it is, you kinda need to jump around to follow the code.

 

You don't have to take any of this on board of course, the code will work regardless. At work we develop primarily in python and it's great working with clean documented code when using 3rd party packages. These would be things I would be looking out for if I was searching for a python engine to use making a game.

 

All the best with this endeavour smile.png


PARTNERS