File: enemy.py

package info (click to toggle)
oneisenough 0.40-4
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 616 kB
  • sloc: python: 697; makefile: 7; sh: 2
file content (37 lines) | stat: -rw-r--r-- 1,211 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import pygame
import os
import random

from pygame.locals import *

from locals import *
from util import *

from object import Object

class Enemy(Object):

  def __init__(self, screen, position = None):
    image_file = 'balldollar.png'
    self.otype = OBJECT_DOLLAR
    Object.__init__(self, screen, image_file, position, ENEMY_SPEED, ENEMY_ACC, ENEMY_BOUNCE)
    return

  def update(self, borders, collideobjects, move_modifier = 1.0):
    Object.update(self, borders, collideobjects, move_modifier)
    self.acc((random.randint(-1,1),random.randint(-1,1)))
    Object.align(self, collideobjects, [self.get_type()])
    Object.follow(self, collideobjects, [self.get_type()], 0.1, 30)
    Object.avoid(self, collideobjects, [self.get_type()], 0.3, 20)
    for co in collideobjects:
      if co.get_type() == OBJECT_PLAYER:
        if co.gravity > 0:
          for gtarget in co.gravitytarget:
            if gtarget == self.otype:
              Object.follow(self, [co], [OBJECT_PLAYER], co.gravity, co.provocation)
        else:
          Object.follow(self, [co], [OBJECT_PLAYER], 0.09 * (2 - co.hp / PLAYER_HP) , PLAYER_HP + 60 - co.hp)


    self.dec(0.3)
    return