Use random

This commit is contained in:
mattn 2014-07-09 20:05:49 +09:00
parent a01c40b35a
commit 0fb18f15ef
2 changed files with 8 additions and 22 deletions

View File

@ -1,7 +1,5 @@
scriptencoding utf-8 scriptencoding utf-8
let s:datadir = expand('<sfile>:h:h') . '/data'
let s:cursor_off = 0 let s:cursor_off = 0
let s:cursor_on = 1 let s:cursor_on = 1
let s:t_ve = &t_ve let s:t_ve = &t_ve
@ -54,13 +52,7 @@ function! s:stage_wipeout() abort
bdelete bdelete
endfunction endfunction
function! s:loaddata() abort
return eval(join(readfile(s:datadir . '/stage.json'), ''))
endfunction
function! s:loop() function! s:loop()
let sf = s:loaddata()
call s:stage_init() call s:stage_init()
" clear whole screen " clear whole screen
@ -84,8 +76,9 @@ function! s:loop()
let dy = 40 let dy = 40
let si = 0 let si = 0
let sl = 0
let sc = 0 let sc = 0
let st = sf[si][0] let st = 100
let cf = get(g:, 'flappyvird_face', '(; @_@)') let cf = get(g:, 'flappyvird_face', '(; @_@)')
let cw = len(cf) let cw = len(cf)
let cb = getline(ry)[jx :jx+cw-1] let cb = getline(ry)[jx :jx+cw-1]
@ -187,22 +180,20 @@ function! s:loop()
if st == 0 if st == 0
" draw bar " draw bar
let bw = 4 + s:rand() % (7 - sl / 5)
let bb = 1 + s:rand() % (sh - bw - 3)
for i in range(1, sh) for i in range(1, sh)
let l = getline(i) let l = getline(i)
let of = i >= sf[si][1] && i <= sf[si][1] + sf[si][2] let of = i >= bb && i <= bb + bw
call setline(i, l[:ww-sf[si][3]] . repeat(of ? ' ' : '*', sf[si][3])) call setline(i, l[:ww] . repeat(of ? ' ' : '*', 3))
endfor endfor
" shift to next bar " shift to next bar
let si += 1 let si += 1
" if it's end of bars, finish
if si == len(sf)
let state = s:STATE_FINISH
continue
endif
" set next bar timer " set next bar timer
let st = sf[si][0] let st = (60 - sl) + s:rand() % 20
let sl += 1
else else
let st -= 1 let st -= 1
endif endif

View File

@ -1,5 +0,0 @@
[
[40, 2, 5, 2], [60, 10, 5, 3], [40, 2, 5, 2], [60, 10, 5, 3], [40, 2, 8, 2], [80, 10, 5, 3],
[80, 8, 5, 2], [70, 10, 4, 3], [50, 1, 8, 5], [60, 10, 4, 3], [40, 2, 5, 2], [60, 10, 4, 3],
[40, 2, 5, 2], [60, 10, 5, 3], [40, 2, 5, 2], [60, 10, 4, 3], [40, 2, 8, 2], [60, 10, 4, 3],
]