mirror of
https://github.com/icela/FriceDemo.git
synced 2026-10-16 21:12:46 +08:00
add new demos
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
import org.frice.Game;
|
||||
import org.frice.anim.move.SimpleMove;
|
||||
import org.frice.obj.sub.ShapeObject;
|
||||
import org.frice.resource.graphics.ColorResource;
|
||||
import org.frice.util.shape.FCircle;
|
||||
import org.frice.util.shape.FRectangle;
|
||||
import org.frice.util.time.FTimer;
|
||||
|
||||
import static org.frice.Initializer.launch;
|
||||
|
||||
/**
|
||||
* An awesome demo
|
||||
*
|
||||
* @author SuperSodaSea
|
||||
*/
|
||||
public class Demo11 extends Game {
|
||||
|
||||
private ColorResource colors[];
|
||||
private double a = 0;
|
||||
private double b = 0;
|
||||
private FTimer timer = new FTimer(15);
|
||||
|
||||
@Override
|
||||
public void onInit() {
|
||||
colors = new ColorResource[]{
|
||||
ColorResource.东条希,
|
||||
ColorResource.南小鸟,
|
||||
ColorResource.园田海未,
|
||||
ColorResource.小泉花阳,
|
||||
ColorResource.星空凛,
|
||||
ColorResource.洵濑绘理,
|
||||
ColorResource.矢泽妮可,
|
||||
ColorResource.西木野真姬,
|
||||
ColorResource.高坂穗乃果
|
||||
};
|
||||
// setSize(1200, 720);
|
||||
setTitle("IAmSoSquare Demo");
|
||||
setAutoGC(true);
|
||||
addObject(new ShapeObject(ColorResource.IntelliJ_IDEA黑, new FRectangle(getWidth(), getHeight())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
super.onRefresh();
|
||||
if (timer.ended()) {
|
||||
a += 0.0002;
|
||||
b += a;
|
||||
addObject(new ShapeObject(colors[(int) (System.currentTimeMillis() / 100 % colors.length)],
|
||||
new FCircle(10), getWidth() / 2, getHeight() / 2) {{
|
||||
addAnim(new SimpleMove((int) (Math.sin(b) * 256), (int) (Math.cos(b) * 256)));
|
||||
}});
|
||||
System.out.println(getLayers()[0].getObjects().size());
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
launch(Demo11.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
import org.frice.Game;
|
||||
import org.frice.anim.move.AccelerateMove;
|
||||
import org.frice.anim.move.SimpleMove;
|
||||
import org.frice.obj.sub.ShapeObject;
|
||||
import org.frice.resource.graphics.ColorResource;
|
||||
import org.frice.util.shape.FCircle;
|
||||
import org.frice.util.shape.FRectangle;
|
||||
import org.frice.util.time.FTimer;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import static org.frice.Initializer.launch;
|
||||
|
||||
/**
|
||||
* An awesome demo
|
||||
*
|
||||
* @author SuperSodaSea
|
||||
*/
|
||||
public class Demo12 extends Game {
|
||||
|
||||
private ColorResource[] colors;
|
||||
private FTimer timer2;
|
||||
private Random random = new Random(System.currentTimeMillis());
|
||||
private double x;
|
||||
private double y;
|
||||
|
||||
@Override
|
||||
public void onInit() {
|
||||
setSize(300, 300);
|
||||
timer2 = new FTimer(30);
|
||||
colors = new ColorResource[]{ColorResource.东条希, ColorResource.高坂穗乃果, ColorResource.西木野真姬, ColorResource.矢泽妮可, ColorResource.洵濑绘理, ColorResource.星空凛, ColorResource.南小鸟};
|
||||
addObject(new ShapeObject(ColorResource.IntelliJ_IDEA黑, new FRectangle(getBounds())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
if (timer2.ended()) {
|
||||
if (mouse.getX() > 0) x = mouse.getX();
|
||||
if (mouse.getY() > 0) y = mouse.getY();
|
||||
addObject(new ShapeObject(colors[(int) ((System.currentTimeMillis() / 100) % colors.length)], new FCircle(10), x, y) {{
|
||||
addAnim(new AccelerateMove(0, 800));
|
||||
addAnim(new SimpleMove((int) (random.nextInt(Demo12.this.getWidth()) - getX()), -10));
|
||||
}});
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
launch(Demo12.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
import org.frice.Game;
|
||||
import org.frice.obj.sub.ShapeObject;
|
||||
import org.frice.resource.graphics.ColorResource;
|
||||
import org.frice.util.shape.FCircle;
|
||||
import org.frice.util.shape.FRectangle;
|
||||
import org.frice.util.time.FTimer;
|
||||
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.util.Arrays;
|
||||
import java.util.Queue;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
import static org.frice.Initializer.launch;
|
||||
|
||||
/**
|
||||
* Created by ice1000 on 2016/8/23.
|
||||
*
|
||||
* @author ice1000, KirCute
|
||||
*/
|
||||
public class Demo15 extends Game {
|
||||
public static void main(String[] args) {
|
||||
launch(Demo15.class);
|
||||
}
|
||||
|
||||
private int direction = KeyEvent.VK_LEFT, x = 30, y = 20, fx = 10, fy = 10;
|
||||
private FTimer timer;
|
||||
private boolean isIncreasing = true;
|
||||
private Queue<ShapeObject> body;
|
||||
private ShapeObject food;
|
||||
private Random random = new Random(System.currentTimeMillis());
|
||||
|
||||
@Override
|
||||
public void onInit() {
|
||||
super.onInit();
|
||||
this.setLocationRelativeTo(null);
|
||||
this.setSize(600, 400);
|
||||
timer = new FTimer(100);
|
||||
this.setTitle("Snake game demo");
|
||||
this.addKeyListener(null, (KeyEvent e) -> {
|
||||
if (Arrays.asList(KeyEvent.VK_LEFT, KeyEvent.VK_RIGHT, KeyEvent.VK_UP, KeyEvent.VK_DOWN).contains(e.getKeyCode()))
|
||||
direction = e.getKeyCode();
|
||||
}, null);
|
||||
body = new LinkedBlockingQueue<>();
|
||||
food = generateFood(10, 10);
|
||||
this.addObject(food);
|
||||
ShapeObject object = generateBody(30, 20);
|
||||
body.add(object);
|
||||
this.addObject(object);
|
||||
this.setAutoGC(false);
|
||||
this.setResizable(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
super.onRefresh();
|
||||
if (timer.ended()) {
|
||||
ShapeObject object;
|
||||
switch (direction) {
|
||||
case KeyEvent.VK_LEFT:
|
||||
object = generateBody(--x, y);
|
||||
break;
|
||||
case KeyEvent.VK_RIGHT:
|
||||
object = generateBody(++x, y);
|
||||
break;
|
||||
case KeyEvent.VK_UP:
|
||||
object = generateBody(x, --y);
|
||||
break;
|
||||
case KeyEvent.VK_DOWN:
|
||||
object = generateBody(x, ++y);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
// x += 60;
|
||||
// x %= 60;
|
||||
// y += 40;
|
||||
// y %= 40;
|
||||
x = this.moved(x, true);
|
||||
y = this.moved(y, false);
|
||||
if (x == fx && y == fy) {
|
||||
this.removeObject(food);
|
||||
isIncreasing = true;
|
||||
fx = random.nextInt(this.getWidth() / 10 - 1);
|
||||
fy = random.nextInt(this.getHeight() / 10 - 1);
|
||||
food = generateFood(fx, fy);
|
||||
this.addObject(food);
|
||||
}
|
||||
body.add(object);
|
||||
this.addObject(object);
|
||||
if (!isIncreasing) this.removeObject(body.poll());
|
||||
isIncreasing = false;
|
||||
}
|
||||
}
|
||||
|
||||
private ShapeObject generateBody(int x, int y) {
|
||||
return new ShapeObject(ColorResource.八云蓝, new FRectangle(10, 10), x * 10, y * 10);
|
||||
}
|
||||
|
||||
private ShapeObject generateFood(int x, int y) {
|
||||
return new ShapeObject(ColorResource.如果奇迹有颜色那么一定是橙色, new FCircle(5), x * 10, y * 10);
|
||||
}
|
||||
|
||||
private int moved(int i, boolean isX) {
|
||||
return isX ? (i + this.getWidth() / 10 - 2) % (this.getWidth() / 10 - 2) : (i + this.getHeight() / 10 - 4) % (this.getHeight() / 10 - 4);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
import org.frice.platform.adapter.JvmImage
|
||||
import org.frice.util.*
|
||||
import org.frice.util.message.FLog
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* test: http://lofi.e-hentai.org/g/813858/63f5aba277/
|
||||
* test: http://www.yaoqmh.net/shaonvmanhua/5122.html
|
||||
* Created by ice1000 on 2016/9/3.
|
||||
*
|
||||
* @author ice1000
|
||||
*/
|
||||
fun process() {
|
||||
val scanner = Scanner(System.`in`)
|
||||
var count = 0
|
||||
while (scanner.hasNext()) forceRun {
|
||||
val images = findTag(readText(scanner.nextLine()), "img")
|
||||
images.forEach { i ->
|
||||
FLog.i("processing $i.... please wait.")
|
||||
val from = i.indexOf('\"') + 1
|
||||
val link = i.substring(from, i.indexOf('\"', from))
|
||||
FLog.i("url is $link")
|
||||
forceRun { (readImage(link) as JvmImage).image2File("$count.png") }
|
||||
count++
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) = process()
|
||||
@@ -0,0 +1,40 @@
|
||||
import org.frice.Game;
|
||||
import org.frice.anim.move.AccelerateMove;
|
||||
import org.frice.obj.button.SimpleText;
|
||||
import org.frice.obj.sub.ShapeObject;
|
||||
import org.frice.resource.graphics.ColorResource;
|
||||
import org.frice.util.shape.FCircle;
|
||||
import org.frice.util.time.FTimer;
|
||||
|
||||
import static org.frice.Initializer.launch;
|
||||
|
||||
/**
|
||||
* Created by ice1000 on 2016/8/29.
|
||||
*
|
||||
* @author ice1000
|
||||
*/
|
||||
public class Demo20 extends Game {
|
||||
private FTimer timer = new FTimer(10);
|
||||
|
||||
@Override
|
||||
public void onLastInit() {
|
||||
SimpleText text = new SimpleText(ColorResource.西木野取款姬, "Intel", 20, 100);
|
||||
text.setTextSize(100);
|
||||
addObject(text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
try {
|
||||
if (timer.ended())
|
||||
addObject(new ShapeObject(ColorResource.BLUE, new FCircle(30), getMousePosition().x - 30, getMousePosition().y - 30) {{
|
||||
addAnim(new AccelerateMove(0, 500));
|
||||
}});
|
||||
} catch (NullPointerException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
launch(Demo20.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
import org.frice.Game
|
||||
import org.frice.launch
|
||||
import org.frice.obj.sub.ShapeObject
|
||||
import org.frice.resource.graphics.ColorResource
|
||||
import org.frice.util.shape.FCircle
|
||||
import org.frice.util.shape.FRectangle
|
||||
import org.frice.util.time.FTimer
|
||||
import java.awt.event.KeyEvent
|
||||
import java.awt.event.KeyListener
|
||||
import java.util.*
|
||||
import java.util.concurrent.LinkedBlockingQueue
|
||||
|
||||
class Demo22 : Game() {
|
||||
|
||||
private var direction = KeyEvent.VK_LEFT
|
||||
private var xx = 30
|
||||
private var yy = 20
|
||||
private var fx = 10
|
||||
private var fy = 10
|
||||
private var timer = FTimer(100)
|
||||
private var isIncreasing = true
|
||||
lateinit private var body: Queue<ShapeObject>
|
||||
lateinit private var food: ShapeObject
|
||||
|
||||
override fun onInit() {
|
||||
super.onInit()
|
||||
setLocationRelativeTo(null)
|
||||
setSize(600, 400)
|
||||
title = "Snake game demo"
|
||||
addKeyListener(object : KeyListener {
|
||||
override fun keyTyped(e: KeyEvent) = Unit
|
||||
override fun keyPressed(e: KeyEvent) {
|
||||
direction = e.keyCode
|
||||
}
|
||||
|
||||
override fun keyReleased(e: KeyEvent) = Unit
|
||||
})
|
||||
body = LinkedBlockingQueue<ShapeObject>()
|
||||
food = generateFood(10, 10)
|
||||
addObject(food)
|
||||
addObject(generateBody(30, 20).apply { body.add(this) })
|
||||
autoGC = false
|
||||
isResizable = false
|
||||
}
|
||||
|
||||
override fun onRefresh() {
|
||||
super.onRefresh()
|
||||
if (timer.ended()) {
|
||||
val obj: ShapeObject = when (direction) {
|
||||
KeyEvent.VK_LEFT -> generateBody(--xx, yy)
|
||||
KeyEvent.VK_RIGHT -> generateBody(++xx, yy)
|
||||
KeyEvent.VK_UP -> generateBody(xx, --yy)
|
||||
else -> generateBody(xx, ++yy)
|
||||
}
|
||||
xx = moved(xx, true)
|
||||
yy = moved(yy, false)
|
||||
if (xx == fx && yy == fy) {
|
||||
removeObject(food)
|
||||
isIncreasing = true
|
||||
fx = random.nextInt(this.width / 10 - 1)
|
||||
fy = random.nextInt(this.height / 10 - 1)
|
||||
food = generateFood(fx, fy)
|
||||
addObject(food)
|
||||
}
|
||||
body.add(obj)
|
||||
addObject(obj)
|
||||
if (!isIncreasing) removeObject(body.poll())
|
||||
isIncreasing = false
|
||||
}
|
||||
}
|
||||
|
||||
val random = Random(System.currentTimeMillis())
|
||||
|
||||
private fun generateBody(x: Int, y: Int) = ShapeObject(ColorResource.吾王蓝, FRectangle(10, 10), (x * 10).toDouble(), (y * 10).toDouble())
|
||||
private fun generateFood(x: Int, y: Int) = ShapeObject(ColorResource.如果奇迹有颜色那么一定是橙色, FCircle(5.0), (x * 10).toDouble(), (y * 10).toDouble())
|
||||
private fun moved(i: Int, isX: Boolean) = if (isX) (i + this.width / 10 - 2) % (this.width / 10 - 2) else (i + (this.height / 10 - 4)) % (this.height / 10 - 4)
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun main(args: Array<String>) = launch(Demo22::class.java)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
import org.frice.Game;
|
||||
import org.frice.obj.effects.FunctionEffect;
|
||||
import org.frice.util.time.FTimer;
|
||||
|
||||
import static org.frice.Initializer.launch;
|
||||
|
||||
public class Demo24 extends Game {
|
||||
private int count = 0;
|
||||
private FTimer timer = new FTimer(10);
|
||||
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
if (timer.ended()) {
|
||||
count++;
|
||||
clearObjects();
|
||||
addObject(
|
||||
new FunctionEffect(x -> (
|
||||
Math.sin((x + count) / 10) * 20 +
|
||||
Math.cos((x + count) / 20) * 20 +
|
||||
Math.sin((x + count) / 30) * 20 +
|
||||
Math.cos((x + count) / 40) * 20 +
|
||||
100
|
||||
), 0, 100, getWidth(), getHeight()),
|
||||
new FunctionEffect(x -> (
|
||||
Math.sin((x + count + count) / 30) * 20 +
|
||||
Math.cos((x + count + count) / 20) * 20 +
|
||||
Math.sin((x + count + count) / 40) * 20 +
|
||||
200
|
||||
), 0, 100, getWidth(), getHeight()));
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
launch(Demo24.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
import org.frice.Game;
|
||||
import org.frice.anim.move.AccelerateMove;
|
||||
import org.frice.anim.move.SimpleMove;
|
||||
import org.frice.obj.sub.ShapeObject;
|
||||
import org.frice.resource.graphics.ColorResource;
|
||||
import org.frice.util.FileUtils;
|
||||
import org.frice.util.shape.FCircle;
|
||||
import org.frice.util.shape.FRectangle;
|
||||
import org.frice.util.time.FTimer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.frice.Initializer.launch;
|
||||
|
||||
public class Demo7 extends Game {
|
||||
public static void main(String[] args) {
|
||||
launch(Demo7.class);
|
||||
}
|
||||
|
||||
private FTimer timer = new FTimer(3000);
|
||||
private ShapeObject bird;
|
||||
private List<ShapeObject> objects = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public void onInit() {
|
||||
setSize(500, 800);
|
||||
setTitle("Flappy bird demo by ice1000");
|
||||
bird = new ShapeObject(ColorResource.宝强绿, new FCircle(20), 50, 200) {{
|
||||
addAnim(new AccelerateMove(0, 800));
|
||||
}};
|
||||
addObject(bird);
|
||||
addKeyListener(null, e -> {
|
||||
bird.stopAnims();
|
||||
bird.addAnim(new AccelerateMove(0, 800));
|
||||
bird.addAnim(new SimpleMove(0, -400));
|
||||
}, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
if (timer.ended()) addObject(getObj((int) (Math.random() * 400)));
|
||||
objects.removeIf(ShapeObject::getDied);
|
||||
if (bird.getY() > getHeight() + 20 || objects.stream().anyMatch(o -> o.collides(bird))) {
|
||||
new Thread(() -> FileUtils.image2File(getScreenCut().getImage(), "截屏.png")).start();
|
||||
dialogShow("Game Over");
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
private ShapeObject[] getObj(int height) {
|
||||
return new ShapeObject[]{new ShapeObject(ColorResource.八云紫, new FRectangle(50, height), 550, 0) {{
|
||||
addAnim(new SimpleMove(-150, 0));
|
||||
objects.add(this);
|
||||
}}, new ShapeObject(ColorResource.八云紫, new FRectangle(50, getHeight() - height - 400), 550, height + 400) {{
|
||||
addAnim(new SimpleMove(-150, 0));
|
||||
objects.add(this);
|
||||
}}};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import org.frice.Game;
|
||||
import org.frice.anim.rotate.SimpleRotate;
|
||||
import org.frice.obj.sub.ShapeObject;
|
||||
import org.frice.resource.graphics.ColorResource;
|
||||
import org.frice.util.shape.FOval;
|
||||
|
||||
import static org.frice.Initializer.launch;
|
||||
|
||||
public class DemoRotate extends Game {
|
||||
@Override
|
||||
public void onInit() {
|
||||
setSize(400, 400);
|
||||
ShapeObject object = new ShapeObject(ColorResource.西木野取款姬, new FOval(40.0, 80.0), 160.0, 120.0);
|
||||
object.addAnim(new SimpleRotate(-10.0));
|
||||
ShapeObject object1 = new ShapeObject(ColorResource.八云蓝, new FOval(40.0, 80.0), 160.0, 120.0);
|
||||
object1.addAnim(new SimpleRotate(10.0));
|
||||
addObject(object, object1);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
launch(DemoRotate.class);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -9,7 +9,7 @@ allprojects {
|
||||
|
||||
buildscript {
|
||||
ext.kotlin_version = '1.2.0'
|
||||
ext.frice_version_num = '1.7.10'
|
||||
ext.frice_version_num = '1.8.0'
|
||||
ext.frice_version = "v$frice_version_num"
|
||||
repositories {
|
||||
mavenCentral()
|
||||
|
||||
Reference in New Issue
Block a user