Ignore:
Timestamp:
09/01/13 17:31:39 (8 years ago)
Author:
Jeremy Thurgood <firxen@…>
Branch:
default
Phase:
public
Message:

Move protagonist object to the right place.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • nagslang/screens/area.py

    r64 r65  
    55import pymunk.pygame_util
    66
    7 from nagslang.game_object import (
    8     GameObject, SingleShapePhysicser, FacingImageRenderer)
     7from nagslang.events import ScreenChange
     8from nagslang.level import Level
     9from nagslang.protagonist import Protagonist
    910from nagslang.screens.base import Screen
    10 from nagslang.level import Level
    11 from nagslang.events import ScreenChange
    12 from nagslang.resources import resources
    13 from nagslang.mutators import FLIP_H
    1411
    1512
     
    2926        elif ev.type == pygame.locals.KEYUP:
    3027            self.key_up(ev.key)
    31 
    32 
    33 class Protagonist(GameObject):
    34     def __init__(self, position):
    35         self.body = pymunk.Body(10, 10000)
    36         self.body.position = position
    37         self.body.velocity_func = self.velocity_func
    38 
    39         self.shape = pymunk.Circle(self.body, 30)
    40         self.shape.elasticity = 1.0
    41         self.shape.friction = 10.0
    42 
    43         super(Protagonist, self).__init__(
    44             FacingImageRenderer(
    45                 resources.get_image('creatures', 'werewolf_1.png'),
    46                 resources.get_image(
    47                     'creatures', 'werewolf_1.png', transforms=(FLIP_H,))),
    48             SingleShapePhysicser(self.shape))
    49 
    50         self.go_human()
    51 
    52     def velocity_func(self, body, gravity, damping, dt):
    53         return pymunk.Body.update_velocity(body, gravity, self.damping, dt)
    54 
    55     def go_werewolf(self):
    56         self.werewolf = True
    57         self.body.mass = 100
    58         self.body.moment = 10000
    59         self.body.velocity_limit = 1000
    60         self.shape.color = pygame.color.THECOLORS['red']
    61         self.impulse_factor = 4000
    62         self.damping = 0.9
    63 
    64     def go_human(self):
    65         self.werewolf = False
    66         self.body.mass = 10
    67         self.body.moment = 1000
    68         self.body.velocity_limit = 1000
    69         self.shape.color = pygame.color.THECOLORS['blue']
    70         self.impulse_factor = 500
    71         self.damping = 0.8
    72 
    73     def set_direction(self, dx, dy):
    74         if (dx, dy) == (0, 0):
    75             return
    76         vec = pymunk.Vec2d((dx, dy))
    77         self.body.angle = vec.angle
    78         self.body.apply_impulse(
    79             (dx * self.impulse_factor, dy * self.impulse_factor))
    80 
    81     def toggle_form(self):
    82         if self.werewolf:
    83             self.go_human()
    84         else:
    85             self.go_werewolf()
    8628
    8729
Note: See TracChangeset for help on using the changeset viewer.