3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Godotを待ちながら

Posted at

オープンソースのゲームエンジン"Godot"を触ってみた。
http://www.godotengine.org/projects/godot-engine
とりあえずバージョンアップか何かあるまで放置するので、感想とやった部分をメモっておく。

ググラビリティが低い。

ググると演劇とキャラが上位を占める。
"godot engine"まで入力するのだるい。

でもシンプルで軽い。

pythonライクな独自言語で";"ないので嬉しい。

とはいえビルドがうまくできなくて放置した。

そのうち解決するかもしれない。
たまには情報収集すること。

クリックで掴んでドラッグ、特定の場所におく。がやりたかった。

ボードゲームの駒みたいなの。
猫スプライトの子供にButtonを入れてみた。これでマウスイベント関連の判定を取る。
Screen Shot 2015-08-30 at 10.44.32 PM.png

  • ドラッグ中、intersectで色変え。
    Screen Shot 2015-08-30 at 10.45.21 PM.png

  • intersect状態でドロップすると中心にスナップ。
    Screen Shot 2015-08-30 at 10.45.28 PM.png

  • scriptはこんな感じ。

cat.gd

extends Node2D

var mypos=null
var dragOn=false
var catchUp=false
var atari=null
var house=null


func _ready():
	# Initialization here
	set_process_input(true)
	set_process(true)

	house=get_node('house')
	atari=get_node("cat")
	
func _input(event):

	if (get_node("cat/Button").is_hovered() and event.is_pressed()):
		dragOn = !dragOn
		mypos = atari.get_pos()
		
		print(mypos,dragOn)
		
		
	elif (event.type==InputEvent.MOUSE_MOTION):
		print("Mouse Motion at: ",event.pos,dragOn)
		mypos=event.pos
		
		
	elif (dragOn==false and catchUp==true):
		print('now catch')
		

func _process(delta):

	if dragOn==false:
		atari.set_scale(Vector2(1,1))

		
	if dragOn==true:
		atari.set_scale(Vector2(1.2,1.2))
		atari.set_pos(mypos)
		
		var atariSize = atari.get_texture().get_size()
		var houseSize = house.get_texture().get_size()

		var myAtari=Rect2(mypos - atariSize/2 , atariSize)
		
		var myHouse = Rect2(house.get_pos(), houseSize)

		
		if myAtari.intersects(myHouse):
			catchUp=true
			print(catchUp)
		if !myAtari.intersects(myHouse):
			catchUp=false
			print(catchUp)

	if catchUp==true and dragOn==true:
		house.set_modulate(Color(1, 0, 0))
		atari.set_modulate(Color(0.0, 1.0, 1.0))

		
	elif catchUp==true:
		house.set_modulate(Color(1, 1, 0))
		atari.set_modulate(Color(1.0, 1.0, 0.0))
		
		animMove(get_pos(),house.get_pos())
		atari.set_modulate(Color(1, 0, 0))

		
	else:
		house.set_modulate(Color(1, 1, 1))
		atari.set_modulate(Color(1.0, 1.0, 1.0))



func animMove(orgPos,tgtPos):
	var tgtCenterPos=Vector2( tgtPos+house.get_texture().get_size() / 2 )
	atari.set_pos(tgtCenterPos)

こんな状態で放置している

Screen Shot 2015-10-27 at 07.13.45.png

moveObject.gd
extends Node2D

var who = ["cat","dog"]
var labelText = "HOME"


# status
var moveobjlist = ["moveObj_a","moveObj_b","moveObj_c"]
var status = 0

var DRAG_ON=false
var CATCH_UP=false

# childs
var moveobj=null
var button = null
var sprite = null

var myObjList = []
var myObj = {}
var movable = null

var state = null

var bdAtari = null


# attributes
var myPos = Vector2(0,0)
var atari = null

var myAtari =null
var atariSize = null
var mySprite = null



func _ready():
	set_process_input(true)
	set_process(true)
	
	
	
	labelText = who[0]+"'s HOME"
	get_node("Label").set_text(labelText)

# collision
	bdAtari=Rect2(get_node("board").get_pos(),get_node("board").get_texture().get_size())


	for i in moveobjlist:
	
		moveobj = get_node(i)
		button = moveobj.get_node("button")
		sprite = moveobj.get_node("sprite")
		
		myObj={"obj":moveobj,"button":button,"sprite":sprite}
		myObjList.append(myObj)

	
	movable = myObjList[0].obj
	state = get_node("labelState")

func _input(event):
	for i in myObjList:
		if (i.button.is_hovered() and event.is_pressed()):
			DRAG_ON=!DRAG_ON
			myPos = i.obj.get_pos()
			movable = i.obj
			mySprite = i.sprite
			print(i.obj.get_name(),str(myPos))

				
		elif (event.type==InputEvent.MOUSE_MOTION):
			myPos=event.pos
	

	


func _process(delta):

	state.set_text(str(status))

	if DRAG_ON==false:
        movable.set_scale(Vector2(1,1))

	if DRAG_ON==true:
		movable.set_scale(Vector2(1.2,1.2))
		movable.set_pos(myPos)
		
		var atariSize = mySprite.get_texture().get_size()
		var myAtari=Rect2(myPos - atariSize/2 , atariSize)
		
		if myAtari.intersects(bdAtari):
            CATCH_UP=true
            print("in")
		elif !myAtari.intersects(bdAtari):
            CATCH_UP=false
            print("out")
	
	
	if CATCH_UP==true and DRAG_ON==true:
        get_node("board").set_modulate(Color(1, 0, 0))
	
	else:
		get_node("board").set_modulate(Color(1, 1, 1))
	#print(str(myPos))
3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?