Class: MovieMaker::Action::MoveFacingDirection

Inherits:
SpriteAction
  • Object
show all
Defined in:
lib/movie_maker/action.rb

Overview

Moves a sprite from X,Y –> X2,Y2

Instance Attribute Summary

Attributes inherited from SpriteAction

#background, #image, #screen, #sprite, #start_at, #stop_at

Instance Method Summary collapse

Methods inherited from SpriteAction

#finalized?, #playing?, #started?

Constructor Details

#initialize(options = {}, coordinates = [0,0]) ⇒ MoveFacingDirection

Returns a new instance of MoveFacingDirection.



200
201
202
203
204
# File 'lib/movie_maker/action.rb', line 200

def initialize(options = {}, coordinates = [0,0])
	super(options)
	@to_x = coordinates[0]
	@to_y = coordinates[1]
end

Instance Method Details

#finalizeObject



230
231
232
# File 'lib/movie_maker/action.rb', line 230

def finalize
	@finalized = true
end

#setupObject



206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# File 'lib/movie_maker/action.rb', line 206

def setup
	@from_x = @sprite.x
	@from_y = @sprite.y

	@x_step = (@to_x - @from_x).to_f / @duration.to_f
	@y_step = (@to_y - @from_y).to_f / @duration.to_f				
	
	#
	# investigate this further later ...
	#
	@sprite.angle = (Math.atan(@y_step / @x_step) * 180.0/Math::PI) + 315
	@sprite.angle -= 45		if @framework == :gosu
	
	@setup_done = true
end

#update(time) ⇒ Object

The core of the MoveClass, the actual move-logic



223
224
225
226
227
228
# File 'lib/movie_maker/action.rb', line 223

def update(time)
	setup	unless @setup_done
	
	@sprite.x = @from_x + time * @x_step
	@sprite.y = @from_y + time * @y_step
end