def update(towers): import GUI global scalar global themap global end global blocks_per_side global monsters global bullets global rects_to_replace global mpath for rect in rects_to_replace: GUI.make_rect((rect[0]//scalar)*scalar,(rect[1]//scalar)*scalar,rect[2]) monsters_past = [] rects_to_replace = [] for index,monster in enumerate(monsters): #Directions: 0 = left, 1 = up, 2 = right, 3 = down moves = monster.is_move_time() cover_thing(monster,[1]) for i in xrange(moves): x,y = monster.get_pos() pathindex = monster.get_pathindex() if pathindex >= len(mpath): print "A monster got past! One lifepoint down!" monsters_past.append(index) break direction = mpath[pathindex] monster.move() if direction == 0: x -= 1 elif direction == 1: y -= 1 elif direction == 2: x += 1 elif direction == 3: y += 1 monsters[index].set_pos(x,y) monsters[index].set_prev_direction(direction) monster.set_pos(x,y) monster.set_prev_direction(direction) GUI.draw_monster(monster) for index in reversed(monsters_past): del monsters[index] for tower in towers: if not tower.is_time_to_shoot(): continue target = 0 tax = 0 tay = 0 trange = tower.get_range() walked = 0 for monster in monsters: mx,my = monster.get_pos() tx,ty = tower.get_pos() xoff,yoff = monster.get_offset() mx += xoff my += yoff tx *= scalar ty *= scalar tx += scalar/2 ty += scalar/2 distance = getdistance(mx,my,tx,ty) moved = monster.get_pxmoved() if distance <= trange and moved > walked: target = monster walked = moved tax = tx tay = ty if target == 0: continue tower.shot() bullet = Bullet.Bullet(tax,tay,target,tower.get_bullet_speed(),tower.get_damage()) bullets.append(bullet) bullets_to_remove = [] for index,bullet in enumerate(bullets): cover_thing(bullet,[0,1,2,3,4,5,6,7,8,9,10,11]) target = bullet.get_target() if not target in monsters: bullets_to_remove.append(index) continue tx,ty = target.get_pos() xoff,yoff = target.get_offset() tx += xoff ty += yoff speed = bullet.get_speed() for i in xrange(speed): bx,by = bullet.get_pos() if bx == tx and by == ty: bullets_to_remove.append(index) kill = target.hit(bullet.get_damage()) if kill: remove_monster(target) break if bx > tx: bx -= 1 if bx < tx: bx += 1 if by > ty: by -= 1 if by < ty: by += 1 bullet.set_pos(bx,by) bullets[index].set_pos(bx,by) GUI.draw_bullet(bullet) for index in reversed(bullets_to_remove): del bullets[index] rects_to_replace = list(set(rects_to_replace))