Exemplo n.º 1
0
def spawnEnemy():
    e= Objects.Enemy(level)
    Enemies.append(e)
    distance = Objects.calcDistance(p1,e)
    if distance < e.size+p1.size+5: 
        if e in Enemies:
            Enemies.remove(e)
            spawnEnemy()
    else:
        for g in Enemies:
            if e!=g:
                distance = Objects.calcDistance(e,g)
                if distance < e.size+g.size+5: 
                    if e in Enemies:
                        Enemies.remove(e)
                        spawnEnemy()
Exemplo n.º 2
0
def Move():
    p1.position[0] += p1.speed[0]
    p1.position[1] -= p1.speed[1]
    if p1.position[0]<150 or p1.position[0]>650 or p1.position[1]<150 or p1.position[1]>450: Die(p1)
    p1.speed[0] *= p1.decel
    p1.speed[1] *= p1.decel
    if abs(p1.speed[0])<.01: p1.speed[0] = 0
    if abs(p1.speed[1])<.01: p1.speed[1] = 0
    for e in Enemies:
        distance = Objects.calcDistance(p1, e)
        if p1.being_hit == 0 and e.being_hit==0 and distance < (p1.size+e.size-1):
            p1.being_hit = 1
            e.being_hit = 1
            calcOrientation(p1)
            calcOrientation(e)
            distance = Objects.calcDistance(p1, e)
            while distance < p1.size+e.size: 
                if p1.position[0]!=e.position[0]: 
                    e.position[0]+=.1*(e.position[0]-p1.position[0])/abs(p1.position[0]-e.position[0])*abs(e.position[0]-p1.position[0])/(abs(e.position[1]-p1.position[1])+1)
                    p1.position[0]-=.1*(e.position[0]-p1.position[0])/abs(p1.position[0]-e.position[0])*abs(e.position[0]-p1.position[0])/(abs(e.position[1]-p1.position[1])+1)
                if p1.position[1]!=e.position[1]: 
                    e.position[1]+=.1*(e.position[1]-p1.position[1])/abs(p1.position[1]-e.position[1])
                    p1.position[1]-=.1*(e.position[1]-p1.position[1])/abs(p1.position[1]-e.position[1])
                distance = Objects.calcDistance(p1, e)
            calcFinalSpeeds(p1, e)

    for i in range(len(Enemies)):
        try:
            if Enemies[i].alive==True:
                e = Enemies[i]
                if level>1:
                    if i==3:
                        e.goal[0] = p1.position[0]
                        e.goal[1] = p1.position[1]
                    else:
                        while abs(e.position[0]-e.goal[0])<3: e.goal[0] = randint(e.goalLimits[0],e.goalLimits[2])
                        while abs(e.position[1]-e.goal[1])<3: e.goal[1] = randint(e.goalLimits[1],e.goalLimits[3])
                    e.speed[0] -= e.accel * (e.position[0]-e.goal[0])/abs(e.position[0]-e.goal[0])
                    e.speed[1] += e.accel * (e.position[1]-e.goal[1])/abs(e.position[1]-e.goal[1])
                e.position[0] += e.speed[0]
                e.position[1] -= e.speed[1]
                if e.position[0]<150 or e.position[0]>650 or e.position[1]<150 or e.position[1]>450: Die(e)
                e.speed[0] *= e.decel
                e.speed[1] *= e.decel
                if abs(e.speed[0])<.01: e.speed[0] = 0
                if abs(e.speed[1])<.01: e.speed[1] = 0
                for j in range(i,len(Enemies)):
                    try:
                        if Enemies[j].alive==True:
                            g = Enemies[j]
                        if e!=g:
                            distance = Objects.calcDistance(e,g)
                            if e.being_hit == 0 and g.being_hit==0 and distance < (e.size+g.size):
                                e.being_hit = 1
                                g.being_hit = 1
                                calcOrientation(e)
                                calcOrientation(g)
                                distance = Objects.calcDistance(e, g)
                                while distance < e.size+g.size: 
                                  if e.position[0]!=g.position[0]:
                                    e.position[0]+=.5*(e.position[0]-g.position[0])/abs(e.position[0]-g.position[0])
                                  if e.position[1]!=g.position[1]: 
                                    e.position[1]+=.5*(e.position[1]-g.position[1])/abs(g.position[1]-e.position[1])
                                  distance = Objects.calcDistance(e, g)
                                calcFinalSpeeds(e, g)
                    except: continue
        except: continue