diff --git a/actor.py b/actor.py index 68d3ac7..1ec3df3 100644 --- a/actor.py +++ b/actor.py @@ -30,6 +30,8 @@ class BaseActor(pygame.sprite.Sprite): self.image = image self.rect = self.image.get_rect() + self.image_points = [] + def get_id(self): return self.id @@ -76,6 +78,18 @@ class BaseActor(pygame.sprite.Sprite): def set_friction(self, new_friction): self.friction = new_friction + def get_image_point(self, point): + if point < 0 or point > len(self.image_points): + return (0, 0) + else: + return self.image_points[point] + + def set_image_point_tuple(self, point): + self.image_points.append(point) + + def set_image_point_xy(self, point_x, point_y): + self.image_points.append((point_x, point_y)) + def draw(self, canvas): if self.image is not None: canvas.blit(self.image, self.rect) @@ -87,6 +101,7 @@ class BulletActor(BaseActor): """ Actor class with fixed velocity bullet behavior. """ def __init__(self, id, image, name = "Default", animated = False, visible = True, solid = True, frame_rate = 60.0): BaseActor.__init__(self, id, image, name, animated, visible, solid) + self.then = pygame.time.get_ticks() self.now = pygame.time.get_ticks() self.frame_rate = frame_rate @@ -119,7 +134,7 @@ class BulletActor(BaseActor): print "NEW VEL Y: " + str((self.velocity[1] * delta_t) * (self.frame_rate / 1000)) self.position[0] += (self.velocity[0] * delta_t) * (self.frame_rate / 1000) self.position[1] += (self.velocity[1] * delta_t) * (self.frame_rate / 1000) - self.rect.center = (self.position[0], self.position[1]) + self.rect.center = (self.position[0], self.position[1]) if game.DEBUG: print "NEW POSITION: " + str(self.position) @@ -127,4 +142,3 @@ class BulletActor(BaseActor): # TODO: Update animation frame if any. self.then = self.now - diff --git a/intro.py b/intro.py index 8928f84..a8813ac 100644 --- a/intro.py +++ b/intro.py @@ -16,11 +16,10 @@ import game class IntroState(BaseState): def __init__(self): + BaseState.__init__(self) + self.count = 0 - screen_center = self.get_screen_center() - self.rectangle = pygame.Rect(screen_center[0] - 50, screen_center[1] - 50, 100, 100) self.next_transition = VALID_STATES['STAY'] - self.background_color = (139, 210, 228) self.screen_vertical_half = pygame.display.Info().current_h / 2 @@ -36,6 +35,7 @@ class IntroState(BaseState): image2 = pygame.image.load('gfx/submarino1.png') self.submarine = actor.BaseActor(1, image2, "Submarine", True, True, False) + self.submarine.set_image_point_tuple((117, 284)) # Instert second animation frame of the subamrine. # Create the particle system. @@ -54,24 +54,33 @@ class IntroState(BaseState): if event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: self.next_transition = VALID_STATES['QUIT'] + else: + self.next_transition = VALID_STATES['MENU'] if event.type == pygame.QUIT: self.next_transition = VALID_STATES['QUIT'] - def update(self): + if event.type == pygame.MOUSEBUTTONDOWN: + self.next_transition = VALID_STATES['MENU'] + def update(self): self.sine_movement.update() sm_position = self.sine_movement.get_position() self.submarine.set_position([sm_position[0], self.screen_vertical_half + math.sin(0.05 * float(sm_position[0])) * 42.0]) + if game.DEBUG: + print + print "OBJECT: " + self.sine_movement.get_name() + print "Velocity: " + str(self.sine_movement.get_velocity()) + print "Position: " + str(self.sine_movement.get_position()) + print self.sine_movement.is_moving() + if self.next_transition != VALID_STATES['QUIT']: sm_position = self.sine_movement.get_position() - if sm_position[0] > pygame.display.Info().current_w + 300: + if sm_position[0] > pygame.display.Info().current_w + 300: self.next_transition = VALID_STATES['MENU'] - else: - self.next_transition = VALID_STATES['STAY'] + return self.next_transition def render(self, canvas): canvas.fill(self.background_color) - self.sine_movement.draw(canvas) self.submarine.draw(canvas)