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!


mousetail

Member Since 30 Nov 2012
Offline Last Active Today, 07:17 AM

#5199085 Stuttering on game start - missed collisions

Posted by mousetail on 19 December 2014 - 06:27 AM

I didn't read your code, but the usual problem is that you are going so fast that you are above the object you are colliding with one frame, (So no collision) and below it the next, (So still no collision). The normal way to fix this is to collide using a polygon that includes all positions the object has been in in between the frames. Also, what units are you measuring gravity in? Pixels? A pixel does not necessary equal a meter, so its better to just set it to any value that looks realistic enough and works. (Unless you need it to be more accurate for some reason, are using a physics engine, or have a different good reason)

 

The stuttering could be caused if you are still trying to load data while the game loop is already running. It could have something to do with your event system to, I don't know about that one.




#5192247 Procedural Map Generation

Posted by mousetail on 11 November 2014 - 05:07 AM

Usually, the method is to first generate a few rooms, then connect them with passageways until they are all connected. The rooms can be in any place so that should be easy. For the passageways you will need to experiment with a few algorithms to find one that works. A lot I tried were either to slow or used to much memory, so the one I ended up with was based on just moving first the x then the y towards the target, and if you ran into a obstacle, only do X (or only do Y) until you are past it. This is probably not the best method, since it often fails to find a path, but its fast and avoids obstacles pretty well.

My program was in python, so I don't know if seeing my code would be helpful for you, if it is, just ask!




#5190887 Vertically scrolling underwater game, what to use as background?

Posted by mousetail on 03 November 2014 - 06:22 AM

bubles and rocks, and creatures, maybe you can have a wall on the sides that can move?




#5187300 Slow performance on A*

Posted by mousetail on 15 October 2014 - 09:40 PM

The first loop is to only grow my grid until  I have all the weights between the start point and the end point,
the second loop runs threw all the tiles to see if they have a adjacent tile with a value yet
the third loop runs threw all the adjacent tiles, and selects the smallest one to be the value of the tile. I also evaluate tiles that already have a value again for if a new route from the other direction has been generated.
 
This is what I understood from the wikipedia entry on A*, but I am not sure if I am doing it correctly. The main difference seems to be that the wikipeda formula checks for a straight line first, but I can't do that because there is allays a straight line, I just want it to avoid walls, but if there is no way to do that, it will just crash threw them. I also want it to be more likely to follow existing pathways part of the way instead of making new ones.
 
With my earlier simpler method, it would just make a straight line, right threw rooms and sometimes along walls, turning every wall piece into a door, witch looked very ugly.
 

100*weightsgrid.size*getadjacent

that is 100*10000*4=4000000 (4M), that is a pretty big number, but every nesting seems to be necessary. This is also only the maximun number, usually it will reach its destination before 100 tries, or neer the edge, getadjacent will only return 3 values, but actually it will be a full 4M most of the time.


#5187113 Slow performance on A*

Posted by mousetail on 15 October 2014 - 02:55 AM

For my level generator, I need to connect my rooms with passageways. I don't want pasageways to run straight thew other rooms, or crash straight allong walls, turning a whole row into doors, wich looks ugly, so I decided to use a more complicated algorithm to find the path for the paths:

        weightsgrid=Grid([self.rowsize, len(self.data)/self.rowsize],-1)
        weightsgrid[pointa]=1
        tries=0
        while weightsgrid[pointb]==-1 and tries<100:
            tries+=1
            for coords in weightsgrid:
                if weightsgrid[coords]>=-1:
                    posible=[]
                    if weightsgrid[coords]!=-1:
                        posible.append(weightsgrid[coords])
                    for adj in getadjacent(coords):
                        try:
                            if weightsgrid[adj]>0:
                                posible.append(weightsgrid[adj]+max(weights[self[adj]],weights[self[coords]]))
                                #print "Did SOmething"
                            else:
                                pass
                        except IndexError:
                            pass
                            #Can forget about this error since we don't care about values outside the grid
                    if len(posible)>0:
                        weightsgrid[coords]=min(posible)
        
        walkposition=tuple(pointb)
        l=None
        tries=0
        if not function:
            l=[]
            function=l.append
        while walkposition!=tuple(pointa) and tries<len(self.data):
            try:
                walkposition=min(getadjacent(walkposition),
                             key=lambda x: weightsgrid[x] if weightsgrid[x]!=-1 else 8388608)
            except IndexError:
                print walkposition
            #weightsgrid[walkposition]=8388608
            function(walkposition)
            tries+=1
            #print tries
        self.weightsgrid=weightsgrid
        return l

note that the class that generates subclasses grid, so self is also a grid object. The function works mostly well, but takes 2 or 3 seconds to run (least is 0.1 second, most is 5 seconds) and since I need to run it 19-38 times each time I generate a level, it becomes kinda unacceptable. Since I am doing this to learn, in the future I might need to use a similar system to for enemy movement, so I want to know what I am doing wrong.
 
