#runtime "hsptv" #regcmd 18 #cmd hsptv_send $00 #module #define global box q #define global rand _ #define global randn o #define global sincos e #define global size z #define global randpm l #define global hit g #defcfunc hit int dx, int dy, int r return dx * dx + dy * dy < r #deffunc box int x1, int y1, int x2, int y2 pos x1, y1 line x2, y1 line x2, y2 line x1, y2 line x1, y1 return /* #defcfunc rand return (1.0 / 32768) * rnd(32768) */ #defcfunc randpm int n return rnd(n * 2 + 1) - n /* #defcfunc randn double n return rand() * n */ #deffunc sincos double r sin_@ = sin(r) cos_@ = cos(r) return #deffunc size int n font "Verdana", n, 16 return #global #enum ObjectState = 0 #enum PosX #enum PosY #enum VelX #enum VelY #enum ExtParam1 #enum Elements #enum TBomb = 0 #enum TEnemy #enum TItem #enum TShot #enum TShip #enum TParticle #enum MaxTypes #enum STitle = 0 #enum SInGame #enum SGameOver #const ReloadTime 50 #const MaxObjects 128 #const MaxShots 5 #const MaxBrakes 30 buffer 1, 320, 240 buffer 2, 320, 240 //scene = STitle randomize notesel ranking hsptv_send ranking, -1 gosub *init onexit *close repeat await 20 gsel 1 hsvcolor , , 228 gmode 3, 320, 240, limit(228 - brakeCount * 5, 64, 256) grect 160, 120 pin = in stick in, 15 prevShotKey = shotKey getkey shotKey, 'Z' getkey reloadKey, 'C' getkey brakeKey, 'X' getkey slowKey, 16 if scene { if frames < 10 { spy -= 6 } else { if scene == SInGame { b = (frames \ 50 == 0) if b | frames \ limit(10 - frames / 500, 2, 10) == 0 { type = (b == 0) gosub *find i = frames / 500 if b { v_ = randpm(1) x_ = rnd(320) + 160 j = 3 } else { v = randpm(3) x_ = rnd(480) + 80 j = 1 } found = 1, x_, -10, v, 1 + abs(v) + sqrt(rnd(j + i)) } if (shotKey & shotRepeat == 0) * shots { shotRepeat = 10 chain *= (shots != MaxShots) type = TShot gosub *find found = 1, spx, spy, 0, -12 shots-- reload = (shots == 0) * ReloadTime } shotRepeat = (shotRepeat - 1) * shotKey } else { if frames >= 50 & prevShotKey == 0 & shotKey { hsptv_send ranking, score scene = STitle } } if brakeCount { brakeCount-- if brakeCount : else { brake = 0 } } else : if brakeKey & brake >= 4 { bt = 0 + sqrt(brake) * 100 - 100 brakeCount = bt } if reload { reload-- shots = (reload == 0) * MaxShots } else : if reloadKey { reload = ReloadTime } } repeat MaxTypes type = cnt repeat MaxObjects dup state, objects(ObjectState, cnt, type) if state { dup px, state(PosX) dup py, state(PosY) dup vx, state(VelX) dup vy, state(VelY) dup ep1, state(ExtParam1) if type >= TItem | brakeCount \ 4 == 0 { px += vx py += vy } if type == TShot { if py + 10 < 0 { state = 0 chain = 0 } hsvcolor box px - 2, py - 3, px + 2, py + 3 } if type == TShip { x = px + 3 * (2 - slowKey) * (((in & 4) >> 2) - (in & 1)) if x >= 85 & x <= 235 { px = x } //py += 2 * (((in & 8) >> 2) - (in & 2)) hsvcolor line px - 8, py + 8, px, py - 8 line px + 8, py + 8 line px, py - 8 } if type <= TEnemy { // Enemy | Bomb if px < 0 | px >= 640 { vx = 0 - vx } x = px / 2 y = py / 2 i = (2 - type) * 7 j = i * i repeat MaxObjects dup shot, objects(ObjectState, cnt, TShot) if shot { if hit(shot(PosX) - x, shot(PosY) - y, j) { shot = 0 state = 0 score += 500 - type * 450 chain++ if chain == MaxShots { score += 2000 perfectTime = 50 } n = 20 - type * 12 gosub *make_particles } } loop if hit(spx - x, spy - y, j / 4) { scene = SGameOver frames = 0 ship = 0, 10000 state = 0 n = 40 gosub *make_particles } hsvcolor if type { //circle x - 6, y - 6, x + 6, y + 6, 0 n = 8 s = 6 angle = 0.1 * ep1 gosub *draw_polygon ep1++ } else { if state : else { a = 0 repeat 2 t_ = cnt repeat MaxObjects dup found, objects(ObjectState, cnt, t_) if found { if hit(found(PosX) - px, found(PosY) - py, 10000) { a++ found = 0 x = found(PosX) / 2 y = found(PosY) / 2 n = 8 gosub *make_particles gosub *make_item } } loop loop a-- score += a * a * 100 } else { line x + 8, y - 8, x, y + 8 line x - 8, y - 8 line x, y + 8 } } if state : else { x = px / 2 y = py / 2 gosub *make_item } if py > 500 { state = 0 } } if type == TItem { if hit(spx - px, spy - py, 400) { if brakeCount { score += 1000 } else { brake += (brake < MaxBrakes) } state = 0 } if brakeCount { color 32, 64, 128 } else { color 32, 128, 64 } x = px y = py n = 4 s = 6 angle = 0.3 * ep1 gosub *draw_polygon ep1++ } if type == TParticle { hsvcolor gmode 3, ep1, ep1, state * 8 grect px / 2, py / 2 state-- } } loop loop gsel 2 hsvcolor boxf hsvcolor , , 255 size 10 if reload { #const _t (ReloadTime / MaxShots) i = (ReloadTime - reload) / _t #undef _t } else { i = shots } if reload / 5 \ 2 : else { pos 260, 220 : mes "Shot: " + i } if brakeCount { i = brake * brakeCount / bt } else { i = brake } if brakeCount / 5 \ 2 : else { pos 10, 220 : mes "Brake: " + i } size 16 pos 320 mes score pos 160 - ginfo_mesx / 2, 14 mes score hsvcolor , , 1 /* if perfectTime { perfectTime-- pos 129, 34 mes "perfect!" } */ if scene == SGameOver { pos 117, 64 mes "game over" } } else { scene = (prevShotKey == 0) * shotKey //* SInGame if scene { gosub *init } gsel 2 hsvcolor boxf hsvcolor , , 1 size 16 pos 138, 64 mes "brake" //mes 160 - ginfo_mesx / 2 size 10 items = notemax / 3 offset -= ((in & 2) != 0) * (offset > 0) offset += ((in & 8) != 0) * (offset < limit(items - 10, 0, 30)) n = limit(items - offset, 0, 10) repeat n i = (cnt + offset) * 3 noteget rank_score, i noteget rank_name, i + 1 y = 120 + cnt * 11 pos 90, y : mes strf("%02d %s", cnt + offset + 1, rank_name) pos 320 : mes rank_score pos 230 - ginfo_mesx, y : mes rank_score loop } gsel redraw 0 // game pos 320, 240 gmode , 320, 240 grotate 1, , , , 640, 480 hsvcolor // frame gmode 3, 160, 480, 164 grect 80, 240 grect 560, 240 if scene { gmode 3, 200, 40, 64 grect 320, 44 } // hud gmode 2, 320, 240, 256 grotate 2, , , , 640, 480 redraw frames++ loop *init #const _t (MaxObjects + 1) dim objects, Elements, _t, MaxTypes #undef _t dup ship, objects(0, 0, TShip) dup spx, ship(PosX) dup spy, ship(PosY) ship = 1, 160, 260 shots = MaxShots shotRepeat = 0 reload = 0 score = 0 brake = 0 brakeCount = 0 chain = 0 perfectTime = 0 frames = 0 return // in type *find repeat MaxObjects + 1 dup found, objects(ObjectState, cnt, type) if found : else : break loop return // in x, y, n *make_particles t = type m = n / 4 repeat n type = TParticle gosub *find found = rnd(10) + n, x * 2 + randpm(m), y * 2 + randpm(m), randpm(3), randpm(3), rnd(30) + n loop type = t return // in x, y *make_item type = TItem gosub *find found = 1, x, y, 0, 2 return // in x, y, n, s, angle *draw_polygon repeat n + 1 sincos angle + M_PI * cnt * 2 / n fx = x + cos_ * s fy = y + sin_ * s if cnt { line fx, fy } else { pos fx, fy } loop return *close end