about summary refs log tree commit diff stats
path: root/data/maps/daedalus/rooms/J2 Room.txtpb
blob: 48ae0c22c5fdd171735e94c4287777a106e542a6 (plain) (blame)
1
2
3
4
5
6
7
name: "J2 Room"
display_name: "Southwest Area"
letters {
  key: "j"
  level2: true
  path: "Components/Collectables/collectable8"
}
b { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.fourisland.fourpuzzle.gamestate.mapview.viewpoint;

import com.fourisland.fourpuzzle.Game;
import com.fourisland.fourpuzzle.util.Interval;

/**
 *
 * @author hatkirby
 */
public class MovingViewpoint implements Viewpoint {
    
    private double x;
    private double y;
    private int sx;
    private int sy;
    private int dx;
    private int dy;
    private double speed;
    private int xdist;
    private int ydist;
    private Runnable callback;
    private Interval in;
    
    public MovingViewpoint(int sx, int sy, int dx, int dy, Runnable callback)
    {
        this(sx, sy, dx, dy, callback, 1000);
    }
    
    public MovingViewpoint(int sx, int sy, int dx, int dy, Runnable callback, int length)
    {
        this.x = sx;
        this.y = sy;
        this.sx = sx;
        this.sy = sy;
        this.dx = dx;
        this.dy = dy;
        this.speed = length / (double) Game.FPS;
        this.xdist = dx - sx;
        this.ydist = dy - sy;
        this.callback = callback;
        this.in = Interval.createMillisInterval((int) speed);
    }
    
    private void refresh()
    {
        x += (xdist / speed);
        y += (ydist / speed);
        
        if (((sx < dx) && (x > dx)) || ((sx > dx) && (x < dx)))
        {
            x = dx;
        }
        
        if (((sy < dy) && (y > dy)) || ((sy > dy) && (y < dy)))
        {
            y = dy;
        }
        
        if ((x == dx) && (y == dy))
        {
            callback.run();
        }
    }

    public int getX()
    {
        if (in.isElapsed())
        {
            refresh();
        }
        
        return (int) x;
    }

    public int getY()
    {
        if (in.isElapsed())
        {
            refresh();
        }
        
        return (int) y;
    }
    
}