Just in case you need it, this is the rest of my generator function:

        numrooms=len(self.data)//512
        rooms=[]
        print "0}GENERATING ROOMS"
        for i in range(numrooms):
            ok=False
            tries=0
            while not ok:
                x=random.randint(10,self.rowsize-19)
                y=random.randint(10,len(self.data)/self.rowsize-19)
                width=random.randint(8,16)
                height=random.randint(8,16)
                floormats=random.choice([(3,4),(5,6)])
                room=[x,y,width,height,floormats,Storage_Obj()]
                ok=True
                for room2 in rooms:
                    if ((room[0]<room2[0]+room2[2]+3) and #room.right>room2.x and room.x<room2.right
                        (room2[0]<room[0]+room[2]+3) and
                        (room[1]<room2[1]+room2[3]+3) and
                        (room2[1]<room[1]+room[3]+3)):
                        #print room,room2
                        ok=False
                if not ok:
                    tries+=1
                    #print "tries: ",tries
                if tries>1000:
                    print "failed after",tries,"tries"
                    break
            if tries<=1000:
                rooms.append(room)
        
        print "Len(rooms)=",len(rooms)           
            #print [x,y,width,height,floormats]
        print "0}Bordering rooms!"
        for room in rooms:
            for i in range(room[0],room[0]+room[2]+2):
                
                for j in range(room[1],room[1]+room[3]+2):
                    ok=False
                    while not ok:
                        if (i==room[0] or i==room[0]+room[2]+1 or #x position
                            j==room[1] or j==room[1]+room[3]+1):
                            self[i,j]=random.choice([1,1,1,1,1,2])
                        else:
                            self[i,j]=random.choice(room[4])
                        ok=True
        print "0}Connecting rooms!"
        timesperroom=1
        totaltimes=timesperroom*len(rooms)
        timestried=0
        lasttime=datetime.datetime.now()
        for room1 in rooms:
            room2s=[random.choice(rooms) for i in range(timesperroom)]
            for room2 in room2s:
                if room1!=room2:
                    timestried+=1
                    center1=room1[0]+room1[2]//2,room1[1]+room1[3]//2
                    center2=room2[0]+room2[2]//2,room2[1]+room2[3]//2
                    #try:
                    print "Running a*! ({0:0>2}/{1:>2}) time: {2}".format(timestried,totaltimes,datetime.datetime.now()-lasttime)
                    lasttime=datetime.datetime.now()
                    self.astar

edit: I see people don't get my problem, so I am going to post a few screen shots to show what I mean:

gamedev1.png

these are my rooms, but I need to connect them. So I run A* and I get:

gamedev2.png

this is great, except that it takes 5 minutes to run!




#5153539 Quantity over quality in a game when it comes to art - thoughts?

Posted by mousetail on 14 May 2014 - 06:15 AM

Though the background is really nice on the first picture, I would also get a better font and think about where to place those numbers. The stars could also be better.




#5117056 How to render a 2D isometric world in Python/Pygame

Posted by mousetail on 15 December 2013 - 04:27 AM

The code I used for my game is like this:

import math,pygame
class Square(object):
    def __init__(self, image, gridpos,level=0):
        self.image=image
        self.gridpos=gridpos
        self.isopos=[int(i*16) for i in gridpos]
        self.recalculateRealpos()
        
        self.level=level
    def draw(self, surface):
        pos=(self.realpos[0]+self.offset[0]+surface.get_width()/2,
             self.realpos[1]+self.offset[1])
        surface.blit(self.image,pos)
    def update(self,*args): pass
    def recalculateRealpos(self):
        self.realpos=(int((self.isopos[0]-self.isopos[1])*2),
                      int((self.isopos[0]+self.isopos[1])))
        self.offset=(-self.image.get_width()/2,-self.image.get_height()-2*self.isopos[2]+48)
    def __gt__(self, other):
        if math.ceil(self.realpos[1]/16.0)!=math.ceil(other.realpos[1]/16.0):
            return self.realpos[1]>other.realpos[1]
        else:
            return self.level>other.level
    def __lt__(self, other):
        if math.ceil(self.realpos[1]/16.0)!=math.ceil(other.realpos[1]/16.0):
            return self.realpos[1]<other.realpos[1]
        else:
            return self.level<other.level

All you need to do is sort your list of objects and it looks fine. The system also supports relative scrolling, though it got to slow for me with larger rooms. Note that my tile size here was 64*64 and you might need to switch up the numbers if you have different sizes or angles. You can download the source for my game if you want to see how it is used (see my signature)

I am not sure if this is what you are looking for, but I hope it helps.




#5060532 What an emperor of a space empire does?

Posted by mousetail on 09 May 2013 - 04:52 AM

He sits around, eats snacks and lets his governors do the work I would say, but that wouldn't make a very interesting game...




#5017071 can python be used to create professional games

Posted by mousetail on 03 January 2013 - 06:40 AM

Is it possible to create professional, commercial games with python?

If not, is there any other engine/language that is both professional, fast, and easy to use? 




#5007038 Space game ideas

Posted by mousetail on 04 December 2012 - 05:09 AM

What are you defining as a "scene"?

I mean one 'room' were you can walk around freely without having to load stop and wait for it to load new data, or teleport to new scenes with whom there is no other physical connection.


#5005683 Space game ideas

Posted by mousetail on 30 November 2012 - 07:55 AM

I am planning to make a space rpg, and i want it to be free-world(no fixed story line(but maybe a starting story at the beginning), just wandering about the universe looking for quests). I have 3 questions:
* how do I make new stars accessible only when you get better ships? something like hyperspace could allow a one-time upgrade that could take you far distances, but i want to gradually open up more groups of planets? just making them faster wont work, because you can still get there if you have patience, and users might not guess that there will be a easier way to get there, also if you are halfway, you cant go back without flying for a long time.
* how do I make a basic story for a free-world game? how do i keep it interesting, while not forcing people to follow a fixed story-line, but still get there upgrades to go to newer places in multiple ways maybe? All the free-world games i have seen are MMORPG's, do they have to be multi-player to be free-world?
*how do I make the scale of the planets good, probably I would at least have to have a separate scene for each planet, but that will be unrealistic, because everything is so much bigger on the planet then in space. also, how do I arrange a massive universe, even with 'small' planets, should i have you just zap to the next scene when you hit the wall, or maybe a hyperspace system?
any suggestions are welcomed, thanks.


PARTNERS