projects
/
super-star-trek.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
c16dbbf
)
More code slimming.
author
Eric S. Raymond
<esr@thyrsus.com>
Fri, 6 Oct 2006 19:00:27 +0000
(19:00 +0000)
committer
Eric S. Raymond
<esr@thyrsus.com>
Fri, 6 Oct 2006 19:00:27 +0000
(19:00 +0000)
src/sst.py
patch
|
blob
|
history
diff --git
a/src/sst.py
b/src/sst.py
index 76fa31a6a911303b02f8141927cdd6907b4730fd..fe383343417e5a2706ea8f75a88537b7fb39c226 100644
(file)
--- a/
src/sst.py
+++ b/
src/sst.py
@@
-424,6
+424,7
@@
class enemy:
self.kpower = power # enemy energy level
game.enemies.append(self)
def move(self, loc):
self.kpower = power # enemy energy level
game.enemies.append(self)
def move(self, loc):
+ motion = (loc != self.kloc)
if self.kloc.x is not None and self.kloc.y is not None:
game.quad[self.kloc.x][self.kloc.y] = IHDOT
if loc:
if self.kloc.x is not None and self.kloc.y is not None:
game.quad[self.kloc.x][self.kloc.y] = IHDOT
if loc:
@@
-434,6
+435,7
@@
class enemy:
self.kloc = coord() # enemy sector location
self.kdist = self.kavgd = None
game.enemies.remove(self)
self.kloc = coord() # enemy sector location
self.kdist = self.kavgd = None
game.enemies.remove(self)
+ return motion
def __repr__(self):
return "<%s=%f>" % (self.kloc, self.kpower) # For debugging
def __repr__(self):
return "<%s=%f>" % (self.kloc, self.kpower) # For debugging
@@
-781,35
+783,33
@@
def movebaddy(enemy):
if idebug:
proutn("NSTEPS = %d:" % nsteps)
# Compute preferred values of delta X and Y
if idebug:
proutn("NSTEPS = %d:" % nsteps)
# Compute preferred values of delta X and Y
- mx = game.sector.x - enemy.kloc.x
- my = game.sector.y - enemy.kloc.y
- if 2.0 * abs(mx) < abs(my):
- mx = 0
- if 2.0 * abs(my) < abs(game.sector.x-enemy.kloc.x):
- my = 0
- if mx != 0:
- if mx*motion < 0:
- mx = -1
+ m = game.sector - enemy.kloc
+ if 2.0 * abs(m.x) < abs(m.y):
+ m.x = 0
+ if 2.0 * abs(m.y) < abs(game.sector.x-enemy.kloc.x):
+ m.y = 0
+ if m.x != 0:
+ if m.x*motion < 0:
+ m.x = -1
else:
else:
- mx = 1
- if my != 0:
- if my*motion < 0:
- my = -1
+ m
.
x = 1
+ if m
.
y != 0:
+ if m
.
y*motion < 0:
+ m
.
y = -1
else:
else:
- my = 1
+ m
.
y = 1
next = enemy.kloc
# main move loop
for ll in range(nsteps):
if idebug:
proutn(" %d" % (ll+1))
# Check if preferred position available
next = enemy.kloc
# main move loop
for ll in range(nsteps):
if idebug:
proutn(" %d" % (ll+1))
# Check if preferred position available
- look.x = next.x + mx
- look.y = next.y + my
- if mx < 0:
+ look = next + m
+ if m.x < 0:
krawlx = 1
else:
krawlx = -1
krawlx = 1
else:
krawlx = -1
- if my < 0:
+ if m
.
y < 0:
krawly = 1
else:
krawly = -1
krawly = 1
else:
krawly = -1
@@
-820,14
+820,14
@@
def movebaddy(enemy):
if look.x < 0 or look.x >= QUADSIZE:
if motion < 0 and tryexit(enemy, look, irun):
return
if look.x < 0 or look.x >= QUADSIZE:
if motion < 0 and tryexit(enemy, look, irun):
return
- if krawlx == m
x or m
y == 0:
+ if krawlx == m
.x or m.
y == 0:
break
look.x = next.x + krawlx
krawlx = -krawlx
elif look.y < 0 or look.y >= QUADSIZE:
if motion < 0 and tryexit(enemy, look, irun):
return
break
look.x = next.x + krawlx
krawlx = -krawlx
elif look.y < 0 or look.y >= QUADSIZE:
if motion < 0 and tryexit(enemy, look, irun):
return
- if krawly == m
y or m
x == 0:
+ if krawly == m
.y or m.
x == 0:
break
look.y = next.y + krawly
krawly = -krawly
break
look.y = next.y + krawly
krawly = -krawly
@@
-837,10
+837,10
@@
def movebaddy(enemy):
(enemy.type == IHC or enemy.type == IHS):
collision(rammed=True, enemy=enemy)
return
(enemy.type == IHC or enemy.type == IHS):
collision(rammed=True, enemy=enemy)
return
- if krawlx != m
x and m
y != 0:
+ if krawlx != m
.x and m.
y != 0:
look.x = next.x + krawlx
krawlx = -krawlx
look.x = next.x + krawlx
krawlx = -krawlx
- elif krawly != m
y and m
x != 0:
+ elif krawly != m
.y and m.
x != 0:
look.y = next.y + krawly
krawly = -krawly
else:
look.y = next.y + krawly
krawly = -krawly
else:
@@
-855,13
+855,7
@@
def movebaddy(enemy):
break; # done early
if idebug:
skip(1)
break; # done early
if idebug:
skip(1)
- # Put commander in place within same quadrant
- game.quad[enemy.kloc.x][enemy.kloc.y] = IHDOT
- game.quad[next.x][next.y] = enemy.type
- if next != enemy.kloc:
- # it moved
- enemy.kloc = next
- enemy.kdist = enemy.kavgd = distance(game.sector, next)
+ if enemy.move(next):
if not damaged(DSRSENS) or game.condition == "docked":
proutn("***")
cramen(enemy.type)
if not damaged(DSRSENS) or game.condition == "docked":
proutn("***")
cramen(enemy.type)