Ignore:
Timestamp:
09/05/13 21:26:13 (8 years ago)
Author:
Stefano Rivera <stefano@…>
Branch:
default
Phase:
public
Rebase:
66303837306133316364613963373364326364616434393063323333343264303466663633643535
Message:

Bullets that mostly die when they hit things

File:
1 edited

Legend:

Unmodified
Added
Removed
  • nagslang/game_object.py

    r286 r293  
    123123        if interactible is not None:
    124124            self.interactible.set_game_object(self)
     125        self.remove = False  # If true, will be removed from drawables
    125126
    126127    def get_space(self):
     
    333334
    334335class Bullet(GameObject):
    335     def __init__(self, space, position, impulse):
     336    def __init__(self, space, position, impulse, source_collision_type):
    336337        body = make_body(1, pymunk.inf, position)
     338        self.last_position = position
    337339        self.shape = pymunk.Circle(body, 2)
     340        self.shape.sensor = True
    338341        self.shape.collision_type = COLLISION_TYPE_PROJECTILE
     342        self.source_collision_type = source_collision_type
    339343        super(Bullet, self).__init__(
    340344            SingleShapePhysicser(space, self.shape),
     
    342346        )
    343347        self.physicser.apply_impulse(impulse)
     348
     349    def animate(self):
     350        super(Bullet, self).animate()
     351        position = self.physicser.position
     352        r = self.get_space().segment_query(self.last_position, position)
     353        self.last_position = position
     354        for collision in r:
     355            if collision.shape.collision_type == self.source_collision_type:
     356                continue
     357            if collision.shape == self.physicser.get_shape():
     358                continue
     359            print "Hit", collision.shape.collision_type
     360            self.physicser.remove_from_space()
     361            self.remove = True
     362            break
    344363
    345364
Note: See TracChangeset for help on using the changeset viewer.