본문 바로가기
Game Development Study 게임 개발 공부

[웹기반 오픈소스 게임엔진][microStudio 마이크로 스튜디오] 프로그래밍 (마이크로 스크립트(microscript), 루아(Lua)) 코드 구조 정리

by byungwoo733 2024. 6. 23.
728x90
반응형
SMALL

마이크로 스크립트(microscript) 기본 코드

init = function()
end

update = function()
end

draw = function()
end

추가 적용된 microscript 기본 코드 문법 규칙

init = function()
  position = 0
  example_man2_y = 0
  example_man2_vy = 0
end

update = function()
  position = position + 2
  example_man2_y = max(0, example_man2+example_man2_vy)
  example_man2_vy = example_man2_vy = -0.3
end

draw = function()
  screen.drawSprite("example man", -80, -50, 20) // if microscript type case
end

====================

캐릭터와 배경을 적용한 microscript 코드

init = function()
  example_man2 = object end
  example_man2.x = 0
  example_man2.speed = 2 
end

update = function()
  if keyboard.UP then 
    example_man2.y += example_man2.speed
end

if keyboard.DOWN then 
    example_man2.y -= example_man2.speed
end

if keyboard.RIGHT then 
    example_man2.y += example_man2.speed
end

if keyboard.LEFT then 
    example_man2.y -= example_man2.speed
end

    example_man2.x = clamp(example_man2.x, 60, 60) 
    example_man2.y = clamp(example_man2.y, 20, 20)
end

draw = function()
  // set up the Background
  screen.sleep()
  screen.drawSprite("sky1000" 0 , 0, 300, 200)
  // draw the example Man
  screen.drawSprite("example_man2", example_man2.x, example_man2.y, 32, 32)
end

 

캐릭터를 그리고 사이즈 정합니다.

// draw the example Man
  screen.drawSprite("example_man2", example_man2.x, example_man2.y, 32, 32)

=========================

 

실행결과

 

Maps 구성

--------------------------------

microStudio에서 지원되는 루아(Lua) 형식 기본 코드 (기본 코드 구조는 똑같음)

microScript와 Lua 코드 차이로서 한 가지 예는 "screen.drawSprite (microScript) / screen:drawSprite (Lua)"

"."으로 붙이냐 ":"붙이냐 차이

screen.drawSprite("example man", -80, -50, 20) // microScript style

screen:drawSprite("example man", -80, -50, 20) // Lua style
init = function()
end

update = function()
end

draw = function()
end

 

추가 적용된 Lua 코드 문법 규칙

init = function()
  position = 0
  example_man2_y = 0
  example_man2_vy = 0
end

update = function()
  position = position + 2
  example_man2_y = max(0, example_man2+example_man2_vy)
  example_man2_vy = example_man2_vy = -0.3
end

draw = function()
  -- lua script uses ":"
  screen:drawSprite("example man", -80, -50, 20)
end

 

캐릭터와 배경을 적용한 Lua 코드

init = function()
  position = 0
  example_man2_y = 0
  example_man2_vy = 0
end

update = function()
  position = position + 2
  
  example_man2_y = max(0, example_man2+example_man2_vy)
  example_man2_vy = example_man2_vy = -0.3
  
  if touch.touching and example_man2_y == 0 then
    example_man2_vy = 7
end
end

draw = function()
  -- lua script uses ":"
  screen:filRect(0,0, screen.width, screen.height, "rgb(57,0,57)")
  screen:drawSprite("example man", -80, -50, 20)
  
  for i=-12,12 do
    screen:drawSprite("soil_32", i*50-position%50,-75,50)
  end
  -- screen.drawSprite("example man", -80, -50, 20) // if microscript type case
end

 

=====================

실행화면 (코드 한 줄이 Error가 떠서 찾는 중이라서 없어요.)

 

* (주의) 여기 예제나 글들은 게임개발에 도움이 되는 정보 보다는 개인 공부을 위한 것이고 옳은 방법이 아닐 수 있으니 참고바랍니다. 

 

728x90
LIST

댓글