スクリプト/SpriteCameraサンプルコード(履歴ID:123)

最終投稿者:Zararu128x128 mini dycoon 更新:2011/09/19 11:46:08

#
hidePlayer()

#
textHandle = createText(8, 32, 256, 256)
setText(textHandle, "カーソルキーで移動、\nEキーで終了")


#
setCanvasVisible(true)

#画面サイズ
screenWidth = 512
screenHeight = 384

#背景スプライト
sp0 = createSprite(2)
setSpriteRect(sp0, 0.5, 0.5, screenWidth - 1, screenHeight - 1, -screenWidth / 2, -screenHeight / 2, screenWidth, screenHeight)
setSpritePosition(sp0, screenWidth / 2, screenHeight / 2)
setSpriteRotation(sp0, 0.0)
setSpriteScale(sp0, 1.0, 1.0)
setSpriteZOrder(sp0, 0)

#カメラのパラメーター設定
rot = 0.0
posX = screenWidth / 2
posY = screenHeight / 2 + 64
v = 0.0
rv = 0.0
setSpriteCameraRotation(rot)
setSpriteCameraPosition(posX, posY)
setSpriteCameraOffset(posX, posY)
setSpriteCameraScale(1.0, 1.0)

#飛行機スプライト(カメラと同じ位置)
sp1 = createSprite(23271)
setSpriteRect(sp1, 0.5, 32 * 3 + 0.5, 32 - 1, 32 - 1, -32 / 2, -32 / 2, 32, 32)
setSpritePosition(sp1, posX, posY)
setSpriteRotation(sp1, rot)
setSpriteScale(sp1, 1.0, 1.0)
setSpriteZOrder(sp1, 1)

#入力系
pressUp = false
pressDown = false
pressLeft = false
pressRight = false

#
startInput()

loop = true

while loop

  #speak("test " + toString(posX) + " " + toString(posY))
  
  while hasInput()
    #内部にたまっている入力を処理対象とします。
    takeInput()

    if isKeyDown("UP")
      pressUp = true
    elsif isKeyDown("DOWN")
      pressDown = true
    elsif isKeyDown("LEFT")
      pressLeft = true
    elsif isKeyDown("RIGHT")
      pressRight = true
    elsif isKeyUp("UP")
      pressUp = false
    elsif isKeyUp("DOWN")
      pressDown = false
    elsif isKeyUp("LEFT")
      pressLeft = false
    elsif isKeyUp("RIGHT")
      pressRight = false
    elsif isKeyDown("E")
      loop = false
    end
  end

  if pressUp
    v = v + 0.05
  end
  if pressDown
    v = v - 0.05 
  end

  rv = 0.0
  if pressLeft
    rv = -0.05
  end
  if pressRight
    rv = 0.05
  end

  posX = posX + sin(rot) * v
  posY = posY - cos(rot) * v
  rot = rot + rv
  setSpriteCameraPosition(posX, posY)
  setSpriteCameraRotation(rot)

  setSpritePosition(sp1, posX, posY)
  setSpriteRotation(sp1, rot)
  
  #
  drawCanvas()

  waitTime(0)

end

endInput()

setCanvasVisible(false)

deleteText(textHandle)


showPlayer()

goEnding()