/
Alien_Gold.py
75 lines (57 loc) · 2.34 KB
/
Alien_Gold.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
# Alien_Gold by Frank Mock 2016
import pygame
import random
import Constants
from Alien import *
from spritesheet_functions import SpriteSheet
# This class derives from the "Alien" class
class Alien_Gold(Alien):
def __init__(self):
# Call the parent class (Sprite) constructor
super().__init__()
# Alien spritesheet stored in resources directory
sprite_sheet = SpriteSheet("resources/gold-ship.png")
# Load all the frames from spritesheet into a list
image = sprite_sheet.get_image(0, 0, 52, 28)
self.ship_frames.append(image)
image = sprite_sheet.get_image(52, 0, 52, 28)
self.ship_frames.append(image)
image = sprite_sheet.get_image(0, 28, 52, 28)
self.ship_frames.append(image)
image = sprite_sheet.get_image(52, 28, 52, 28)
self.ship_frames.append(image)
# Set the image the alien sip starts with
self.image = self.ship_frames[0]
# Fetch the rectangle object that has the dimensions of the image
# image.
# Update the position of this object by setting the values
# of rect.x and rect.y
self.rect = self.image.get_rect()
self.hitpoints = 6
self.start_hitpoints = 6
self.not_damaged = True
def load_frames(self):
pass
# The update method is called for each game frame and describes
# what should change with the object for that frame
def update(self):
self.rect.x += self.change_x
self.rect.y += self.change_y
if self.rect.right >= self.right_boundary or \
self.rect.left <= self.left_boundary:
self.change_x *= -1
if self.rect.bottom >= self.bottom_boundary or \
self.rect.top <= self.top_boundary:
self.change_y *= -1
# Change to next sprite sheet image every 20 pixels of sprite movement
pos = self.rect.x
size = 2
if self.not_damaged:
frame = (pos // 20) % 2
else:
frame = (pos // 20) % len(self.ship_frames)
self.image = self.ship_frames[frame]
# Randomly activate bombing ability
rand = random.randrange(200)
if(rand < 10):
self.bombing = False