-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathactions.py
More file actions
152 lines (110 loc) · 4.06 KB
/
actions.py
File metadata and controls
152 lines (110 loc) · 4.06 KB
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
import entities
import worldmodel
import pygame
import math
import random
import point
import image_store
BLOB_ANIMATION_RATE_SCALE = 50
BLOB_ANIMATION_MIN = 1
BLOB_ANIMATION_MAX = 3
ORE_CORRUPT_MIN = 20000
ORE_CORRUPT_MAX = 30000
QUAKE_STEPS = 10
QUAKE_DURATION = 1100
QUAKE_ANIMATION_RATE = 100
VEIN_SPAWN_DELAY = 500
VEIN_RATE_MIN = 8000
VEIN_RATE_MAX = 17000
def sign(x):
if x < 0:
return -1
elif x > 0:
return 1
else:
return 0
###
def next_position(world, entity_pt, dest_pt):
horiz = sign(dest_pt.x - entity_pt.x)
new_pt = point.Point(entity_pt.x + horiz, entity_pt.y)
if horiz == 0 or world.is_occupied(new_pt):
vert = sign(dest_pt.y - entity_pt.y)
new_pt = point.Point(entity_pt.x, entity_pt.y + vert)
if vert == 0 or world.is_occupied(new_pt):
new_pt = point.Point(entity_pt.x, entity_pt.y)
return new_pt
###
def blob_next_position(world, entity_pt, dest_pt):
horiz = sign(dest_pt.x - entity_pt.x)
new_pt = point.Point(entity_pt.x + horiz, entity_pt.y)
if horiz == 0 or (world.is_occupied(new_pt) and
not isinstance(world.get_tile_occupant(new_pt),
entities.Ore)):
vert = sign(dest_pt.y - entity_pt.y)
new_pt = point.Point(entity_pt.x, entity_pt.y + vert)
if vert == 0 or (world.is_occupied(new_pt) and
not isinstance(world.get_tile_occupant(new_pt),
entities.Ore)):
new_pt = point.Point(entity_pt.x, entity_pt.y)
return new_pt
###
def find_open_around(world, pt, distance):
for dy in range(-distance, distance + 1):
for dx in range(-distance, distance + 1):
new_pt = point.Point(pt.x + dx, pt.y + dy)
if (world.within_bounds(new_pt) and
(not world.is_occupied(new_pt))):
return new_pt
return None
def create_blob(world, name, pt, rate, ticks, i_store):
blob = entities.OreBlob(name, pt, rate,
image_store.get_images(i_store, 'blob'),
random.randint(BLOB_ANIMATION_MIN, BLOB_ANIMATION_MAX)
* BLOB_ANIMATION_RATE_SCALE)
schedule_blob(world, blob, ticks, i_store)
return blob
def schedule_blob(world, blob, ticks, i_store):
schedule_action(world, blob, blob.create_ore_blob_action(world, i_store),
ticks + blob.get_rate())
schedule_animation(world, blob)
def schedule_miner(world, miner, ticks, i_store):
schedule_action(world, miner, miner.create_miner_action(world, i_store),
ticks + miner.get_rate())
schedule_animation(world, miner)
def create_ore(world, name, pt, ticks, i_store):
ore = entities.Ore(name, pt, image_store.get_images(i_store, 'ore'),
random.randint(ORE_CORRUPT_MIN, ORE_CORRUPT_MAX))
schedule_ore(world, ore, ticks, i_store)
return ore
def schedule_ore(world, ore, ticks, i_store):
schedule_action(world, ore,
ore.create_ore_transform_action(world, i_store),
ticks + ore.get_rate())
def create_quake(world, pt, ticks, i_store):
quake = entities.Quake("quake", pt,
image_store.get_images(i_store, 'quake'), QUAKE_ANIMATION_RATE)
schedule_quake(world, quake, ticks)
return quake
def schedule_quake(world, quake, ticks):
schedule_animation(world, quake, QUAKE_STEPS)
schedule_action(world, quake, quake.create_entity_death_action(world),
ticks + QUAKE_DURATION)
def create_vein(world, name, pt, ticks, i_store):
vein = entities.Vein("vein" + name,
random.randint(VEIN_RATE_MIN, VEIN_RATE_MAX),
pt, image_store.get_images(i_store, 'vein'))
return vein
def schedule_vein(world, vein, ticks, i_store):
schedule_action(world, vein, vein.create_vein_action(world, i_store),
ticks + vein.get_rate())
def schedule_action(world, entity, action, time):
entity.add_pending_action(action)
world.schedule_action(action, time)
def schedule_animation(world, entity, repeat_count=0):
schedule_action(world, entity,
entity.create_animation_action(world, repeat_count),
entity.get_animation_rate())
def clear_pending_actions(world, entity):
for action in entity.get_pending_actions():
world.unschedule_action(action)
entity.clear_pending_actions()