-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
173 lines (134 loc) · 4.19 KB
/
main.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
import pgzrun
import sys
from random import *
import time
mod = sys.modules['__main__']
TITLE = "ALIENS..."
WIDTH = 1000
HEIGHT = 1000
FONT = 'calibri'
IMG_PREFIX = "player"
k = True
in_house = False
start1 = True
start2 = False
game_over = True
start_delay = 2
# a counter to delay between changes
delay_timer = 0
# which of the 3 images to display (value from 1 to 3)
image_number = 1
player = mod.Actor(IMG_PREFIX+"-down-1")
house = mod.Actor('houseoverworldbig')
stairs = mod.Actor('stairs')
speach = mod.Actor('dialoguebox')
arrow = mod.Actor('smallarrow')
sword = mod.Actor('sword2')
player.x = 100
player.y = 100
def place_actors():
player.x = randint(40, 300)
player.y = randint(40, 300)
house.x = 500
house.y = 500
stairs.pos = 500, 850
speach.pos = 500, 100
arrow.pos = 450, 850
sword.pos = 500, 400
def start_music():
mod.music.play('background')
def stop_music():
mod.music.stop()
def kCheck():
global k
k = False
def update():
global delay_timer, image_number
global in_house, playerTouchingHouse, touchingStairs
playerTouchingHouse = player.colliderect(house)
if playerTouchingHouse and mod.keyboard.space:
in_house = True
touchingStairs = player.colliderect(stairs)
if touchingStairs and in_house:
player.pos = 500, 520
in_house = False
direction = "none"
if mod.keyboard.a or mod.keyboard.left:
player.x -= 3
direction = "left"
if mod.keyboard.d or mod.keyboard.right:
player.x += 3
direction = "right"
if mod.keyboard.s or mod.keyboard.down:
player.y += 3
direction = "down"
if mod.keyboard.w or mod.keyboard.up:
player.y -= 3
direction = "up"
# Only move whilst key is pressed
if (delay_timer == 10):
delay_timer = 0
if (direction != 'none'):
image_number += 1
if (image_number > 2):
image_number = 1
else:
delay_timer += 1
if (direction != 'none'):
image_name = "{}-{}-{}".format(IMG_PREFIX, direction, image_number)
player.image = image_name
def nextStart1():
global start1, start2
if start1:
start1 = False
start2 = True
def nextStart2():
global start1, start2
if start2:
start1 = False
start2 = False
def draw():
global start1, start2
global game_over, playerTouchingHouse, in_house
mod.screen.clear()
if start1:
mod.screen.fill((0, 0, 0))
mod.screen.draw.text('K-NOX GAMES PRESENTS:', (250, 400), fontsize=64, color="green", background="orange", fontname=FONT)
mod.clock.schedule(nextStart1, start_delay)
elif start2:
mod.screen.fill((0, 0, 0))
mod.screen.draw.text('ALIENS', (400, 400), fontsize=64, color='green', background="orange", fontname=FONT)
mod.clock.schedule(nextStart2, start_delay)
else:
mod.screen.fill((4, 139, 87))
start1 = False
start2 = False
game_over = False
if not game_over and not playerTouchingHouse:
mod.screen.fill((4, 139, 87))
mod.screen.draw.text('x: ' + str(player.x), (40, 40), fontname=FONT)
mod.screen.draw.text('y: ' + str(player.y), (40, 60), fontname=FONT)
house.draw()
player.draw()
if not game_over and playerTouchingHouse:
house.draw()
player.draw()
mod.screen.draw.text('x: ' + str(player.x), (40, 40), fontname=FONT)
mod.screen.draw.text('y: ' + str(player.y), (40, 60), fontname=FONT)
mod.screen.draw.text('SPACE TO OPEN DOOR', (40, 80), fontname=FONT)
if not game_over and in_house:
mod.screen.fill((165, 42, 42))
stairs.draw()
arrow.draw()
sword.draw()
player.draw()
speach.draw()
mod.screen.draw.text('YOU ARE IN THE CASTLE.', (400, 100), fontsize=20, color='green', fontname=FONT)
mod.clock.schedule(kCheck, 1)
mod.screen.draw.text('x: ' + str(player.x), (40, 40), fontname=FONT)
mod.screen.draw.text('y: ' + str(player.y), (40, 60), fontname=FONT)
if player.x == 500 and player.y == 500:
mod.clock.schedule(stop_music, 0.1)
start_music()
place_actors()
pgzrun.go()