結局遊べるところまで完成させてしまいました。短期集中連載第2弾とでも呼びましょうか。
これと全く同じものをHSPコンテスト2007へ投稿しました。ので、いつも通り利用・改造・転載など自由ですが、これの改造をHSPコンテスト2007へ投稿することはご遠慮ください。
関連:stick命令をgetkey命令で実装する
fujidigさんによるバグの指摘#include "hsptv.as"
// 独自stick定義モジュール
#undef stick
#module modStick
// getkeyキーコード
#const GETKEY_LEFT 37
#const GETKEY_UP 38
#const GETKEY_RIGHT 39
#const GETKEY_DOWN 40
#const GETKEY_Z 'Z'
#const GETKEY_X 'X'
#deffunc _initStick
dim KEY_CODE, 6
KEY_CODE(0) = GETKEY_X, GETKEY_Z, GETKEY_DOWN, GETKEY_RIGHT, GETKEY_UP, GETKEY_LEFT
return
#deffunc _stick var vTarget, int NO_TRIGGER, int CHECK_MODE, local tmp
vTarget = 0
repeat 6; = length(KEY_CODE) // start.ax軽量化のために定数化
getkey tmp, KEY_CODE(cnt)
vTarget = vTarget << 1 | tmp
loop
if (CHECK_MODE == WIN_ACTIVE_CHECK_ON) & (ginfo_act == -1){
// HSPウィンドウがアクティブでない
prev = vTarget
vTarget = 0
} else {
tmp = vTarget
vTarget &= (-1 ^ prev) | NO_TRIGGER
prev = tmp
}
return
#define global stick(%1, %2=0, %3=1) _stick %1, %2, %3
#global
_initStick // 配列の初期化
// 独自stick定義モジュールここまで
#const global BLOCK_SIZE 32
#const global BLOCK_HSIZE BLOCK_SIZE / 2
#const global BLOCK_COLOR_MAX 8
#const global AREA_WIDTH 10
#const global AREA_HEIGHT 15
#const global AREA_WIDTH2 AREA_WIDTH * BLOCK_SIZE
#const global AREA_HEIGHT2 BLOCK_SIZE * AREA_HEIGHT
#const global AREA_X ( 640 - AREA_WIDTH2 ) / 2
#const global AREA_Y ( 480 - AREA_HEIGHT2 ) / 2
#const HIGHSCORE_MAX 6
#enum STATE_NORMAL = 1
#enum STATE_BLINK
#enum STATE_GAMEOVER
#module
//
// 指定した色でブロックを描く
#deffunc draw_block int x, int y, int c, int mode
hsvcolor 191 * c / BLOCK_COLOR_MAX, 255, 255 - 155 * ( mode != 0 )
boxf AREA_X + BLOCK_SIZE * x, AREA_Y + BLOCK_SIZE * y, AREA_X + BLOCK_SIZE * ( x + 1 ) - 2, AREA_Y + BLOCK_SIZE * ( y + 1 ) - 2
return
//
// エリアを再描画
#deffunc draw_area var map
color
boxf AREA_X, AREA_Y, AREA_X + AREA_WIDTH2 - 1, AREA_Y + AREA_HEIGHT2 - 1
repeat AREA_HEIGHT
y = cnt
repeat AREA_WIDTH
p = peek( map, y * AREA_WIDTH + cnt )
if p : draw_block cnt, y, p
loop
loop
return
//
// チェックされた行を塗りつぶす
#deffunc blink_sellines var check
repeat AREA_HEIGHT
if peek( check, cnt ) {
boxf AREA_X, AREA_Y + BLOCK_SIZE * cnt, AREA_X + AREA_WIDTH2 - 1, AREA_Y + BLOCK_SIZE * ( cnt + 1 ) - 1
}
loop
return
//
// テトリミノを描く
#deffunc draw_tetrimino int block_type, int block_color, int _x, int _y, int mode
repeat 4
y = _y + cnt
if ( AREA_HEIGHT <= y )|( y < 0 ) : continue
_cnt = cnt
repeat 4
x = _x + cnt
if ( AREA_WIDTH <= x ) : break
if block_type >> ( _cnt * 4 + cnt ) & 1 {
draw_block x, y, block_color + 1, mode
}
loop
loop
return
//
// マップにブロックを固定
#deffunc fix_to_map var map, int block_type, int block_color, int _x, int _y
repeat 4
y = _y + cnt
_cnt = cnt
repeat 4
x = _x + cnt
if block_type >> ( _cnt * 4 + cnt ) & 1 {
if (x < 0)|(AREA_WIDTH <= x) : continue
if (y < 0)|(AREA_HEIGHT <= y) : continue
poke map, y * AREA_WIDTH + x, block_color + 1
}
loop
loop
return
//
// 消せる行をチェックし、変数へ結果を返す
#deffunc check_del_lines var map, var check
ret = 0
repeat AREA_HEIGHT
i = 1
_cnt = cnt
repeat AREA_WIDTH
if peek( map, _cnt * AREA_WIDTH + cnt ) == 0 {
i = 0
break
}
loop
poke check, cnt, i
ret += i
loop
return ret
//
// nLine行目を消し、上にあるラインを下へ落とす
#deffunc del_line var map, int nLine
; if ( nLine < 0 ) | ( AREA_HEIGHT <= nLine ) : return -1
if nLine > 0 {
memcpy map, map, nLine * AREA_WIDTH, AREA_WIDTH, 0
}
memset map, 0, AREA_WIDTH, 0
return; 0
//
// 指定した行をすべて削除
#deffunc del_sellines var map, var check
i = AREA_HEIGHT - 1
repeat AREA_HEIGHT, 1
if peek( check, AREA_HEIGHT - cnt ) {
del_line map, i
} else {
i--
}
loop
return; 0
//
// テトリミノが壁やブロックと衝突するか検出
#defcfunc hit_check var map, int block_type, int _x, int _y
ret = 0
repeat 4
y = _y + cnt
_cnt = cnt
repeat 4
x = _x + cnt
if block_type >> ( _cnt * 4 + cnt ) & 1 {
if ( x < 0 ) | ( AREA_WIDTH <= x ) | ( AREA_HEIGHT <= y ) {
ret = 1
break
}
if y >= 0 : if peek( map, y * AREA_WIDTH + x ) {
ret = 1
break
}
}
loop
if ret : break
loop
return ret
#global
cls 1
randomize
hsptv_up -1, ""
dim block_type, 4, 7 // Zが時計回り
block_type( 0, 0 ) = $0660, $0660, $0660, $0660 // ■
block_type( 0, 1 ) = $2222, $00F0, $4444, $0F00 // |
block_type( 0, 2 ) = $0270, $0232, $0072, $0262 // ┤
block_type( 0, 3 ) = $0360, $0462, $06C0, $4620 // s
block_type( 0, 4 ) = $0630, $0264, $0C60, $2640 // z
block_type( 0, 5 ) = $2260, $0470, $0644, $0E20 // 「
block_type( 0, 6 ) = $4460, $0740, $0622, $02E0 // └
dim high_score, HIGHSCORE_MAX
sdim ranker_name, 50, HIGHSCORE_MAX
sdim map, AREA_WIDTH * AREA_HEIGHT
sdim line_check, AREA_HEIGHT
sqarea_x = AREA_X, AREA_X + AREA_WIDTH2, AREA_X + AREA_WIDTH2, AREA_X
sqarea_y = AREA_Y, AREA_Y, AREA_Y + AREA_HEIGHT2, AREA_Y + AREA_HEIGHT2
;pos ginfo_winx : mes "Gameover"
;gameover_width = ginfo_mesx : gameover_height = ginfo_mesy
#const gameover_width 64
#const gameover_height 18
#const fall_limit 17
gmode GMODE_ALPHA, , , 192
*restart
gosub *reload_highscore
memset map, 0, AREA_WIDTH * AREA_HEIGHT
next_type = rnd(7)
state = STATE_NORMAL
score = 0
gosub *create_new_tetrimino
*main
stick keys, 8
if state == STATE_BLINK {
state_limit--
if state_limit == 0 {
state = STATE_NORMAL
del_sellines map, line_check
gosub *create_new_tetrimino
}
}
if state == STATE_GAMEOVER {
if state_limit : state_limit--
if state_limit == 1 : hsptv_up score, ""
if ( state_limit == 0 ) & ( keys >> 4 & 1 ) : goto *restart
}
if state == STATE_NORMAL {
gosub *move_tetrimino
}
gosub *draw
wait 2
goto *main
*draw
redraw 0
draw_area map
gosub *draw_score
gosub *draw_next
if state == STATE_NORMAL {
gosub *draw_ghost
draw_tetrimino block_type( moving_rot, moving_type ), moving_type, moving_x, moving_y, 0
}
if state == STATE_BLINK {
c = 255 * ( state_limit / 3 \ 2 )
color c, c, c
blink_sellines line_check
}
if state == STATE_GAMEOVER {
color
gsquare -1, sqarea_x, sqarea_y
x = AREA_X + ( AREA_WIDTH2 - gameover_width ) / 2
y = AREA_Y + ( AREA_HEIGHT2 - gameover_height ) / 2
color 100, 100, 100
pos x+2, y+2
mes "Gameover"
color 255, 255, 255
pos x, y
mes "Gameover"
if ( state_limit == 0 ) {
pos x-50, y+40 : mes "push Z key to restart"
}
}
redraw 1
return
*draw_next
color
boxf BLOCK_HSIZE, BLOCK_HSIZE, BLOCK_HSIZE * 9 - 1, BLOCK_HSIZE * 11 - 1
pos BLOCK_HSIZE, BLOCK_HSIZE
draw_tetrimino block_type( 0, next_type ), next_type, -4, 1, 0
return
*draw_score
color
boxf BLOCK_HSIZE, BLOCK_SIZE * 6, BLOCK_HSIZE * 9 - 1, BLOCK_HSIZE * 29 - 1
color 255, 255, 255
pos BLOCK_HSIZE + 6, BLOCK_SIZE * 6 + 9
mes strf( "score:%08d", score )
mes "--------------"
repeat HIGHSCORE_MAX
mes "" + ( cnt + 1 ) + ":" + ranker_name( cnt )
mes strf( " %08d", highscore(cnt) )
loop
return
*move_tetrimino
if state != STATE_NORMAL : return
// 横方向の移動
next_moving_x = moving_x + ( keys >> 2 & 1 ) - ( keys & 1 )
if hit_check( map, block_type( moving_rot, moving_type ), next_moving_x, moving_y ) == 0 {
moving_x = next_moving_x
}
// 縦方向の移動
fall_count += 1 + 3 * ( keys >> 3 & 1 )
if fall_count >= fall_limit {
fall_count = 0
if hit_check( map, block_type( moving_rot, moving_type ), moving_x, moving_y + 1 ) == 0 {
moving_y++
} else {
// これ以上落下できないので、今の位置に固定
fix_to_map map, block_type( moving_rot, moving_type ), moving_type, moving_x, moving_y
gosub *check_delete
}
}
if keys & 2 {
moving_y = ghost_y
fall_count = fall_limit
}
// 回転処理
if keys & %110000 {
next_rot = moving_rot + (keys >> 4 & 1) - (keys >> 5 & 1) & 3
if hit_check( map, block_type( next_rot, moving_type ), moving_x, moving_y ) == 0 {
moving_rot = next_rot
// fall_count--
}
}
return
*check_delete
check_del_lines map, line_check
if stat {
score += stat * stat * 10
state = STATE_BLINK
state_limit = 12
} else {
gosub *create_new_tetrimino
}
return
*draw_ghost
repeat
if hit_check( map, block_type( moving_rot, moving_type ), moving_x, moving_y + cnt ) {
ghost_y = moving_y + cnt - 1
break
}
loop
if ghost_y > moving_y {
draw_tetrimino block_type( moving_rot, moving_type ), moving_type, moving_x, ghost_y, 1
}
return
*create_new_tetrimino
moving_x = AREA_WIDTH / 2 - 2// 動かしているテトリミノの位置(左上)
moving_y = -2
moving_rot = 0 // 動かしているテトリミノの回転
moving_type = next_type // 動かしているテトリミノの種類(兼色の種類)
next_type = rnd(7)
if hit_check( map, block_type( moving_rot, moving_type ), moving_x, moving_y ) {
// ゲームオーバー
state = STATE_GAMEOVER
state_limit = 20
gosub *reload_highscore
}
return
*reload_highscore
repeat HIGHSCORE_MAX
hsptv_getrank highscore(cnt), ranker_name(cnt), s, cnt
loop
return
2007年8月12日日曜日
ちっちゃなテトリス
登録:
コメントの投稿 (Atom)
0 件のコメント:
コメントを投稿