Game Development Reference
In-Depth Information
def shoot (target_x, target_y)
if can_shoot?
@last_shot = Gosu . milliseconds
Bullet . new(object_pool, @x , @y , target_x, target_y)
. fire( self , 1500 ) # Old value was 100
end
end
# ...
end
Now bullets fly like they are supposed to. I can only wonder why haven't I noticed this bug
in the very beginning.
Making Camera Look Ahead
One of the most annoying things with current state of prototype is that Camera is dragging
behind instead of showing what is in the direction you are moving. To fix the issue, we need
to change the way how Camera moves around. First we need to know where Camera
wants to be. We will use Utils.point_at_distance to choose a spot ahead of the
Tank . Then, Camera#update needs to be rewritten, so Camera can dynamically adjust
to it's desired spot. Here are the changes:
class Camera
# ...
def desired_spot
if @target . physics . moving?
Utils . point_at_distance(
@target . x, @target . y,
@target . direction,
@target . physics . speed . ceil * 25 )
else
[ @target . x, @target . y ]
end
end
# ...
def update
des_x, des_y = desired_spot
shift = Utils . adjust_speed(
@target . physics . speed) . floor + 1
if @x < des_x
if des_x - @x < shift
@x = des_x
else
@x += shift
Search WWH ::




Custom Search