Skip to content

Instantly share code, notes, and snippets.

@RKX1209
Created March 26, 2016 17:11
Show Gist options
  • Save RKX1209/c0acec79101b86a8f983 to your computer and use it in GitHub Desktop.
Save RKX1209/c0acec79101b86a8f983 to your computer and use it in GitHub Desktop.
Dnlang: Parse syntax and translate to AST
function script_enemy_main() {
let imgBoss = "script\img\ExRumia.png";
let frame = 0;
let angleBase = 90;
return;
}
function Initialize() {
SetX(GetCenterX);
SetY(GetClipMinY + 120);
SetLife(2000);
LoadGraphic(imgBoss);
SetTexture(imgBoss);
SetGraphicRect(0, 0, 63, 63);
}
function @MainLoop() {
SetCollisionA(GetX, GetY, 24);
SetCollisionB(GetX, GetY, 24);
++frame;
if(frame == 30) {
nway(angleBase, 3, 5, YELLOW01);
angleBase += 8;
} else if(frame == 60) {
nway(angleBase, 5, 3, WHITE01);
angleBase += 8;
frame = 0;
}
}
function @DrawLoop() {
DrawGraphic(GetX, GetY);
}
function @Finalize() {
DeleteGraphic(imgBoss);
}
function nway(dir, way, span, color) {
let radius = 32;
let angle = dir - (way - 1) / 2 * span;
while(way > 0) {
let x = GetX + offsetX(radius, angle);
let y = GetY + offsetY(radius, angle);
CreateShot01(x, y, 1, angle, color, 0);
angle += span;
--way;
}
}
function offsetX(radius, angle) {
return radius * cos(angle);
}
function offsetY(radius, angle) {
return radius * sin(angle);
}
(FUNC_DEF script_enemy_main PARAM
(BLOCK
(DECL imgBoss script\img\ExRumia.png)
(DECL frame 0)
(DECL angleBase 90) RETURN))
(FUNC_DEF Initialize PARAM
(BLOCK
(CALL SetX GetCenterX)
(CALL SetY (+ GetClipMinY 120))
(CALL SetLife 2000)
(CALL LoadGraphic imgBoss)
(CALL SetTexture imgBoss)
(CALL SetGraphicRect 0 0 63 63)))
(FUNC_DEF @MainLoop PARAM
(BLOCK
(CALL SetCollisionA GetX GetY 24)
(CALL SetCollisionB GetX GetY 24) (++ frame) (IF (== frame 30)
(BLOCK
(CALL nway angleBase 3 5 YELLOW01) angleBase (+= 8)) (IF (== frame 60)
(BLOCK
(CALL nway angleBase 5 3 WHITE01) angleBase (+= 8) frame (= 0))))))
(FUNC_DEF @DrawLoop PARAM
(BLOCK
(CALL DrawGraphic GetX GetY)))
(FUNC_DEF @Finalize PARAM
(BLOCK
(CALL DeleteGraphic imgBoss)))
(FUNC_DEF nway
(PARAM dir way span color)
(BLOCK
(DECL radius 32)
(DECL angle (- dir (/ (- way 1) (* 2 span)))) (WHILE (> way 0)
(BLOCK
(DECL x (+ GetX
(CALL offsetX radius angle)))
(DECL y (+ GetY
(CALL offsetY radius angle)))
(CALL CreateShot01 x y 1 angle color 0) angle (+= span) (-- way)))))
(FUNC_DEF offsetX
(PARAM radius angle)
(BLOCK (RETURN (* radius
(CALL cos angle)))))
(FUNC_DEF offsetY
(PARAM radius angle)
(BLOCK (RETURN (* radius
(CALL sin angle)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment