se.angergard.game.util.Util.java Source code

Java tutorial

Introduction

Here is the source code for se.angergard.game.util.Util.java

Source

/********************************************************************************
 *
 *   Copyright 2014 Theodor Angergard
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 *
 *******************************************************************************/

package se.angergard.game.util;

import com.badlogic.gdx.graphics.*;
import com.badlogic.gdx.graphics.Pixmap.Format;
import com.badlogic.gdx.math.*;

public class Util {

    public static final Texture createSolidCircleTexture(Color color, int width, int height) {
        Pixmap map = new Pixmap(width, height, Format.RGBA8888);
        Color alpha = new Color(0, 0, 0, 0);
        map.setColor(alpha);
        map.fill();
        map.setColor(color);
        map.fillCircle(width / 2, height / 2, ((width + height) / 2) / 2);
        Texture texture = new Texture(map);
        map.dispose();
        return texture;
    }

    public static final Texture createSolidTexture(Color color, int width, int height) {
        Pixmap map = new Pixmap(width, height, Format.RGB888);
        map.setColor(color);
        map.fill();
        Texture texture = new Texture(map);
        map.dispose();
        return texture;
    }

    // Yes, I'm lazy
    public static final boolean intersects(Rectangle r1, Rectangle r2) {
        java.awt.Rectangle jr1 = new java.awt.Rectangle();
        jr1.setBounds((int) r1.x, (int) r1.y, (int) r1.width, (int) r1.height);

        java.awt.Rectangle jr2 = new java.awt.Rectangle();
        jr2.setBounds((int) r2.x, (int) r2.y, (int) r2.width, (int) r2.height);

        return jr1.intersects(jr2);
    }

}