def cball_loop(g, s): try: s.rect.x += s.vx except AttributeError: return s.rect.y += s.vy s.z += s.vz s.vz += 1 if s.vz == 8: if s in g.sprites: g.sprites.remove(s) img_name = get_hole_for_damage(s.damage) g.bkgr_blit(g.images[img_name], (s.rect.centerx, s.rect.centery)) g.level.game.sm.Play(sound_info.hitground.nextone(), wait=3) if HOLES_ARE_TILES: tw, th = g.iso_w, g.iso_h tx, ty = s.rect.centerx / tw, s.rect.centery / th dirs = [(0, 0)] if HOLES_ARE_TILES > 1: dirs.extend([(-1, 0), (1, 0), (0, 1), (0, -1)]) for dx, dy in dirs: xx, yy = tx + dx, ty + dy v = g.get((xx, yy)) if v in (0, 7): g.set((xx, yy), 30) #ss = effect.effect_new(g,s.rect,steam.Effect(20,20,8,0,(117,110,94)),20) num_steam, num_steam_add = s.num_steam, s.num_steam_add ss = effect.effect_new( g, s.rect, steam.Effect(int(num_steam * 2), int(num_steam_add * 2), num_steam_add, 0, (0, 0, 0)), 20) ss.z = 8 print 'gahhh' a = s for r in g.robots: rx, ry = r.x, r.y ax, ay = a.rect.x, a.rect.y dx, dy = rx - ax, ry - ay dist = (dx * dx + dy * dy)**0.5 if dist and dist < 32 * 4: r.min = min(r._min, r.min + 12.0) inc = 31.0 x, y = rx + dx * inc / dist, ry + dy * inc / dist robot.robot_shove(g, r, (x, y)) if dist < 32 * 3: #1.5: r.state = 'dead' #print s.rect s.frame += 1
def cball_loop(g,s): try: s.rect.x += s.vx except AttributeError: return s.rect.y += s.vy s.z += s.vz s.vz += 1 if s.vz == 8: if s in g.sprites: g.sprites.remove(s) img_name = get_hole_for_damage(s.damage) g.bkgr_blit(g.images[img_name],(s.rect.centerx,s.rect.centery)) g.level.game.sm.Play(sound_info.hitground.nextone(), wait=3) if HOLES_ARE_TILES: tw,th = g.iso_w,g.iso_h tx,ty = s.rect.centerx/tw,s.rect.centery/th dirs = [(0,0)] if HOLES_ARE_TILES > 1: dirs.extend([(-1,0),(1,0),(0,1),(0,-1)]) for dx,dy in dirs: xx,yy = tx+dx,ty+dy v = g.get((xx,yy)) if v in (0,7): g.set((xx,yy),30) #ss = effect.effect_new(g,s.rect,steam.Effect(20,20,8,0,(117,110,94)),20) num_steam, num_steam_add = s.num_steam, s.num_steam_add ss = effect.effect_new(g,s.rect,steam.Effect(int(num_steam*2), int(num_steam_add*2),num_steam_add,0,(0,0,0)),20) ss.z = 8 print 'gahhh' a = s for r in g.robots: rx,ry = r.x,r.y ax,ay = a.rect.x,a.rect.y dx,dy = rx-ax,ry-ay dist = (dx*dx+dy*dy)**0.5 if dist and dist < 32*4: r.min = min(r._min,r.min+12.0) inc = 31.0 x,y = rx + dx*inc/dist, ry + dy*inc/dist robot.robot_shove(g,r,(x,y)) if dist < 32*3: #1.5: r.state = 'dead' #print s.rect s.frame += 1
def cball_hit_old(g,a_cannon_ball,b): ss = effect.effect_new(g,b.rect,steam.Effect(60,20,4,0),20) # lets hit the unit, and see if it dies. if b.unit.hit(a_cannon_ball.damage): g.level.game.sm.Play(sound_info.destroyenemy.nextone()) # if b.unit.name == "factory": # g.level.game.state = states.NextLevel(g.level.game, g.level.game.state) # print "you won!" # return if b in g.sprites: g.sprites.remove(b) img_name = get_hole_for_damage(a_cannon_ball.damage) g.bkgr_blit(g.images[img_name],(a_cannon_ball.rect.centerx,a_cannon_ball.rect.centery)) #do an explosion here... #that looks like... ss = effect.effect_new(g,b.rect,SpriteBlast(),20) else: # we only play the hit sound if the thing doesn't die? g.level.game.sm.Play(sound_info.hitenemy.nextone()) try: g.sprites.remove(a_cannon_ball) except ValueError: # already removed??? yeah that happens :) # if the ball hits more than one tile pass print "hit!", b.unit.name pass
def cball_hit_old(g, a_cannon_ball, b): ss = effect.effect_new(g, b.rect, steam.Effect(60, 20, 4, 0), 20) # lets hit the unit, and see if it dies. if b.unit.hit(a_cannon_ball.damage): g.level.game.sm.Play(sound_info.destroyenemy.nextone()) # if b.unit.name == "factory": # g.level.game.state = states.NextLevel(g.level.game, g.level.game.state) # print "you won!" # return if b in g.sprites: g.sprites.remove(b) img_name = get_hole_for_damage(a_cannon_ball.damage) g.bkgr_blit(g.images[img_name], (a_cannon_ball.rect.centerx, a_cannon_ball.rect.centery)) #do an explosion here... #that looks like... ss = effect.effect_new(g, b.rect, SpriteBlast(), 20) else: # we only play the hit sound if the thing doesn't die? g.level.game.sm.Play(sound_info.hitenemy.nextone()) try: g.sprites.remove(a_cannon_ball) except ValueError: # already removed??? yeah that happens :) # if the ball hits more than one tile pass print "hit!", b.unit.name pass
def tile_wall(g,t,s): #when hit, this cracks if s not in g.sprites: return g.sprites.remove(s) g.level.game.sm.Play(sound_info.hitwall.nextone()) tx,ty = t.tx,t.ty for a,dx,dy in [(2,0,0),(1,-1,0),(1,1,0),(1,0,1),(1,0,-1)]: v = g.get((tx+dx,ty+dy)) if v in (4,5,6): v = min(7,v + a) g.set((tx+dx,ty+dy),v) import effect tw,th = g.iso_w,g.iso_h e = effect.effect_new(g,pygame.Rect(t.tx*tw+tw/2,t.ty*th+th/2,1,1),WallBlast(),20) e.z = s.z+16
def tile_wall(g, t, s): #when hit, this cracks if s not in g.sprites: return g.sprites.remove(s) g.level.game.sm.Play(sound_info.hitwall.nextone()) tx, ty = t.tx, t.ty for a, dx, dy in [(2, 0, 0), (1, -1, 0), (1, 1, 0), (1, 0, 1), (1, 0, -1)]: v = g.get((tx + dx, ty + dy)) if v in (4, 5, 6): v = min(7, v + a) g.set((tx + dx, ty + dy), v) import effect tw, th = g.iso_w, g.iso_h e = effect.effect_new( g, pygame.Rect(t.tx * tw + tw / 2, t.ty * th + th / 2, 1, 1), WallBlast(), 20) e.z = s.z + 16
def cball_new(g, pos, dest, damage=1.0, pressure=16): #g.level.game.sm.Play(random.choice(sound_info.cannon)) #g.level.game.sm.Play(sound_info.cannon.nextone()) if pressure < 9: g.level.game.sm.Play(sound_info.cannon[0], wait=3) print "cannon 1 sound" elif pressure >= 9 and pressure < 15: g.level.game.sm.Play(sound_info.cannon[1], wait=3) print "cannon 2 sound" elif pressure >= 15 and pressure < 25: g.level.game.sm.Play(sound_info.cannon[2], wait=3) print "cannon 3 sound" elif pressure >= 25: print "cannon 4 sound, two cannon 3 sounds played at once." g.level.game.sm.Play(sound_info.cannon[2], wait=3) g.level.game.sm.Play(sound_info.cannon[2], wait=3) # Here we use a different graphic for the cannon balls depending on Damage. if damage <= 1.: img_name = 'cball' num_steam, num_steam_add = 20, 5 elif damage > 1. and damage < 4.: img_name = 'cball2' num_steam, num_steam_add = 30, 10 elif damage >= 4. and damage < 6.: img_name = 'cball3' num_steam, num_steam_add = 25, 15 elif damage >= 6. and damage < 8.: img_name = 'cball4' num_steam, num_steam_add = 35, 20 elif damage >= 8. and damage < 10.: img_name = 'cball4' num_steam, num_steam_add = 42, 23 elif damage >= 10.: img_name = 'cball4' num_steam, num_steam_add = 50, 25 s = isovid.Sprite(g.images[img_name], pos) # we assign the damage that is done by this cannon ball. s.damage = damage s.num_steam, s.num_steam_add = num_steam, num_steam_add s.frame = 0 g.sprites.append(s) s.loop = cball_loop s.hit = cball_hit s.groups = g.string2groups("cball") s.agroups = g.string2groups("robot,cannon") #,factory,truck,cannon") #s.rect, s._rect dx, dy = dest[0] - s.rect.x, dest[1] - s.rect.y dist = (dx * dx + dy * dy)**0.5 if dist <= 0: return v = float(pressure) s.vx, s.vy = dx * v / dist, dy * v / dist s.vz = -5 s.z = 0 # we add a steam effect for when firing the cannon ball. # It's steamyness is different depending on the damage of the cannon. rect = pygame.Rect(s.rect) rect.x += s.vx * 2 rect.y += s.vy * 2 effect.effect_new( g, rect, steam.Effect(num_steam, num_steam_add, 12, 0, (255, 255, 255)), 20)
def cball_new(g,pos,dest, damage = 1.0,pressure=16): #g.level.game.sm.Play(random.choice(sound_info.cannon)) #g.level.game.sm.Play(sound_info.cannon.nextone()) if pressure < 9: g.level.game.sm.Play(sound_info.cannon[0], wait=3) print "cannon 1 sound" elif pressure >= 9 and pressure < 15: g.level.game.sm.Play(sound_info.cannon[1], wait=3) print "cannon 2 sound" elif pressure >= 15 and pressure < 25: g.level.game.sm.Play(sound_info.cannon[2], wait=3) print "cannon 3 sound" elif pressure >= 25: print "cannon 4 sound, two cannon 3 sounds played at once." g.level.game.sm.Play(sound_info.cannon[2], wait=3) g.level.game.sm.Play(sound_info.cannon[2], wait=3) # Here we use a different graphic for the cannon balls depending on Damage. if damage <= 1.: img_name = 'cball' num_steam, num_steam_add = 20, 5 elif damage > 1. and damage < 4.: img_name = 'cball2' num_steam, num_steam_add = 30, 10 elif damage >= 4. and damage < 6.: img_name = 'cball3' num_steam, num_steam_add = 25, 15 elif damage >= 6. and damage < 8.: img_name = 'cball4' num_steam, num_steam_add = 35, 20 elif damage >= 8. and damage < 10.: img_name = 'cball4' num_steam, num_steam_add = 42, 23 elif damage >= 10.: img_name = 'cball4' num_steam, num_steam_add = 50, 25 s = isovid.Sprite(g.images[img_name],pos) # we assign the damage that is done by this cannon ball. s.damage = damage s.num_steam, s.num_steam_add = num_steam, num_steam_add s.frame = 0 g.sprites.append(s) s.loop = cball_loop s.hit = cball_hit s.groups = g.string2groups("cball") s.agroups = g.string2groups("robot,cannon") #,factory,truck,cannon") #s.rect, s._rect dx,dy = dest[0]-s.rect.x,dest[1]-s.rect.y dist = (dx*dx+dy*dy)**0.5 if dist <= 0: return v = float(pressure) s.vx, s.vy = dx*v/dist,dy*v/dist s.vz = -5 s.z = 0 # we add a steam effect for when firing the cannon ball. # It's steamyness is different depending on the damage of the cannon. rect = pygame.Rect(s.rect) rect.x += s.vx*2 rect.y += s.vy *2 effect.effect_new(g,rect,steam.Effect(num_steam,num_steam_add,12,0,(255,255,255)),20)