-
Notifications
You must be signed in to change notification settings - Fork 0
/
mine.py
83 lines (63 loc) · 2.58 KB
/
mine.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import pygame
import random
class ControlData:
def __init__(self):
self.moveX = 0
self.moveY = 0
class Mine(pygame.sprite.Sprite):
def __init__(self, screen):
pygame.sprite.Sprite.__init__(self)
randomNo = random.randint(1,2)
self.screen = screen
self.image = pygame.image.load("Mine.png")
self.image = self.image.convert_alpha()
self.rect = self.image.get_rect()
randomY = random.randint(1,640)
randomX = random.randint(1,920)
self.rect.center = (randomX, randomY)
'Position the sprite'
self.x = randomX
self.y = randomY
pdr = ControlData()
pdr.moveX = 4
pdl = ControlData()
pdl.moveX = -4
pdd = ControlData()
pdd.moveY = 4
pdu = ControlData()
pdu.moveY = -4
if randomNo == 1:
self.pattern = [pdr, pdr, pdr, pdr, pdr, pdr, pdr, pdr, pdr, pdr,
pdd, pdd, pdd, pdd, pdd, pdd, pdd, pdd, pdd, pdd,
pdl, pdl, pdl, pdl, pdl, pdl, pdl, pdl, pdl, pdl,
pdu, pdu, pdu, pdu, pdu, pdu, pdu, pdu, pdu, pdu]
if randomNo == 2:
self.pattern = [pdr, pdr, pdr, pdr, pdr, pdr, pdr, pdr, pdr, pdr,
pdd, pdd, pdd, pdd, pdd, pdd, pdd, pdd, pdd, pdd,
pdl, pdl, pdl, pdl, pdl, pdl, pdl, pdl, pdl, pdl,
pdd, pdd, pdd, pdd, pdd, pdd, pdd, pdd, pdd, pdd]
if randomNo == 3:
self.pattern = [pdr, pdr, pdr, pdr, pdr, pdr, pdr, pdr, pdr, pdr,
pdu, pdu, pdu, pdu, pdu, pdu, pdu, pdu, pdu, pdu,
pdl, pdl, pdl, pdl, pdl, pdl, pdl, pdl, pdl, pdl,
pdu, pdu, pdu, pdu, pdu, pdu, pdu, pdu, pdu, pdu]
self.patternIndex = 0
def update(self):
'Update the sprite position using the array of pattern data'
cd = self.pattern[self.patternIndex]
self.x += cd.moveX
self.y += cd.moveY
'Increment the patternIndex so that we move to the next piece of pattern data'
self.patternIndex += 1
'Reset the patternIndex if we are at the end of the array'
if self.patternIndex >= len(self.pattern):
self.patternIndex = 0
if self.x > self.screen.get_width():
self.kill()
if self.x < 0:
selfkill()
if self.y > self.screen.get_height():
self.kill()
if self.y < 0:
self.kill()
self.rect.center = (self.x, self.y)