From: <ob...@us...> - 2007-10-20 21:41:30
|
Revision: 302 http://eos-game.svn.sourceforge.net/eos-game/?rev=302&view=rev Author: oberon7 Date: 2007-10-20 14:41:24 -0700 (Sat, 20 Oct 2007) Log Message: ----------- Incremental progress on networked multiplayer. Rudimentary support for all bodies except FlakBombs. Modified Paths: -------------- body.py game.py net.py projectile.py sprite.py staticbody.py vessel.py Modified: body.py =================================================================== --- body.py 2007-10-20 20:06:37 UTC (rev 301) +++ body.py 2007-10-20 21:41:24 UTC (rev 302) @@ -93,13 +93,13 @@ self.on_screen = True self.explosion = None self.apparent_size = None - game.objects[net_id] = self self.net_id = net_id self.image_name = image_name + game.objects.add(self) def get_state(self): return { - 'create_func' : 'body.RoundBody', + 'classname' : self.__class__.__name__, 'create_kw' : {'net_id' : self.net_id}, 'position' : self.get_position(), 'velocity' : self.get_velocity(), @@ -279,8 +279,6 @@ if game.collision_space.query(self.geom): game.collision_space.remove(self.geom) self.body.disable() - if self.net_id in game.objects: # FIXME - del game.objects[self.net_id] def push(self, force): """Apply the force vector to the body for this frame""" Modified: game.py =================================================================== --- game.py 2007-10-20 20:06:37 UTC (rev 301) +++ game.py 2007-10-20 21:41:24 UTC (rev 302) @@ -34,7 +34,7 @@ frame_no = 0 # current frame number server = None client = None -objects = {} +objects = sprite.NetGroup() local_player = None starfield = None camera = None Modified: net.py =================================================================== --- net.py 2007-10-20 20:06:37 UTC (rev 301) +++ net.py 2007-10-20 21:41:24 UTC (rev 302) @@ -5,19 +5,23 @@ # Multiplayer networking # $Id$ +import ai import body import game import marshal +import projectile import pygame import random import select import socket import SocketServer +import staticbody import struct import threading import time import vessel + class SocketCommunicator: control_fmt = '!l' @@ -75,8 +79,8 @@ def get_game_state(self): game_state = {} - for net_id, object in game.objects.items(): - game_state[net_id] = object.get_state() + for object in game.objects: + game_state[object.net_id] = object.get_state() return game_state def set_client_state(self, client_state): @@ -113,15 +117,32 @@ self.server_generation = None def create_object(self, object_state): - if object_state['create_func'] == 'body.RoundBody': - cls = body.RoundBody - elif object_state['create_func'] == 'vessel.Vessel.load': - cls = vessel.Vessel.load + if object_state['classname'] == 'Shot': + create_func = projectile.Shot + elif object_state['classname'] == 'ExplodingShot': + create_func = projectile.ExplodingShot + elif object_state['classname'] == 'PhaseDisruptorShot': + create_func = projectile.PhaseDisruptorShot + elif object_state['classname'] == 'Rocket': + create_func = projectile.Rocket + elif object_state['classname'] == 'Missile': + create_func = projectile.Missile + elif object_state['classname'] == 'Fullerene': + create_func = projectile.Fullerene + elif object_state['classname'] == 'FlakBomb': + return None # TODO + create_func = projectile.FlakBomb + elif object_state['classname'] == 'AIVessel': + create_func = ai.AIVessel.load + elif object_state['classname'] == 'Vessel': + create_func = vessel.Vessel.load + elif object_state['classname'] == 'Planet': + create_func = staticbody.Planet else: - raise ValueError, `object_state['create_func']` + raise ValueError, `object_state['classname']` args = object_state.get('create_args', tuple()) kw = object_state.get('create_kw', dict()) - return cls(*args, **kw) + return create_func(*args, **kw) def get_client_state(self, keystate): return game.local_player.net_id, game.local_player.vessel_class, keystate @@ -132,12 +153,19 @@ object = game.objects.get(net_id) if object is None: # create objects - object = self.create_object(object_state) - object.set_local_state(object_state) + try: + object = self.create_object(object_state) + except AssertionError, e: + # FIXME: flak shards reference their shooter, but there + # shooter doesn't exist (since that's the original FlakBomb) + print e + object = None + if object is not None: + object.set_local_state(object_state) # destroy objects - for net_id in game.objects.keys(): - if net_id not in game_state: - game.objects[net_id].kill() + for object in game.objects: + if object.net_id not in game_state: + object.kill() def step(self, keystate): self.send(self.server, self.server_generation, self.client_generation, self.get_client_state(keystate)) Modified: projectile.py =================================================================== --- projectile.py 2007-10-20 20:06:37 UTC (rev 301) +++ projectile.py 2007-10-20 21:41:24 UTC (rev 302) @@ -94,14 +94,17 @@ exploding = False layer = sprite.layers.effects - def __init__(self, charge, gunmount): + def __init__(self, charge, gunmount, net_id=None): self.mass = charge self.radius = max(charge, 1) - RoundBody.__init__( - self, gunmount.position, - vector.unit(gunmount.heading) * self.speed + gunmount.velocity, - collides_with=everything & ~gunmount.category - ) + if gunmount is None: + RoundBody.__init__(self, net_id=net_id) + else: + RoundBody.__init__( + self, gunmount.position, + vector.unit(gunmount.heading) * self.speed + gunmount.velocity, + collides_with=everything & ~gunmount.category, + net_id=net_id) self.charge = charge self.distance = 0 self.distance_per_frame = self.speed / game.fps @@ -112,7 +115,12 @@ self.step = range(self.particles) self.colormax = 255 media.play_sound('fullerene.wav', position=self.position) - + + def get_state(self): + state = RoundBody.get_state(self) + state['create_args'] = (self.charge, None) + return state + def clear(self): display.surface.fill((0,0,0), self.rect) @@ -328,7 +336,7 @@ layer = sprite.layers.effects def __init__(self, shooter, image, damage, velocity, position=None, heading=None, - range=None, max_ttl=None, fade_range=None, damage_loss=0, radius=1, mass=0.1): + range=None, max_ttl=None, fade_range=None, damage_loss=0, radius=1, mass=0.1, net_id=None): """Generic projectile shot shooter -- body that fired the shot @@ -342,12 +350,16 @@ damage_loss -- Reduction in damage at max range radius -- shot collision radius """ + if type(shooter) is int: + shooter_net_id = shooter + shooter = game.objects.get(shooter_net_id) + assert shooter is not None, 'Could not find shooter: %d' % shooter_net_id self.radius = radius self.mass = mass RoundBody.__init__(self, position or shooter.position, shooter.velocity + velocity, heading, collides_with=everything & ~shooter.category, - image_name=image) + image_name=image, net_id=net_id) self.shooter = shooter self.start_position = position or shooter.position self.damage_value = self.start_damage = damage @@ -363,6 +375,11 @@ self.damage_loss = damage_loss / flight_time / game.fps else: self.damage_loss = 0 + + def get_state(self): + state = RoundBody.get_state(self) + state['create_args'] = (self.shooter.net_id, self.image_name, self.start_damage, vector.vector2()) + return state def clear(self): display.surface.fill((0,0,0), self.rect) @@ -381,7 +398,7 @@ self.image.set_alpha(255) if self.max_time is not None and game.time > self.max_time: self.out_of_range() - + out_of_range = RoundBody.kill def collide(self, other, contacts): @@ -444,7 +461,12 @@ self.bomb_bay = bomb_bay self.detonating = False self.target = getattr(self.shooter.control.target, 'sprite', None) - + + def get_state(self): + state = RoundBody.get_state(self) + state['create_args'] = (self.shooter.net_id, self.start_damage, vector.vector2()) + return state + def update(self): Shot.update(self) if (not self.detonating and isinstance(self.shooter, ai.AIVessel) @@ -568,13 +590,18 @@ """Unguided, dumb self propelled rocket""" def __init__(self, shooter, heading, image, damage, mass, length, thrust, max_turn_rate, - max_velocity, max_ttl, position=None, radius=1, target=None): + max_velocity, max_ttl, position=None, radius=1, target=None, net_id=None): ExplodingShot.__init__( self, shooter, image, damage, vector.vector2(), position, heading, - max_ttl=max_ttl, radius=radius, mass=mass) + max_ttl=max_ttl, radius=radius, mass=mass, net_id=net_id) self.max_velocity = float(max_velocity) self.thrust_vector = vector.unit(heading) * float(thrust) * 100 - self.image = self.src_image # XXX Bug + + def get_state(self): + state = ExplodingShot.get_state(self) + thrust = vector.length(self.thrust_vector) / 100 + state['create_args'] = (self.shooter.net_id, self.get_heading(), self.image_name, self.start_damage, self.mass, None, thrust, None, self.max_velocity, None) + return state def update(self): ExplodingShot.update(self) @@ -589,10 +616,10 @@ """Guided, self propelled missile""" def __init__(self, shooter, heading, image, damage, mass, length, thrust, max_turn_rate, - max_velocity, max_ttl, position=None, radius=1, target=None): + max_velocity, max_ttl, position=None, radius=1, target=None, net_id=None): ExplodingShot.__init__( self, shooter, image, damage, vector.vector2(), position, heading, - max_ttl=max_ttl, radius=radius, mass=mass) + max_ttl=max_ttl, radius=radius, mass=mass, net_id=net_id) self.target = pygame.sprite.GroupSingle(target) self.max_velocity = float(max_velocity) self.max_turn_rate = float(max_turn_rate) @@ -609,7 +636,12 @@ opacity=200, emit_rate=100, thrust_velocity=200.0) - + + def get_state(self): + state = ExplodingShot.get_state(self) + state['create_args'] = (self.shooter.net_id, self.get_heading(), self.image_name, self.start_damage, self.mass, None, self.thrust / 100, self.max_turn_rate, self.max_velocity, None) + return state + def update(self): ExplodingShot.update(self) if self.explosion is None: Modified: sprite.py =================================================================== --- sprite.py 2007-10-20 20:06:37 UTC (rev 301) +++ sprite.py 2007-10-20 21:41:24 UTC (rev 302) @@ -107,6 +107,25 @@ self._activesprites.insert(0, sprite) +class NetGroup(pygame.sprite.AbstractGroup): + + def __init__(self): + pygame.sprite.AbstractGroup.__init__(self) + self._by_net_id = {} + + def add_internal(self, sprite): + pygame.sprite.AbstractGroup.add_internal(self, sprite) + assert hasattr(sprite, 'net_id'), sprite.__class__.__name__ + self._by_net_id[sprite.net_id] = sprite + + def remove_internal(self, sprite): + del self._by_net_id[sprite.net_id] + pygame.sprite.AbstractGroup.remove_internal(self, sprite) + + def get(self, *args, **kw): + return self._by_net_id.get(*args, **kw) + + class SpriteLayers: """Sprite layer manager""" Modified: staticbody.py =================================================================== --- staticbody.py 2007-10-20 20:06:37 UTC (rev 301) +++ staticbody.py 2007-10-20 21:41:24 UTC (rev 302) @@ -22,8 +22,8 @@ base = None # Established planetary base layer = sprite.layers.background - def __init__(self, name, image, x=0, y=0, resources=0): - RoundBody.__init__(self, position=(int(x), int(y)), heading=-vector.rightangle) + def __init__(self, name, image, x=0, y=0, resources=0, net_id=None): + RoundBody.__init__(self, position=(int(x), int(y)), heading=-vector.rightangle, net_id=net_id) self.body.disable() # immobile self.name = name self.image_name = random.choice(image.split(',')) @@ -32,6 +32,11 @@ self.resources = float(resources) self.update() + def get_state(self): + state = RoundBody.get_state(self) + state['create_args'] = (self.name, self.image_name) + return state + def update(self): RoundBody.update(self) if self.base is not None: Modified: vessel.py =================================================================== --- vessel.py 2007-10-20 20:06:37 UTC (rev 301) +++ vessel.py 2007-10-20 21:41:24 UTC (rev 302) @@ -177,7 +177,6 @@ self._repair_time = None self.damage_time = 0 self.race = race - self.state_history = [] @classmethod def load(cls, config_file, **kw): @@ -272,7 +271,6 @@ def get_state(self): state = body.RoundBody.get_state(self) - state['create_func'] = 'vessel.Vessel.load' state['create_kw']['config_file'] = self.config_file return state @@ -692,7 +690,7 @@ timeout = 1500 # millis shields stay active def __init__(self, vessel, max_level, regeneration, image=None): - sprite.Sprite.__init__(self, vessel.groups()) + sprite.Sprite.__init__(self, vessel.layer) self.vessel = vessel self.max_level = self.level = float(max_level) self.regeneration = self.max_regeneration = float(regeneration) @@ -899,7 +897,7 @@ mass_factor = 0.005 # Mass per durability unit per ship length unit def __init__(self, vessel, durability, dissipation=0, image=None, regeneration=0): - sprite.Sprite.__init__(self, vessel.groups()) + sprite.Sprite.__init__(self, vessel.layer) if image is not None: self.armor_img = image else: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cd...@us...> - 2007-10-21 05:41:34
|
Revision: 305 http://eos-game.svn.sourceforge.net/eos-game/?rev=305&view=rev Author: cduncan Date: 2007-10-20 22:41:31 -0700 (Sat, 20 Oct 2007) Log Message: ----------- - off-screen pointies are now rendered in code rather than in fixed images - Scale pointies properly for different resolutions - Fix naree shield tranparency, positioning and jitter Modified Paths: -------------- art/naree/shield.xcf body.py data/cress-shield.png data/gnat-shield.png data/lotus-shield.png game.py media.py staticbody.py vessel.py Removed Paths: ------------- data/pointy-blue.gif data/pointy-green.gif data/pointy-red.gif Modified: art/naree/shield.xcf =================================================================== (Binary files differ) Modified: body.py =================================================================== --- body.py 2007-10-21 03:08:08 UTC (rev 304) +++ body.py 2007-10-21 05:41:31 UTC (rev 305) @@ -143,9 +143,9 @@ self.category = category self.collides_with = collides_with if game.local_player and self.category & game.local_player.category: - self.offscreen_img = 'pointy-green.gif' + self.offscreen_img = 'pointy-green' elif self.category: - self.offscreen_img = 'pointy-red.gif' + self.offscreen_img = 'pointy-red' def __del__(self): if self.geom is not None and game.collision_space.query(self.geom): @@ -169,8 +169,7 @@ sinh = math.sin(h) cosh = math.cos(h) # create rotation matrix in the Z-axis - self.body.setRotation( - (cosh, -sinh, 0, sinh, cosh, 0, 0, 0, 1)) + self.body.setRotation((cosh, -sinh, 0, sinh, cosh, 0, 0, 0, 1)) self.heading = h def _turn_rate_fget(self): @@ -211,7 +210,7 @@ distance = vector.distance(self.position, camera_pos) if distance < self.max_visible_dist and self.position != camera_pos: angle = vector.radians(self.position - camera_pos) - image = media.image(self.offscreen_img, angle, game.camera.base_scale) + image = media.image(self.offscreen_img, game.camera.base_scale, angle) rect = image.get_rect(center=self.rect.center) x, y = vector.to_tuple(self.position) if self.rect.top < display.rect.top: Modified: data/cress-shield.png =================================================================== (Binary files differ) Modified: data/gnat-shield.png =================================================================== (Binary files differ) Modified: data/lotus-shield.png =================================================================== (Binary files differ) Deleted: data/pointy-blue.gif =================================================================== (Binary files differ) Deleted: data/pointy-green.gif =================================================================== (Binary files differ) Deleted: data/pointy-red.gif =================================================================== (Binary files differ) Modified: game.py =================================================================== --- game.py 2007-10-21 03:08:08 UTC (rev 304) +++ game.py 2007-10-21 05:41:31 UTC (rev 305) @@ -84,6 +84,7 @@ # Load resources media.preload_images('data/*.png') media.preload_images('data/*.gif') + media.create_images() media.LargeExplosion.preload_images() media.SmallExplosion.preload_images() @@ -105,8 +106,8 @@ import math font = pygame.font.Font('fonts/forgottenfuturist/Forgotbi.ttf', 24) title_image = font.render('Select Ship', True, (255, 255, 255)) - left_arrow = media.image('pointy-green.gif', rotation=math.pi, colorkey=True) - right_arrow = media.image('pointy-green.gif', rotation=0, colorkey=True) + left_arrow = media.image('pointy-green', rotation=math.pi, colorkey=True) + right_arrow = media.image('pointy-green', rotation=0, colorkey=True) choice = 0 rot = -math.pi / 2 while ship is None: Modified: media.py =================================================================== --- media.py 2007-10-21 03:08:08 UTC (rev 304) +++ media.py 2007-10-21 05:41:31 UTC (rev 305) @@ -53,7 +53,11 @@ image.set_colorkey(transparent, RLEACCEL) return image +def set_image(name, image): + global _images + _images[name] = (image, image.get_rect().width) + class Cache: """Simple, fast, bounded cache that gives approximate MRU behavior""" @@ -192,6 +196,19 @@ image_glob = 'data/proton-grenade/*.png' +def create_images(): + def pointy_image(color): + pointy = pygame.Surface((160, 190), SRCALPHA, 32) + pygame.draw.polygon(pointy, color, [(0, 190), (80, 0), (160, 190)]) + color = pygame.color.subtract(color, 60) + pygame.draw.polygon(pointy, color, [(0, 190), (80, 0), (160, 190)], 15) + pygame.draw.circle(pointy, color, (80, 215), 85) + pygame.draw.circle(pointy, (0, 0, 0, 0), (80, 230), 85) + return pygame.transform.rotozoom(pointy, 0, 0.1) + set_image('pointy-blue', pointy_image((55, 80, 216))) + set_image('pointy-green', pointy_image((0, 155, 38))) + set_image('pointy-red', pointy_image((216, 36, 30))) + _sound_cache = {} _sound_last_played = {} Modified: staticbody.py =================================================================== --- staticbody.py 2007-10-21 03:08:08 UTC (rev 304) +++ staticbody.py 2007-10-21 05:41:31 UTC (rev 305) @@ -27,7 +27,7 @@ self.body.disable() # immobile self.name = name self.image_name = random.choice(image.split(',')) - self.offscreen_img = 'pointy-blue.gif' + self.offscreen_img = 'pointy-blue' self.collision_radius = self.radius = media.image(self.image_name).get_rect().width / 2 self.resources = float(resources) self.update() Modified: vessel.py =================================================================== --- vessel.py 2007-10-21 03:08:08 UTC (rev 304) +++ vessel.py 2007-10-21 05:41:31 UTC (rev 305) @@ -759,7 +759,7 @@ if self.time - game.time <= self.fadeout: opacity *= (self.time - game.time) / self.fadeout image.set_alpha(max(opacity - flicker, 10)) - shield_rect = image.get_rect(center=vector.to_tuple(pos)) + shield_rect = image.get_rect(center=self.vessel.rect.center) dirty = surface.blit(image, shield_rect) return dirty else: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cd...@us...> - 2007-10-23 06:30:50
|
Revision: 309 http://eos-game.svn.sourceforge.net/eos-game/?rev=309&view=rev Author: cduncan Date: 2007-10-22 23:30:48 -0700 (Mon, 22 Oct 2007) Log Message: ----------- - Different offscreen pointies for planets - Select planets using "p" to cycle through (click-select is next) Modified Paths: -------------- base.py body.py event.py media.py selection.py staticbody.py Modified: base.py =================================================================== --- base.py 2007-10-21 18:35:47 UTC (rev 308) +++ base.py 2007-10-23 06:30:48 UTC (rev 309) @@ -50,6 +50,10 @@ self.planet = planet self.planet.base = self self.owner = owner + if owner is game.local_player: + planet.offscreen_img = 'pointy-planet-green' + else: + planet.offscreen_img = 'pointy-planet-red' self.rally_point = self.planet if max_level >= level: self.level = level Modified: body.py =================================================================== --- body.py 2007-10-21 18:35:47 UTC (rev 308) +++ body.py 2007-10-23 06:30:48 UTC (rev 309) @@ -25,6 +25,7 @@ friend = 1 foe = 2 shot = 4 +planet = 8 nothing = 0 everything = 0x7fffffff categories = (friend, foe) @@ -92,7 +93,7 @@ self.enabled = True self.on_screen = True self.explosion = None - self.apparent_size = None + self.apparent_size = 1.0 self.net_id = net_id self.image_name = image_name game.objects.add(self) @@ -186,11 +187,11 @@ self.velocity = vector.vector2(*self.body.getLinearVel()[:2]) self.heading = self.get_heading() # place self relative to the camera at proper zoom level - apparent_size, screen_pos = vector.to_screen(self.position) + self.apparent_size, screen_pos = vector.to_screen(self.position) if self.explosion is None: - self.image = media.image(self.image_name, apparent_size, self.heading) + self.image = media.image(self.image_name, self.apparent_size, self.heading) else: - image = self.explosion.next_image(apparent_size) + image = self.explosion.next_image(self.apparent_size) if image is not None: self.image = image else: @@ -201,6 +202,7 @@ def draw(self, surface): """Draw either sprite image or offscreen pointer""" if self.on_screen: + #pygame.draw.circle(surface, (255,255,255), self.rect.center, self.collision_radius * self.appsz, 2) surface.blit(self.image, self.rect) return self.rect elif self.offscreen_img is not None: Modified: event.py =================================================================== --- event.py 2007-10-21 18:35:47 UTC (rev 308) +++ event.py 2007-10-23 06:30:48 UTC (rev 309) @@ -39,7 +39,6 @@ """Top-level event handler""" mouse_timeout = 3000 # Time to hide mouse if not moved or clicked - base_keys = [K_1, K_2, K_3, K_4, K_5, K_6, K_7, K_8, K_9] def __init__(self, handlers=()): """Dispatches pygame events to the handler's methods""" @@ -108,6 +107,8 @@ selection.group.constrain_by_class() elif event.key == K_e: game.target.select_nearest(~game.local_player.category) + elif event.key == K_p: + game.target.select_next_planet() elif event.key == K_MINUS: game.camera.zoom_out() elif event.key == K_EQUALS: Modified: media.py =================================================================== --- media.py 2007-10-21 18:35:47 UTC (rev 308) +++ media.py 2007-10-23 06:30:48 UTC (rev 309) @@ -208,6 +208,21 @@ set_image('pointy-blue', pointy_image((55, 80, 216))) set_image('pointy-green', pointy_image((0, 155, 38))) set_image('pointy-red', pointy_image((216, 36, 30))) + set_image('pointy-white', pointy_image((255, 255, 255))) + def planet_pointy_image(color): + pointy = pygame.Surface((160, 290), SRCALPHA, 32) + pygame.draw.polygon(pointy, color, [(0, 130), (80, 0), (160, 130)]) + color2 = pygame.color.subtract(color, 60) + pygame.draw.polygon(pointy, color2, [(0, 130), (80, 0), (160, 130)], 15) + pygame.draw.circle(pointy, color2, (80, 175), 85) + pygame.draw.circle(pointy, (0, 0, 0, 0), (80, 190), 85) + pygame.draw.circle(pointy, color2, (80, 185), 60) + pygame.draw.circle(pointy, color, (80, 185), 45) + return pygame.transform.rotozoom(pointy, 0, 0.1) + set_image('pointy-planet-blue', planet_pointy_image((55, 80, 216))) + set_image('pointy-planet-green', planet_pointy_image((0, 155, 38))) + set_image('pointy-planet-red', planet_pointy_image((216, 36, 30))) + set_image('pointy-planet-white', pointy_image((255, 255, 255))) _sound_cache = {} _sound_last_played = {} Modified: selection.py =================================================================== --- selection.py 2007-10-21 18:35:47 UTC (rev 308) +++ selection.py 2007-10-23 06:30:48 UTC (rev 309) @@ -17,7 +17,7 @@ class Target(sprite.Sprite): - size_factor = 1.8 + size_factor = 1.5 color = (255, 255, 255) timeout = 2000 sensor = None @@ -28,7 +28,8 @@ self._select_timeout = sys.maxint self._sensor_off_frame = None self.rect = pygame.rect.Rect(0, 0, 0, 0) - self._nearest_iter = None + self._nearest_vessel_iter = None + self._planet_iter = None self.sensor = ai.Sensor(source_vessel, range) self.sensor.disable() @@ -46,10 +47,10 @@ def select_nearest(self, category, cycle=True): """Select the nearest body that is in the category.""" - if self._nearest_iter is not None and self._last_category == category: + if self._nearest_vessel_iter is not None and self._last_category == category: try: while 1: - next = self._nearest_iter.next() + next = self._nearest_vessel_iter.next() if next is not self.selected.sprite and ( getattr(next, 'vessel_type', None) != 'missile'): # Ensure we always select a new target @@ -58,25 +59,33 @@ return except StopIteration: if cycle: - self._nearest_iter = (body for body in self.sensor.detected if body.alive()) + self._nearest_vessel_iter = (body for body in self.sensor.detected + if body.alive()) nearest = self.select_nearest(category, cycle=False) else: - self._nearest_iter = None + self._nearest_vessel_iter = None self.sensor.setDetect(category) self._last_category = category # Enable the sensor for the next few frames self._sensor_off_frame = game.frame_no + 3 self.sensor.enable() + def select_next_planet(self): + if self._planet_iter is None: + self._planet_iter = itertools.cycle(game.map.planets) + self.sensor.disable() + self.select(self._planet_iter.next()) + def update(self): if game.time > self._select_timeout: # forget about all previously selected targets - self._nearest_iter = None + self._nearest_vessel_iter = None + self._planet_iter = None self._select_timeout = sys.maxint if self.sensor.enabled: if self.sensor.closest_vessel: # See what our sensor detected - self._nearest_iter = (body for body in self.sensor.detected if body.alive()) + self._nearest_vessel_iter = (body for body in self.sensor.detected if body.alive()) self.select_nearest(self._last_category) self.sensor.disable() # Stop detection elif game.frame_no > self._sensor_off_frame: @@ -88,13 +97,14 @@ if target is not None: # To avoid lagging behind the target, we update our rect here # which guarantees that the target's rect is already updated - if hasattr(target, 'collision_radius'): - width = target.collision_radius * 2 * self.size_factor - else: - width = max(target.rect.size) * self.size_factor + width = target.collision_radius * 3 * target.apparent_size + if width <= max(target.rect.size): + # compensate for smaller collision radii + width *= 2 + width = max(width, 3) rect.center = target.rect.center rect.size = (width, width) - line_len = max(self.rect.width / 10, 4) + line_len = min(max(self.rect.width / 10, 3), 75) pygame.draw.line(surface, self.color, (rect.left, rect.centery), (rect.left + line_len, rect.centery)) pygame.draw.line(surface, self.color, Modified: staticbody.py =================================================================== --- staticbody.py 2007-10-21 18:35:47 UTC (rev 308) +++ staticbody.py 2007-10-23 06:30:48 UTC (rev 309) @@ -23,11 +23,12 @@ layer = sprite.layers.background def __init__(self, name, image, x=0, y=0, resources=0, net_id=None): - RoundBody.__init__(self, position=(int(x), int(y)), heading=-vector.rightangle, net_id=net_id) + RoundBody.__init__(self, position=(int(x), int(y)), heading=-vector.rightangle, + net_id=net_id) self.body.disable() # immobile self.name = name self.image_name = random.choice(image.split(',')) - self.offscreen_img = 'pointy-blue' + self.offscreen_img = 'pointy-planet-blue' self.collision_radius = self.radius = media.image(self.image_name).get_rect().width / 2 self.resources = float(resources) self.update() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cd...@us...> - 2007-10-26 18:45:24
|
Revision: 314 http://eos-game.svn.sourceforge.net/eos-game/?rev=314&view=rev Author: cduncan Date: 2007-10-26 11:45:20 -0700 (Fri, 26 Oct 2007) Log Message: ----------- - Use white planet pointies for selected planet, dynamically update pointy color - Select planets in distance order when using "p" Modified Paths: -------------- base.py selection.py staticbody.py Modified: base.py =================================================================== --- base.py 2007-10-26 06:26:59 UTC (rev 313) +++ base.py 2007-10-26 18:45:20 UTC (rev 314) @@ -50,10 +50,6 @@ self.planet = planet self.planet.base = self self.owner = owner - if owner is game.local_player: - planet.offscreen_img = 'pointy-planet-green' - else: - planet.offscreen_img = 'pointy-planet-red' self.rally_point = self.planet if max_level >= level: self.level = level Modified: selection.py =================================================================== --- selection.py 2007-10-26 06:26:59 UTC (rev 313) +++ selection.py 2007-10-26 18:45:20 UTC (rev 314) @@ -13,6 +13,7 @@ import media import sprite from vessel import Vessel +import vector class Target(sprite.Sprite): @@ -71,8 +72,10 @@ self.sensor.enable() def select_next_planet(self): + def distance(planet): + return vector.distance(planet.position, game.camera.position) if self._planet_iter is None: - self._planet_iter = itertools.cycle(game.map.planets) + self._planet_iter = itertools.cycle(sorted(game.map.planets, key=distance)) self.sensor.disable() self.select(self._planet_iter.next()) Modified: staticbody.py =================================================================== --- staticbody.py 2007-10-26 06:26:59 UTC (rev 313) +++ staticbody.py 2007-10-26 18:45:20 UTC (rev 314) @@ -28,7 +28,6 @@ self.body.disable() # immobile self.name = name self.image_name = random.choice(image.split(',')) - self.offscreen_img = 'pointy-planet-blue' self.collision_radius = self.radius = media.image(self.image_name).get_rect().width / 2 self.resources = float(resources) self.update() @@ -37,9 +36,17 @@ state = RoundBody.get_state(self) state['create_args'] = (self.name, self.image_name) return state - + def update(self): RoundBody.update(self) if self.base is not None: self.base.update() + if self in game.target.selected: + self.offscreen_img = 'pointy-planet-white' + elif self.base is None: + self.offscreen_img = 'pointy-planet-blue' + elif self.base.owner.category & game.local_player.category: + self.offscreen_img = 'pointy-planet-green' + else: + self.offscreen_img = 'pointy-planet-red' This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |