├── .gitattributes ├── settings.gradle ├── old ├── Demo10.groovy ├── Demo30.rb ├── Demo19.kt ├── Demo20.java ├── Demo17.scala ├── Demo24.java ├── Demo18.scala ├── Demo6.java ├── Demo8.java ├── Demo3.kt ├── Demo5.rb ├── Demo12.java ├── Demo25.cs ├── Demo11.java ├── Demo29.rkt ├── Demo4.groovy ├── Demo2.java ├── Demo26.cs ├── Demo7.java ├── Demo13.java ├── Demo1.java ├── Demo23.kt ├── Demo9.java ├── Demo22.kt ├── Demo14.java ├── Demo28.cs ├── Demo15.java ├── Demo21.kt └── Demo16.kt ├── .gitignore ├── 1.8.0 ├── DemoRotate.java ├── Demo19.kt ├── Demo24.java ├── Demo20.java ├── Demo12.java ├── Demo11.java ├── Demo7.java ├── Demo22.kt └── Demo15.java ├── demo ├── Demo30.rb ├── Demo19.kt ├── Demo20.java ├── Demo17.scala ├── Demo24.java ├── Demo18.scala ├── Demo6.java ├── Demo8.java ├── Demo3.kt ├── Demo5.rb ├── Demo12.java ├── Demo25.cs ├── Demo11.java ├── Demo29.rkt ├── Demo2.java ├── Demo26.cs ├── Demo7.java ├── Demo13.java ├── Demo1.java ├── Demo23.kt ├── Demo9.java ├── Demo22.kt ├── Demo14.java ├── Demo28.cs ├── Demo15.java ├── Demo21.kt └── Demo16.kt ├── README.md ├── 1.7.9 ├── Demo24.java ├── Demo20.java ├── Demo12.java ├── Demo11.java ├── Demo7.java └── Demo15.java ├── 1.7.6 └── Demo7.java ├── 1.7.0 └── Demo7QuadTree.java └── LICENSE /.gitattributes: -------------------------------------------------------------------------------- 1 | demo/* linguist-vendored -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'demos' 2 | -------------------------------------------------------------------------------- /old/Demo10.groovy: -------------------------------------------------------------------------------- 1 | import org.frice.Game 2 | import org.frice.obj.button.SimpleButton 3 | import org.frice.obj.button.SimpleText 4 | import static org.frice.Initializer.* 5 | 6 | /** 7 | * Created by ice1000 on 2016/8/18. 8 | * @author ice1000 9 | * @since v0.3.3 10 | */ 11 | class Demo10 extends Game { 12 | static void main(String[] args) { 13 | launch Demo10 14 | } 15 | 16 | @Override 17 | void onInit() { 18 | addObject new SimpleButton("我是一个按钮", 50, 50, 100, 100), new SimpleText("啊啊啊啊", 300, 300) 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | 3 | # Mobile Tools for Java (J2ME) 4 | .mtj.tmp/ 5 | 6 | # Package & Target Files # 7 | *.jar 8 | *.war 9 | *.ear 10 | *.db 11 | 12 | # Debug & Demo21 Output # 13 | *.log 14 | *.xml 15 | 16 | # Image Files # 17 | *.png 18 | *.jpg 19 | *.gif 20 | *.bmp 21 | 22 | # Audio Files # 23 | *.wav 24 | *.mid 25 | *.mp3 26 | 27 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 28 | hs_err_pid* 29 | .idea/copyright/ 30 | .idea/modules/lib/ 31 | lib/ 32 | out/ 33 | tres/ 34 | .idea/ 35 | .gradle/ 36 | *.propreties 37 | build/ 38 | fuckGod.properties 39 | settings.properties 40 | demo/Demo4.groovy 41 | demo/Demo10.groovy -------------------------------------------------------------------------------- /1.8.0/DemoRotate.java: -------------------------------------------------------------------------------- 1 | import org.frice.Game; 2 | import org.frice.anim.rotate.SimpleRotate; 3 | import org.frice.obj.sub.ShapeObject; 4 | import org.frice.resource.graphics.ColorResource; 5 | import org.frice.util.shape.FOval; 6 | 7 | import static org.frice.Initializer.launch; 8 | 9 | public class DemoRotate extends Game { 10 | @Override 11 | public void onInit() { 12 | setSize(400, 400); 13 | ShapeObject object = new ShapeObject(ColorResource.西木野取款姬, new FOval(40.0, 80.0), 160.0, 120.0); 14 | object.addAnim(new SimpleRotate(-10.0)); 15 | ShapeObject object1 = new ShapeObject(ColorResource.八云蓝, new FOval(40.0, 80.0), 160.0, 120.0); 16 | object1.addAnim(new SimpleRotate(10.0)); 17 | addObject(object, object1); 18 | } 19 | 20 | public static void main(String[] args) { 21 | launch(DemoRotate.class); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /old/Demo30.rb: -------------------------------------------------------------------------------- 1 | require_relative '../src/engine' 2 | 3 | class Demo < Game 4 | def on_init 5 | @shit = 0 6 | title 'boy next door' 7 | size 500, 500 8 | # @ass = FObject.new 9 | # @ass.add_anim 233 10 | add_object FLine.new(5, 5, 100, 100) 11 | end 12 | 13 | def on_last_init 14 | # TkcLine.new(@canvas, 5, 5, 100, 100, 'fill' => 'blue', 'width' => 2) 15 | # message_box 'ah', 'ass we can' 16 | shape = ShapeObject.new('rect', 1, 1, 100, 100) 17 | shape.color = 'red' 18 | image = ImageResource.from_file 'fork_you.gif' 19 | image_o = ImageObject.new image, 300, 300 20 | add_object shape, image_o, SimpleText.new(200, 200, 'Ah I\'m fucking coming', 'green') 21 | end 22 | 23 | def on_refresh 24 | @shit += 3 25 | test_add 26 | end 27 | 28 | def test_add 29 | add_object FLine.new(0 + @shit, 5, 100, 100) 30 | end 31 | end 32 | 33 | Demo.new 34 | -------------------------------------------------------------------------------- /demo/Demo30.rb: -------------------------------------------------------------------------------- 1 | require_relative '../src/engine' 2 | 3 | class Demo < Game 4 | def on_init 5 | @shit = 0 6 | title 'boy next door' 7 | size 500, 500 8 | # @ass = FObject.new 9 | # @ass.add_anim 233 10 | add_object FLine.new(5, 5, 100, 100) 11 | end 12 | 13 | def on_last_init 14 | # TkcLine.new(@canvas, 5, 5, 100, 100, 'fill' => 'blue', 'width' => 2) 15 | # message_box 'ah', 'ass we can' 16 | shape = ShapeObject.new('rect', 1, 1, 100, 100) 17 | shape.color = 'red' 18 | image = ImageResource.from_file 'fork_you.gif' 19 | image_o = ImageObject.new image, 300, 300 20 | add_object shape, image_o, SimpleText.new(200, 200, 'Ah I\'m fucking coming', 'green') 21 | end 22 | 23 | def on_refresh 24 | @shit += 3 25 | test_add 26 | end 27 | 28 | def test_add 29 | add_object FLine.new(0 + @shit, 5, 100, 100) 30 | end 31 | end 32 | 33 | Demo.new 34 | -------------------------------------------------------------------------------- /1.8.0/Demo19.kt: -------------------------------------------------------------------------------- 1 | import org.frice.platform.adapter.JvmImage 2 | import org.frice.util.* 3 | import org.frice.util.message.FLog 4 | import java.util.* 5 | 6 | /** 7 | * test: http://lofi.e-hentai.org/g/813858/63f5aba277/ 8 | * test: http://www.yaoqmh.net/shaonvmanhua/5122.html 9 | * Created by ice1000 on 2016/9/3. 10 | * 11 | * @author ice1000 12 | */ 13 | fun process() { 14 | val scanner = Scanner(System.`in`) 15 | var count = 0 16 | while (scanner.hasNext()) forceRun { 17 | val images = findTag(readText(scanner.nextLine()), "img") 18 | images.forEach { i -> 19 | FLog.i("processing $i.... please wait.") 20 | val from = i.indexOf('\"') + 1 21 | val link = i.substring(from, i.indexOf('\"', from)) 22 | FLog.i("url is $link") 23 | forceRun { (readImage(link) as JvmImage).image2File("$count.png") } 24 | count++ 25 | } 26 | } 27 | } 28 | 29 | fun main(args: Array) = process() -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # FriceDemo 2 | 3 | demos for frice engine 4 | 5 | Sometimes, I change APIs, so old demos might be deprecated. I'll appreciate if you can help me update them. :joy: 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /old/Demo19.kt: -------------------------------------------------------------------------------- 1 | import org.frice.platform.adapter.JvmImage 2 | import org.frice.utils.* 3 | import org.frice.utils.message.FLog 4 | import java.util.* 5 | 6 | /** 7 | * test: http://lofi.e-hentai.org/g/813858/63f5aba277/ 8 | * test: http://www.yaoqmh.net/shaonvmanhua/5122.html 9 | * Created by ice1000 on 2016/9/3. 10 | * 11 | * @author ice1000 12 | */ 13 | fun process() { 14 | val scanner = Scanner(System.`in`) 15 | var count = 0 16 | while (scanner.hasNext()) forceRun { 17 | val images = findTag(readText(scanner.nextLine()), "img") 18 | images.forEach { i -> 19 | FLog.i("processing $i.... please wait.") 20 | val from = i.indexOf('\"') + 1 21 | val link = i.substring(from, i.indexOf('\"', from)) 22 | FLog.i("url is $link") 23 | forceRun { (readImage(link) as JvmImage).image2File("$count.png") } 24 | count++ 25 | } 26 | } 27 | } 28 | 29 | fun main(args: Array) = process() -------------------------------------------------------------------------------- /demo/Demo19.kt: -------------------------------------------------------------------------------- 1 | import org.frice.platform.adapter.JvmImage 2 | import org.frice.utils.* 3 | import org.frice.utils.message.FLog 4 | import java.util.* 5 | 6 | /** 7 | * test: http://lofi.e-hentai.org/g/813858/63f5aba277/ 8 | * test: http://www.yaoqmh.net/shaonvmanhua/5122.html 9 | * Created by ice1000 on 2016/9/3. 10 | * 11 | * @author ice1000 12 | */ 13 | fun process() { 14 | val scanner = Scanner(System.`in`) 15 | var count = 0 16 | while (scanner.hasNext()) forceRun { 17 | val images = findTag(readText(scanner.nextLine()), "img") 18 | images.forEach { i -> 19 | FLog.i("processing $i.... please wait.") 20 | val from = i.indexOf('\"') + 1 21 | val link = i.substring(from, i.indexOf('\"', from)) 22 | FLog.i("url is $link") 23 | forceRun { (readImage(link) as JvmImage).image2File("$count.png") } 24 | count++ 25 | } 26 | } 27 | } 28 | 29 | fun main(args: Array) = process() -------------------------------------------------------------------------------- /demo/Demo20.java: -------------------------------------------------------------------------------- 1 | import org.frice.Game; 2 | import org.frice.anim.move.AccelerateMove; 3 | import org.frice.obj.sub.ShapeObject; 4 | import org.frice.resource.graphics.ColorResource; 5 | import org.frice.utils.shape.FCircle; 6 | import org.frice.utils.time.FTimer; 7 | 8 | import static org.frice.Initializer.launch; 9 | 10 | /** 11 | * Created by ice1000 on 2016/8/29. 12 | * 13 | * @author ice1000 14 | */ 15 | public class Demo20 extends Game { 16 | FTimer timer = new FTimer(10); 17 | 18 | @Override 19 | public void onRefresh() { 20 | try { 21 | if (timer.ended()) 22 | addObject(new ShapeObject(ColorResource.BLUE, new FCircle(30), getMousePosition().x - 30, getMousePosition().y - 30) {{ 23 | addAnim(AccelerateMove.getGravity()); 24 | }}); 25 | } catch (NullPointerException ignored) { 26 | } 27 | } 28 | 29 | public static void main(String[] args) { 30 | launch(Demo20.class); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /old/Demo20.java: -------------------------------------------------------------------------------- 1 | import org.frice.Game; 2 | import org.frice.anim.move.AccelerateMove; 3 | import org.frice.obj.sub.ShapeObject; 4 | import org.frice.resource.graphics.ColorResource; 5 | import org.frice.utils.shape.FCircle; 6 | import org.frice.utils.time.FTimer; 7 | 8 | import static org.frice.Initializer.launch; 9 | 10 | /** 11 | * Created by ice1000 on 2016/8/29. 12 | * 13 | * @author ice1000 14 | */ 15 | public class Demo20 extends Game { 16 | FTimer timer = new FTimer(10); 17 | 18 | @Override 19 | public void onRefresh() { 20 | try { 21 | if (timer.ended()) 22 | addObject(new ShapeObject(ColorResource.BLUE, new FCircle(30), getMousePosition().x - 30, getMousePosition().y - 30) {{ 23 | addAnim(AccelerateMove.getGravity()); 24 | }}); 25 | } catch (NullPointerException ignored) { 26 | } 27 | } 28 | 29 | public static void main(String[] args) { 30 | launch(Demo20.class); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /demo/Demo17.scala: -------------------------------------------------------------------------------- 1 | import org.frice.Game 2 | import org.frice.anim.move.SimpleMove 3 | import org.frice.obj.sub.ShapeObject 4 | import org.frice.resource.graphics.ColorResource 5 | import org.frice.utils.shape.FCircle 6 | import org.frice.utils.time.FTimer 7 | import org.frice.Initializer.launch 8 | 9 | /** 10 | * Created by ice1000 on 2016/8/28. 11 | * 12 | * @author ice1000 13 | */ 14 | class Demo17 extends Game { 15 | 16 | var obj: ShapeObject = _ 17 | val timer = new FTimer(200) 18 | 19 | override def onInit(): Unit = { 20 | super.onInit() 21 | super.setAutoGC(true) 22 | } 23 | 24 | override def onRefresh(): Unit = { 25 | super.onRefresh() 26 | if (timer.ended()) { 27 | obj = new ShapeObject(ColorResource.西木野真姬, new FCircle(10), 10, 10) 28 | obj setMass 5.0 29 | obj.addForce(0, 50) 30 | obj.getAnims add new SimpleMove(400, 0) 31 | super.addObject(obj) 32 | } 33 | } 34 | } 35 | 36 | object Demo17 { 37 | def main(args: Array[String]): Unit = { 38 | launch(new Demo17) 39 | } 40 | } -------------------------------------------------------------------------------- /old/Demo17.scala: -------------------------------------------------------------------------------- 1 | import org.frice.Game 2 | import org.frice.anim.move.SimpleMove 3 | import org.frice.obj.sub.ShapeObject 4 | import org.frice.resource.graphics.ColorResource 5 | import org.frice.utils.shape.FCircle 6 | import org.frice.utils.time.FTimer 7 | import org.frice.Initializer.launch 8 | 9 | /** 10 | * Created by ice1000 on 2016/8/28. 11 | * 12 | * @author ice1000 13 | */ 14 | class Demo17 extends Game { 15 | 16 | var obj: ShapeObject = _ 17 | val timer = new FTimer(200) 18 | 19 | override def onInit(): Unit = { 20 | super.onInit() 21 | super.setAutoGC(true) 22 | } 23 | 24 | override def onRefresh(): Unit = { 25 | super.onRefresh() 26 | if (timer.ended()) { 27 | obj = new ShapeObject(ColorResource.西木野真姬, new FCircle(10), 10, 10) 28 | obj setMass 5.0 29 | obj.addForce(0, 50) 30 | obj.getAnims add new SimpleMove(400, 0) 31 | super.addObject(obj) 32 | } 33 | } 34 | } 35 | 36 | object Demo17 { 37 | def main(args: Array[String]): Unit = { 38 | launch(new Demo17) 39 | } 40 | } -------------------------------------------------------------------------------- /1.7.9/Demo24.java: -------------------------------------------------------------------------------- 1 | import org.frice.Game; 2 | import org.frice.obj.effects.FunctionEffect; 3 | import org.frice.utils.time.FTimer; 4 | 5 | import static org.frice.Initializer.launch; 6 | 7 | public class Demo24 extends Game { 8 | private int count = 0; 9 | private FTimer timer = new FTimer(10); 10 | 11 | @Override 12 | public void onRefresh() { 13 | if (timer.ended()) { 14 | count++; 15 | clearObjects(); 16 | addObject( 17 | new FunctionEffect(x -> ( 18 | Math.sin((x + count) / 10) * 20 + 19 | Math.cos((x + count) / 20) * 20 + 20 | Math.sin((x + count) / 30) * 20 + 21 | Math.cos((x + count) / 40) * 20 + 22 | 100 23 | ), 0, 100, getWidth(), getHeight()), 24 | new FunctionEffect(x -> ( 25 | Math.sin((x + count + count) / 30) * 20 + 26 | Math.cos((x + count + count) / 20) * 20 + 27 | Math.sin((x + count + count) / 40) * 20 + 28 | 200 29 | ), 0, 100, getWidth(), getHeight())); 30 | } 31 | } 32 | 33 | public static void main(String[] args) { 34 | launch(Demo24.class); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /1.8.0/Demo24.java: -------------------------------------------------------------------------------- 1 | import org.frice.Game; 2 | import org.frice.obj.effects.FunctionEffect; 3 | import org.frice.util.time.FTimer; 4 | 5 | import static org.frice.Initializer.launch; 6 | 7 | public class Demo24 extends Game { 8 | private int count = 0; 9 | private FTimer timer = new FTimer(10); 10 | 11 | @Override 12 | public void onRefresh() { 13 | if (timer.ended()) { 14 | count++; 15 | clearObjects(); 16 | addObject( 17 | new FunctionEffect(x -> ( 18 | Math.sin((x + count) / 10) * 20 + 19 | Math.cos((x + count) / 20) * 20 + 20 | Math.sin((x + count) / 30) * 20 + 21 | Math.cos((x + count) / 40) * 20 + 22 | 100 23 | ), 0, 100, getWidth(), getHeight()), 24 | new FunctionEffect(x -> ( 25 | Math.sin((x + count + count) / 30) * 20 + 26 | Math.cos((x + count + count) / 20) * 20 + 27 | Math.sin((x + count + count) / 40) * 20 + 28 | 200 29 | ), 0, 100, getWidth(), getHeight())); 30 | } 31 | } 32 | 33 | public static void main(String[] args) { 34 | launch(Demo24.class); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /demo/Demo24.java: -------------------------------------------------------------------------------- 1 | package demo; 2 | 3 | import org.frice.Game; 4 | import org.frice.obj.effects.FunctionEffect; 5 | import org.frice.utils.time.FTimer; 6 | 7 | import static org.frice.Initializer.launch; 8 | 9 | public class Demo24 extends Game { 10 | private int count = 0; 11 | private FTimer timer = new FTimer(10); 12 | 13 | @Override 14 | public void onRefresh() { 15 | if (timer.ended()) { 16 | count++; 17 | clearObjects(); 18 | addObject( 19 | new FunctionEffect(x -> ( 20 | Math.sin((x + count) / 10) * 20 + 21 | Math.cos((x + count) / 20) * 20 + 22 | Math.sin((x + count) / 30) * 20 + 23 | Math.cos((x + count) / 40) * 20 + 24 | 100 25 | ), 0, 100, getWidth(), getHeight()), 26 | new FunctionEffect(x -> ( 27 | Math.sin((x + count + count) / 30) * 20 + 28 | Math.cos((x + count + count) / 20) * 20 + 29 | Math.sin((x + count + count) / 40) * 20 + 30 | 200 31 | ), 0, 100, getWidth(), getHeight())); 32 | } 33 | } 34 | 35 | public static void main(String[] args) { 36 | launch(Demo24.class); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /old/Demo24.java: -------------------------------------------------------------------------------- 1 | package demo; 2 | 3 | import org.frice.Game; 4 | import org.frice.obj.effects.FunctionEffect; 5 | import org.frice.utils.time.FTimer; 6 | 7 | import static org.frice.Initializer.launch; 8 | 9 | public class Demo24 extends Game { 10 | private int count = 0; 11 | private FTimer timer = new FTimer(10); 12 | 13 | @Override 14 | public void onRefresh() { 15 | if (timer.ended()) { 16 | count++; 17 | clearObjects(); 18 | addObject( 19 | new FunctionEffect(x -> ( 20 | Math.sin((x + count) / 10) * 20 + 21 | Math.cos((x + count) / 20) * 20 + 22 | Math.sin((x + count) / 30) * 20 + 23 | Math.cos((x + count) / 40) * 20 + 24 | 100 25 | ), 0, 100, getWidth(), getHeight()), 26 | new FunctionEffect(x -> ( 27 | Math.sin((x + count + count) / 30) * 20 + 28 | Math.cos((x + count + count) / 20) * 20 + 29 | Math.sin((x + count + count) / 40) * 20 + 30 | 200 31 | ), 0, 100, getWidth(), getHeight())); 32 | } 33 | } 34 | 35 | public static void main(String[] args) { 36 | launch(Demo24.class); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /demo/Demo18.scala: -------------------------------------------------------------------------------- 1 | import kotlin.jvm.functions.Function1 2 | import org.frice.Game 3 | import org.frice.obj.effects.FunctionEffect 4 | import org.frice.utils.time.FTimer 5 | import org.frice.Initializer.launch 6 | 7 | /** 8 | * Created by ice1000 on 2016/8/28. 9 | * 10 | * @author ice1000 11 | */ 12 | class Demo18 extends Game { 13 | 14 | var obj: FunctionEffect = _ 15 | val timer = new FTimer(50) 16 | var i = 5.0 17 | 18 | override def onInit(): Unit = { 19 | super.onInit() 20 | super.setAutoGC(true) 21 | obj = getFunction(5) 22 | super.addObject(obj) 23 | } 24 | 25 | override def onRefresh(): Unit = { 26 | super.onRefresh() 27 | if (timer.ended()) { 28 | i += 0.3 29 | super.removeObject(obj) 30 | obj = getFunction(i) 31 | super.addObject(obj) 32 | } 33 | } 34 | 35 | def getFunction(d: Double): FunctionEffect = new FunctionEffect( 36 | new Function1[Double, Double] { 37 | override def invoke(double: Double): Double = Math.sin(double / d) * 100 + 200 38 | }, 10, 10, 600, 500) 39 | } 40 | 41 | object Demo18 { 42 | def main(args: Array[String]): Unit = { 43 | launch(new Demo18) 44 | } 45 | } -------------------------------------------------------------------------------- /old/Demo18.scala: -------------------------------------------------------------------------------- 1 | import kotlin.jvm.functions.Function1 2 | import org.frice.Game 3 | import org.frice.obj.effects.FunctionEffect 4 | import org.frice.utils.time.FTimer 5 | import org.frice.Initializer.launch 6 | 7 | /** 8 | * Created by ice1000 on 2016/8/28. 9 | * 10 | * @author ice1000 11 | */ 12 | class Demo18 extends Game { 13 | 14 | var obj: FunctionEffect = _ 15 | val timer = new FTimer(50) 16 | var i = 5.0 17 | 18 | override def onInit(): Unit = { 19 | super.onInit() 20 | super.setAutoGC(true) 21 | obj = getFunction(5) 22 | super.addObject(obj) 23 | } 24 | 25 | override def onRefresh(): Unit = { 26 | super.onRefresh() 27 | if (timer.ended()) { 28 | i += 0.3 29 | super.removeObject(obj) 30 | obj = getFunction(i) 31 | super.addObject(obj) 32 | } 33 | } 34 | 35 | def getFunction(d: Double): FunctionEffect = new FunctionEffect( 36 | new Function1[Double, Double] { 37 | override def invoke(double: Double): Double = Math.sin(double / d) * 100 + 200 38 | }, 10, 10, 600, 500) 39 | } 40 | 41 | object Demo18 { 42 | def main(args: Array[String]): Unit = { 43 | launch(new Demo18) 44 | } 45 | } -------------------------------------------------------------------------------- /1.7.9/Demo20.java: -------------------------------------------------------------------------------- 1 | import org.frice.Game; 2 | import org.frice.anim.move.AccelerateMove; 3 | import org.frice.obj.button.SimpleText; 4 | import org.frice.obj.sub.ShapeObject; 5 | import org.frice.resource.graphics.ColorResource; 6 | import org.frice.utils.shape.FCircle; 7 | import org.frice.utils.time.FTimer; 8 | 9 | import static org.frice.Initializer.launch; 10 | 11 | /** 12 | * Created by ice1000 on 2016/8/29. 13 | * 14 | * @author ice1000 15 | */ 16 | public class Demo20 extends Game { 17 | private FTimer timer = new FTimer(10); 18 | 19 | @Override 20 | public void onLastInit() { 21 | SimpleText text = new SimpleText(ColorResource.西木野取款姬, "Intel", 20, 100); 22 | text.setTextSize(100); 23 | addObject(text); 24 | } 25 | 26 | @Override 27 | public void onRefresh() { 28 | try { 29 | if (timer.ended()) 30 | addObject(new ShapeObject(ColorResource.BLUE, new FCircle(30), getMousePosition().x - 30, getMousePosition().y - 30) {{ 31 | addAnim(new AccelerateMove(0, 500)); 32 | }}); 33 | } catch (NullPointerException ignored) { 34 | } 35 | } 36 | 37 | public static void main(String[] args) { 38 | launch(Demo20.class); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /1.8.0/Demo20.java: -------------------------------------------------------------------------------- 1 | import org.frice.Game; 2 | import org.frice.anim.move.AccelerateMove; 3 | import org.frice.obj.button.SimpleText; 4 | import org.frice.obj.sub.ShapeObject; 5 | import org.frice.resource.graphics.ColorResource; 6 | import org.frice.util.shape.FCircle; 7 | import org.frice.util.time.FTimer; 8 | 9 | import static org.frice.Initializer.launch; 10 | 11 | /** 12 | * Created by ice1000 on 2016/8/29. 13 | * 14 | * @author ice1000 15 | */ 16 | public class Demo20 extends Game { 17 | private FTimer timer = new FTimer(10); 18 | 19 | @Override 20 | public void onLastInit() { 21 | SimpleText text = new SimpleText(ColorResource.西木野取款姬, "Intel", 20, 100); 22 | text.setTextSize(100); 23 | addObject(text); 24 | } 25 | 26 | @Override 27 | public void onRefresh() { 28 | try { 29 | if (timer.ended()) 30 | addObject(new ShapeObject(ColorResource.BLUE, new FCircle(30), getMousePosition().x - 30, getMousePosition().y - 30) {{ 31 | addAnim(new AccelerateMove(0, 500)); 32 | }}); 33 | } catch (NullPointerException ignored) { 34 | } 35 | } 36 | 37 | public static void main(String[] args) { 38 | launch(Demo20.class); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /old/Demo6.java: -------------------------------------------------------------------------------- 1 | import org.frice.Game; 2 | import org.frice.anim.move.AccelerateMove; 3 | import org.frice.anim.move.SimpleMove; 4 | import org.frice.anim.scale.SimpleScale; 5 | import org.frice.event.OnMouseEvent; 6 | import org.frice.obj.sub.ShapeObject; 7 | import org.frice.resource.graphics.ColorResource; 8 | import org.frice.utils.message.FLog; 9 | import org.frice.utils.shape.FOval; 10 | import org.frice.utils.time.FTimer; 11 | 12 | import static org.frice.Initializer.launch; 13 | 14 | /** 15 | * Created by ice1000 on 2016/8/15. 16 | * 17 | * @author ice1000 18 | */ 19 | public class Demo6 extends Game { 20 | public static void main(String[] args) { 21 | launch(Demo6.class); 22 | } 23 | 24 | public FTimer timer = new FTimer(2000); 25 | 26 | @Override 27 | public void onInit() { 28 | setSize(900, 900); 29 | } 30 | 31 | @Override 32 | public void onRefresh() { 33 | super.onRefresh(); 34 | if (timer.ended()) { 35 | addObject(new ShapeObject(ColorResource.基佬紫, 36 | new FOval(80.0, 120.0), 10, 750) {{ 37 | addAnim(new SimpleScale(1.1, 1.1)); 38 | addAnim(AccelerateMove.getGravity()); 39 | addAnim(new SimpleMove(0, -700)); 40 | addAnim(new SimpleMove(100, 0)); 41 | }}); 42 | } 43 | } 44 | 45 | @Override 46 | public void onMouse(OnMouseEvent e) { 47 | setPaused(!getPaused()); 48 | FLog.e("paused"); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /demo/Demo6.java: -------------------------------------------------------------------------------- 1 | import org.frice.Game; 2 | import org.frice.anim.move.AccelerateMove; 3 | import org.frice.anim.move.SimpleMove; 4 | import org.frice.anim.scale.SimpleScale; 5 | import org.frice.event.OnMouseEvent; 6 | import org.frice.obj.sub.ShapeObject; 7 | import org.frice.resource.graphics.ColorResource; 8 | import org.frice.utils.message.FLog; 9 | import org.frice.utils.shape.FOval; 10 | import org.frice.utils.time.FTimer; 11 | 12 | import static org.frice.Initializer.launch; 13 | 14 | /** 15 | * Created by ice1000 on 2016/8/15. 16 | * 17 | * @author ice1000 18 | */ 19 | public class Demo6 extends Game { 20 | public static void main(String[] args) { 21 | launch(Demo6.class); 22 | } 23 | 24 | public FTimer timer = new FTimer(2000); 25 | 26 | @Override 27 | public void onInit() { 28 | setSize(900, 900); 29 | } 30 | 31 | @Override 32 | public void onRefresh() { 33 | super.onRefresh(); 34 | if (timer.ended()) { 35 | addObject(new ShapeObject(ColorResource.基佬紫, 36 | new FOval(80.0, 120.0), 10, 750) {{ 37 | addAnim(new SimpleScale(1.1, 1.1)); 38 | addAnim(AccelerateMove.getGravity()); 39 | addAnim(new SimpleMove(0, -700)); 40 | addAnim(new SimpleMove(100, 0)); 41 | }}); 42 | } 43 | } 44 | 45 | @Override 46 | public void onMouse(OnMouseEvent e) { 47 | setPaused(!getPaused()); 48 | FLog.e("paused"); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /demo/Demo8.java: -------------------------------------------------------------------------------- 1 | import org.frice.Game; 2 | import org.frice.event.OnMouseEvent; 3 | import org.frice.obj.sub.ImageObject; 4 | import org.frice.resource.image.FileImageResource; 5 | import org.frice.resource.image.FrameImageResource; 6 | import org.frice.utils.audio.AudioManager; 7 | import org.frice.utils.audio.AudioPlayer; 8 | import org.jetbrains.annotations.NotNull; 9 | 10 | import static org.frice.Initializer.launch; 11 | 12 | /** 13 | * Created by ice1000 on 2016/8/16. 14 | * 15 | * @author ice1000 16 | * @since v0.3.1 17 | */ 18 | public class Demo8 extends Game { 19 | 20 | private AudioPlayer player; 21 | private int cnt = 0; 22 | 23 | @Override 24 | public void onInit() { 25 | ImageObject object = new ImageObject(new FrameImageResource(this, new FileImageResource[]{ 26 | new FileImageResource("1.png"), 27 | new FileImageResource("2.png"), 28 | new FileImageResource("3.png"), 29 | new FileImageResource("4.png"), 30 | new FileImageResource("5.png") 31 | }, 1000), 100.0, 100.0); 32 | addObject(object); 33 | setCursor(object); 34 | player = AudioManager.getPlayer("1.wav"); 35 | player.start(); 36 | // new Color(0x1BA61C); 37 | } 38 | 39 | @Override 40 | public void onMouse(@NotNull OnMouseEvent e) { 41 | cnt++; 42 | if (cnt > 10) player.exit(); 43 | } 44 | 45 | public static void main(String[] args) { 46 | launch(Demo8.class); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /old/Demo8.java: -------------------------------------------------------------------------------- 1 | import org.frice.Game; 2 | import org.frice.event.OnMouseEvent; 3 | import org.frice.obj.sub.ImageObject; 4 | import org.frice.resource.image.FileImageResource; 5 | import org.frice.resource.image.FrameImageResource; 6 | import org.frice.utils.audio.AudioManager; 7 | import org.frice.utils.audio.AudioPlayer; 8 | import org.jetbrains.annotations.NotNull; 9 | 10 | import static org.frice.Initializer.launch; 11 | 12 | /** 13 | * Created by ice1000 on 2016/8/16. 14 | * 15 | * @author ice1000 16 | * @since v0.3.1 17 | */ 18 | public class Demo8 extends Game { 19 | 20 | private AudioPlayer player; 21 | private int cnt = 0; 22 | 23 | @Override 24 | public void onInit() { 25 | ImageObject object = new ImageObject(new FrameImageResource(this, new FileImageResource[]{ 26 | new FileImageResource("1.png"), 27 | new FileImageResource("2.png"), 28 | new FileImageResource("3.png"), 29 | new FileImageResource("4.png"), 30 | new FileImageResource("5.png") 31 | }, 1000), 100.0, 100.0); 32 | addObject(object); 33 | setCursor(object); 34 | player = AudioManager.getPlayer("1.wav"); 35 | player.start(); 36 | // new Color(0x1BA61C); 37 | } 38 | 39 | @Override 40 | public void onMouse(@NotNull OnMouseEvent e) { 41 | cnt++; 42 | if (cnt > 10) player.exit(); 43 | } 44 | 45 | public static void main(String[] args) { 46 | launch(Demo8.class); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /demo/Demo3.kt: -------------------------------------------------------------------------------- 1 | import org.frice.Game 2 | import org.frice.launch 3 | import org.frice.obj.sub.ImageObject 4 | import org.frice.resource.image.FileImageResource 5 | import org.frice.utils.message.FLog 6 | import org.frice.utils.time.FTimer 7 | import java.awt.Rectangle 8 | import java.io.File 9 | import java.util.* 10 | 11 | /** 12 | * Demo for timer 13 | * 14 | * Created by ice1000 on 2016/8/13. 15 | * @author ice1000 16 | * @since v0.1 17 | */ 18 | class Demo3 : Game() { 19 | private val dickTimer = FTimer(1000) 20 | 21 | private var fuck = 0.0 22 | 23 | private val objList = arrayListOf() 24 | private var mode = 0 25 | override fun onInit() { 26 | bounds = Rectangle(100, 100, 640, 480) 27 | title = "Demo3 of Frice" 28 | // refreshPerSecond = 100 29 | // back = ColorResource.BLUE 30 | } 31 | 32 | override fun onRefresh() { 33 | if (dickTimer.ended()) { 34 | val texture = FileImageResource("test.png") 35 | val obj: ImageObject 36 | if (fuck > 300) mode = 1 else if (fuck < 1) mode = 0 37 | when (mode) { 38 | 0 -> { 39 | obj = ImageObject(texture, fuck, fuck) 40 | objList.add(obj) 41 | addObject(obj) 42 | fuck += 100 43 | } 44 | 1 -> { 45 | obj = objList[objList.size - 1] 46 | objList.remove(obj) 47 | removeObject(obj) 48 | fuck -= 100 49 | } 50 | } 51 | FLog.v("objList.size = ${objList.size}") 52 | } 53 | } 54 | 55 | companion object { 56 | @JvmStatic 57 | fun main(args: Array) { 58 | launch(Demo3::class.java) 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /demo/Demo5.rb: -------------------------------------------------------------------------------- 1 | # This demo worked now 2 | require 'java' 3 | 4 | # change the import path in your own one 5 | # don't use this path on your computer 6 | require './FriceEngine.jar' 7 | 8 | java_import org.frice.Game 9 | java_import org.frice.obj.sub.ShapeObject 10 | java_import org.frice.resource.graphics.ColorResource 11 | java_import org.frice.utils.graphics.shape.FOval 12 | java_import org.frice.utils.time.FTimer 13 | java_import org.frice.utils.message.FDialog 14 | 15 | 16 | module JavaAWT 17 | java_import java.awt.Rectangle do |package, name| 18 | 'J' + name 19 | end 20 | end 21 | 22 | module JavaSwing 23 | include JavaAWT 24 | end 25 | 26 | class Demo5 < Game 27 | 28 | def on_init 29 | set_bounds JavaAWT::JRectangle.new 100, 100, 800, 800 30 | set_title 'JRuby demo by ice1000' 31 | 32 | @click_count = 0 33 | 34 | @bool = false 35 | 36 | color = ColorResource.new '111111' 37 | @oval = FOval.new 20.0, 15.0 38 | 39 | @obj = ShapeObject.new color, @oval, 20.0, 20.0 40 | @timer = FTimer.new 1000 41 | 42 | # now it's the problem. The object doesn't appear on the game window. 43 | add_object @obj 44 | end 45 | 46 | def on_refresh 47 | if @timer.ended 48 | if @bool 49 | remove_object @obj 50 | @bool = false 51 | else 52 | add_object @obj 53 | @bool = true 54 | end 55 | end 56 | end 57 | 58 | def on_click(e) 59 | FDialog.new(self).show "onClick #{@click_count}" 60 | @click_count += 1 61 | end 62 | 63 | def on_mouse(e) 64 | end 65 | end 66 | 67 | Demo5.new 68 | 69 | # org.frice.game.Game.new -------------------------------------------------------------------------------- /old/Demo3.kt: -------------------------------------------------------------------------------- 1 | import org.frice.Game 2 | import org.frice.launch 3 | import org.frice.obj.sub.ImageObject 4 | import org.frice.resource.image.FileImageResource 5 | import org.frice.utils.message.FLog 6 | import org.frice.utils.time.FTimer 7 | import java.awt.Rectangle 8 | import java.io.File 9 | import java.util.* 10 | 11 | /** 12 | * Demo for timer 13 | * 14 | * Created by ice1000 on 2016/8/13. 15 | * @author ice1000 16 | * @since v0.1 17 | */ 18 | class Demo3 : Game() { 19 | private val dickTimer = FTimer(1000) 20 | 21 | private var fuck = 0.0 22 | 23 | private val objList = arrayListOf() 24 | private var mode = 0 25 | override fun onInit() { 26 | bounds = Rectangle(100, 100, 640, 480) 27 | title = "Demo3 of Frice" 28 | // refreshPerSecond = 100 29 | // back = ColorResource.BLUE 30 | } 31 | 32 | override fun onRefresh() { 33 | if (dickTimer.ended()) { 34 | val texture = FileImageResource("test.png") 35 | val obj: ImageObject 36 | if (fuck > 300) mode = 1 else if (fuck < 1) mode = 0 37 | when (mode) { 38 | 0 -> { 39 | obj = ImageObject(texture, fuck, fuck) 40 | objList.add(obj) 41 | addObject(obj) 42 | fuck += 100 43 | } 44 | 1 -> { 45 | obj = objList[objList.size - 1] 46 | objList.remove(obj) 47 | removeObject(obj) 48 | fuck -= 100 49 | } 50 | } 51 | FLog.v("objList.size = ${objList.size}") 52 | } 53 | } 54 | 55 | companion object { 56 | @JvmStatic 57 | fun main(args: Array) { 58 | launch(Demo3::class.java) 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /old/Demo5.rb: -------------------------------------------------------------------------------- 1 | # This demo worked now 2 | require 'java' 3 | 4 | # change the import path in your own one 5 | # don't use this path on your computer 6 | require './FriceEngine.jar' 7 | 8 | java_import org.frice.Game 9 | java_import org.frice.obj.sub.ShapeObject 10 | java_import org.frice.resource.graphics.ColorResource 11 | java_import org.frice.utils.graphics.shape.FOval 12 | java_import org.frice.utils.time.FTimer 13 | java_import org.frice.utils.message.FDialog 14 | 15 | 16 | module JavaAWT 17 | java_import java.awt.Rectangle do |package, name| 18 | 'J' + name 19 | end 20 | end 21 | 22 | module JavaSwing 23 | include JavaAWT 24 | end 25 | 26 | class Demo5 < Game 27 | 28 | def on_init 29 | set_bounds JavaAWT::JRectangle.new 100, 100, 800, 800 30 | set_title 'JRuby demo by ice1000' 31 | 32 | @click_count = 0 33 | 34 | @bool = false 35 | 36 | color = ColorResource.new '111111' 37 | @oval = FOval.new 20.0, 15.0 38 | 39 | @obj = ShapeObject.new color, @oval, 20.0, 20.0 40 | @timer = FTimer.new 1000 41 | 42 | # now it's the problem. The object doesn't appear on the game window. 43 | add_object @obj 44 | end 45 | 46 | def on_refresh 47 | if @timer.ended 48 | if @bool 49 | remove_object @obj 50 | @bool = false 51 | else 52 | add_object @obj 53 | @bool = true 54 | end 55 | end 56 | end 57 | 58 | def on_click(e) 59 | FDialog.new(self).show "onClick #{@click_count}" 60 | @click_count += 1 61 | end 62 | 63 | def on_mouse(e) 64 | end 65 | end 66 | 67 | Demo5.new 68 | 69 | # org.frice.game.Game.new -------------------------------------------------------------------------------- /demo/Demo12.java: -------------------------------------------------------------------------------- 1 | import org.frice.Game; 2 | import org.frice.anim.move.AccelerateMove; 3 | import org.frice.anim.move.SimpleMove; 4 | import org.frice.obj.sub.ShapeObject; 5 | import org.frice.resource.graphics.ColorResource; 6 | import org.frice.utils.shape.FCircle; 7 | import org.frice.utils.time.FTimer; 8 | 9 | import java.awt.*; 10 | import java.util.Random; 11 | 12 | import static org.frice.Initializer.launch; 13 | 14 | /** 15 | * An awesome demo 16 | * 17 | * @author SuperSodaSea 18 | */ 19 | public class Demo12 extends Game { 20 | 21 | private ColorResource[] colors; 22 | private FTimer timer2; 23 | 24 | @Override 25 | public void onInit() { 26 | timer2 = new FTimer(30); 27 | colors = new ColorResource[]{ 28 | ColorResource.东条希, 29 | ColorResource.高坂穗乃果, 30 | ColorResource.西木野真姬, 31 | ColorResource.矢泽妮可, 32 | ColorResource.洵濑绘理, 33 | ColorResource.星空凛, 34 | ColorResource.南小鸟 35 | }; 36 | setBackground(ColorResource.IntelliJ_IDEA黑.getColor()); 37 | } 38 | 39 | Random random = new Random(System.currentTimeMillis()); 40 | 41 | @Override 42 | public void onRefresh() { 43 | if (timer2.ended()) { 44 | addObject(new ShapeObject(colors[(int) ((System.currentTimeMillis() / 100) % colors.length)], 45 | new FCircle(10), mouse.getX(), mouse.getY()) {{ 46 | addAnim(AccelerateMove.getGravity(20)); 47 | addAnim(new SimpleMove((int) (random.nextInt(Demo12.this.getWidth()) - getX()), -10)); 48 | }}); 49 | } 50 | } 51 | 52 | public static void main(String[] args) { 53 | launch(Demo12.class); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /old/Demo12.java: -------------------------------------------------------------------------------- 1 | import org.frice.Game; 2 | import org.frice.anim.move.AccelerateMove; 3 | import org.frice.anim.move.SimpleMove; 4 | import org.frice.obj.sub.ShapeObject; 5 | import org.frice.resource.graphics.ColorResource; 6 | import org.frice.utils.shape.FCircle; 7 | import org.frice.utils.time.FTimer; 8 | 9 | import java.awt.*; 10 | import java.util.Random; 11 | 12 | import static org.frice.Initializer.launch; 13 | 14 | /** 15 | * An awesome demo 16 | * 17 | * @author SuperSodaSea 18 | */ 19 | public class Demo12 extends Game { 20 | 21 | private ColorResource[] colors; 22 | private FTimer timer2; 23 | 24 | @Override 25 | public void onInit() { 26 | timer2 = new FTimer(30); 27 | colors = new ColorResource[]{ 28 | ColorResource.东条希, 29 | ColorResource.高坂穗乃果, 30 | ColorResource.西木野真姬, 31 | ColorResource.矢泽妮可, 32 | ColorResource.洵濑绘理, 33 | ColorResource.星空凛, 34 | ColorResource.南小鸟 35 | }; 36 | setBackground(ColorResource.IntelliJ_IDEA黑.getColor()); 37 | } 38 | 39 | Random random = new Random(System.currentTimeMillis()); 40 | 41 | @Override 42 | public void onRefresh() { 43 | if (timer2.ended()) { 44 | addObject(new ShapeObject(colors[(int) ((System.currentTimeMillis() / 100) % colors.length)], 45 | new FCircle(10), mouse.getX(), mouse.getY()) {{ 46 | addAnim(AccelerateMove.getGravity(20)); 47 | addAnim(new SimpleMove((int) (random.nextInt(Demo12.this.getWidth()) - getX()), -10)); 48 | }}); 49 | } 50 | } 51 | 52 | public static void main(String[] args) { 53 | launch(Demo12.class); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /demo/Demo25.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows.Forms; 3 | using FriceEngine; 4 | using FriceEngine.Animation; 5 | using FriceEngine.Object; 6 | using FriceEngine.Resource; 7 | using FriceEngine.Utils.Graphics; 8 | using FriceEngine.Utils.Message; 9 | using FriceEngine.Utils.Time; 10 | 11 | namespace Frice.Demo 12 | { 13 | public class Demo25 : Game 14 | { 15 | public override void OnInit() 16 | { 17 | SetBounds(300, 300, 800, 600); 18 | 19 | SetTitle("Fuck the world"); 20 | 21 | //replace with a file path in desk 22 | var b = ImageObject.FromFile(@"C:\frice.png", 300, 400, 50, 50); 23 | // var c = ImageObject.FromWeb("https://avatars1.githubusercontent.com/u/21008243", 400, 300); 24 | 25 | //can resize: 26 | // c.Height = 100; 27 | // c.Width = 100; 28 | b.MoveList.Add(new SimpleMove(-10, -10)); 29 | // c.MoveList.Add(new SimpleMove(-10, 10)); 30 | AddObject(b); 31 | AddObject(new SimpleText(ColorResource.高坂穗乃果, "Hello World", 10, 10)); 32 | // AddObject(c); 33 | } 34 | 35 | private void Add() 36 | { 37 | var a = ImageObject.FromFile(@"C:\frice.png", Mouse.X - 50, Mouse.Y - 50, 100, 100); 38 | a.MoveList.Add(new SimpleMove(100, -400)); 39 | a.MoveList.Add(new AccelerateMove(0, 1000)); 40 | AddObject(a); 41 | } 42 | 43 | public override void OnClick(FPoint mousePosition) 44 | { 45 | FLog.D("On click called."); 46 | Add(); 47 | base.OnClick(mousePosition); 48 | } 49 | 50 | public override void OnRefresh() 51 | { 52 | Add(); 53 | base.OnRefresh(); 54 | } 55 | 56 | public static void Main(string[] args) 57 | { 58 | Application.Run(new Demo25()); 59 | } 60 | 61 | } 62 | } -------------------------------------------------------------------------------- /old/Demo25.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows.Forms; 3 | using FriceEngine; 4 | using FriceEngine.Animation; 5 | using FriceEngine.Object; 6 | using FriceEngine.Resource; 7 | using FriceEngine.Utils.Graphics; 8 | using FriceEngine.Utils.Message; 9 | using FriceEngine.Utils.Time; 10 | 11 | namespace Frice.Demo 12 | { 13 | public class Demo25 : Game 14 | { 15 | public override void OnInit() 16 | { 17 | SetBounds(300, 300, 800, 600); 18 | 19 | SetTitle("Fuck the world"); 20 | 21 | //replace with a file path in desk 22 | var b = ImageObject.FromFile(@"C:\frice.png", 300, 400, 50, 50); 23 | // var c = ImageObject.FromWeb("https://avatars1.githubusercontent.com/u/21008243", 400, 300); 24 | 25 | //can resize: 26 | // c.Height = 100; 27 | // c.Width = 100; 28 | b.MoveList.Add(new SimpleMove(-10, -10)); 29 | // c.MoveList.Add(new SimpleMove(-10, 10)); 30 | AddObject(b); 31 | AddObject(new SimpleText(ColorResource.高坂穗乃果, "Hello World", 10, 10)); 32 | // AddObject(c); 33 | } 34 | 35 | private void Add() 36 | { 37 | var a = ImageObject.FromFile(@"C:\frice.png", Mouse.X - 50, Mouse.Y - 50, 100, 100); 38 | a.MoveList.Add(new SimpleMove(100, -400)); 39 | a.MoveList.Add(new AccelerateMove(0, 1000)); 40 | AddObject(a); 41 | } 42 | 43 | public override void OnClick(FPoint mousePosition) 44 | { 45 | FLog.D("On click called."); 46 | Add(); 47 | base.OnClick(mousePosition); 48 | } 49 | 50 | public override void OnRefresh() 51 | { 52 | Add(); 53 | base.OnRefresh(); 54 | } 55 | 56 | public static void Main(string[] args) 57 | { 58 | Application.Run(new Demo25()); 59 | } 60 | 61 | } 62 | } -------------------------------------------------------------------------------- /1.8.0/Demo12.java: -------------------------------------------------------------------------------- 1 | import org.frice.Game; 2 | import org.frice.anim.move.AccelerateMove; 3 | import org.frice.anim.move.SimpleMove; 4 | import org.frice.obj.sub.ShapeObject; 5 | import org.frice.resource.graphics.ColorResource; 6 | import org.frice.util.shape.FCircle; 7 | import org.frice.util.shape.FRectangle; 8 | import org.frice.util.time.FTimer; 9 | 10 | import java.util.Random; 11 | 12 | import static org.frice.Initializer.launch; 13 | 14 | /** 15 | * An awesome demo 16 | * 17 | * @author SuperSodaSea 18 | */ 19 | public class Demo12 extends Game { 20 | 21 | private ColorResource[] colors; 22 | private FTimer timer2; 23 | private Random random = new Random(System.currentTimeMillis()); 24 | private double x; 25 | private double y; 26 | 27 | @Override 28 | public void onInit() { 29 | setSize(300, 300); 30 | timer2 = new FTimer(30); 31 | colors = new ColorResource[]{ColorResource.东条希, ColorResource.高坂穗乃果, ColorResource.西木野真姬, ColorResource.矢泽妮可, ColorResource.洵濑绘理, ColorResource.星空凛, ColorResource.南小鸟}; 32 | addObject(new ShapeObject(ColorResource.IntelliJ_IDEA黑, new FRectangle(getBounds()))); 33 | } 34 | 35 | @Override 36 | public void onRefresh() { 37 | if (timer2.ended()) { 38 | if (mouse.getX() > 0) x = mouse.getX(); 39 | if (mouse.getY() > 0) y = mouse.getY(); 40 | addObject(new ShapeObject(colors[(int) ((System.currentTimeMillis() / 100) % colors.length)], new FCircle(10), x, y) {{ 41 | addAnim(new AccelerateMove(0, 800)); 42 | addAnim(new SimpleMove((int) (random.nextInt(Demo12.this.getWidth()) - getX()), -10)); 43 | }}); 44 | } 45 | } 46 | 47 | public static void main(String[] args) { 48 | launch(Demo12.class); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /1.7.9/Demo12.java: -------------------------------------------------------------------------------- 1 | import org.frice.Game; 2 | import org.frice.anim.move.AccelerateMove; 3 | import org.frice.anim.move.SimpleMove; 4 | import org.frice.obj.sub.ShapeObject; 5 | import org.frice.resource.graphics.ColorResource; 6 | import org.frice.utils.shape.FCircle; 7 | import org.frice.utils.shape.FRectangle; 8 | import org.frice.utils.time.FTimer; 9 | 10 | import java.util.Random; 11 | 12 | import static org.frice.Initializer.launch; 13 | 14 | /** 15 | * An awesome demo 16 | * 17 | * @author SuperSodaSea 18 | */ 19 | public class Demo12 extends Game { 20 | 21 | private ColorResource[] colors; 22 | private FTimer timer2; 23 | private Random random = new Random(System.currentTimeMillis()); 24 | private double x; 25 | private double y; 26 | 27 | @Override 28 | public void onInit() { 29 | setSize(300, 300); 30 | timer2 = new FTimer(30); 31 | colors = new ColorResource[]{ColorResource.东条希, ColorResource.高坂穗乃果, ColorResource.西木野真姬, ColorResource.矢泽妮可, ColorResource.洵濑绘理, ColorResource.星空凛, ColorResource.南小鸟}; 32 | addObject(new ShapeObject(ColorResource.IntelliJ_IDEA黑, new FRectangle(getBounds()))); 33 | } 34 | 35 | @Override 36 | public void onRefresh() { 37 | if (timer2.ended()) { 38 | if (mouse.getX() > 0) x = mouse.getX(); 39 | if (mouse.getY() > 0) y = mouse.getY(); 40 | addObject(new ShapeObject(colors[(int) ((System.currentTimeMillis() / 100) % colors.length)], new FCircle(10), x, y) {{ 41 | addAnim(new AccelerateMove(0, 800)); 42 | addAnim(new SimpleMove((int) (random.nextInt(Demo12.this.getWidth()) - getX()), -10)); 43 | }}); 44 | } 45 | } 46 | 47 | public static void main(String[] args) { 48 | launch(Demo12.class); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /1.7.9/Demo11.java: -------------------------------------------------------------------------------- 1 | import org.frice.Game; 2 | import org.frice.anim.move.SimpleMove; 3 | import org.frice.obj.sub.ShapeObject; 4 | import org.frice.resource.graphics.ColorResource; 5 | import org.frice.utils.shape.FCircle; 6 | import org.frice.utils.shape.FRectangle; 7 | import org.frice.utils.time.FTimer; 8 | 9 | import static org.frice.Initializer.launch; 10 | 11 | /** 12 | * An awesome demo 13 | * 14 | * @author SuperSodaSea 15 | */ 16 | public class Demo11 extends Game { 17 | 18 | private ColorResource colors[]; 19 | private double a = 0; 20 | private double b = 0; 21 | private FTimer timer = new FTimer(15); 22 | 23 | @Override 24 | public void onInit() { 25 | colors = new ColorResource[]{ 26 | ColorResource.东条希, 27 | ColorResource.南小鸟, 28 | ColorResource.园田海未, 29 | ColorResource.小泉花阳, 30 | ColorResource.星空凛, 31 | ColorResource.洵濑绘理, 32 | ColorResource.矢泽妮可, 33 | ColorResource.西木野真姬, 34 | ColorResource.高坂穗乃果 35 | }; 36 | // setSize(1200, 720); 37 | setTitle("IAmSoSquare Demo"); 38 | setAutoGC(true); 39 | addObject(new ShapeObject(ColorResource.IntelliJ_IDEA黑, new FRectangle(getWidth(), getHeight()))); 40 | } 41 | 42 | @Override 43 | public void onRefresh() { 44 | super.onRefresh(); 45 | if (timer.ended()) { 46 | a += 0.0002; 47 | b += a; 48 | addObject(new ShapeObject(colors[(int) (System.currentTimeMillis() / 100 % colors.length)], 49 | new FCircle(10), getWidth() / 2, getHeight() / 2) {{ 50 | addAnim(new SimpleMove((int) (Math.sin(b) * 256), (int) (Math.cos(b) * 256))); 51 | }}); 52 | System.out.println(getLayers()[0].getObjects().size()); 53 | } 54 | } 55 | 56 | public static void main(String[] args) { 57 | launch(Demo11.class); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /1.8.0/Demo11.java: -------------------------------------------------------------------------------- 1 | import org.frice.Game; 2 | import org.frice.anim.move.SimpleMove; 3 | import org.frice.obj.sub.ShapeObject; 4 | import org.frice.resource.graphics.ColorResource; 5 | import org.frice.util.shape.FCircle; 6 | import org.frice.util.shape.FRectangle; 7 | import org.frice.util.time.FTimer; 8 | 9 | import static org.frice.Initializer.launch; 10 | 11 | /** 12 | * An awesome demo 13 | * 14 | * @author SuperSodaSea 15 | */ 16 | public class Demo11 extends Game { 17 | 18 | private ColorResource colors[]; 19 | private double a = 0; 20 | private double b = 0; 21 | private FTimer timer = new FTimer(15); 22 | 23 | @Override 24 | public void onInit() { 25 | colors = new ColorResource[]{ 26 | ColorResource.东条希, 27 | ColorResource.南小鸟, 28 | ColorResource.园田海未, 29 | ColorResource.小泉花阳, 30 | ColorResource.星空凛, 31 | ColorResource.洵濑绘理, 32 | ColorResource.矢泽妮可, 33 | ColorResource.西木野真姬, 34 | ColorResource.高坂穗乃果 35 | }; 36 | // setSize(1200, 720); 37 | setTitle("IAmSoSquare Demo"); 38 | setAutoGC(true); 39 | addObject(new ShapeObject(ColorResource.IntelliJ_IDEA黑, new FRectangle(getWidth(), getHeight()))); 40 | } 41 | 42 | @Override 43 | public void onRefresh() { 44 | super.onRefresh(); 45 | if (timer.ended()) { 46 | a += 0.0002; 47 | b += a; 48 | addObject(new ShapeObject(colors[(int) (System.currentTimeMillis() / 100 % colors.length)], 49 | new FCircle(10), getWidth() / 2, getHeight() / 2) {{ 50 | addAnim(new SimpleMove((int) (Math.sin(b) * 256), (int) (Math.cos(b) * 256))); 51 | }}); 52 | System.out.println(getLayers()[0].getObjects().size()); 53 | } 54 | } 55 | 56 | public static void main(String[] args) { 57 | launch(Demo11.class); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /demo/Demo11.java: -------------------------------------------------------------------------------- 1 | import org.frice.Game; 2 | import org.frice.anim.move.SimpleMove; 3 | import org.frice.obj.sub.ShapeObject; 4 | import org.frice.resource.graphics.ColorResource; 5 | import org.frice.utils.shape.FCircle; 6 | import org.frice.utils.shape.FRectangle; 7 | import org.frice.utils.time.FTimer; 8 | 9 | import static org.frice.Initializer.launch; 10 | 11 | /** 12 | * An awesome demo 13 | * 14 | * @author SuperSodaSea 15 | */ 16 | public class Demo11 extends Game { 17 | 18 | private ColorResource colors[]; 19 | private double a = 0; 20 | private double b = 0; 21 | private FTimer timer = new FTimer(15); 22 | 23 | @Override 24 | public void onInit() { 25 | colors = new ColorResource[]{ 26 | ColorResource.东条希, 27 | ColorResource.南小鸟, 28 | ColorResource.园田海未, 29 | ColorResource.小泉花阳, 30 | ColorResource.星空凛, 31 | ColorResource.洵濑绘理, 32 | ColorResource.矢泽妮可, 33 | ColorResource.西木野真姬, 34 | ColorResource.高坂穗乃果 35 | }; 36 | // setSize(1200, 720); 37 | setTitle("IAmSoSquare Demo"); 38 | setAutoGC(true); 39 | addObject(new ShapeObject(ColorResource.IntelliJ_IDEA黑, new FRectangle(getWidth(), getHeight()))); 40 | } 41 | 42 | @Override 43 | public void onRefresh() { 44 | super.onRefresh(); 45 | if (timer.ended()) { 46 | a += 0.0002; 47 | b += a; 48 | addObject(new ShapeObject(colors[(int) (System.currentTimeMillis() / 100 % colors.length)], 49 | new FCircle(2), getWidth() / 2, getHeight() / 2) {{ 50 | addAnim(new SimpleMove((int) (Math.sin(b) * 256), (int) (Math.cos(b) * 256))); 51 | }}); 52 | System.out.println(getLayers()[0].getObjects().size()); 53 | } 54 | } 55 | 56 | public static void main(String[] args) { 57 | launch(Demo11.class); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /old/Demo11.java: -------------------------------------------------------------------------------- 1 | import org.frice.Game; 2 | import org.frice.anim.move.SimpleMove; 3 | import org.frice.obj.sub.ShapeObject; 4 | import org.frice.resource.graphics.ColorResource; 5 | import org.frice.utils.shape.FCircle; 6 | import org.frice.utils.shape.FRectangle; 7 | import org.frice.utils.time.FTimer; 8 | 9 | import static org.frice.Initializer.launch; 10 | 11 | /** 12 | * An awesome demo 13 | * 14 | * @author SuperSodaSea 15 | */ 16 | public class Demo11 extends Game { 17 | 18 | private ColorResource colors[]; 19 | private double a = 0; 20 | private double b = 0; 21 | private FTimer timer = new FTimer(15); 22 | 23 | @Override 24 | public void onInit() { 25 | colors = new ColorResource[]{ 26 | ColorResource.东条希, 27 | ColorResource.南小鸟, 28 | ColorResource.园田海未, 29 | ColorResource.小泉花阳, 30 | ColorResource.星空凛, 31 | ColorResource.洵濑绘理, 32 | ColorResource.矢泽妮可, 33 | ColorResource.西木野真姬, 34 | ColorResource.高坂穗乃果 35 | }; 36 | // setSize(1200, 720); 37 | setTitle("IAmSoSquare Demo"); 38 | setAutoGC(true); 39 | addObject(new ShapeObject(ColorResource.IntelliJ_IDEA黑, new FRectangle(getWidth(), getHeight()))); 40 | } 41 | 42 | @Override 43 | public void onRefresh() { 44 | super.onRefresh(); 45 | if (timer.ended()) { 46 | a += 0.0002; 47 | b += a; 48 | addObject(new ShapeObject(colors[(int) (System.currentTimeMillis() / 100 % colors.length)], 49 | new FCircle(2), getWidth() / 2, getHeight() / 2) {{ 50 | addAnim(new SimpleMove((int) (Math.sin(b) * 256), (int) (Math.cos(b) * 256))); 51 | }}); 52 | System.out.println(getLayers()[0].getObjects().size()); 53 | } 54 | } 55 | 56 | public static void main(String[] args) { 57 | launch(Demo11.class); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /demo/Demo29.rkt: -------------------------------------------------------------------------------- 1 | #lang racket 2 | (require "engine.rkt") 3 | ;;flappy bird 4 | 5 | (game (bounds 600 480) 6 | (title "flappy bird") 7 | (oval #:id "bird" #:x 30 #:y 80 #:width 60 #:height 30 #:fill-color "orange" 8 | #:when-colliding (lambda () 9 | (tell "bird" 'set 'stop? #t) 10 | (text #:content "You Lose" #:text-size 20 11 | #:x 250 #:y 200 #:color "blue") 12 | (tell "clock" 'set 'stop? #t) 13 | ) 14 | #:object-class "block" 15 | ) 16 | (rectangle #:id "cilent" #:x 0 #:y 0 #:width 600 #:height 480) 17 | (when-left-clicking #:thunk (lambda () 18 | (tell "bird" 'set 'velocity-y -0.56) 19 | (tell "bird" 'set 'accelerate-y 0.002))) 20 | (when-left-clicking #:object-class "block" 21 | #:thunk (lambda () 22 | (display "hello"))) 23 | 24 | (every #:interval 1800 25 | #:thunk (lambda () 26 | (rectangle #:x 600 #:y 0 #:height (random 50 260) #:width 20 #:velocity-x -0.1 27 | #:class "block" #:fill-color "green" 28 | ) 29 | (rectangle #:x 600 #:y 300 #:height (random 50 180) #:width 20 #:velocity-x -0.1 30 | #:class "block" #:fill-color "blue" 31 | ) 32 | ; 这个地方应该有一个纵坐标大于屏幕高度的判断。如果大于了说明掉到底部了 也要GG 33 | ) 34 | #:id "clock" 35 | ) 36 | ) 37 | -------------------------------------------------------------------------------- /old/Demo29.rkt: -------------------------------------------------------------------------------- 1 | #lang racket 2 | (require "engine.rkt") 3 | ;;flappy bird 4 | 5 | (game (bounds 600 480) 6 | (title "flappy bird") 7 | (oval #:id "bird" #:x 30 #:y 80 #:width 60 #:height 30 #:fill-color "orange" 8 | #:when-colliding (lambda () 9 | (tell "bird" 'set 'stop? #t) 10 | (text #:content "You Lose" #:text-size 20 11 | #:x 250 #:y 200 #:color "blue") 12 | (tell "clock" 'set 'stop? #t) 13 | ) 14 | #:object-class "block" 15 | ) 16 | (rectangle #:id "cilent" #:x 0 #:y 0 #:width 600 #:height 480) 17 | (when-left-clicking #:thunk (lambda () 18 | (tell "bird" 'set 'velocity-y -0.56) 19 | (tell "bird" 'set 'accelerate-y 0.002))) 20 | (when-left-clicking #:object-class "block" 21 | #:thunk (lambda () 22 | (display "hello"))) 23 | 24 | (every #:interval 1800 25 | #:thunk (lambda () 26 | (rectangle #:x 600 #:y 0 #:height (random 50 260) #:width 20 #:velocity-x -0.1 27 | #:class "block" #:fill-color "green" 28 | ) 29 | (rectangle #:x 600 #:y 300 #:height (random 50 180) #:width 20 #:velocity-x -0.1 30 | #:class "block" #:fill-color "blue" 31 | ) 32 | ; 这个地方应该有一个纵坐标大于屏幕高度的判断。如果大于了说明掉到底部了 也要GG 33 | ) 34 | #:id "clock" 35 | ) 36 | ) 37 | -------------------------------------------------------------------------------- /old/Demo4.groovy: -------------------------------------------------------------------------------- 1 | import org.frice.Game 2 | import org.frice.event.OnMouseEvent 3 | import org.frice.platform.FriceImage 4 | import org.frice.resource.image.FileImageResource 5 | import org.frice.resource.image.ImageResource 6 | import org.frice.utils.data.Preference 7 | import org.frice.utils.message.FDialog 8 | import org.jetbrains.annotations.NotNull 9 | import org.jetbrains.annotations.Nullable 10 | 11 | import static org.frice.Initializer.launch 12 | 13 | /** 14 | * Groovy sample 15 | * 16 | * Demo for database operating 17 | */ 18 | class Demo4 extends Game { 19 | 20 | def fuck = new Preference("test.xml") 21 | FDialog dialog 22 | def closed = false 23 | 24 | def image 25 | 26 | @Override 27 | void onInit() { 28 | dialog = new FDialog(this) 29 | image = new FileImageResource("./test.png") 30 | 31 | /* 32 | * Groovy and Kotlin 33 | */ 34 | cursor = new ImageResource() { 35 | @Override 36 | FriceImage getImage() { 37 | Demo4.this.image.image 38 | } 39 | 40 | @Override 41 | void setImage(@NotNull FriceImage bufferedImage) { 42 | Demo4.this.image.image = bufferedImage 43 | } 44 | } 45 | 46 | } 47 | 48 | @Override 49 | void onRefresh() { 50 | if (!closed) switch (dialog.confirm("what do U want?")) { 51 | case 0: 52 | fuck.insert( 53 | dialog.input("inserting, key?"), 54 | dialog.input("inserting, value?")) 55 | break 56 | case 1: 57 | dialog.confirm(fuck.query( 58 | dialog.input("querying, key?"), 59 | dialog.input("querying, value?")).toString()) 60 | break 61 | case 2: 62 | closed = true 63 | break 64 | } 65 | } 66 | 67 | @Override 68 | void onMouse(@Nullable OnMouseEvent e) { 69 | // Do something 70 | } 71 | 72 | static void main(String[] args) { 73 | launch Demo4.class 74 | } 75 | } -------------------------------------------------------------------------------- /demo/Demo2.java: -------------------------------------------------------------------------------- 1 | import org.frice.Game; 2 | import org.frice.Initializer; 3 | import org.frice.anim.move.AccelerateMove; 4 | import org.frice.anim.move.AccurateMove; 5 | import org.frice.obj.sub.ImageObject; 6 | import org.frice.resource.image.WebImageResource; 7 | import org.frice.utils.time.FTimer; 8 | import org.jetbrains.annotations.NotNull; 9 | 10 | import static org.frice.Initializer.launch; 11 | 12 | /** 13 | * Demo for accelerate (AccelerateMove), this is a simple gravity mode. 14 | *

15 | * Created by ice1000 on 2016/8/15. 16 | * 17 | * @author ice1000 18 | * @since v0.2.1 19 | */ 20 | public class Demo2 extends Game { 21 | 22 | private FTimer timer; 23 | private ImageObject object1; 24 | private ImageObject object2; 25 | public static final String URL = "https://avatars3.githubusercontent.com/u/16398479"; 26 | 27 | public static void main(String[] args) { 28 | launch(Demo2.class); 29 | } 30 | 31 | @Override 32 | public void onInit() { 33 | setSize(800, 800); 34 | object1 = new ImageObject(new WebImageResource(URL), 0, 620); 35 | object1.addAnim(new AccelerateMove(0, 10)); 36 | object1.addAnim(new AccurateMove(0, -600)); 37 | object1.addAnim(new AccurateMove(100, 0)); 38 | addObject(object1, object2 = make()); 39 | timer = new FTimer(5000); 40 | } 41 | 42 | @Override 43 | public void onRefresh() { 44 | if (timer.ended()) { 45 | removeObject(object1, object2); 46 | addObject(object1 = make(), object2 = make()); 47 | } 48 | } 49 | 50 | @NotNull 51 | private ImageObject make() { 52 | return new ImageObject( 53 | new WebImageResource(URL), 54 | // new FileImageResource("1.png"), 55 | 20, 720) {{ 56 | addAnim(new AccelerateMove(0, 10)); 57 | addAnim(new AccurateMove(0, -700)); 58 | addAnim(new AccurateMove(280, 0)); 59 | }}; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /old/Demo2.java: -------------------------------------------------------------------------------- 1 | import org.frice.Game; 2 | import org.frice.Initializer; 3 | import org.frice.anim.move.AccelerateMove; 4 | import org.frice.anim.move.AccurateMove; 5 | import org.frice.obj.sub.ImageObject; 6 | import org.frice.resource.image.WebImageResource; 7 | import org.frice.utils.time.FTimer; 8 | import org.jetbrains.annotations.NotNull; 9 | 10 | import static org.frice.Initializer.launch; 11 | 12 | /** 13 | * Demo for accelerate (AccelerateMove), this is a simple gravity mode. 14 | *

15 | * Created by ice1000 on 2016/8/15. 16 | * 17 | * @author ice1000 18 | * @since v0.2.1 19 | */ 20 | public class Demo2 extends Game { 21 | 22 | private FTimer timer; 23 | private ImageObject object1; 24 | private ImageObject object2; 25 | public static final String URL = "https://avatars3.githubusercontent.com/u/16398479"; 26 | 27 | public static void main(String[] args) { 28 | launch(Demo2.class); 29 | } 30 | 31 | @Override 32 | public void onInit() { 33 | setSize(800, 800); 34 | object1 = new ImageObject(new WebImageResource(URL), 0, 620); 35 | object1.addAnim(new AccelerateMove(0, 10)); 36 | object1.addAnim(new AccurateMove(0, -600)); 37 | object1.addAnim(new AccurateMove(100, 0)); 38 | addObject(object1, object2 = make()); 39 | timer = new FTimer(5000); 40 | } 41 | 42 | @Override 43 | public void onRefresh() { 44 | if (timer.ended()) { 45 | removeObject(object1, object2); 46 | addObject(object1 = make(), object2 = make()); 47 | } 48 | } 49 | 50 | @NotNull 51 | private ImageObject make() { 52 | return new ImageObject( 53 | new WebImageResource(URL), 54 | // new FileImageResource("1.png"), 55 | 20, 720) {{ 56 | addAnim(new AccelerateMove(0, 10)); 57 | addAnim(new AccurateMove(0, -700)); 58 | addAnim(new AccurateMove(280, 0)); 59 | }}; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /demo/Demo26.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows.Forms; 3 | using FriceEngine; 4 | using FriceEngine.Animation; 5 | using FriceEngine.Object; 6 | using FriceEngine.Resource; 7 | using FriceEngine.Utils.Graphics; 8 | using FriceEngine.Utils.Message; 9 | using FriceEngine.Utils.Time; 10 | 11 | namespace Frice.Demo 12 | { 13 | 14 | public class Demo26 : Game 15 | { 16 | public override void OnInit() 17 | { 18 | Width = 800; 19 | Height = 600; 20 | 21 | // var b = new ShapeObject(ColorResource.小埋色, new FCircle(40), 300, 200); 22 | var a = new ShapeObject(ColorResource.吾王蓝, new FCircle(40), 300, 200); 23 | // var c = new ShapeObject(ColorResource.基佬紫, new FCircle(40), 300, 200); 24 | //replace with a file path in disk 25 | // var b = ImageObject.FromFile(@"C:\frice.png", 300, 200, 100, 100); 26 | var b = ImageObject.FromWeb("https://avatars3.githubusercontent.com/u/16398479", 300, 200, 100, 100); 27 | var c = ImageObject.FromWeb("https://avatars1.githubusercontent.com/u/21008243", 300, 200, 100, 100); 28 | // AddObjects(a, b, c); 29 | AddObject(a); 30 | AddObject(b); 31 | AddObject(c); 32 | RandomMove(a, 1000); 33 | RandomMove(b, 1500); 34 | RandomMove(c, 750); 35 | } 36 | 37 | public void RandomMove(FObject obj, int time) 38 | { 39 | var ft2 = new FTimeListener2(time, true); 40 | ft2.OnTimeUp += () => 41 | { 42 | obj.MoveList.Clear(); 43 | obj.MoveList.Add(GetRandomMove()); 44 | }; 45 | ft2.Start(); 46 | } 47 | 48 | private static SimpleMove GetRandomMove() 49 | { 50 | var r = new Random(); 51 | var x = r.Next(-100, 100); 52 | var r2 = new Random(x); 53 | var y = r.Next(-100, 100); 54 | 55 | return new SimpleMove(x, y); 56 | } 57 | 58 | public static void Main(string[] args) 59 | { 60 | Application.Run(new Demo26()); 61 | } 62 | } 63 | } -------------------------------------------------------------------------------- /old/Demo26.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows.Forms; 3 | using FriceEngine; 4 | using FriceEngine.Animation; 5 | using FriceEngine.Object; 6 | using FriceEngine.Resource; 7 | using FriceEngine.Utils.Graphics; 8 | using FriceEngine.Utils.Message; 9 | using FriceEngine.Utils.Time; 10 | 11 | namespace Frice.Demo 12 | { 13 | 14 | public class Demo26 : Game 15 | { 16 | public override void OnInit() 17 | { 18 | Width = 800; 19 | Height = 600; 20 | 21 | // var b = new ShapeObject(ColorResource.小埋色, new FCircle(40), 300, 200); 22 | var a = new ShapeObject(ColorResource.吾王蓝, new FCircle(40), 300, 200); 23 | // var c = new ShapeObject(ColorResource.基佬紫, new FCircle(40), 300, 200); 24 | //replace with a file path in disk 25 | // var b = ImageObject.FromFile(@"C:\frice.png", 300, 200, 100, 100); 26 | var b = ImageObject.FromWeb("https://avatars3.githubusercontent.com/u/16398479", 300, 200, 100, 100); 27 | var c = ImageObject.FromWeb("https://avatars1.githubusercontent.com/u/21008243", 300, 200, 100, 100); 28 | // AddObjects(a, b, c); 29 | AddObject(a); 30 | AddObject(b); 31 | AddObject(c); 32 | RandomMove(a, 1000); 33 | RandomMove(b, 1500); 34 | RandomMove(c, 750); 35 | } 36 | 37 | public void RandomMove(FObject obj, int time) 38 | { 39 | var ft2 = new FTimeListener2(time, true); 40 | ft2.OnTimeUp += () => 41 | { 42 | obj.MoveList.Clear(); 43 | obj.MoveList.Add(GetRandomMove()); 44 | }; 45 | ft2.Start(); 46 | } 47 | 48 | private static SimpleMove GetRandomMove() 49 | { 50 | var r = new Random(); 51 | var x = r.Next(-100, 100); 52 | var r2 = new Random(x); 53 | var y = r.Next(-100, 100); 54 | 55 | return new SimpleMove(x, y); 56 | } 57 | 58 | public static void Main(string[] args) 59 | { 60 | Application.Run(new Demo26()); 61 | } 62 | } 63 | } -------------------------------------------------------------------------------- /demo/Demo7.java: -------------------------------------------------------------------------------- 1 | import org.frice.Game; 2 | import org.frice.anim.move.AccelerateMove; 3 | import org.frice.anim.move.SimpleMove; 4 | import org.frice.obj.SideEffect; 5 | import org.frice.obj.sub.ShapeObject; 6 | import org.frice.resource.graphics.ColorResource; 7 | import org.frice.utils.FileUtils; 8 | import org.frice.utils.shape.FCircle; 9 | import org.frice.utils.shape.FRectangle; 10 | import org.frice.utils.time.FTimer; 11 | 12 | import static org.frice.Initializer.launch; 13 | 14 | public class Demo7 extends Game { 15 | public static void main(String[] args) { 16 | launch(Demo7.class); 17 | } 18 | 19 | private FTimer timer = new FTimer(3000); 20 | private ShapeObject object; 21 | private SideEffect gameOver = () -> { 22 | new Thread(() -> FileUtils.image2File(getScreenCut().getImage(), "截屏.png")).start(); 23 | dialogShow("Game Over"); 24 | System.exit(0); 25 | }; 26 | 27 | @Override public void onInit() { 28 | setSize(500, 800); 29 | setTitle("Flappy bird demo by ice1000"); 30 | object = new ShapeObject(ColorResource.宝强绿, new FCircle(20), 50, 200) {{ 31 | addAnim(AccelerateMove.getGravity()); 32 | }}; 33 | addObject(object); 34 | addKeyListener(null, e -> { 35 | object.stopAnims(); 36 | object.addAnim(AccelerateMove.getGravity()); 37 | object.addAnim(new SimpleMove(0, -400)); 38 | }, null); 39 | } 40 | 41 | @Override public void onRefresh() { 42 | if (object.getY() > getHeight() + 20) gameOver.invoke(); 43 | if (timer.ended()) addObject(getObj((int) (Math.random() * 400))); 44 | } 45 | 46 | private ShapeObject[] getObj(int height) { 47 | return new ShapeObject[]{new ShapeObject(ColorResource.教主黄, new FRectangle(50, height), 550, 0) {{ 48 | addAnim(new SimpleMove(-150, 0)); 49 | addCollider(object, gameOver); 50 | }}, new ShapeObject(ColorResource.教主黄, new FRectangle(50, getHeight() - height - 400), 550, height + 400) {{ 51 | addAnim(new SimpleMove(-150, 0)); 52 | addCollider(object, gameOver); 53 | }}}; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /old/Demo7.java: -------------------------------------------------------------------------------- 1 | import org.frice.Game; 2 | import org.frice.anim.move.AccelerateMove; 3 | import org.frice.anim.move.SimpleMove; 4 | import org.frice.obj.SideEffect; 5 | import org.frice.obj.sub.ShapeObject; 6 | import org.frice.resource.graphics.ColorResource; 7 | import org.frice.utils.FileUtils; 8 | import org.frice.utils.shape.FCircle; 9 | import org.frice.utils.shape.FRectangle; 10 | import org.frice.utils.time.FTimer; 11 | 12 | import static org.frice.Initializer.launch; 13 | 14 | public class Demo7 extends Game { 15 | public static void main(String[] args) { 16 | launch(Demo7.class); 17 | } 18 | 19 | private FTimer timer = new FTimer(3000); 20 | private ShapeObject object; 21 | private SideEffect gameOver = () -> { 22 | new Thread(() -> FileUtils.image2File(getScreenCut().getImage(), "截屏.png")).start(); 23 | dialogShow("Game Over"); 24 | System.exit(0); 25 | }; 26 | 27 | @Override public void onInit() { 28 | setSize(500, 800); 29 | setTitle("Flappy bird demo by ice1000"); 30 | object = new ShapeObject(ColorResource.宝强绿, new FCircle(20), 50, 200) {{ 31 | addAnim(AccelerateMove.getGravity()); 32 | }}; 33 | addObject(object); 34 | addKeyListener(null, e -> { 35 | object.stopAnims(); 36 | object.addAnim(AccelerateMove.getGravity()); 37 | object.addAnim(new SimpleMove(0, -400)); 38 | }, null); 39 | } 40 | 41 | @Override public void onRefresh() { 42 | if (object.getY() > getHeight() + 20) gameOver.invoke(); 43 | if (timer.ended()) addObject(getObj((int) (Math.random() * 400))); 44 | } 45 | 46 | private ShapeObject[] getObj(int height) { 47 | return new ShapeObject[]{new ShapeObject(ColorResource.教主黄, new FRectangle(50, height), 550, 0) {{ 48 | addAnim(new SimpleMove(-150, 0)); 49 | addCollider(object, gameOver); 50 | }}, new ShapeObject(ColorResource.教主黄, new FRectangle(50, getHeight() - height - 400), 550, height + 400) {{ 51 | addAnim(new SimpleMove(-150, 0)); 52 | addCollider(object, gameOver); 53 | }}}; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /old/Demo13.java: -------------------------------------------------------------------------------- 1 | import org.frice.Game; 2 | import org.frice.anim.move.AccelerateMove; 3 | import org.frice.anim.move.SimpleMove; 4 | import org.frice.obj.FObject; 5 | import org.frice.obj.sub.ShapeObject; 6 | import org.frice.resource.graphics.ColorResource; 7 | import org.frice.utils.shape.FCircle; 8 | import org.frice.utils.shape.FRectangle; 9 | import org.frice.utils.time.FTimer; 10 | 11 | import java.awt.*; 12 | import java.util.Random; 13 | 14 | import static org.frice.Initializer.launch; 15 | 16 | /** 17 | * An awesome demo 18 | * 19 | * @author SuperSodaSea 20 | */ 21 | public class Demo13 extends Game { 22 | 23 | private ColorResource[] colors; 24 | private FTimer timer2; 25 | private FObject object; 26 | 27 | @Override 28 | public void onInit() { 29 | timer2 = new FTimer(30); 30 | colors = new ColorResource[]{ 31 | ColorResource.东条希, 32 | ColorResource.高坂穗乃果, 33 | ColorResource.西木野真姬, 34 | ColorResource.矢泽妮可, 35 | ColorResource.洵濑绘理, 36 | ColorResource.星空凛, 37 | ColorResource.南小鸟 38 | }; 39 | object = new ShapeObject(new ColorResource(0xffffff), new FRectangle(getWidth(), 10), 1, getHeight() - 50); 40 | addObject(object); 41 | setBackground(new ColorResource(0x2b2b2b).getColor()); 42 | } 43 | 44 | Random random = new Random(System.currentTimeMillis()); 45 | 46 | @Override 47 | public void onRefresh() { 48 | Point mouse = getMousePosition(); 49 | if (timer2.ended() && null != mouse) { 50 | addObject(new ShapeObject(colors[(int) ((System.currentTimeMillis() / 100) % colors.length)], 51 | new FCircle(10), mouse.getX(), mouse.getY()) {{ 52 | addAnim(new SimpleMove((int) (random.nextInt(Demo13.this.getWidth()) - getX()), -500)); 53 | addAnim(AccelerateMove.getGravity(20)); 54 | addCollider(object, () -> { 55 | getAnims().remove(1); 56 | addAnim(AccelerateMove.getGravity(20)); 57 | }); 58 | }}); 59 | } 60 | } 61 | 62 | public static void main(String[] args) { 63 | launch(Demo13.class); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /demo/Demo13.java: -------------------------------------------------------------------------------- 1 | import org.frice.Game; 2 | import org.frice.anim.move.AccelerateMove; 3 | import org.frice.anim.move.SimpleMove; 4 | import org.frice.obj.FObject; 5 | import org.frice.obj.sub.ShapeObject; 6 | import org.frice.resource.graphics.ColorResource; 7 | import org.frice.utils.shape.FCircle; 8 | import org.frice.utils.shape.FRectangle; 9 | import org.frice.utils.time.FTimer; 10 | 11 | import java.awt.*; 12 | import java.util.Random; 13 | 14 | import static org.frice.Initializer.launch; 15 | 16 | /** 17 | * An awesome demo 18 | * 19 | * @author SuperSodaSea 20 | */ 21 | public class Demo13 extends Game { 22 | 23 | private ColorResource[] colors; 24 | private FTimer timer2; 25 | private FObject object; 26 | 27 | @Override 28 | public void onInit() { 29 | timer2 = new FTimer(30); 30 | colors = new ColorResource[]{ 31 | ColorResource.东条希, 32 | ColorResource.高坂穗乃果, 33 | ColorResource.西木野真姬, 34 | ColorResource.矢泽妮可, 35 | ColorResource.洵濑绘理, 36 | ColorResource.星空凛, 37 | ColorResource.南小鸟 38 | }; 39 | object = new ShapeObject(new ColorResource(0xffffff), new FRectangle(getWidth(), 10), 1, getHeight() - 50); 40 | addObject(object); 41 | setBackground(new ColorResource(0x2b2b2b).getColor()); 42 | } 43 | 44 | Random random = new Random(System.currentTimeMillis()); 45 | 46 | @Override 47 | public void onRefresh() { 48 | Point mouse = getMousePosition(); 49 | if (timer2.ended() && null != mouse) { 50 | addObject(new ShapeObject(colors[(int) ((System.currentTimeMillis() / 100) % colors.length)], 51 | new FCircle(10), mouse.getX(), mouse.getY()) {{ 52 | addAnim(new SimpleMove((int) (random.nextInt(Demo13.this.getWidth()) - getX()), -500)); 53 | addAnim(AccelerateMove.getGravity(20)); 54 | addCollider(object, () -> { 55 | getAnims().remove(1); 56 | addAnim(AccelerateMove.getGravity(20)); 57 | }); 58 | }}); 59 | } 60 | } 61 | 62 | public static void main(String[] args) { 63 | launch(Demo13.class); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /1.7.6/Demo7.java: -------------------------------------------------------------------------------- 1 | import org.frice.Game; 2 | import org.frice.anim.move.AccelerateMove; 3 | import org.frice.anim.move.SimpleMove; 4 | import org.frice.obj.sub.ShapeObject; 5 | import org.frice.resource.graphics.ColorResource; 6 | import org.frice.utils.FileUtils; 7 | import org.frice.utils.shape.FCircle; 8 | import org.frice.utils.shape.FRectangle; 9 | import org.frice.utils.time.FTimer; 10 | 11 | import java.util.ArrayList; 12 | import java.util.List; 13 | 14 | import static org.frice.Initializer.launch; 15 | 16 | public class Demo7 extends Game { 17 | public static void main(String[] args) { 18 | launch(Demo7.class); 19 | } 20 | 21 | private FTimer timer = new FTimer(3000); 22 | private ShapeObject bird; 23 | private List objects = new ArrayList<>(); 24 | 25 | @Override public void onInit() { 26 | setSize(500, 800); 27 | setTitle("Flappy bird demo by ice1000"); 28 | bird = new ShapeObject(ColorResource.宝强绿, new FCircle(20), 50, 200) {{ 29 | addAnim(new AccelerateMove(0, 10)); 30 | }}; 31 | addObject(bird); 32 | addKeyListener(null, e -> { 33 | bird.stopAnims(); 34 | bird.addAnim(new AccelerateMove(0, 10)); 35 | bird.addAnim(new SimpleMove(0, -400)); 36 | }, null); 37 | } 38 | 39 | @Override public void onRefresh() { 40 | if (timer.ended()) addObject(getObj((int) (Math.random() * 400))); 41 | objects.removeIf(ShapeObject::getDied); 42 | if (bird.getY() > getHeight() + 20 || objects.stream().anyMatch(o -> o.collides(bird))) { 43 | new Thread(() -> FileUtils.image2File(getScreenCut().getImage(), "截屏.png")).start(); 44 | dialogShow("Game Over"); 45 | System.exit(0); 46 | } 47 | } 48 | 49 | private ShapeObject[] getObj(int height) { 50 | return new ShapeObject[]{new ShapeObject(ColorResource.教主黄, new FRectangle(50, height), 550, 0) {{ 51 | addAnim(new SimpleMove(-150, 0)); 52 | objects.add(this); 53 | }}, new ShapeObject(ColorResource.教主黄, new FRectangle(50, getHeight() - height - 400), 550, height + 400) {{ 54 | addAnim(new SimpleMove(-150, 0)); 55 | objects.add(this); 56 | }}}; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /1.8.0/Demo7.java: -------------------------------------------------------------------------------- 1 | import org.frice.Game; 2 | import org.frice.anim.move.AccelerateMove; 3 | import org.frice.anim.move.SimpleMove; 4 | import org.frice.obj.sub.ShapeObject; 5 | import org.frice.resource.graphics.ColorResource; 6 | import org.frice.util.FileUtils; 7 | import org.frice.util.shape.FCircle; 8 | import org.frice.util.shape.FRectangle; 9 | import org.frice.util.time.FTimer; 10 | 11 | import java.util.ArrayList; 12 | import java.util.List; 13 | 14 | import static org.frice.Initializer.launch; 15 | 16 | public class Demo7 extends Game { 17 | public static void main(String[] args) { 18 | launch(Demo7.class); 19 | } 20 | 21 | private FTimer timer = new FTimer(3000); 22 | private ShapeObject bird; 23 | private List objects = new ArrayList<>(); 24 | 25 | @Override 26 | public void onInit() { 27 | setSize(500, 800); 28 | setTitle("Flappy bird demo by ice1000"); 29 | bird = new ShapeObject(ColorResource.宝强绿, new FCircle(20), 50, 200) {{ 30 | addAnim(new AccelerateMove(0, 800)); 31 | }}; 32 | addObject(bird); 33 | addKeyListener(null, e -> { 34 | bird.stopAnims(); 35 | bird.addAnim(new AccelerateMove(0, 800)); 36 | bird.addAnim(new SimpleMove(0, -400)); 37 | }, null); 38 | } 39 | 40 | @Override 41 | public void onRefresh() { 42 | if (timer.ended()) addObject(getObj((int) (Math.random() * 400))); 43 | objects.removeIf(ShapeObject::getDied); 44 | if (bird.getY() > getHeight() + 20 || objects.stream().anyMatch(o -> o.collides(bird))) { 45 | new Thread(() -> FileUtils.image2File(getScreenCut().getImage(), "截屏.png")).start(); 46 | dialogShow("Game Over"); 47 | System.exit(0); 48 | } 49 | } 50 | 51 | private ShapeObject[] getObj(int height) { 52 | return new ShapeObject[]{new ShapeObject(ColorResource.八云紫, new FRectangle(50, height), 550, 0) {{ 53 | addAnim(new SimpleMove(-150, 0)); 54 | objects.add(this); 55 | }}, new ShapeObject(ColorResource.八云紫, new FRectangle(50, getHeight() - height - 400), 550, height + 400) {{ 56 | addAnim(new SimpleMove(-150, 0)); 57 | objects.add(this); 58 | }}}; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /1.7.9/Demo7.java: -------------------------------------------------------------------------------- 1 | import org.frice.Game; 2 | import org.frice.anim.move.AccelerateMove; 3 | import org.frice.anim.move.SimpleMove; 4 | import org.frice.obj.sub.ShapeObject; 5 | import org.frice.resource.graphics.ColorResource; 6 | import org.frice.utils.FileUtils; 7 | import org.frice.utils.shape.FCircle; 8 | import org.frice.utils.shape.FRectangle; 9 | import org.frice.utils.time.FTimer; 10 | 11 | import java.util.ArrayList; 12 | import java.util.List; 13 | 14 | import static org.frice.Initializer.launch; 15 | 16 | public class Demo7 extends Game { 17 | public static void main(String[] args) { 18 | launch(Demo7.class); 19 | } 20 | 21 | private FTimer timer = new FTimer(3000); 22 | private ShapeObject bird; 23 | private List objects = new ArrayList<>(); 24 | 25 | @Override 26 | public void onInit() { 27 | setSize(500, 800); 28 | setTitle("Flappy bird demo by ice1000"); 29 | bird = new ShapeObject(ColorResource.宝强绿, new FCircle(20), 50, 200) {{ 30 | addAnim(new AccelerateMove(0, 800)); 31 | }}; 32 | addObject(bird); 33 | addKeyListener(null, e -> { 34 | bird.stopAnims(); 35 | bird.addAnim(new AccelerateMove(0, 800)); 36 | bird.addAnim(new SimpleMove(0, -400)); 37 | }, null); 38 | } 39 | 40 | @Override 41 | public void onRefresh() { 42 | if (timer.ended()) addObject(getObj((int) (Math.random() * 400))); 43 | objects.removeIf(ShapeObject::getDied); 44 | if (bird.getY() > getHeight() + 20 || objects.stream().anyMatch(o -> o.collides(bird))) { 45 | new Thread(() -> FileUtils.image2File(getScreenCut().getImage(), "截屏.png")).start(); 46 | dialogShow("Game Over"); 47 | System.exit(0); 48 | } 49 | } 50 | 51 | private ShapeObject[] getObj(int height) { 52 | return new ShapeObject[]{new ShapeObject(ColorResource.八云紫, new FRectangle(50, height), 550, 0) {{ 53 | addAnim(new SimpleMove(-150, 0)); 54 | objects.add(this); 55 | }}, new ShapeObject(ColorResource.八云紫, new FRectangle(50, getHeight() - height - 400), 550, height + 400) {{ 56 | addAnim(new SimpleMove(-150, 0)); 57 | objects.add(this); 58 | }}}; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /demo/Demo1.java: -------------------------------------------------------------------------------- 1 | import org.frice.Game; 2 | import org.frice.anim.move.SimpleMove; 3 | import org.frice.event.OnMouseEvent; 4 | import org.frice.obj.FObject; 5 | import org.frice.obj.sub.ImageObject; 6 | import org.frice.obj.sub.ShapeObject; 7 | import org.frice.resource.graphics.ColorResource; 8 | import org.frice.resource.image.FileImageResource; 9 | import org.frice.utils.shape.FOval; 10 | import org.frice.utils.time.FTimer; 11 | import org.jetbrains.annotations.NotNull; 12 | 13 | import java.util.ArrayList; 14 | 15 | import static org.frice.Initializer.launch; 16 | 17 | /** 18 | * Demo for the simplest use of Frice Engine 19 | * Created by ice1000 on 2016/8/13. 20 | * 21 | * @author ice1000 22 | * @since v0.1 23 | */ 24 | public class Demo1 extends Game { 25 | 26 | private ArrayList objects = new ArrayList<>(); 27 | private FTimer timer; 28 | private FTimer timer2; 29 | private int fuck = 0; 30 | private int mode = 0; 31 | 32 | @Override 33 | public void onInit() { 34 | timer = new FTimer(800); 35 | timer2 = new FTimer(200); 36 | setBackground(ColorResource.PINK.getColor()); 37 | setBounds(100, 100, 800, 800); 38 | setTitle("Fuck Fuck Fuck"); 39 | addObject(new ShapeObject(ColorResource.DARK_GRAY, new FOval(50, 50)) {{ 40 | addAnim(new SimpleMove(10, 20)); 41 | }}); 42 | } 43 | 44 | @Override 45 | public void onRefresh() { 46 | if (timer2.ended()) { 47 | if (fuck > 500) mode = 1; 48 | if (fuck < 1) mode = 0; 49 | } 50 | if (timer.ended()) { 51 | FObject object; 52 | switch (mode) { 53 | case 1: 54 | object = objects.get(objects.size() - 1); 55 | removeObject(object); 56 | objects.remove(object); 57 | fuck -= 100; 58 | break; 59 | case 0: 60 | fuck += 100; 61 | object = new ImageObject(new FileImageResource("test.png"), fuck, fuck); 62 | addObject(object); 63 | objects.add(object); 64 | break; 65 | } 66 | } 67 | } 68 | 69 | @Override 70 | public void onMouse(@NotNull OnMouseEvent onClickEvent) { 71 | // dialog.show("fuck!!!!!!"); 72 | if (dialogConfirmYesNo("Choose")) { 73 | dialogShow("Yes!"); 74 | } else { 75 | dialogShow("No!"); 76 | } 77 | } 78 | 79 | public static void main(String[] args) { 80 | launch(Demo1.class); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /old/Demo1.java: -------------------------------------------------------------------------------- 1 | import org.frice.Game; 2 | import org.frice.anim.move.SimpleMove; 3 | import org.frice.event.OnMouseEvent; 4 | import org.frice.obj.FObject; 5 | import org.frice.obj.sub.ImageObject; 6 | import org.frice.obj.sub.ShapeObject; 7 | import org.frice.resource.graphics.ColorResource; 8 | import org.frice.resource.image.FileImageResource; 9 | import org.frice.utils.shape.FOval; 10 | import org.frice.utils.time.FTimer; 11 | import org.jetbrains.annotations.NotNull; 12 | 13 | import java.util.ArrayList; 14 | 15 | import static org.frice.Initializer.launch; 16 | 17 | /** 18 | * Demo for the simplest use of Frice Engine 19 | * Created by ice1000 on 2016/8/13. 20 | * 21 | * @author ice1000 22 | * @since v0.1 23 | */ 24 | public class Demo1 extends Game { 25 | 26 | private ArrayList objects = new ArrayList<>(); 27 | private FTimer timer; 28 | private FTimer timer2; 29 | private int fuck = 0; 30 | private int mode = 0; 31 | 32 | @Override 33 | public void onInit() { 34 | timer = new FTimer(800); 35 | timer2 = new FTimer(200); 36 | setBackground(ColorResource.PINK.getColor()); 37 | setBounds(100, 100, 800, 800); 38 | setTitle("Fuck Fuck Fuck"); 39 | addObject(new ShapeObject(ColorResource.DARK_GRAY, new FOval(50, 50)) {{ 40 | addAnim(new SimpleMove(10, 20)); 41 | }}); 42 | } 43 | 44 | @Override 45 | public void onRefresh() { 46 | if (timer2.ended()) { 47 | if (fuck > 500) mode = 1; 48 | if (fuck < 1) mode = 0; 49 | } 50 | if (timer.ended()) { 51 | FObject object; 52 | switch (mode) { 53 | case 1: 54 | object = objects.get(objects.size() - 1); 55 | removeObject(object); 56 | objects.remove(object); 57 | fuck -= 100; 58 | break; 59 | case 0: 60 | fuck += 100; 61 | object = new ImageObject(new FileImageResource("test.png"), fuck, fuck); 62 | addObject(object); 63 | objects.add(object); 64 | break; 65 | } 66 | } 67 | } 68 | 69 | @Override 70 | public void onMouse(@NotNull OnMouseEvent onClickEvent) { 71 | // dialog.show("fuck!!!!!!"); 72 | if (dialogConfirmYesNo("Choose")) { 73 | dialogShow("Yes!"); 74 | } else { 75 | dialogShow("No!"); 76 | } 77 | } 78 | 79 | public static void main(String[] args) { 80 | launch(Demo1.class); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /demo/Demo23.kt: -------------------------------------------------------------------------------- 1 | import org.frice.Game 2 | import org.frice.anim.move.AccelerateMove 3 | import org.frice.anim.move.SimpleMove 4 | import org.frice.launch 5 | import org.frice.obj.FObject 6 | import org.frice.obj.SideEffect 7 | import org.frice.obj.sub.ShapeObject 8 | import org.frice.resource.graphics.ColorResource 9 | import org.frice.utils.shape.FOval 10 | import org.frice.utils.shape.FRectangle 11 | import org.frice.utils.time.FTimer 12 | import java.awt.event.KeyEvent 13 | import java.awt.event.KeyListener 14 | 15 | /** 16 | * Created by ice1000 on 2016/9/11. 17 | * 18 | * @author ice1000 19 | */ 20 | class Demo23 : Game() { 21 | 22 | lateinit private var player: FObject 23 | lateinit private var ground: FObject 24 | private var direction = KeyEvent.VK_DOWN 25 | private var jumping = false 26 | private val timer = FTimer(1000) 27 | 28 | override fun onInit() { 29 | ground = ShapeObject(ColorResource.IntelliJ_IDEA黑, FRectangle(1000, 10), -10.0, height - 80.0) 30 | player = ShapeObject(ColorResource.西木野真姬, FOval(10.0, 20.0), 100.0, 100.0) 31 | player.addAnim(AccelerateMove.getGravity()) 32 | player.targets += ground to SideEffect { 33 | player.anims.removeAll { a -> a is AccelerateMove || (a is SimpleMove && a.y != 0) } 34 | jumping = false 35 | } 36 | addKeyListener(object : KeyListener { 37 | override fun keyTyped(e: KeyEvent?) = Unit 38 | override fun keyPressed(e: KeyEvent?) { 39 | direction = e?.keyCode ?: KeyEvent.VK_DOWN 40 | if (!jumping && e?.keyCode ?: KeyEvent.VK_DOWN == KeyEvent.VK_UP) { 41 | jumping = true 42 | player.move(0.0, -20.0) 43 | player.addAnim(AccelerateMove.getGravity()) 44 | player.addAnim(SimpleMove(0, -200)) 45 | } 46 | } 47 | 48 | override fun keyReleased(e: KeyEvent?) { 49 | direction = KeyEvent.VK_DOWN 50 | } 51 | }) 52 | addObject(player, ground) 53 | } 54 | 55 | override fun onRefresh() { 56 | when (direction) { 57 | KeyEvent.VK_LEFT -> player.move(-0.0001, 0.0) 58 | KeyEvent.VK_RIGHT -> player.move(0.0001, 0.0) 59 | } 60 | if (player.x < 10) player.x = 10.0 61 | if (player.x > width - 30) player.x = width - 30.0 62 | if (timer.ended()) { 63 | addObject(ShapeObject(ColorResource.BLUE, FRectangle(30, 30), width + 100.0, ground.y - 30).apply { 64 | addAnim(SimpleMove(-200, 0)) 65 | addCollider(player, SideEffect { 66 | stopped = true 67 | dialogShow("GG!") 68 | System.exit(0) 69 | }) 70 | }) 71 | } 72 | } 73 | } 74 | 75 | fun main(args: Array) { 76 | launch(Demo23::class.java) 77 | } -------------------------------------------------------------------------------- /old/Demo23.kt: -------------------------------------------------------------------------------- 1 | import org.frice.Game 2 | import org.frice.anim.move.AccelerateMove 3 | import org.frice.anim.move.SimpleMove 4 | import org.frice.launch 5 | import org.frice.obj.FObject 6 | import org.frice.obj.SideEffect 7 | import org.frice.obj.sub.ShapeObject 8 | import org.frice.resource.graphics.ColorResource 9 | import org.frice.utils.shape.FOval 10 | import org.frice.utils.shape.FRectangle 11 | import org.frice.utils.time.FTimer 12 | import java.awt.event.KeyEvent 13 | import java.awt.event.KeyListener 14 | 15 | /** 16 | * Created by ice1000 on 2016/9/11. 17 | * 18 | * @author ice1000 19 | */ 20 | class Demo23 : Game() { 21 | 22 | lateinit private var player: FObject 23 | lateinit private var ground: FObject 24 | private var direction = KeyEvent.VK_DOWN 25 | private var jumping = false 26 | private val timer = FTimer(1000) 27 | 28 | override fun onInit() { 29 | ground = ShapeObject(ColorResource.IntelliJ_IDEA黑, FRectangle(1000, 10), -10.0, height - 80.0) 30 | player = ShapeObject(ColorResource.西木野真姬, FOval(10.0, 20.0), 100.0, 100.0) 31 | player.addAnim(AccelerateMove.getGravity()) 32 | player.targets += ground to SideEffect { 33 | player.anims.removeAll { a -> a is AccelerateMove || (a is SimpleMove && a.y != 0) } 34 | jumping = false 35 | } 36 | addKeyListener(object : KeyListener { 37 | override fun keyTyped(e: KeyEvent?) = Unit 38 | override fun keyPressed(e: KeyEvent?) { 39 | direction = e?.keyCode ?: KeyEvent.VK_DOWN 40 | if (!jumping && e?.keyCode ?: KeyEvent.VK_DOWN == KeyEvent.VK_UP) { 41 | jumping = true 42 | player.move(0.0, -20.0) 43 | player.addAnim(AccelerateMove.getGravity()) 44 | player.addAnim(SimpleMove(0, -200)) 45 | } 46 | } 47 | 48 | override fun keyReleased(e: KeyEvent?) { 49 | direction = KeyEvent.VK_DOWN 50 | } 51 | }) 52 | addObject(player, ground) 53 | } 54 | 55 | override fun onRefresh() { 56 | when (direction) { 57 | KeyEvent.VK_LEFT -> player.move(-0.0001, 0.0) 58 | KeyEvent.VK_RIGHT -> player.move(0.0001, 0.0) 59 | } 60 | if (player.x < 10) player.x = 10.0 61 | if (player.x > width - 30) player.x = width - 30.0 62 | if (timer.ended()) { 63 | addObject(ShapeObject(ColorResource.BLUE, FRectangle(30, 30), width + 100.0, ground.y - 30).apply { 64 | addAnim(SimpleMove(-200, 0)) 65 | addCollider(player, SideEffect { 66 | stopped = true 67 | dialogShow("GG!") 68 | System.exit(0) 69 | }) 70 | }) 71 | } 72 | } 73 | } 74 | 75 | fun main(args: Array) { 76 | launch(Demo23::class.java) 77 | } -------------------------------------------------------------------------------- /demo/Demo9.java: -------------------------------------------------------------------------------- 1 | import kotlin.Pair; 2 | import org.frice.Game; 3 | import org.frice.anim.move.SimpleMove; 4 | import org.frice.obj.effects.ParticleEffect; 5 | import org.frice.obj.sub.ImageObject; 6 | import org.frice.resource.graphics.ColorResource; 7 | import org.frice.resource.graphics.ParticleResource; 8 | import org.frice.resource.image.FileImageResource; 9 | import org.frice.utils.audio.AudioManager; 10 | import org.frice.utils.time.FTimer; 11 | 12 | import javax.imageio.ImageIO; 13 | import java.awt.event.KeyEvent; 14 | import java.io.File; 15 | import java.io.IOException; 16 | import java.util.Random; 17 | 18 | import static org.frice.Initializer.launch; 19 | 20 | public class Demo9 extends Game { 21 | private int cnt = 0; 22 | 23 | public static void main(String[] args) { 24 | launch(Demo9.class); 25 | } 26 | 27 | private ImageObject boss; 28 | private FTimer timer = new FTimer(600); 29 | 30 | @Override 31 | public void onInit() { 32 | super.onInit(); 33 | boss = new ImageObject(new FileImageResource("3.png"), 10.0, 20.0); 34 | ImageObject plane = new ImageObject(new FileImageResource("1.png")); 35 | setBounds(100, 100, 500, 500); 36 | addObject(new ParticleEffect(new ParticleResource(this, 500, 500, 37 | ColorResource.WHITE, ColorResource.GREEN), 0, 0)); 38 | addObject(boss, plane); 39 | addKeyPressedEvent(KeyEvent.VK_SPACE, e -> { 40 | ImageObject object = new ImageObject(new FileImageResource("2.png"), plane.getX(), plane.getY()); 41 | object.addAnim(new SimpleMove(0, -300)); 42 | object.addCollider(new Pair<>(boss, () -> { 43 | AudioManager.play("1.wav"); 44 | removeObject(object); 45 | })); 46 | addObject(object); 47 | }); 48 | addKeyPressedEvent(KeyEvent.VK_A, e -> plane.setX(plane.getX() - 20)); 49 | addKeyPressedEvent(KeyEvent.VK_D, e -> plane.setX(plane.getX() + 20)); 50 | addKeyPressedEvent(KeyEvent.VK_S, e -> plane.setY(plane.getY() + 20)); 51 | addKeyPressedEvent(KeyEvent.VK_W, e -> plane.setY(plane.getY() - 20)); 52 | addKeyPressedEvent(KeyEvent.VK_C, e -> new Thread(() -> { 53 | try { 54 | ImageIO.write(getScreenCut().getImage(), "png", new File("截屏" + cnt++ + ".png")); 55 | } catch (IOException ignored) { 56 | System.out.println("车祸现场"); 57 | } 58 | }).start()); 59 | } 60 | 61 | Random random = new Random(System.currentTimeMillis()); 62 | 63 | @Override 64 | public void onRefresh() { 65 | if (timer.ended()) { 66 | boss.getAnims().clear(); 67 | boss.addAnim(new SimpleMove( 68 | random.nextInt(500) - (int) boss.getX(), 69 | random.nextInt(500) - (int) boss.getY())); 70 | } 71 | } 72 | } 73 | 74 | 75 | // 苟利国家生死以,岂因祸福避趋之! 76 | // 祝长者生日快乐! 77 | 78 | 79 | -------------------------------------------------------------------------------- /old/Demo9.java: -------------------------------------------------------------------------------- 1 | import kotlin.Pair; 2 | import org.frice.Game; 3 | import org.frice.anim.move.SimpleMove; 4 | import org.frice.obj.effects.ParticleEffect; 5 | import org.frice.obj.sub.ImageObject; 6 | import org.frice.resource.graphics.ColorResource; 7 | import org.frice.resource.graphics.ParticleResource; 8 | import org.frice.resource.image.FileImageResource; 9 | import org.frice.utils.audio.AudioManager; 10 | import org.frice.utils.time.FTimer; 11 | 12 | import javax.imageio.ImageIO; 13 | import java.awt.event.KeyEvent; 14 | import java.io.File; 15 | import java.io.IOException; 16 | import java.util.Random; 17 | 18 | import static org.frice.Initializer.launch; 19 | 20 | public class Demo9 extends Game { 21 | private int cnt = 0; 22 | 23 | public static void main(String[] args) { 24 | launch(Demo9.class); 25 | } 26 | 27 | private ImageObject boss; 28 | private FTimer timer = new FTimer(600); 29 | 30 | @Override 31 | public void onInit() { 32 | super.onInit(); 33 | boss = new ImageObject(new FileImageResource("3.png"), 10.0, 20.0); 34 | ImageObject plane = new ImageObject(new FileImageResource("1.png")); 35 | setBounds(100, 100, 500, 500); 36 | addObject(new ParticleEffect(new ParticleResource(this, 500, 500, 37 | ColorResource.WHITE, ColorResource.GREEN), 0, 0)); 38 | addObject(boss, plane); 39 | addKeyPressedEvent(KeyEvent.VK_SPACE, e -> { 40 | ImageObject object = new ImageObject(new FileImageResource("2.png"), plane.getX(), plane.getY()); 41 | object.addAnim(new SimpleMove(0, -300)); 42 | object.addCollider(new Pair<>(boss, () -> { 43 | AudioManager.play("1.wav"); 44 | removeObject(object); 45 | })); 46 | addObject(object); 47 | }); 48 | addKeyPressedEvent(KeyEvent.VK_A, e -> plane.setX(plane.getX() - 20)); 49 | addKeyPressedEvent(KeyEvent.VK_D, e -> plane.setX(plane.getX() + 20)); 50 | addKeyPressedEvent(KeyEvent.VK_S, e -> plane.setY(plane.getY() + 20)); 51 | addKeyPressedEvent(KeyEvent.VK_W, e -> plane.setY(plane.getY() - 20)); 52 | addKeyPressedEvent(KeyEvent.VK_C, e -> new Thread(() -> { 53 | try { 54 | ImageIO.write(getScreenCut().getImage(), "png", new File("截屏" + cnt++ + ".png")); 55 | } catch (IOException ignored) { 56 | System.out.println("车祸现场"); 57 | } 58 | }).start()); 59 | } 60 | 61 | Random random = new Random(System.currentTimeMillis()); 62 | 63 | @Override 64 | public void onRefresh() { 65 | if (timer.ended()) { 66 | boss.getAnims().clear(); 67 | boss.addAnim(new SimpleMove( 68 | random.nextInt(500) - (int) boss.getX(), 69 | random.nextInt(500) - (int) boss.getY())); 70 | } 71 | } 72 | } 73 | 74 | 75 | // 苟利国家生死以,岂因祸福避趋之! 76 | // 祝长者生日快乐! 77 | 78 | 79 | -------------------------------------------------------------------------------- /1.8.0/Demo22.kt: -------------------------------------------------------------------------------- 1 | import org.frice.Game 2 | import org.frice.launch 3 | import org.frice.obj.sub.ShapeObject 4 | import org.frice.resource.graphics.ColorResource 5 | import org.frice.util.shape.FCircle 6 | import org.frice.util.shape.FRectangle 7 | import org.frice.util.time.FTimer 8 | import java.awt.event.KeyEvent 9 | import java.awt.event.KeyListener 10 | import java.util.* 11 | import java.util.concurrent.LinkedBlockingQueue 12 | 13 | class Demo22 : Game() { 14 | 15 | private var direction = KeyEvent.VK_LEFT 16 | private var xx = 30 17 | private var yy = 20 18 | private var fx = 10 19 | private var fy = 10 20 | private var timer = FTimer(100) 21 | private var isIncreasing = true 22 | lateinit private var body: Queue 23 | lateinit private var food: ShapeObject 24 | 25 | override fun onInit() { 26 | super.onInit() 27 | setLocationRelativeTo(null) 28 | setSize(600, 400) 29 | title = "Snake game demo" 30 | addKeyListener(object : KeyListener { 31 | override fun keyTyped(e: KeyEvent) = Unit 32 | override fun keyPressed(e: KeyEvent) { 33 | direction = e.keyCode 34 | } 35 | 36 | override fun keyReleased(e: KeyEvent) = Unit 37 | }) 38 | body = LinkedBlockingQueue() 39 | food = generateFood(10, 10) 40 | addObject(food) 41 | addObject(generateBody(30, 20).apply { body.add(this) }) 42 | autoGC = false 43 | isResizable = false 44 | } 45 | 46 | override fun onRefresh() { 47 | super.onRefresh() 48 | if (timer.ended()) { 49 | val obj: ShapeObject = when (direction) { 50 | KeyEvent.VK_LEFT -> generateBody(--xx, yy) 51 | KeyEvent.VK_RIGHT -> generateBody(++xx, yy) 52 | KeyEvent.VK_UP -> generateBody(xx, --yy) 53 | else -> generateBody(xx, ++yy) 54 | } 55 | xx = moved(xx, true) 56 | yy = moved(yy, false) 57 | if (xx == fx && yy == fy) { 58 | removeObject(food) 59 | isIncreasing = true 60 | fx = random.nextInt(this.width / 10 - 1) 61 | fy = random.nextInt(this.height / 10 - 1) 62 | food = generateFood(fx, fy) 63 | addObject(food) 64 | } 65 | body.add(obj) 66 | addObject(obj) 67 | if (!isIncreasing) removeObject(body.poll()) 68 | isIncreasing = false 69 | } 70 | } 71 | 72 | val random = Random(System.currentTimeMillis()) 73 | 74 | private fun generateBody(x: Int, y: Int) = ShapeObject(ColorResource.吾王蓝, FRectangle(10, 10), (x * 10).toDouble(), (y * 10).toDouble()) 75 | private fun generateFood(x: Int, y: Int) = ShapeObject(ColorResource.如果奇迹有颜色那么一定是橙色, FCircle(5.0), (x * 10).toDouble(), (y * 10).toDouble()) 76 | 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) 77 | 78 | companion object { 79 | @JvmStatic 80 | fun main(args: Array) = launch(Demo22::class.java) 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /old/Demo22.kt: -------------------------------------------------------------------------------- 1 | import org.frice.Game 2 | import org.frice.launch 3 | import org.frice.obj.sub.ShapeObject 4 | import org.frice.resource.graphics.ColorResource 5 | import org.frice.utils.shape.FCircle 6 | import org.frice.utils.shape.FRectangle 7 | import org.frice.utils.time.FTimer 8 | import java.awt.event.KeyEvent 9 | import java.awt.event.KeyListener 10 | import java.util.* 11 | import java.util.concurrent.LinkedBlockingQueue 12 | 13 | class Demo22 : Game() { 14 | 15 | private var direction = KeyEvent.VK_LEFT 16 | private var xx = 30 17 | private var yy = 20 18 | private var fx = 10 19 | private var fy = 10 20 | private var timer = FTimer(100) 21 | private var isIncreasing = true 22 | lateinit private var body: Queue 23 | lateinit private var food: ShapeObject 24 | 25 | override fun onInit() { 26 | super.onInit() 27 | setLocationRelativeTo(null) 28 | setSize(600, 400) 29 | title = "Snake game demo" 30 | addKeyListener(object : KeyListener { 31 | override fun keyTyped(e: KeyEvent) = Unit 32 | override fun keyPressed(e: KeyEvent) { 33 | direction = e.keyCode 34 | } 35 | 36 | override fun keyReleased(e: KeyEvent) = Unit 37 | }) 38 | body = LinkedBlockingQueue() 39 | food = generateFood(10, 10) 40 | addObject(food) 41 | addObject(generateBody(30, 20).apply { body.add(this) }) 42 | autoGC = false 43 | isResizable = false 44 | } 45 | 46 | override fun onRefresh() { 47 | super.onRefresh() 48 | if (timer.ended()) { 49 | val obj: ShapeObject = when (direction) { 50 | KeyEvent.VK_LEFT -> generateBody(--xx, yy) 51 | KeyEvent.VK_RIGHT -> generateBody(++xx, yy) 52 | KeyEvent.VK_UP -> generateBody(xx, --yy) 53 | else -> generateBody(xx, ++yy) 54 | } 55 | xx = moved(xx, true) 56 | yy = moved(yy, false) 57 | if (xx == fx && yy == fy) { 58 | removeObject(food) 59 | isIncreasing = true 60 | fx = random.nextInt(this.width / 10 - 1) 61 | fy = random.nextInt(this.height / 10 - 1) 62 | food = generateFood(fx, fy) 63 | addObject(food) 64 | } 65 | body.add(obj) 66 | addObject(obj) 67 | if (!isIncreasing) removeObject(body.poll()) 68 | isIncreasing = false 69 | } 70 | } 71 | 72 | val random = Random(System.currentTimeMillis()) 73 | 74 | private fun generateBody(x: Int, y: Int) = ShapeObject(ColorResource.吾王蓝, FRectangle(10, 10), (x * 10).toDouble(), (y * 10).toDouble()) 75 | private fun generateFood(x: Int, y: Int) = ShapeObject(ColorResource.如果奇迹有颜色那么一定是橙色, FCircle(5.0), (x * 10).toDouble(), (y * 10).toDouble()) 76 | 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) 77 | 78 | companion object { 79 | @JvmStatic 80 | fun main(args: Array) = launch(Demo22::class.java) 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /demo/Demo22.kt: -------------------------------------------------------------------------------- 1 | import org.frice.Game 2 | import org.frice.launch 3 | import org.frice.obj.sub.ShapeObject 4 | import org.frice.resource.graphics.ColorResource 5 | import org.frice.utils.shape.FCircle 6 | import org.frice.utils.shape.FRectangle 7 | import org.frice.utils.time.FTimer 8 | import java.awt.event.KeyEvent 9 | import java.awt.event.KeyListener 10 | import java.util.* 11 | import java.util.concurrent.LinkedBlockingQueue 12 | 13 | class Demo22 : Game() { 14 | 15 | private var direction = KeyEvent.VK_LEFT 16 | private var xx = 30 17 | private var yy = 20 18 | private var fx = 10 19 | private var fy = 10 20 | private var timer = FTimer(100) 21 | private var isIncreasing = true 22 | lateinit private var body: Queue 23 | lateinit private var food: ShapeObject 24 | 25 | override fun onInit() { 26 | super.onInit() 27 | setLocationRelativeTo(null) 28 | setSize(600, 400) 29 | title = "Snake game demo" 30 | addKeyListener(object : KeyListener { 31 | override fun keyTyped(e: KeyEvent) = Unit 32 | override fun keyPressed(e: KeyEvent) { 33 | direction = e.keyCode 34 | } 35 | 36 | override fun keyReleased(e: KeyEvent) = Unit 37 | }) 38 | body = LinkedBlockingQueue() 39 | food = generateFood(10, 10) 40 | addObject(food) 41 | addObject(generateBody(30, 20).apply { body.add(this) }) 42 | autoGC = false 43 | isResizable = false 44 | } 45 | 46 | override fun onRefresh() { 47 | super.onRefresh() 48 | if (timer.ended()) { 49 | val obj: ShapeObject = when (direction) { 50 | KeyEvent.VK_LEFT -> generateBody(--xx, yy) 51 | KeyEvent.VK_RIGHT -> generateBody(++xx, yy) 52 | KeyEvent.VK_UP -> generateBody(xx, --yy) 53 | else -> generateBody(xx, ++yy) 54 | } 55 | xx = moved(xx, true) 56 | yy = moved(yy, false) 57 | if (xx == fx && yy == fy) { 58 | removeObject(food) 59 | isIncreasing = true 60 | fx = random.nextInt(this.width / 10 - 1) 61 | fy = random.nextInt(this.height / 10 - 1) 62 | food = generateFood(fx, fy) 63 | addObject(food) 64 | } 65 | body.add(obj) 66 | addObject(obj) 67 | if (!isIncreasing) removeObject(body.poll()) 68 | isIncreasing = false 69 | } 70 | } 71 | 72 | val random = Random(System.currentTimeMillis()) 73 | 74 | private fun generateBody(x: Int, y: Int) = ShapeObject(ColorResource.吾王蓝, FRectangle(10, 10), (x * 10).toDouble(), (y * 10).toDouble()) 75 | private fun generateFood(x: Int, y: Int) = ShapeObject(ColorResource.如果奇迹有颜色那么一定是橙色, FCircle(5.0), (x * 10).toDouble(), (y * 10).toDouble()) 76 | 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) 77 | 78 | companion object { 79 | @JvmStatic 80 | fun main(args: Array) = launch(Demo22::class.java) 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /1.7.0/Demo7QuadTree.java: -------------------------------------------------------------------------------- 1 | import org.frice.Game; 2 | import org.frice.anim.move.AccelerateMove; 3 | import org.frice.anim.move.SimpleMove; 4 | import org.frice.obj.PhysicalObject; 5 | import org.frice.obj.SideEffect; 6 | import org.frice.obj.sub.ShapeObject; 7 | import org.frice.resource.graphics.ColorResource; 8 | import org.frice.utils.QuadTree; 9 | import org.frice.utils.message.FLog; 10 | import org.frice.utils.shape.FCircle; 11 | import org.frice.utils.shape.FQuad; 12 | import org.frice.utils.shape.FRectangle; 13 | import org.frice.utils.time.FTimer; 14 | import org.jetbrains.annotations.NotNull; 15 | 16 | import java.util.ArrayList; 17 | import java.util.Arrays; 18 | import java.util.List; 19 | import java.util.Random; 20 | 21 | import static org.frice.Initializer.launch; 22 | 23 | public class Demo7QuadTree extends Game { 24 | public static void main(String[] args) { 25 | launch(Demo7QuadTree.class); 26 | } 27 | 28 | private Random random = new Random(); 29 | private FTimer timer = new FTimer(3000); 30 | private ShapeObject bird; 31 | private SideEffect gameOver; 32 | 33 | @Override 34 | public void onInit() { 35 | setSize(500, 800); 36 | setTitle("Flappy bird demo by ice1000"); 37 | bird = new ShapeObject(ColorResource.宝强绿, new FCircle(20.0), 50.0, 200.0); 38 | bird.addAnim(AccelerateMove.getGravity()); 39 | addObject(bird); 40 | gameOver = () -> { 41 | dialogShow("Game Over"); 42 | System.exit(0); 43 | }; 44 | addKeyListener(null, e -> { 45 | bird.stopAnims(); 46 | bird.addAnim(AccelerateMove.getGravity()); 47 | bird.addAnim(new SimpleMove(0, -400)); 48 | }, null); 49 | } 50 | 51 | @Override 52 | public void onRefresh() { 53 | QuadTree quadTree = new QuadTree(0, new FQuad(0, 0, 500, 800)); 54 | if (bird.getY() > getHeight() + 20) gameOver.invoke(); 55 | if (timer.ended()) { 56 | quadTree.clear(); 57 | ShapeObject[] newObjects = getObj(random.nextInt(400)); 58 | instantAddObject(newObjects); 59 | Arrays.stream(newObjects).forEachOrdered(quadTree::insert); 60 | } 61 | 62 | ArrayList> returnObjects = new ArrayList<>(); 63 | quadTree.retrieve(returnObjects, bird); 64 | FLog.e(" size " + returnObjects.size()); 65 | 66 | returnObjects.stream().filter(objs -> objs.contains(bird)).forEachOrdered(rets -> { 67 | rets.remove(bird); 68 | rets.forEach(wall -> { 69 | ((ShapeObject) wall).setRes(ColorResource.基佬紫); 70 | if (bird.collides(wall)) gameOver.invoke(); 71 | }); 72 | }); 73 | } 74 | 75 | @NotNull 76 | private ShapeObject[] getObj(int height) { 77 | return new ShapeObject[]{new ShapeObject(ColorResource.高坂穗乃果, new FRectangle(50, height), 550, 0) {{ 78 | addAnim(new SimpleMove(-150, 0)); 79 | addCollider(bird, gameOver); 80 | }}, new ShapeObject(ColorResource.高坂穗乃果, new FRectangle(50, getHeight() - height - 400), 550, height + 400) {{ 81 | addAnim(new SimpleMove(-150, 0)); 82 | addCollider(bird, gameOver); 83 | }}}; 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /demo/Demo14.java: -------------------------------------------------------------------------------- 1 | import org.frice.Game; 2 | import org.frice.anim.move.AccelerateMove; 3 | import org.frice.anim.move.SimpleMove; 4 | import org.frice.obj.SideEffect; 5 | import org.frice.obj.button.FText; 6 | import org.frice.obj.button.SimpleText; 7 | import org.frice.obj.sub.ShapeObject; 8 | import org.frice.resource.graphics.ColorResource; 9 | import org.frice.utils.data.Preference; 10 | import org.frice.utils.shape.FCircle; 11 | import org.frice.utils.shape.FRectangle; 12 | import org.frice.utils.time.FTimer; 13 | import org.jetbrains.annotations.NotNull; 14 | 15 | import javax.imageio.ImageIO; 16 | import java.awt.event.KeyEvent; 17 | import java.io.File; 18 | import java.io.IOException; 19 | import java.util.Random; 20 | 21 | import static org.frice.Initializer.launch; 22 | 23 | public class Demo14 extends Game { 24 | public static void main(String[] args) { 25 | launch(Demo14.class); 26 | } 27 | 28 | private FTimer timer = new FTimer(3000); 29 | private FText text; 30 | private ShapeObject object; 31 | private SideEffect gameOver; 32 | private int score = -1, best; 33 | private Preference preference; 34 | private static final String key = "FUCK"; 35 | 36 | @Override 37 | public void onInit() { 38 | setSize(500, 800); 39 | setAutoGC(false); 40 | preference = new Preference("fuckGod.properties"); 41 | best = (int) preference.query(key, 0); 42 | setBackground(ColorResource.IntelliJ_IDEA黑.getColor()); 43 | setTitle("Flappy bird demo by ice1000"); 44 | object = new ShapeObject(ColorResource.宝强绿, new FCircle(20.0), 50.0, 200.0); 45 | object.addAnim(AccelerateMove.getGravity()); 46 | text = new SimpleText("Press any key to jump", 20, 20); 47 | addObject(text, object); 48 | gameOver = () -> { 49 | new Thread(() -> { 50 | try { 51 | ImageIO.write(getScreenCut().getImage(), "png", new File("车祸现场.png")); 52 | } catch (IOException ignored) { 53 | } 54 | }).start(); 55 | dialogShow("Game Over"); 56 | System.exit(0); 57 | }; 58 | addKeyPressedEvent(KeyEvent.VK_SPACE, e -> { 59 | object.getAnims().clear(); 60 | object.addAnim(AccelerateMove.getGravity()); 61 | object.addAnim(new SimpleMove(0, -400)); 62 | }); 63 | } 64 | 65 | @Override 66 | public void onRefresh() { 67 | if (object.getY() > getHeight() + 20) gameOver.invoke(); 68 | if (timer.ended()) { 69 | addObject(getObj()); 70 | score++; 71 | if (score > best) best = score; 72 | text.setText("score: " + score + " best: " + best); 73 | preference.insert(key, best); 74 | } 75 | } 76 | 77 | Random random = new Random(System.currentTimeMillis()); 78 | 79 | @NotNull 80 | private ShapeObject[] getObj() { 81 | int height = random.nextInt(400); 82 | return new ShapeObject[]{new ShapeObject(ColorResource.吾王蓝, 83 | new FRectangle(50, height), 550.0, 0.0) {{ 84 | addAnim(new SimpleMove(-150, 0)); 85 | addCollider(object, gameOver); 86 | }}, new ShapeObject(ColorResource.吾王蓝, 87 | new FRectangle(50, getHeight() - height - 400), 550.0, height + 400.0) {{ 88 | addAnim(new SimpleMove(-150, 0)); 89 | addCollider(object, gameOver); 90 | }}}; 91 | } 92 | } -------------------------------------------------------------------------------- /old/Demo14.java: -------------------------------------------------------------------------------- 1 | import org.frice.Game; 2 | import org.frice.anim.move.AccelerateMove; 3 | import org.frice.anim.move.SimpleMove; 4 | import org.frice.obj.SideEffect; 5 | import org.frice.obj.button.FText; 6 | import org.frice.obj.button.SimpleText; 7 | import org.frice.obj.sub.ShapeObject; 8 | import org.frice.resource.graphics.ColorResource; 9 | import org.frice.utils.data.Preference; 10 | import org.frice.utils.shape.FCircle; 11 | import org.frice.utils.shape.FRectangle; 12 | import org.frice.utils.time.FTimer; 13 | import org.jetbrains.annotations.NotNull; 14 | 15 | import javax.imageio.ImageIO; 16 | import java.awt.event.KeyEvent; 17 | import java.io.File; 18 | import java.io.IOException; 19 | import java.util.Random; 20 | 21 | import static org.frice.Initializer.launch; 22 | 23 | public class Demo14 extends Game { 24 | public static void main(String[] args) { 25 | launch(Demo14.class); 26 | } 27 | 28 | private FTimer timer = new FTimer(3000); 29 | private FText text; 30 | private ShapeObject object; 31 | private SideEffect gameOver; 32 | private int score = -1, best; 33 | private Preference preference; 34 | private static final String key = "FUCK"; 35 | 36 | @Override 37 | public void onInit() { 38 | setSize(500, 800); 39 | setAutoGC(false); 40 | preference = new Preference("fuckGod.properties"); 41 | best = (int) preference.query(key, 0); 42 | setBackground(ColorResource.IntelliJ_IDEA黑.getColor()); 43 | setTitle("Flappy bird demo by ice1000"); 44 | object = new ShapeObject(ColorResource.宝强绿, new FCircle(20.0), 50.0, 200.0); 45 | object.addAnim(AccelerateMove.getGravity()); 46 | text = new SimpleText("Press any key to jump", 20, 20); 47 | addObject(text, object); 48 | gameOver = () -> { 49 | new Thread(() -> { 50 | try { 51 | ImageIO.write(getScreenCut().getImage(), "png", new File("车祸现场.png")); 52 | } catch (IOException ignored) { 53 | } 54 | }).start(); 55 | dialogShow("Game Over"); 56 | System.exit(0); 57 | }; 58 | addKeyPressedEvent(KeyEvent.VK_SPACE, e -> { 59 | object.getAnims().clear(); 60 | object.addAnim(AccelerateMove.getGravity()); 61 | object.addAnim(new SimpleMove(0, -400)); 62 | }); 63 | } 64 | 65 | @Override 66 | public void onRefresh() { 67 | if (object.getY() > getHeight() + 20) gameOver.invoke(); 68 | if (timer.ended()) { 69 | addObject(getObj()); 70 | score++; 71 | if (score > best) best = score; 72 | text.setText("score: " + score + " best: " + best); 73 | preference.insert(key, best); 74 | } 75 | } 76 | 77 | Random random = new Random(System.currentTimeMillis()); 78 | 79 | @NotNull 80 | private ShapeObject[] getObj() { 81 | int height = random.nextInt(400); 82 | return new ShapeObject[]{new ShapeObject(ColorResource.吾王蓝, 83 | new FRectangle(50, height), 550.0, 0.0) {{ 84 | addAnim(new SimpleMove(-150, 0)); 85 | addCollider(object, gameOver); 86 | }}, new ShapeObject(ColorResource.吾王蓝, 87 | new FRectangle(50, getHeight() - height - 400), 550.0, height + 400.0) {{ 88 | addAnim(new SimpleMove(-150, 0)); 89 | addCollider(object, gameOver); 90 | }}}; 91 | } 92 | } -------------------------------------------------------------------------------- /demo/Demo28.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows.Forms; 3 | using FriceEngine; 4 | using FriceEngine.Animation; 5 | using FriceEngine.Object; 6 | using FriceEngine.Resource; 7 | using FriceEngine.Utils.Misc; 8 | using FriceEngine.Utils.Time; 9 | 10 | namespace FriceEngineTest 11 | { 12 | public class Demo : WpfGame 13 | { 14 | public static void Main(string[] args) 15 | { 16 | new Demo(); 17 | } 18 | private readonly ImageObject[] _lo = 19 | { 20 | ImageObject.FromFile("lo1.png", 550, 300), 21 | ImageObject.FromFile("lo2.png", 550, 300), 22 | ImageObject.FromFile("lo3.png", 550, 300), 23 | ImageObject.FromFile("lo4.png", 550, 300), 24 | ImageObject.FromFile("lo5.png", 550, 300) 25 | }; 26 | 27 | private readonly ImageObject[] _lou = 28 | { 29 | ImageObject.FromFile("lo1u.png", 550, -50), 30 | ImageObject.FromFile("lo2u.png", 550, -50), 31 | ImageObject.FromFile("lo3u.png", 550, -50), 32 | ImageObject.FromFile("lo4u.png", 550, -50), 33 | ImageObject.FromFile("lo5u.png", 550, -50) 34 | }; 35 | 36 | private int _loLast, _louLast, _s; 37 | private FTimeListener _timer; 38 | private Action _lambda; 39 | private ImageObject _bird; 40 | private TextObject _score; 41 | 42 | public override void OnInit() 43 | { 44 | AddObject(ImageObject.FromFile("back.png", 0, 0)); 45 | Height = 500; 46 | Width = 400; 47 | _bird = ImageObject.FromFile("an.png", 20, 300); 48 | _score = new TextObject(ColorResource.Black, 49 | "Click to jump.", 16, 10, 10); 50 | ResetGravity(); 51 | _lambda = () => 52 | { 53 | _bird.Y = 200; 54 | _bird.ClearAnims(); 55 | ResetGravity(); 56 | MessageBox.Show(@"GG!"); 57 | _score.Text = "Restart!"; 58 | _s = 0; 59 | }; 60 | foreach (var o in _lo) _bird.TargetList.Add(new Pair(o, _lambda)); 61 | foreach (var o in _lou) _bird.TargetList.Add(new Pair(o, _lambda)); 62 | AddObject(_bird, _score); 63 | _timer = new FTimeListener(1800, () => 64 | { 65 | _score.Text = "Score: " + _s++; 66 | // RemoveObject(_lo[_loLast], _lou[_louLast]); 67 | _lou[_louLast].ClearAnims(); 68 | _lo[_loLast].ClearAnims(); 69 | _loLast = Random.Next(_lo.Length); 70 | _louLast = Random.Next(_lou.Length); 71 | _lou[_louLast].X = 550; 72 | _lo[_loLast].X = 550; 73 | _lou[_louLast].AddAnims(new SimpleMove(-400, 0)); 74 | _lo[_loLast].AddAnims(new SimpleMove(-400, 0)); 75 | AddObject(_lo[_loLast], _lou[_louLast]); 76 | }, true); 77 | AddTimelistener(_timer); 78 | base.OnInit(); 79 | } 80 | 81 | public override void OnClick(double x, double y, int button) 82 | { 83 | _bird.ClearAnims(); 84 | ResetGravity(); 85 | base.OnClick(x, y, button); 86 | } 87 | 88 | public override void OnRefresh() 89 | { 90 | if (_bird.Y > Height + 50) _lambda.Invoke(); 91 | else if (_bird.Y < 0) 92 | { 93 | _bird.Y = 0; 94 | _bird.ClearAnims(); 95 | _bird.AddAnims(new AccelerateMove(0, 1800)); 96 | } 97 | base.OnRefresh(); 98 | } 99 | 100 | public override void OnLoseFocus() => GamePause(); 101 | public override void OnFocus() => GameStart(); 102 | private void ResetGravity() => _bird.AddAnims(new AccelerateMove(0, 1800), new SimpleMove(0, -500)); 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /old/Demo28.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows.Forms; 3 | using FriceEngine; 4 | using FriceEngine.Animation; 5 | using FriceEngine.Object; 6 | using FriceEngine.Resource; 7 | using FriceEngine.Utils.Misc; 8 | using FriceEngine.Utils.Time; 9 | 10 | namespace FriceEngineTest 11 | { 12 | public class Demo : WpfGame 13 | { 14 | public static void Main(string[] args) 15 | { 16 | new Demo(); 17 | } 18 | private readonly ImageObject[] _lo = 19 | { 20 | ImageObject.FromFile("lo1.png", 550, 300), 21 | ImageObject.FromFile("lo2.png", 550, 300), 22 | ImageObject.FromFile("lo3.png", 550, 300), 23 | ImageObject.FromFile("lo4.png", 550, 300), 24 | ImageObject.FromFile("lo5.png", 550, 300) 25 | }; 26 | 27 | private readonly ImageObject[] _lou = 28 | { 29 | ImageObject.FromFile("lo1u.png", 550, -50), 30 | ImageObject.FromFile("lo2u.png", 550, -50), 31 | ImageObject.FromFile("lo3u.png", 550, -50), 32 | ImageObject.FromFile("lo4u.png", 550, -50), 33 | ImageObject.FromFile("lo5u.png", 550, -50) 34 | }; 35 | 36 | private int _loLast, _louLast, _s; 37 | private FTimeListener _timer; 38 | private Action _lambda; 39 | private ImageObject _bird; 40 | private TextObject _score; 41 | 42 | public override void OnInit() 43 | { 44 | AddObject(ImageObject.FromFile("back.png", 0, 0)); 45 | Height = 500; 46 | Width = 400; 47 | _bird = ImageObject.FromFile("an.png", 20, 300); 48 | _score = new TextObject(ColorResource.Black, 49 | "Click to jump.", 16, 10, 10); 50 | ResetGravity(); 51 | _lambda = () => 52 | { 53 | _bird.Y = 200; 54 | _bird.ClearAnims(); 55 | ResetGravity(); 56 | MessageBox.Show(@"GG!"); 57 | _score.Text = "Restart!"; 58 | _s = 0; 59 | }; 60 | foreach (var o in _lo) _bird.TargetList.Add(new Pair(o, _lambda)); 61 | foreach (var o in _lou) _bird.TargetList.Add(new Pair(o, _lambda)); 62 | AddObject(_bird, _score); 63 | _timer = new FTimeListener(1800, () => 64 | { 65 | _score.Text = "Score: " + _s++; 66 | // RemoveObject(_lo[_loLast], _lou[_louLast]); 67 | _lou[_louLast].ClearAnims(); 68 | _lo[_loLast].ClearAnims(); 69 | _loLast = Random.Next(_lo.Length); 70 | _louLast = Random.Next(_lou.Length); 71 | _lou[_louLast].X = 550; 72 | _lo[_loLast].X = 550; 73 | _lou[_louLast].AddAnims(new SimpleMove(-400, 0)); 74 | _lo[_loLast].AddAnims(new SimpleMove(-400, 0)); 75 | AddObject(_lo[_loLast], _lou[_louLast]); 76 | }, true); 77 | AddTimelistener(_timer); 78 | base.OnInit(); 79 | } 80 | 81 | public override void OnClick(double x, double y, int button) 82 | { 83 | _bird.ClearAnims(); 84 | ResetGravity(); 85 | base.OnClick(x, y, button); 86 | } 87 | 88 | public override void OnRefresh() 89 | { 90 | if (_bird.Y > Height + 50) _lambda.Invoke(); 91 | else if (_bird.Y < 0) 92 | { 93 | _bird.Y = 0; 94 | _bird.ClearAnims(); 95 | _bird.AddAnims(new AccelerateMove(0, 1800)); 96 | } 97 | base.OnRefresh(); 98 | } 99 | 100 | public override void OnLoseFocus() => GamePause(); 101 | public override void OnFocus() => GameStart(); 102 | private void ResetGravity() => _bird.AddAnims(new AccelerateMove(0, 1800), new SimpleMove(0, -500)); 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /1.8.0/Demo15.java: -------------------------------------------------------------------------------- 1 | import org.frice.Game; 2 | import org.frice.obj.sub.ShapeObject; 3 | import org.frice.resource.graphics.ColorResource; 4 | import org.frice.util.shape.FCircle; 5 | import org.frice.util.shape.FRectangle; 6 | import org.frice.util.time.FTimer; 7 | 8 | import java.awt.event.KeyEvent; 9 | import java.util.Arrays; 10 | import java.util.Queue; 11 | import java.util.Random; 12 | import java.util.concurrent.LinkedBlockingQueue; 13 | 14 | import static org.frice.Initializer.launch; 15 | 16 | /** 17 | * Created by ice1000 on 2016/8/23. 18 | * 19 | * @author ice1000, KirCute 20 | */ 21 | public class Demo15 extends Game { 22 | public static void main(String[] args) { 23 | launch(Demo15.class); 24 | } 25 | 26 | private int direction = KeyEvent.VK_LEFT, x = 30, y = 20, fx = 10, fy = 10; 27 | private FTimer timer; 28 | private boolean isIncreasing = true; 29 | private Queue body; 30 | private ShapeObject food; 31 | private Random random = new Random(System.currentTimeMillis()); 32 | 33 | @Override 34 | public void onInit() { 35 | super.onInit(); 36 | this.setLocationRelativeTo(null); 37 | this.setSize(600, 400); 38 | timer = new FTimer(100); 39 | this.setTitle("Snake game demo"); 40 | this.addKeyListener(null, (KeyEvent e) -> { 41 | if (Arrays.asList(KeyEvent.VK_LEFT, KeyEvent.VK_RIGHT, KeyEvent.VK_UP, KeyEvent.VK_DOWN).contains(e.getKeyCode())) 42 | direction = e.getKeyCode(); 43 | }, null); 44 | body = new LinkedBlockingQueue<>(); 45 | food = generateFood(10, 10); 46 | this.addObject(food); 47 | ShapeObject object = generateBody(30, 20); 48 | body.add(object); 49 | this.addObject(object); 50 | this.setAutoGC(false); 51 | this.setResizable(false); 52 | } 53 | 54 | @Override 55 | public void onRefresh() { 56 | super.onRefresh(); 57 | if (timer.ended()) { 58 | ShapeObject object; 59 | switch (direction) { 60 | case KeyEvent.VK_LEFT: 61 | object = generateBody(--x, y); 62 | break; 63 | case KeyEvent.VK_RIGHT: 64 | object = generateBody(++x, y); 65 | break; 66 | case KeyEvent.VK_UP: 67 | object = generateBody(x, --y); 68 | break; 69 | case KeyEvent.VK_DOWN: 70 | object = generateBody(x, ++y); 71 | break; 72 | default: 73 | return; 74 | } 75 | // x += 60; 76 | // x %= 60; 77 | // y += 40; 78 | // y %= 40; 79 | x = this.moved(x, true); 80 | y = this.moved(y, false); 81 | if (x == fx && y == fy) { 82 | this.removeObject(food); 83 | isIncreasing = true; 84 | fx = random.nextInt(this.getWidth() / 10 - 1); 85 | fy = random.nextInt(this.getHeight() / 10 - 1); 86 | food = generateFood(fx, fy); 87 | this.addObject(food); 88 | } 89 | body.add(object); 90 | this.addObject(object); 91 | if (!isIncreasing) this.removeObject(body.poll()); 92 | isIncreasing = false; 93 | } 94 | } 95 | 96 | private ShapeObject generateBody(int x, int y) { 97 | return new ShapeObject(ColorResource.八云蓝, new FRectangle(10, 10), x * 10, y * 10); 98 | } 99 | 100 | private ShapeObject generateFood(int x, int y) { 101 | return new ShapeObject(ColorResource.如果奇迹有颜色那么一定是橙色, new FCircle(5), x * 10, y * 10); 102 | } 103 | 104 | private int moved(int i, boolean isX) { 105 | return isX ? (i + this.getWidth() / 10 - 2) % (this.getWidth() / 10 - 2) : (i + this.getHeight() / 10 - 4) % (this.getHeight() / 10 - 4); 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /1.7.9/Demo15.java: -------------------------------------------------------------------------------- 1 | import org.frice.Game; 2 | import org.frice.obj.sub.ShapeObject; 3 | import org.frice.resource.graphics.ColorResource; 4 | import org.frice.utils.shape.FCircle; 5 | import org.frice.utils.shape.FRectangle; 6 | import org.frice.utils.time.FTimer; 7 | 8 | import java.awt.event.KeyEvent; 9 | import java.util.Arrays; 10 | import java.util.Queue; 11 | import java.util.Random; 12 | import java.util.concurrent.LinkedBlockingQueue; 13 | 14 | import static org.frice.Initializer.launch; 15 | 16 | /** 17 | * Created by ice1000 on 2016/8/23. 18 | * 19 | * @author ice1000, KirCute 20 | */ 21 | public class Demo15 extends Game { 22 | public static void main(String[] args) { 23 | launch(Demo15.class); 24 | } 25 | 26 | private int direction = KeyEvent.VK_LEFT, x = 30, y = 20, fx = 10, fy = 10; 27 | private FTimer timer; 28 | private boolean isIncreasing = true; 29 | private Queue body; 30 | private ShapeObject food; 31 | private Random random = new Random(System.currentTimeMillis()); 32 | 33 | @Override 34 | public void onInit() { 35 | super.onInit(); 36 | this.setLocationRelativeTo(null); 37 | this.setSize(600, 400); 38 | timer = new FTimer(100); 39 | this.setTitle("Snake game demo"); 40 | this.addKeyListener(null, (KeyEvent e) -> { 41 | if (Arrays.asList(KeyEvent.VK_LEFT, KeyEvent.VK_RIGHT, KeyEvent.VK_UP, KeyEvent.VK_DOWN).contains(e.getKeyCode())) 42 | direction = e.getKeyCode(); 43 | }, null); 44 | body = new LinkedBlockingQueue<>(); 45 | food = generateFood(10, 10); 46 | this.addObject(food); 47 | ShapeObject object = generateBody(30, 20); 48 | body.add(object); 49 | this.addObject(object); 50 | this.setAutoGC(false); 51 | this.setResizable(false); 52 | } 53 | 54 | @Override 55 | public void onRefresh() { 56 | super.onRefresh(); 57 | if (timer.ended()) { 58 | ShapeObject object; 59 | switch (direction) { 60 | case KeyEvent.VK_LEFT: 61 | object = generateBody(--x, y); 62 | break; 63 | case KeyEvent.VK_RIGHT: 64 | object = generateBody(++x, y); 65 | break; 66 | case KeyEvent.VK_UP: 67 | object = generateBody(x, --y); 68 | break; 69 | case KeyEvent.VK_DOWN: 70 | object = generateBody(x, ++y); 71 | break; 72 | default: 73 | return; 74 | } 75 | // x += 60; 76 | // x %= 60; 77 | // y += 40; 78 | // y %= 40; 79 | x = this.moved(x, true); 80 | y = this.moved(y, false); 81 | if (x == fx && y == fy) { 82 | this.removeObject(food); 83 | isIncreasing = true; 84 | fx = random.nextInt(this.getWidth() / 10 - 1); 85 | fy = random.nextInt(this.getHeight() / 10 - 1); 86 | food = generateFood(fx, fy); 87 | this.addObject(food); 88 | } 89 | body.add(object); 90 | this.addObject(object); 91 | if (!isIncreasing) this.removeObject(body.poll()); 92 | isIncreasing = false; 93 | } 94 | } 95 | 96 | private ShapeObject generateBody(int x, int y) { 97 | return new ShapeObject(ColorResource.八云蓝, new FRectangle(10, 10), x * 10, y * 10); 98 | } 99 | 100 | private ShapeObject generateFood(int x, int y) { 101 | return new ShapeObject(ColorResource.如果奇迹有颜色那么一定是橙色, new FCircle(5), x * 10, y * 10); 102 | } 103 | 104 | private int moved(int i, boolean isX) { 105 | return isX ? (i + this.getWidth() / 10 - 2) % (this.getWidth() / 10 - 2) : (i + this.getHeight() / 10 - 4) % (this.getHeight() / 10 - 4); 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /demo/Demo15.java: -------------------------------------------------------------------------------- 1 | import org.frice.Game; 2 | import org.frice.obj.sub.ShapeObject; 3 | import org.frice.resource.graphics.ColorResource; 4 | import org.frice.utils.shape.FCircle; 5 | import org.frice.utils.shape.FRectangle; 6 | import org.frice.utils.time.FTimer; 7 | 8 | import java.awt.event.KeyEvent; 9 | import java.awt.event.KeyListener; 10 | import java.util.Arrays; 11 | import java.util.Queue; 12 | import java.util.Random; 13 | import java.util.concurrent.LinkedBlockingQueue; 14 | 15 | import static org.frice.Initializer.launch; 16 | 17 | /** 18 | * Created by ice1000 on 2016/8/23. 19 | * 20 | * @author ice1000, KirCute 21 | */ 22 | public class Demo15 extends Game { 23 | public static void main(String[] args) { 24 | launch(Demo15.class); 25 | } 26 | 27 | private int direction = KeyEvent.VK_LEFT, x = 30, y = 20, fx = 10, fy = 10; 28 | private FTimer timer; 29 | private boolean isIncreasing = true; 30 | private Queue body; 31 | private ShapeObject food; 32 | Random random = new Random(System.currentTimeMillis()); 33 | 34 | @Override 35 | public void onInit() { 36 | super.onInit(); 37 | this.setLocationRelativeTo(null); 38 | this.setSize(600, 400); 39 | timer = new FTimer(100); 40 | this.setTitle("Snake game demo"); 41 | this.addKeyListener(new KeyListener() { 42 | @Override 43 | public void keyTyped(KeyEvent e) { 44 | } 45 | 46 | @Override 47 | public void keyPressed(KeyEvent e) { 48 | if (Arrays.asList( 49 | KeyEvent.VK_LEFT, 50 | KeyEvent.VK_RIGHT, 51 | KeyEvent.VK_UP, 52 | KeyEvent.VK_DOWN 53 | ).contains(e.getKeyCode())) direction = e.getKeyCode(); 54 | } 55 | 56 | @Override 57 | public void keyReleased(KeyEvent e) { 58 | } 59 | }); 60 | body = new LinkedBlockingQueue<>(); 61 | food = generateFood(10, 10); 62 | this.addObject(food); 63 | ShapeObject object = generateBody(30, 20); 64 | body.add(object); 65 | this.addObject(object); 66 | this.setAutoGC(false); 67 | this.setResizable(false); 68 | } 69 | 70 | @Override 71 | public void onRefresh() { 72 | super.onRefresh(); 73 | if (timer.ended()) { 74 | ShapeObject object; 75 | switch (direction) { 76 | case KeyEvent.VK_LEFT: 77 | object = generateBody(--x, y); 78 | break; 79 | case KeyEvent.VK_RIGHT: 80 | object = generateBody(++x, y); 81 | break; 82 | case KeyEvent.VK_UP: 83 | object = generateBody(x, --y); 84 | break; 85 | case KeyEvent.VK_DOWN: 86 | object = generateBody(x, ++y); 87 | break; 88 | default: 89 | return; 90 | } 91 | // x += 60; 92 | // x %= 60; 93 | // y += 40; 94 | // y %= 40; 95 | x = this.moved(x, true); 96 | y = this.moved(y, false); 97 | if (x == fx && y == fy) { 98 | this.removeObject(food); 99 | isIncreasing = true; 100 | fx = random.nextInt(this.getWidth() / 10 - 1); 101 | fy = random.nextInt(this.getHeight() / 10 - 1); 102 | food = generateFood(fx, fy); 103 | this.addObject(food); 104 | } 105 | body.add(object); 106 | this.addObject(object); 107 | if (!isIncreasing) this.removeObject(body.poll()); 108 | isIncreasing = false; 109 | } 110 | } 111 | 112 | private ShapeObject generateBody(int x, int y) { 113 | return new ShapeObject(ColorResource.吾王蓝, new FRectangle(10, 10), x * 10, y * 10); 114 | } 115 | 116 | private ShapeObject generateFood(int x, int y) { 117 | return new ShapeObject(ColorResource.如果奇迹有颜色那么一定是橙色, new FCircle(5), x * 10, y * 10); 118 | } 119 | 120 | private int moved(int i, boolean isX) { 121 | return ((isX) ? ((i + this.getWidth() / 10 - 2) % (this.getWidth() / 10 - 2)) : ((i + (this.getHeight() / 10 - 4)) % (this.getHeight() / 10 - 4))); 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /old/Demo15.java: -------------------------------------------------------------------------------- 1 | import org.frice.Game; 2 | import org.frice.obj.sub.ShapeObject; 3 | import org.frice.resource.graphics.ColorResource; 4 | import org.frice.utils.shape.FCircle; 5 | import org.frice.utils.shape.FRectangle; 6 | import org.frice.utils.time.FTimer; 7 | 8 | import java.awt.event.KeyEvent; 9 | import java.awt.event.KeyListener; 10 | import java.util.Arrays; 11 | import java.util.Queue; 12 | import java.util.Random; 13 | import java.util.concurrent.LinkedBlockingQueue; 14 | 15 | import static org.frice.Initializer.launch; 16 | 17 | /** 18 | * Created by ice1000 on 2016/8/23. 19 | * 20 | * @author ice1000, KirCute 21 | */ 22 | public class Demo15 extends Game { 23 | public static void main(String[] args) { 24 | launch(Demo15.class); 25 | } 26 | 27 | private int direction = KeyEvent.VK_LEFT, x = 30, y = 20, fx = 10, fy = 10; 28 | private FTimer timer; 29 | private boolean isIncreasing = true; 30 | private Queue body; 31 | private ShapeObject food; 32 | Random random = new Random(System.currentTimeMillis()); 33 | 34 | @Override 35 | public void onInit() { 36 | super.onInit(); 37 | this.setLocationRelativeTo(null); 38 | this.setSize(600, 400); 39 | timer = new FTimer(100); 40 | this.setTitle("Snake game demo"); 41 | this.addKeyListener(new KeyListener() { 42 | @Override 43 | public void keyTyped(KeyEvent e) { 44 | } 45 | 46 | @Override 47 | public void keyPressed(KeyEvent e) { 48 | if (Arrays.asList( 49 | KeyEvent.VK_LEFT, 50 | KeyEvent.VK_RIGHT, 51 | KeyEvent.VK_UP, 52 | KeyEvent.VK_DOWN 53 | ).contains(e.getKeyCode())) direction = e.getKeyCode(); 54 | } 55 | 56 | @Override 57 | public void keyReleased(KeyEvent e) { 58 | } 59 | }); 60 | body = new LinkedBlockingQueue<>(); 61 | food = generateFood(10, 10); 62 | this.addObject(food); 63 | ShapeObject object = generateBody(30, 20); 64 | body.add(object); 65 | this.addObject(object); 66 | this.setAutoGC(false); 67 | this.setResizable(false); 68 | } 69 | 70 | @Override 71 | public void onRefresh() { 72 | super.onRefresh(); 73 | if (timer.ended()) { 74 | ShapeObject object; 75 | switch (direction) { 76 | case KeyEvent.VK_LEFT: 77 | object = generateBody(--x, y); 78 | break; 79 | case KeyEvent.VK_RIGHT: 80 | object = generateBody(++x, y); 81 | break; 82 | case KeyEvent.VK_UP: 83 | object = generateBody(x, --y); 84 | break; 85 | case KeyEvent.VK_DOWN: 86 | object = generateBody(x, ++y); 87 | break; 88 | default: 89 | return; 90 | } 91 | // x += 60; 92 | // x %= 60; 93 | // y += 40; 94 | // y %= 40; 95 | x = this.moved(x, true); 96 | y = this.moved(y, false); 97 | if (x == fx && y == fy) { 98 | this.removeObject(food); 99 | isIncreasing = true; 100 | fx = random.nextInt(this.getWidth() / 10 - 1); 101 | fy = random.nextInt(this.getHeight() / 10 - 1); 102 | food = generateFood(fx, fy); 103 | this.addObject(food); 104 | } 105 | body.add(object); 106 | this.addObject(object); 107 | if (!isIncreasing) this.removeObject(body.poll()); 108 | isIncreasing = false; 109 | } 110 | } 111 | 112 | private ShapeObject generateBody(int x, int y) { 113 | return new ShapeObject(ColorResource.吾王蓝, new FRectangle(10, 10), x * 10, y * 10); 114 | } 115 | 116 | private ShapeObject generateFood(int x, int y) { 117 | return new ShapeObject(ColorResource.如果奇迹有颜色那么一定是橙色, new FCircle(5), x * 10, y * 10); 118 | } 119 | 120 | private int moved(int i, boolean isX) { 121 | return ((isX) ? ((i + this.getWidth() / 10 - 2) % (this.getWidth() / 10 - 2)) : ((i + (this.getHeight() / 10 - 4)) % (this.getHeight() / 10 - 4))); 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /demo/Demo21.kt: -------------------------------------------------------------------------------- 1 | import org.frice.Game 2 | import org.frice.anim.RotateAnim 3 | import org.frice.anim.move.AccelerateMove 4 | import org.frice.anim.move.SimpleMove 5 | import org.frice.anim.scale.SimpleScale 6 | import org.frice.launch 7 | import org.frice.obj.PhysicalObject 8 | import org.frice.obj.SideEffect 9 | import org.frice.obj.button.SimpleButton 10 | import org.frice.obj.effects.ParticleEffect 11 | import org.frice.obj.sub.ImageObject 12 | import org.frice.obj.sub.ShapeObject 13 | import org.frice.resource.graphics.ColorResource 14 | import org.frice.resource.graphics.ParticleResource 15 | import org.frice.resource.image.WebImageResource 16 | import org.frice.utils.QuadTree 17 | import org.frice.utils.data.Preference 18 | import org.frice.utils.data.XMLPreference 19 | import org.frice.utils.greyify 20 | import org.frice.utils.message.FLog 21 | import org.frice.utils.shape.* 22 | import org.frice.utils.time.FTimer 23 | import java.util.* 24 | import java.util.function.Consumer 25 | 26 | /** 27 | * Sample 28 | * Created by ice1000 on 2016/8/21. 29 | * 30 | * @author ice1000 31 | */ 32 | class Demo21 : Game() { 33 | private lateinit var preference: Preference 34 | private lateinit var xmlPreference: XMLPreference 35 | private val timer = FTimer(200) 36 | private val objs = LinkedList() 37 | 38 | private lateinit var colored: ImageObject 39 | 40 | override fun onInit() { 41 | super.onInit() 42 | autoGC = true 43 | 44 | colored = ImageObject(WebImageResource("https://avatars1.githubusercontent.com/u/21008243?v=3&s=200"), 300.0, 300.0) 45 | colored.collisionBox = object : FShapeQuad { 46 | override val height = 50.0 47 | override val width = height 48 | override val x = 350.0 49 | override val y = 350.0 50 | } 51 | 52 | addObject(ParticleEffect(ParticleResource(this, width / 10, height / 10, 0.01), width * 0.1, height * 0.1)) 53 | addObject(SimpleButton(text = "I am a button", x = 30.0, y = 30.0, width = 100.0, height = 30.0).also { 54 | it.onMouseListener = Consumer { 55 | val obj = ShapeObject(ColorResource.西木野真姬, FOval(40.0, 30.0), 100.0, 100.0).apply { 56 | mass = 3.0 57 | addForce(-1.0, -1.0) 58 | addAnim(SimpleMove(200, 200)) 59 | addAnim(SimpleScale(1.1, 1.0)) 60 | addAnim(RotateAnim(0.1)) 61 | } 62 | objs.add(obj) 63 | addObject(obj) 64 | } 65 | }) 66 | // AudioManager.getPlayer("1.wav").start() 67 | // AudioManager.play("1.wav") 68 | 69 | // setCursor(WebImageResource("https://avatars1.githubusercontent.com/u/16477304?v=3&s=84")) 70 | 71 | preference = Preference("settings.properties") 72 | preference.insert("fuck", "microsoft") 73 | 74 | xmlPreference = XMLPreference("settings.xml") 75 | xmlPreference.insert("shit", "goddamn it") 76 | 77 | FLog.v(preference.query("fuck", "Apple")) 78 | FLog.v(xmlPreference.query("shit", "no we don't")) 79 | 80 | FOval(1.0, 1.0) 81 | FCircle(1.0) 82 | FPoint(1, 2) 83 | 84 | // addObject(ImageObject(FileImageResource("1.png"), 10.0, 10.0)) 85 | addObject(colored) 86 | 87 | FLog.v(ColorResource.小泉花阳.color.rgb.greyify()) 88 | } 89 | 90 | val random = Random(System.currentTimeMillis()) 91 | 92 | override fun onRefresh() { 93 | super.onRefresh() 94 | if (timer.ended()) { 95 | objs.removeAll(PhysicalObject::died) 96 | addObject(ShapeObject(ColorResource.IntelliJ_IDEA黑, FCircle(10.0), mouse.x, mouse.y).apply { 97 | addAnim(AccelerateMove.getGravity()) 98 | addAnim(SimpleMove(random.nextInt(400) - 200, 0)) 99 | targets.clear() 100 | addCollider(colored, SideEffect { res = ColorResource.MAGENTA }) 101 | objs.forEach { 102 | addCollider(it, SideEffect { 103 | anims.clear() 104 | targets.clear() 105 | addAnim(SimpleMove(0, -300)) 106 | addAnim(SimpleScale(1.1, 1.1)) 107 | }) 108 | } 109 | }) 110 | } 111 | } 112 | 113 | // override fun onMouse(e: OnMouseEvent) { 114 | // super.onMouse(e) 115 | // FLog.v(e.toString()) 116 | // FLog.v(mousePosition) 117 | // } 118 | 119 | override fun onExit() = System.exit(0) 120 | } 121 | 122 | fun main(args: Array) { 123 | launch(Demo21::class.java) 124 | } -------------------------------------------------------------------------------- /old/Demo21.kt: -------------------------------------------------------------------------------- 1 | import org.frice.Game 2 | import org.frice.anim.RotateAnim 3 | import org.frice.anim.move.AccelerateMove 4 | import org.frice.anim.move.SimpleMove 5 | import org.frice.anim.scale.SimpleScale 6 | import org.frice.launch 7 | import org.frice.obj.PhysicalObject 8 | import org.frice.obj.SideEffect 9 | import org.frice.obj.button.SimpleButton 10 | import org.frice.obj.effects.ParticleEffect 11 | import org.frice.obj.sub.ImageObject 12 | import org.frice.obj.sub.ShapeObject 13 | import org.frice.resource.graphics.ColorResource 14 | import org.frice.resource.graphics.ParticleResource 15 | import org.frice.resource.image.WebImageResource 16 | import org.frice.utils.QuadTree 17 | import org.frice.utils.data.Preference 18 | import org.frice.utils.data.XMLPreference 19 | import org.frice.utils.greyify 20 | import org.frice.utils.message.FLog 21 | import org.frice.utils.shape.* 22 | import org.frice.utils.time.FTimer 23 | import java.util.* 24 | import java.util.function.Consumer 25 | 26 | /** 27 | * Sample 28 | * Created by ice1000 on 2016/8/21. 29 | * 30 | * @author ice1000 31 | */ 32 | class Demo21 : Game() { 33 | private lateinit var preference: Preference 34 | private lateinit var xmlPreference: XMLPreference 35 | private val timer = FTimer(200) 36 | private val objs = LinkedList() 37 | 38 | private lateinit var colored: ImageObject 39 | 40 | override fun onInit() { 41 | super.onInit() 42 | autoGC = true 43 | 44 | colored = ImageObject(WebImageResource("https://avatars1.githubusercontent.com/u/21008243?v=3&s=200"), 300.0, 300.0) 45 | colored.collisionBox = object : FShapeQuad { 46 | override val height = 50.0 47 | override val width = height 48 | override val x = 350.0 49 | override val y = 350.0 50 | } 51 | 52 | addObject(ParticleEffect(ParticleResource(this, width / 10, height / 10, 0.01), width * 0.1, height * 0.1)) 53 | addObject(SimpleButton(text = "I am a button", x = 30.0, y = 30.0, width = 100.0, height = 30.0).also { 54 | it.onMouseListener = Consumer { 55 | val obj = ShapeObject(ColorResource.西木野真姬, FOval(40.0, 30.0), 100.0, 100.0).apply { 56 | mass = 3.0 57 | addForce(-1.0, -1.0) 58 | addAnim(SimpleMove(200, 200)) 59 | addAnim(SimpleScale(1.1, 1.0)) 60 | addAnim(RotateAnim(0.1)) 61 | } 62 | objs.add(obj) 63 | addObject(obj) 64 | } 65 | }) 66 | // AudioManager.getPlayer("1.wav").start() 67 | // AudioManager.play("1.wav") 68 | 69 | // setCursor(WebImageResource("https://avatars1.githubusercontent.com/u/16477304?v=3&s=84")) 70 | 71 | preference = Preference("settings.properties") 72 | preference.insert("fuck", "microsoft") 73 | 74 | xmlPreference = XMLPreference("settings.xml") 75 | xmlPreference.insert("shit", "goddamn it") 76 | 77 | FLog.v(preference.query("fuck", "Apple")) 78 | FLog.v(xmlPreference.query("shit", "no we don't")) 79 | 80 | FOval(1.0, 1.0) 81 | FCircle(1.0) 82 | FPoint(1, 2) 83 | 84 | // addObject(ImageObject(FileImageResource("1.png"), 10.0, 10.0)) 85 | addObject(colored) 86 | 87 | FLog.v(ColorResource.小泉花阳.color.rgb.greyify()) 88 | } 89 | 90 | val random = Random(System.currentTimeMillis()) 91 | 92 | override fun onRefresh() { 93 | super.onRefresh() 94 | if (timer.ended()) { 95 | objs.removeAll(PhysicalObject::died) 96 | addObject(ShapeObject(ColorResource.IntelliJ_IDEA黑, FCircle(10.0), mouse.x, mouse.y).apply { 97 | addAnim(AccelerateMove.getGravity()) 98 | addAnim(SimpleMove(random.nextInt(400) - 200, 0)) 99 | targets.clear() 100 | addCollider(colored, SideEffect { res = ColorResource.MAGENTA }) 101 | objs.forEach { 102 | addCollider(it, SideEffect { 103 | anims.clear() 104 | targets.clear() 105 | addAnim(SimpleMove(0, -300)) 106 | addAnim(SimpleScale(1.1, 1.1)) 107 | }) 108 | } 109 | }) 110 | } 111 | } 112 | 113 | // override fun onMouse(e: OnMouseEvent) { 114 | // super.onMouse(e) 115 | // FLog.v(e.toString()) 116 | // FLog.v(mousePosition) 117 | // } 118 | 119 | override fun onExit() = System.exit(0) 120 | } 121 | 122 | fun main(args: Array) { 123 | launch(Demo21::class.java) 124 | } -------------------------------------------------------------------------------- /demo/Demo16.kt: -------------------------------------------------------------------------------- 1 | import org.frice.Game 2 | import org.frice.anim.move.AccelerateMove 3 | import org.frice.anim.move.SimpleMove 4 | import org.frice.event.OnMouseEvent 5 | import org.frice.launch 6 | import org.frice.obj.SideEffect 7 | import org.frice.obj.sub.ImageObject 8 | import org.frice.obj.sub.ShapeObject 9 | import org.frice.resource.graphics.ColorResource 10 | import org.frice.resource.image.ImageResource 11 | import org.frice.resource.image.WebImageResource 12 | import org.frice.utils.message.FLog 13 | import org.frice.utils.shape.FRectangle 14 | import org.frice.utils.unless 15 | import java.awt.MouseInfo 16 | import java.util.* 17 | 18 | /** 19 | * Created by ifdog on 2016/8/22. 20 | * 21 | * @author ifdog, ice1000 22 | */ 23 | class Demo16 : Game() { 24 | private lateinit var 拍: ShapeObject 25 | private lateinit var 球: ImageObject 26 | private lateinit var 底部: ShapeObject 27 | private var 发球 = false 28 | private var xa = -200 29 | private var ya = -200 30 | private var r = 5.0 31 | private var sum = 0 32 | 33 | override fun onInit() { 34 | setBounds(100, 100, 800, 600) 35 | title = "蛤蛤打砖块" 36 | r = 32.0 37 | 拍 = ShapeObject(ColorResource.BLACK, FRectangle(100, 15), 100.0, 500.0) 38 | 球 = ImageObject(ImageResource.fromWeb("http://download.easyicon.net/png/540680/32/"), 120.0, 470.0) 39 | 底部 = ShapeObject(ColorResource.BLACK, FRectangle(850, 100), -20.0, 600.0) 40 | addObject(拍) 41 | addObject(球) 42 | addObject(底部) 43 | addBlocks() 44 | } 45 | 46 | override fun onRefresh() { 47 | val point = MouseInfo.getPointerInfo().location 48 | val theX = point.x - this.x.toDouble() - 拍.width / 2 49 | if (0 < theX && theX < width - 拍.width) { 50 | 拍.x = theX 51 | if (!发球) 球.x = 拍.x + 拍.width / 2 - 球.width / 2 52 | } 53 | if (球.y + r > height) { 54 | dialogShow("Game over") 55 | System.exit(0) 56 | } 57 | if (球.y + r > 480 && 球.y + r < 拍.y && 球.x + r > 拍.x && 球.x + r < 拍.x + 拍.width) { 58 | 球.anims.clear() 59 | 球.y = 460.0 60 | ya = (-1.05 * ya).toInt() 61 | 球.anims.add(SimpleMove(xa, ya)) 62 | FLog.v("q") 63 | } 64 | if (球.y + r < 0.0) { 65 | 球.anims.clear() 66 | 球.y = -5.0 67 | ya = (-1.05 * ya).toInt() 68 | 球.anims.add(SimpleMove(xa, ya)) 69 | FLog.v("w") 70 | } 71 | if (球.x + r < 0.0) { 72 | 球.anims.clear() 73 | xa = (-1.05 * xa).toInt() 74 | 球.x = -5.0 75 | 球.anims.add(SimpleMove(xa, ya)) 76 | FLog.v("e") 77 | } 78 | if (球.x + r > 800.0) { 79 | 球.anims.clear() 80 | xa = (-1.05 * xa).toInt() 81 | 球.x = 795.0 82 | 球.anims.add(SimpleMove(xa, ya)) 83 | FLog.v("r") 84 | } 85 | } 86 | 87 | val random = Random(System.currentTimeMillis()) 88 | 89 | override fun onMouse(e: OnMouseEvent) { 90 | unless(发球) { 91 | 发球 = true 92 | xa = ((random.nextGaussian() - 0.5) * 50 + 200).toInt() 93 | ya = 0 - ((random.nextGaussian() - 0.5) * 50 + 200).toInt() 94 | 球.anims.add(SimpleMove(xa, ya)) 95 | } 96 | } 97 | 98 | 99 | private fun check(activeObj: ImageObject, staticObj: ImageObject) { 100 | val x1 = staticObj.x 101 | val x2 = staticObj.x + staticObj.width 102 | val y1 = staticObj.y 103 | val y2 = staticObj.y + staticObj.height 104 | val x = activeObj.x + r 105 | val y = activeObj.y + r 106 | when { 107 | (x > x1 - 5) && (x < x2 + 5) && (y <= y1 + 5) -> ya = (-1.05 * ya).toInt() 108 | (x > x1 - 5) && (x < x2 + 5) && (y > y2 - 5) -> ya = (-1.05 * ya).toInt() 109 | (x <= x1 + 5) && (y > y1 - 5) && (y <= y2 + 5) -> xa = (-1.05 * xa).toInt() 110 | (x > x2 - 5) && (y > y1 - 5) && (y < y2 + 5) -> xa = (-1.05 * xa).toInt() 111 | } 112 | } 113 | 114 | fun addBlocks() { 115 | val y = WebImageResource("http://download.easyicon.net/png/1147697/24/") 116 | (0..9).forEach { i -> 117 | (1..8).forEach { j -> 118 | val t = ImageObject(y, (80 * i).toDouble(), (20 + j * 25).toDouble()) 119 | addObject(t) 120 | 球.targets += t to SideEffect { 121 | if (t.anims.isEmpty()) { 122 | t.addAnim(AccelerateMove.getGravity()) 123 | t.targets += 底部 to SideEffect { 124 | t.died = true 125 | removeObject(t) 126 | sum-- 127 | FLog.v(sum) 128 | } 129 | t.targets += 拍 to SideEffect { 130 | removeObject(t) 131 | t.died = true 132 | sum++ 133 | FLog.v(sum) 134 | } 135 | 球.anims.clear() 136 | check(球, t) 137 | 球.addAnim(SimpleMove(xa, ya)) 138 | } 139 | } 140 | } 141 | } 142 | } 143 | 144 | companion object { 145 | @JvmStatic 146 | fun main(args: Array) { 147 | launch(Demo16::class.java) 148 | } 149 | } 150 | } 151 | -------------------------------------------------------------------------------- /old/Demo16.kt: -------------------------------------------------------------------------------- 1 | import org.frice.Game 2 | import org.frice.anim.move.AccelerateMove 3 | import org.frice.anim.move.SimpleMove 4 | import org.frice.event.OnMouseEvent 5 | import org.frice.launch 6 | import org.frice.obj.SideEffect 7 | import org.frice.obj.sub.ImageObject 8 | import org.frice.obj.sub.ShapeObject 9 | import org.frice.resource.graphics.ColorResource 10 | import org.frice.resource.image.ImageResource 11 | import org.frice.resource.image.WebImageResource 12 | import org.frice.utils.message.FLog 13 | import org.frice.utils.shape.FRectangle 14 | import org.frice.utils.unless 15 | import java.awt.MouseInfo 16 | import java.util.* 17 | 18 | /** 19 | * Created by ifdog on 2016/8/22. 20 | * 21 | * @author ifdog, ice1000 22 | */ 23 | class Demo16 : Game() { 24 | private lateinit var 拍: ShapeObject 25 | private lateinit var 球: ImageObject 26 | private lateinit var 底部: ShapeObject 27 | private var 发球 = false 28 | private var xa = -200 29 | private var ya = -200 30 | private var r = 5.0 31 | private var sum = 0 32 | 33 | override fun onInit() { 34 | setBounds(100, 100, 800, 600) 35 | title = "蛤蛤打砖块" 36 | r = 32.0 37 | 拍 = ShapeObject(ColorResource.BLACK, FRectangle(100, 15), 100.0, 500.0) 38 | 球 = ImageObject(ImageResource.fromWeb("http://download.easyicon.net/png/540680/32/"), 120.0, 470.0) 39 | 底部 = ShapeObject(ColorResource.BLACK, FRectangle(850, 100), -20.0, 600.0) 40 | addObject(拍) 41 | addObject(球) 42 | addObject(底部) 43 | addBlocks() 44 | } 45 | 46 | override fun onRefresh() { 47 | val point = MouseInfo.getPointerInfo().location 48 | val theX = point.x - this.x.toDouble() - 拍.width / 2 49 | if (0 < theX && theX < width - 拍.width) { 50 | 拍.x = theX 51 | if (!发球) 球.x = 拍.x + 拍.width / 2 - 球.width / 2 52 | } 53 | if (球.y + r > height) { 54 | dialogShow("Game over") 55 | System.exit(0) 56 | } 57 | if (球.y + r > 480 && 球.y + r < 拍.y && 球.x + r > 拍.x && 球.x + r < 拍.x + 拍.width) { 58 | 球.anims.clear() 59 | 球.y = 460.0 60 | ya = (-1.05 * ya).toInt() 61 | 球.anims.add(SimpleMove(xa, ya)) 62 | FLog.v("q") 63 | } 64 | if (球.y + r < 0.0) { 65 | 球.anims.clear() 66 | 球.y = -5.0 67 | ya = (-1.05 * ya).toInt() 68 | 球.anims.add(SimpleMove(xa, ya)) 69 | FLog.v("w") 70 | } 71 | if (球.x + r < 0.0) { 72 | 球.anims.clear() 73 | xa = (-1.05 * xa).toInt() 74 | 球.x = -5.0 75 | 球.anims.add(SimpleMove(xa, ya)) 76 | FLog.v("e") 77 | } 78 | if (球.x + r > 800.0) { 79 | 球.anims.clear() 80 | xa = (-1.05 * xa).toInt() 81 | 球.x = 795.0 82 | 球.anims.add(SimpleMove(xa, ya)) 83 | FLog.v("r") 84 | } 85 | } 86 | 87 | val random = Random(System.currentTimeMillis()) 88 | 89 | override fun onMouse(e: OnMouseEvent) { 90 | unless(发球) { 91 | 发球 = true 92 | xa = ((random.nextGaussian() - 0.5) * 50 + 200).toInt() 93 | ya = 0 - ((random.nextGaussian() - 0.5) * 50 + 200).toInt() 94 | 球.anims.add(SimpleMove(xa, ya)) 95 | } 96 | } 97 | 98 | 99 | private fun check(activeObj: ImageObject, staticObj: ImageObject) { 100 | val x1 = staticObj.x 101 | val x2 = staticObj.x + staticObj.width 102 | val y1 = staticObj.y 103 | val y2 = staticObj.y + staticObj.height 104 | val x = activeObj.x + r 105 | val y = activeObj.y + r 106 | when { 107 | (x > x1 - 5) && (x < x2 + 5) && (y <= y1 + 5) -> ya = (-1.05 * ya).toInt() 108 | (x > x1 - 5) && (x < x2 + 5) && (y > y2 - 5) -> ya = (-1.05 * ya).toInt() 109 | (x <= x1 + 5) && (y > y1 - 5) && (y <= y2 + 5) -> xa = (-1.05 * xa).toInt() 110 | (x > x2 - 5) && (y > y1 - 5) && (y < y2 + 5) -> xa = (-1.05 * xa).toInt() 111 | } 112 | } 113 | 114 | fun addBlocks() { 115 | val y = WebImageResource("http://download.easyicon.net/png/1147697/24/") 116 | (0..9).forEach { i -> 117 | (1..8).forEach { j -> 118 | val t = ImageObject(y, (80 * i).toDouble(), (20 + j * 25).toDouble()) 119 | addObject(t) 120 | 球.targets += t to SideEffect { 121 | if (t.anims.isEmpty()) { 122 | t.addAnim(AccelerateMove.getGravity()) 123 | t.targets += 底部 to SideEffect { 124 | t.died = true 125 | removeObject(t) 126 | sum-- 127 | FLog.v(sum) 128 | } 129 | t.targets += 拍 to SideEffect { 130 | removeObject(t) 131 | t.died = true 132 | sum++ 133 | FLog.v(sum) 134 | } 135 | 球.anims.clear() 136 | check(球, t) 137 | 球.addAnim(SimpleMove(xa, ya)) 138 | } 139 | } 140 | } 141 | } 142 | } 143 | 144 | companion object { 145 | @JvmStatic 146 | fun main(args: Array) { 147 | launch(Demo16::class.java) 148 | } 149 | } 150 | } 151 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------