-
Notifications
You must be signed in to change notification settings - Fork 0
/
game_enemies.py
50 lines (36 loc) · 1.52 KB
/
game_enemies.py
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
38
39
40
41
42
43
44
45
46
47
48
49
50
'''
Created on 3 okt. 2015
@author: danhe
'''
from game_tools import Sprite
from math import copysign, sqrt
from random import random
class Enemy1(Sprite):
def __init__(self, id, position):
super(Enemy1, self).__init__(source='graphics/enemy1.png', pos=position)
self.id = id
self.velocity = [0, 0]
self.map_position = position
self.map_offset = [0, 0]
return
def update(self):
self.velocity[0] += 2*(0.5-random())
self.velocity[1] += 2*(0.5-random())
self.map_offset = self.parent.offset
if not self.parent.collide_point(self.map_position[0],self.map_position[1]):
self.map_position[0] -= self.velocity[0]
self.map_position[1] -= self.velocity[1]
self.velocity = [0,0]
for child in self.parent.children:
if child.id == self.id or child.id == 'sprite':
continue
if self.collide_widget(child):
self.map_position[0] -= self.velocity[0]
self.map_position[1] -= self.velocity[1]
self.velocity = [0,0]
print(self.id,child.id,self.collide_widget(child))
self.map_position[0] += self.velocity[0]
self.map_position[1] += self.velocity[1]
self.x = self.map_position[0] + self.map_offset[0]
self.y = self.map_position[1] + self.map_offset[1]
return