レースもどき
# DXRuby0.0.5 サンプル レースもどき require 'dxruby' # コースデータ line1 = [53, 430, 568, 438, 568, 438, 607, 261, 607, 261, 520, 200, 520, 200, 531, 151, 531, 151, 602, 115, 602, 115, 562, 19, 562, 19, 113, 21, 113, 21, 34, 83, 34, 83, 81, 180, 81, 180, 221, 207, 221, 207, 251, 274, 251, 274, 204, 299, 204, 299, 61, 262, 61, 262, 26, 358, 26, 358, 53, 430] line2 = [93, 330, 88, 380, 88, 380, 479, 392, 479, 392, 536, 302, 536, 302, 534, 267, 534, 267, 461, 210, 461, 210, 459, 151, 459, 151, 518, 91, 518, 91, 487, 53, 487, 53, 156, 77, 156, 77, 125, 110, 125, 110, 292, 197, 292, 197, 311, 268, 311, 268, 227, 342, 227, 342, 93, 330] # コース作成 $image = Image.new(640,480) $image.box(0,0,639,480,[255,0,200,0]) for i in 0..(line1.size/2-2) $image.line(line1[i*2], line1[i*2+1], line1[i*2+2], line1[i*2+3], [255,128,128,128]) end for i in 0..(line2.size/2-2) $image.line(line2[i*2], line2[i*2+1], line2[i*2+2], line2[i*2+3], [255,128,128,128]) end # 自前で塗りつぶし Green = [255,0,200,0] def paint(x, y, col) px = x flag = [1, 1] arr = [] return if y < 1 or y > 478 while px > 0 and $image.get(px-1,y) == Green do # 左端まで検索 px = px - 1 end while px <= 639 and $image.get(px,y) == Green do # 右端まで塗る $image.set(px,y,col) (0..1).each do |i| if $image.get(px, y+i*2-1) == Green then if flag[i] == 1 then arr.push([px, y+i*2-1, col]) flag[i] = 0 end else flag[i] = 1 end end px = px + 1 end arr.each do |ax, ay, acol| paint(ax,ay,acol) end end paint(200,300,[255,128,128,128]) # 車データ carimage = Image.new(8,6) carimage.box(0, 0, 7, 5, [255, 255, 0, 0]).box(5, 1, 6, 4, [255, 0, 0, 255]) x = 200 y = 300 angle = 0 speed = 0 dx = 0 dy = 0 Window.scale = 2 Window.width = 200 Window.height = 200 Window.loop do # 移動処理 speed = speed + 0.1 if Input.padDown?(P_BUTTON0) speed = speed - 0.1 if Input.padDown?(P_BUTTON1) angle = angle - 45 if Input.padPush?(P_LEFT) angle = angle + 45 if Input.padPush?(P_RIGHT) dx = dx * 0.95 + Math.cos(Math::PI / 180 * angle) * speed * 0.05 dy = dy * 0.95 + Math.sin(Math::PI / 180 * angle) * speed * 0.05 x = x + dx y = y + dy if $image.get(100, 100) == Green then dx = dx * 0.5 dy = dy * 0.5 speed = 0.5 end # imageオブジェクトの細工 $image.x = x.to_i $image.y = y.to_i $image.width = 200 $image.height = 200 # 描画 Window.draw(0,0,$image) Window.drawRot(100, 100, carimage, angle) break if Input.keyPush?(K_ESCAPE) end
わざわざ自前でペイントルーチンとか作ってみたり。
これもちゃんとした画像を外部ツールで作ればかっこいいゲームになるはずだ。
内容はしょぼいが。