Skip to content

Commit

Permalink
v2.1: Added action repeats and stringing.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustavo R. 'Gustavo6046' Rehermann committed Oct 14, 2018
1 parent b710611 commit b1c770f
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 21 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ build
dist
*.zip
*.exe
JumpZombie.dec
*.dec
*.json
2 changes: 1 addition & 1 deletion JumpZombie.zc2
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class RunZombie inherits ZombieMan replaces ZombieMan #2055

label RunLoop
{
x3
x 3
{
POSS ABCD 2 A_Recoil(-0.7);
TNT1 A 0 A_Chase;
Expand Down
Binary file added NewRocket.pk3
Binary file not shown.
61 changes: 61 additions & 0 deletions NewRocket.zc2
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
class NDoomRocket extends Rocket replaces Rocket
{
set Gravity to 0.0235;
set Speed to 14;
set Damage to 40; // direct hit damage

label Spawn
{
TNT1 A 0 {
x6 A_SpawnItemEx("NRocketFire", -cos(angle) * 3, -sin(angle) * 3, -velz, FRandom(-1, 1), FRandom(-1, 1), FRandom(-1, 1));
A_SpawnItemEx("NRocketCorona");
A_ScaleVelocity(1.25);
};
x10 MISL A 0 [Bright] A_SpawnItemEx("NRocketTrail", -cos(angle) * 20, -sin(angle) * 20, -velz, FRandom(-5, 5) + cos(angle) * 2, FRandom(-5, 5) + sin(angle) * 2, FRandom(-5, 5));
MISL A 2 [Bright];
loop;
};

label Death
{
TNT1 A 0 A_QuakeEx(4, 4, 2.25, 16, 0, 128);
x120 TNT1 A 0 A_SpawnItemEx("NRocketTrail", FRandom(-20, 20), FRandom(-20, 20), FRandom(-20, 20), FRandom(-6, 6) - velx, FRandom(-6, 6) - vely, FRandom(-6, 6));
MISL B 5 [Bright] A_Explode(150, 210);
MISL C 5 [Bright];
MISL D 5 [Bright];
stop;
};
}

class NRocketFX
{
set Gravity to 0.0082;
set Speed to 9;
set Alpha to 0.35;
set RenderStyle to Translucent;
combo Projectile;
}

class NRocketFire extends NRocketFX
{
set Scale to 0.2;
set Alpha to 0.8;
set RenderStyle to Add;

label Spawn
{
FSPK ABC 2 [Bright];
stop;
};
}

class NRocketTrail extends NRocketFX
{
set Scale to 0.55;

label Spawn
{
RTRL ABCD 6 [Bright];
stop;
};
}
27 changes: 22 additions & 5 deletions general.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,8 +487,20 @@ def _parse_literal(self, literal):
def _parse_action(self, a):
return "{}({})".format(a[0], (', '.join(self._parse_literal(x) for x in a[1]) if a[1] is not None else []))

def _parse_state_action_or_body(self, a):
if a[0] == 'action':
return [self._parse_state_action(a[1])]

else:
res = []

for x in a[1]:
res.extend(self._parse_state_action_or_body(x))

return res

def _parse_state_action(self, a):
args = (', '.join(self._parse_literal(x) for x in a[1]) if a[1] is not None else [])
args = (', '.join(a[1]) if a[1] is not None else [])

if len(args) > 0:
return "{}({})".format(a[0], args)
Expand All @@ -500,11 +512,13 @@ def _parse_state(self, actor, label, s):
if s[0] == 'frames':
name, frames, duration, modifiers, action = s[1]

if action is not None:
action = self._parse_state_action(action)

for f in frames:
label.states.append(ZDState(name, f, duration, modifiers, action=action))
if action is None:
label.states.append(ZDState(name, f, duration, modifiers))

else:
for a in self._parse_state_action_or_body(action):
label.states.append(ZDState(name, f, duration, modifiers, action=a))

elif s[0] == 'call':
ZDCall(self, label, s[1])
Expand Down Expand Up @@ -548,6 +562,9 @@ def _parse(self, actors):
elif btype == 'flag':
actor.flags.append(bdata)

elif btype == 'flag combo':
actor.raw.append(bdata)

elif btype == 'unflag':
actor.antiflags.append(bdata)

Expand Down
56 changes: 42 additions & 14 deletions zdlexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@


s = string
string_body = regex(r'[^"\\]+')
string_body_1 = regex(r'[^"\\]+')
string_body_2 = regex(r'[^\'\\]+')
string_esc = string('\\') >> (
string('\\')
| string('/')
Expand All @@ -18,8 +19,14 @@
| regex(r'u[0-9a-fA-F]{4}').map(lambda s: chr(int(s[1:], 16)))
| regex(r'x[0-9a-fA-F]{2}').map(lambda s: chr(int(s[1:], 16)))
)
string_delim = s('"') | s("'")
string_literal = string_delim + (string_body | string_esc).many().concat() + string_delim
string_delim_1 = s('"')
string_delim_2 = s("'")
string_body_plex_1 = (string_body_1 | string_esc).many().concat()
string_body_plex_2 = (string_body_2 | string_esc).many().concat()
string_literal = (
(string_delim_1 + string_body_plex_1 + string_delim_1)
| (string_delim_2 + string_body_plex_2 + string_delim_2)
)
lwhitespace = whitespace | s('\n') | s('\r')

@generate
Expand All @@ -41,26 +48,24 @@ def _parse_literal(literal):
return _parse_action(literal[1])

def _parse_action(a):
print(a)
return "{}({})".format(a[0], ', '.join(_parse_literal(x) for x in a[1]))

@generate
def literal():
return (
string_literal.tag('string')
| call_literal.tag('call expr')
| regex(r'[\+\-]?[0-9]+(.[0-9+])?(e[\+\-]?\d+)?').map(float).tag('number')
| regex(r'[\+\-]?\d+(.\d+)?(e[\+\-]?\d+)?').tag('number')
| regex(r'[a-zA-Z_][a-zA-Z0-9_\[\]]*').tag('actor variable')
| regex(r'0x[0-9A-Fa-f]+').map(float).tag('number')
| regex(r'0b[01]+').map(float).tag('number')
| regex(r'0x[0-9A-Fa-f]+').map(int).tag('number')
| regex(r'0b[01]+').map(int).tag('number')
)
yield

@generate
def paren_expr():
return s('(') + expression + s(')')
yield


@generate
def expression():
Expand All @@ -69,18 +74,23 @@ def expression():
(
(
literal.map(_parse_literal)
| regex(r'[\+\-\|\>\<\~\&\!\=\*\/\%]+')
| paren_expr
| regex(r'[\+\-\|\>\<\~\&\!\=\*\/\%]+').desc('operator')
| paren_expr.desc('parenthetic expression')
).sep_by(whitespace.optional()).map(lambda x: ' '.join(x))
)
<< whitespace.optional()
)
) | paren_expr
yield

@generate
def argument_list():
return literal.sep_by(regex(',\s*'))
yield

@generate
def expr_argument_list():
return expression.sep_by(regex(',\s*'))
yield

@generate
def actor_function_call():
Expand All @@ -92,7 +102,7 @@ def state_call():
return seq(
regex('[a-zA-Z_]+').desc('called state function name').skip(whitespace.optional()),
s('(').then(whitespace.optional()).then(
argument_list
expr_argument_list
).skip(whitespace.optional()).skip(s(')')).optional()
)
yield
Expand All @@ -115,6 +125,7 @@ def class_body():
((whitespace >> string('to') << whitespace) | (whitespace.optional() >> s('=') << whitespace.optional())).desc("'to' or equal sign") >> literal.tag('value')
).map(dict).tag('property')
| (((string('is') << whitespace) | string("+")) >> regex('[a-zA-Z0-9_.]+').desc('flag name')).tag('flag')
| (string('combo') >> whitespace >> regex('[a-zA-Z0-9_.]+').desc('combo name')).tag('flag combo')
| (((string("isn't") << whitespace) | string('-')) >> regex('[a-zA-Z0-9_\.]+').desc('flag name')).tag('unflag')
| seq((string("function ") | string('method ')) >> regex('[a-zA-Z_]+').desc('function name').tag('name'), state_body.tag('body')).map(dict).tag('function')
| (seq(((string("label") | string('state')) << whitespace) >> regex('[a-zA-Z_]+').desc('label name').tag('name'), state_body.tag('body')).map(dict) << whitespace.optional()).tag('label')
Expand Down Expand Up @@ -147,13 +158,30 @@ def normal_state():
modifier.many().desc('modifier').skip(
whitespace.optional()
).optional(),
state_call.optional()
state_action.optional()
)
yield

@generate
def state_action():
return action_body_repeat.tag('inline body') | state_call.tag('action') | action_body.tag('inline body')
yield

@generate
def action_body():
return s('{') >> whitespace.optional() >> (state_action << s(';') << whitespace.optional()).many().optional() << s('}')
yield

@generate
def action_body_repeat():
return seq(
s('x') >> whitespace.optional() >> regex(r'\d+').map(int).desc('amount of times to repeat') << whitespace.optional(), state_action
).map(lambda x: [x[1] for _ in range(x[0])])
yield

@generate
def flow_control():
return (string('stop') | string('fail') | string('loop') | string('goto') + whitespace.map(lambda _: ' ') + regex(r'[a-zA-Z]+\s?(?:\+\d+)?') | string('wait'))
return (string('stop') | string('fail') | string('loop') | string('goto') + whitespace.map(lambda _: ' ') + regex(r'[a-zA-Z0-9\.]+\s?(?:\+\d+)?') | string('wait'))
yield

@generate
Expand Down

0 comments on commit b1c770f

Please sign in to comment.