diff --git a/.gitignore b/.gitignore
index dbc99c23a0..5814594b60 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,7 +3,6 @@
*.class
*.war
*.ear
-*.gif
hs_err_pid*
## Robovm
diff --git a/build.gradle b/build.gradle
index bc43fef102..3094edfff4 100644
--- a/build.gradle
+++ b/build.gradle
@@ -16,8 +16,9 @@ allprojects {
version = '1.0'
ext {
- appName = "Moment"
+ appName = "Mindustry"
gdxVersion = '1.9.6'
+ aiVersion = '1.8.0'
}
repositories {
@@ -36,7 +37,6 @@ project(":desktop") {
compile project(":core")
compile "com.badlogicgames.gdx:gdx-backend-lwjgl3:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
-
}
}
@@ -59,12 +59,12 @@ project(":core") {
dependencies {
+ compile fileTree(dir: '../core/lib', include: '*.jar')
compile "com.badlogicgames.gdx:gdx:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-ai:1.8.1"
- compile fileTree(dir: '../core/lib', include: '*.jar')
}
}
tasks.eclipse.doLast {
delete ".project"
-}
+}
\ No newline at end of file
diff --git a/core/assets/maps/canyon.png b/core/assets/maps/canyon.png
new file mode 100644
index 0000000000..b46ec157f1
Binary files /dev/null and b/core/assets/maps/canyon.png differ
diff --git a/core/assets/maps/delta.png b/core/assets/maps/delta.png
new file mode 100644
index 0000000000..79a5dccc68
Binary files /dev/null and b/core/assets/maps/delta.png differ
diff --git a/core/assets/maps/map.png b/core/assets/maps/map.png
index 80ec87b523..0c7af60bbe 100644
Binary files a/core/assets/maps/map.png and b/core/assets/maps/map.png differ
diff --git a/core/assets/maps/pit.png b/core/assets/maps/pit.png
new file mode 100644
index 0000000000..fb4db8e271
Binary files /dev/null and b/core/assets/maps/pit.png differ
diff --git a/core/assets/sprites/moment.png b/core/assets/sprites/mindsutry.png
similarity index 100%
rename from core/assets/sprites/moment.png
rename to core/assets/sprites/mindsutry.png
diff --git a/core/assets/sprites/moment.atlas b/core/assets/sprites/mindustry.atlas
similarity index 99%
rename from core/assets/sprites/moment.atlas
rename to core/assets/sprites/mindustry.atlas
index 47f7f3fe89..13f07673c3 100644
--- a/core/assets/sprites/moment.atlas
+++ b/core/assets/sprites/mindustry.atlas
@@ -1,5 +1,5 @@
-moment.png
+mindsutry.png
size: 256,32
format: RGBA8888
filter: Nearest,Nearest
diff --git a/core/assets/ui/out/button-map-down.9.png b/core/assets/ui/out/button-map-down.9.png
new file mode 100644
index 0000000000..8b1180b92b
Binary files /dev/null and b/core/assets/ui/out/button-map-down.9.png differ
diff --git a/core/assets/ui/out/button-map-over.9.png b/core/assets/ui/out/button-map-over.9.png
new file mode 100644
index 0000000000..be806bab8d
Binary files /dev/null and b/core/assets/ui/out/button-map-over.9.png differ
diff --git a/core/assets/ui/out/button-map.9.png b/core/assets/ui/out/button-map.9.png
new file mode 100644
index 0000000000..3af3ea0e10
Binary files /dev/null and b/core/assets/ui/out/button-map.9.png differ
diff --git a/core/assets/ui/out/vis-blue.png b/core/assets/ui/out/vis-blue.png
deleted file mode 100644
index c31c5175b0..0000000000
Binary files a/core/assets/ui/out/vis-blue.png and /dev/null differ
diff --git a/core/assets/ui/out/vis-check-down.png b/core/assets/ui/out/vis-check-down.png
deleted file mode 100644
index 71abb29dbd..0000000000
Binary files a/core/assets/ui/out/vis-check-down.png and /dev/null differ
diff --git a/core/assets/ui/out/vis-check-over.png b/core/assets/ui/out/vis-check-over.png
deleted file mode 100644
index dbc4767a63..0000000000
Binary files a/core/assets/ui/out/vis-check-over.png and /dev/null differ
diff --git a/core/assets/ui/out/vis-check-tick-disabled.png b/core/assets/ui/out/vis-check-tick-disabled.png
deleted file mode 100644
index 834d4cb602..0000000000
Binary files a/core/assets/ui/out/vis-check-tick-disabled.png and /dev/null differ
diff --git a/core/assets/ui/out/vis-check-tick.png b/core/assets/ui/out/vis-check-tick.png
deleted file mode 100644
index 0507b398e3..0000000000
Binary files a/core/assets/ui/out/vis-check-tick.png and /dev/null differ
diff --git a/core/assets/ui/out/vis-check.png b/core/assets/ui/out/vis-check.png
deleted file mode 100644
index fb891f7921..0000000000
Binary files a/core/assets/ui/out/vis-check.png and /dev/null differ
diff --git a/core/assets/ui/out/vis-radio-down.png b/core/assets/ui/out/vis-radio-down.png
deleted file mode 100644
index 68c658e568..0000000000
Binary files a/core/assets/ui/out/vis-radio-down.png and /dev/null differ
diff --git a/core/assets/ui/out/vis-radio-over.png b/core/assets/ui/out/vis-radio-over.png
deleted file mode 100644
index 8213edaa1d..0000000000
Binary files a/core/assets/ui/out/vis-radio-over.png and /dev/null differ
diff --git a/core/assets/ui/out/vis-radio-tick-disabled.png b/core/assets/ui/out/vis-radio-tick-disabled.png
deleted file mode 100644
index d158662473..0000000000
Binary files a/core/assets/ui/out/vis-radio-tick-disabled.png and /dev/null differ
diff --git a/core/assets/ui/out/vis-radio-tick.png b/core/assets/ui/out/vis-radio-tick.png
deleted file mode 100644
index de52864eb1..0000000000
Binary files a/core/assets/ui/out/vis-radio-tick.png and /dev/null differ
diff --git a/core/assets/ui/out/vis-radio.png b/core/assets/ui/out/vis-radio.png
deleted file mode 100644
index 6b418cf4ea..0000000000
Binary files a/core/assets/ui/out/vis-radio.png and /dev/null differ
diff --git a/core/assets/ui/out/vis-red.png b/core/assets/ui/out/vis-red.png
deleted file mode 100644
index 7ed23eef0a..0000000000
Binary files a/core/assets/ui/out/vis-red.png and /dev/null differ
diff --git a/core/assets/ui/uiskin.atlas b/core/assets/ui/uiskin.atlas
index a5776908e9..c88288f61f 100644
--- a/core/assets/ui/uiskin.atlas
+++ b/core/assets/ui/uiskin.atlas
@@ -6,14 +6,14 @@ filter: Nearest,Nearest
repeat: none
blank
rotate: false
- xy: 164, 2
+ xy: 898, 76
size: 8, 8
orig: 8, 8
offset: 0, 0
index: -1
border
rotate: false
- xy: 292, 42
+ xy: 134, 2
size: 12, 12
split: 4, 4, 4, 4
orig: 12, 12
@@ -21,21 +21,21 @@ border
index: -1
border-circle
rotate: false
- xy: 939, 98
+ xy: 498, 64
size: 28, 28
orig: 28, 28
offset: 0, 0
index: -1
border-circle-error
rotate: false
- xy: 969, 98
+ xy: 528, 64
size: 28, 28
orig: 28, 28
offset: 0, 0
index: -1
border-dark-blue
rotate: false
- xy: 133, 21
+ xy: 648, 87
size: 3, 3
split: 1, 1, 1, 1
orig: 3, 3
@@ -43,7 +43,7 @@ border-dark-blue
index: -1
border-error
rotate: false
- xy: 133, 16
+ xy: 241, 41
size: 3, 3
split: 1, 1, 1, 1
orig: 3, 3
@@ -51,7 +51,7 @@ border-error
index: -1
border-white
rotate: false
- xy: 118, 2
+ xy: 120, 2
size: 12, 12
split: 4, 4, 4, 4
orig: 12, 12
@@ -67,7 +67,7 @@ bump
index: -1
button
rotate: false
- xy: 913, 86
+ xy: 991, 86
size: 24, 40
split: 10, 10, 8, 8
orig: 24, 40
@@ -126,7 +126,15 @@ button-gray-over
orig: 24, 40
offset: 0, 0
index: -1
-button-over
+button-map
+ rotate: false
+ xy: 861, 86
+ size: 24, 40
+ split: 10, 10, 8, 8
+ orig: 24, 40
+ offset: 0, 0
+ index: -1
+button-map-down
rotate: false
xy: 809, 86
size: 24, 40
@@ -134,10 +142,26 @@ button-over
orig: 24, 40
offset: 0, 0
index: -1
-button-red
+button-map-over
rotate: false
xy: 835, 86
size: 24, 40
+ split: 10, 10, 8, 8
+ orig: 24, 40
+ offset: 0, 0
+ index: -1
+button-over
+ rotate: false
+ xy: 887, 86
+ size: 24, 40
+ split: 10, 10, 8, 8
+ orig: 24, 40
+ offset: 0, 0
+ index: -1
+button-red
+ rotate: false
+ xy: 913, 86
+ size: 24, 40
split: 10, 10, 10, 8
pad: 8, 8, 2, 2
orig: 24, 40
@@ -145,7 +169,7 @@ button-red
index: -1
button-select
rotate: false
- xy: 219, 28
+ xy: 138, 16
size: 24, 24
split: 4, 4, 4, 4
orig: 24, 24
@@ -153,7 +177,7 @@ button-select
index: -1
button-window-bg
rotate: false
- xy: 861, 86
+ xy: 939, 86
size: 24, 40
split: 10, 10, 10, 8
pad: 8, 8, 2, 2
@@ -162,7 +186,7 @@ button-window-bg
index: -1
button-window-over
rotate: false
- xy: 887, 86
+ xy: 965, 86
size: 24, 40
split: 10, 10, 10, 8
pad: 8, 8, 2, 2
@@ -192,35 +216,35 @@ check-over
index: -1
clear
rotate: false
- xy: 306, 44
+ xy: 634, 62
size: 10, 10
orig: 10, 10
offset: 0, 0
index: -1
color-picker-bar-selector
rotate: false
- xy: 999, 98
+ xy: 618, 60
size: 14, 28
orig: 14, 28
offset: 0, 0
index: -1
color-picker-cross
rotate: false
- xy: 318, 44
+ xy: 648, 74
size: 10, 10
orig: 10, 10
offset: 0, 0
index: -1
color-picker-selector-horizontal
rotate: false
- xy: 92, 5
+ xy: 335, 83
size: 6, 1
orig: 6, 1
offset: 0, 0
index: -1
color-picker-selector-vertical
rotate: false
- xy: 168, 34
+ xy: 1017, 86
size: 1, 6
orig: 1, 6
offset: 0, 0
@@ -234,14 +258,14 @@ cursor
index: -1
cursor-normal
rotate: false
- xy: 245, 21
+ xy: 646, 62
size: 10, 10
orig: 10, 10
offset: 0, 0
index: -1
default-pane
rotate: false
- xy: 266, 33
+ xy: 164, 37
size: 5, 3
split: 1, 1, 1, 1
orig: 5, 3
@@ -265,7 +289,7 @@ default-select
index: -1
default-select-selection
rotate: false
- xy: 171, 38
+ xy: 898, 71
size: 3, 3
split: 1, 1, 1, 1
orig: 3, 3
@@ -273,42 +297,42 @@ default-select-selection
index: -1
grey
rotate: false
- xy: 645, 71
+ xy: 340, 80
size: 1, 1
orig: 1, 1
offset: 0, 0
index: -1
menu-bg
rotate: false
- xy: 645, 71
+ xy: 340, 80
size: 1, 1
orig: 1, 1
offset: 0, 0
index: -1
icon-arrow-down
rotate: false
- xy: 257, 21
+ xy: 660, 74
size: 10, 10
orig: 10, 10
offset: 0, 0
index: -1
icon-arrow-left
rotate: false
- xy: 640, 59
+ xy: 658, 62
size: 10, 10
orig: 10, 10
offset: 0, 0
index: -1
icon-arrow-right
rotate: false
- xy: 330, 44
+ xy: 672, 74
size: 10, 10
orig: 10, 10
offset: 0, 0
index: -1
icon-arrow-up
rotate: false
- xy: 977, 78
+ xy: 670, 62
size: 10, 10
orig: 10, 10
offset: 0, 0
@@ -336,63 +360,63 @@ icon-close-over
index: -1
icon-copy
rotate: false
- xy: 989, 78
+ xy: 684, 74
size: 10, 10
orig: 10, 10
offset: 0, 0
index: -1
icon-cursor
rotate: false
- xy: 1001, 78
+ xy: 682, 62
size: 10, 10
orig: 10, 10
offset: 0, 0
index: -1
icon-defense
rotate: false
- xy: 640, 47
+ xy: 696, 74
size: 10, 10
orig: 10, 10
offset: 0, 0
index: -1
icon-distribution
rotate: false
- xy: 645, 74
+ xy: 694, 62
size: 10, 10
orig: 10, 10
offset: 0, 0
index: -1
icon-dots
rotate: false
- xy: 657, 74
+ xy: 708, 74
size: 10, 10
orig: 10, 10
offset: 0, 0
index: -1
icon-dots-down
rotate: false
- xy: 669, 74
+ xy: 706, 62
size: 10, 10
orig: 10, 10
offset: 0, 0
index: -1
icon-down
rotate: false
- xy: 681, 74
+ xy: 720, 74
size: 10, 10
orig: 10, 10
offset: 0, 0
index: -1
icon-drive
rotate: false
- xy: 939, 86
+ xy: 82, 4
size: 36, 10
orig: 36, 10
offset: 0, 0
index: -1
icon-eraser
rotate: false
- xy: 693, 74
+ xy: 718, 62
size: 10, 10
orig: 10, 10
offset: 0, 0
@@ -420,21 +444,21 @@ icon-file-pdf
index: -1
icon-file-text
rotate: false
- xy: 705, 74
+ xy: 732, 74
size: 10, 10
orig: 10, 10
offset: 0, 0
index: -1
icon-fill
rotate: false
- xy: 717, 74
+ xy: 730, 62
size: 10, 10
orig: 10, 10
offset: 0, 0
index: -1
icon-folder
rotate: false
- xy: 729, 74
+ xy: 744, 74
size: 10, 10
orig: 10, 10
offset: 0, 0
@@ -448,7 +472,7 @@ icon-folder-new
index: -1
icon-folder-parent
rotate: false
- xy: 741, 74
+ xy: 742, 62
size: 10, 10
orig: 10, 10
offset: 0, 0
@@ -462,14 +486,14 @@ icon-folder-star
index: -1
icon-grid
rotate: false
- xy: 753, 74
+ xy: 756, 74
size: 10, 10
orig: 10, 10
offset: 0, 0
index: -1
icon-home
rotate: false
- xy: 765, 74
+ xy: 754, 62
size: 10, 10
orig: 10, 10
offset: 0, 0
@@ -483,91 +507,91 @@ icon-list-settings
index: -1
icon-load-1
rotate: false
- xy: 777, 74
+ xy: 768, 74
size: 10, 10
orig: 10, 10
offset: 0, 0
index: -1
icon-load-2
rotate: false
- xy: 789, 74
+ xy: 766, 62
size: 10, 10
orig: 10, 10
offset: 0, 0
index: -1
icon-load-3
rotate: false
- xy: 801, 74
+ xy: 780, 74
size: 10, 10
orig: 10, 10
offset: 0, 0
index: -1
icon-lock
rotate: false
- xy: 813, 74
+ xy: 778, 62
size: 10, 10
orig: 10, 10
offset: 0, 0
index: -1
icon-lock-open
rotate: false
- xy: 825, 74
+ xy: 792, 74
size: 10, 10
orig: 10, 10
offset: 0, 0
index: -1
icon-minus
rotate: false
- xy: 837, 74
+ xy: 790, 62
size: 10, 10
orig: 10, 10
offset: 0, 0
index: -1
icon-open
rotate: false
- xy: 849, 74
+ xy: 804, 74
size: 10, 10
orig: 10, 10
offset: 0, 0
index: -1
icon-open-gray
rotate: false
- xy: 861, 74
+ xy: 802, 62
size: 10, 10
orig: 10, 10
offset: 0, 0
index: -1
icon-pencil
rotate: false
- xy: 873, 74
+ xy: 816, 74
size: 10, 10
orig: 10, 10
offset: 0, 0
index: -1
icon-pick
rotate: false
- xy: 885, 74
+ xy: 814, 62
size: 10, 10
orig: 10, 10
offset: 0, 0
index: -1
icon-plus
rotate: false
- xy: 897, 74
+ xy: 828, 74
size: 10, 10
orig: 10, 10
offset: 0, 0
index: -1
icon-production
rotate: false
- xy: 909, 74
+ xy: 826, 62
size: 10, 10
orig: 10, 10
offset: 0, 0
index: -1
icon-redo
rotate: false
- xy: 921, 74
+ xy: 840, 74
size: 10, 10
orig: 10, 10
offset: 0, 0
@@ -581,7 +605,7 @@ icon-refresh
index: -1
icon-rename
rotate: false
- xy: 933, 74
+ xy: 838, 62
size: 10, 10
orig: 10, 10
offset: 0, 0
@@ -602,56 +626,49 @@ icon-star-outline
index: -1
icon-tap
rotate: false
- xy: 945, 74
+ xy: 852, 74
size: 10, 10
orig: 10, 10
offset: 0, 0
index: -1
icon-trash
rotate: false
- xy: 957, 74
+ xy: 850, 62
size: 10, 10
orig: 10, 10
offset: 0, 0
index: -1
icon-undo
rotate: false
- xy: 652, 62
+ xy: 864, 74
size: 10, 10
orig: 10, 10
offset: 0, 0
index: -1
icon-up
rotate: false
- xy: 652, 50
+ xy: 862, 62
size: 10, 10
orig: 10, 10
offset: 0, 0
index: -1
icon-zoom
rotate: false
- xy: 664, 62
+ xy: 876, 74
size: 10, 10
orig: 10, 10
offset: 0, 0
index: -1
list-selection
rotate: false
- xy: 340, 83
- size: 1, 1
- orig: 1, 1
- offset: 0, 0
- index: -1
-vis-blue
- rotate: false
- xy: 340, 83
+ xy: 78, 2
size: 1, 1
orig: 1, 1
offset: 0, 0
index: -1
padded-list-selection
rotate: false
- xy: 58, 2
+ xy: 58, 5
size: 10, 1
split: 4, 4, 0, 1
orig: 10, 1
@@ -659,56 +676,49 @@ padded-list-selection
index: -1
progressbar
rotate: false
- xy: 618, 56
+ xy: 1017, 94
size: 1, 32
orig: 1, 32
offset: 0, 0
index: -1
progressbar-filled
rotate: false
- xy: 621, 56
+ xy: 1020, 94
size: 1, 32
orig: 1, 32
offset: 0, 0
index: -1
progressbar-filled-vertical
rotate: false
- xy: 171, 43
+ xy: 207, 43
size: 32, 1
orig: 32, 1
offset: 0, 0
index: -1
progressbar-vertical
rotate: false
- xy: 58, 5
+ xy: 207, 40
size: 32, 1
orig: 32, 1
offset: 0, 0
index: -1
radio-off
rotate: false
- xy: 498, 64
- size: 28, 28
- orig: 28, 28
- offset: 0, 0
- index: -1
-vis-radio
- rotate: false
- xy: 498, 64
+ xy: 558, 64
size: 28, 28
orig: 28, 28
offset: 0, 0
index: -1
radio-on
rotate: false
- xy: 528, 64
+ xy: 588, 60
size: 28, 28
orig: 28, 28
offset: 0, 0
index: -1
scroll
rotate: false
- xy: 977, 90
+ xy: 171, 38
size: 34, 6
split: 4, 4, 2, 2
orig: 34, 6
@@ -734,7 +744,7 @@ scroll-knob-horizontal
index: -1
scroll-knob-vertical
rotate: false
- xy: 82, 8
+ xy: 219, 46
size: 34, 6
split: 12, 12, 2, 2
orig: 34, 6
@@ -742,56 +752,56 @@ scroll-knob-vertical
index: -1
select-box-list-bg
rotate: false
- xy: 650, 89
+ xy: 340, 77
size: 1, 1
orig: 1, 1
offset: 0, 0
index: -1
window-bg
rotate: false
- xy: 650, 89
+ xy: 340, 77
size: 1, 1
orig: 1, 1
offset: 0, 0
index: -1
select-down
rotate: false
- xy: 132, 2
+ xy: 148, 6
size: 14, 8
orig: 14, 8
offset: 0, 0
index: -1
select-up
rotate: false
- xy: 148, 2
+ xy: 255, 44
size: 14, 8
orig: 14, 8
offset: 0, 0
index: -1
selection
rotate: false
- xy: 650, 86
+ xy: 588, 91
size: 1, 1
orig: 1, 1
offset: 0, 0
index: -1
separator
rotate: false
- xy: 974, 83
+ xy: 148, 3
size: 1, 1
orig: 1, 1
offset: 0, 0
index: -1
tree-over
rotate: false
- xy: 974, 83
+ xy: 148, 3
size: 1, 1
orig: 1, 1
offset: 0, 0
index: -1
separator-menu
rotate: false
- xy: 648, 71
+ xy: 271, 51
size: 1, 1
orig: 1, 1
offset: 0, 0
@@ -833,7 +843,7 @@ slider-knob-over
index: -1
slider-vertical
rotate: false
- xy: 70, 2
+ xy: 58, 2
size: 8, 1
orig: 8, 1
offset: 0, 0
@@ -848,21 +858,21 @@ slot
index: -1
splitpane
rotate: false
- xy: 80, 2
+ xy: 68, 2
size: 8, 1
orig: 8, 1
offset: 0, 0
index: -1
splitpane-over
rotate: false
- xy: 90, 2
+ xy: 70, 5
size: 8, 1
orig: 8, 1
offset: 0, 0
index: -1
splitpane-vertical
rotate: false
- xy: 1015, 118
+ xy: 133, 16
size: 1, 8
orig: 1, 8
offset: 0, 0
@@ -876,44 +886,30 @@ splitpane-vertical-over
index: -1
sub-menu
rotate: false
- xy: 266, 38
+ xy: 888, 70
size: 8, 14
orig: 8, 14
offset: 0, 0
index: -1
textfield
rotate: false
- xy: 588, 60
+ xy: 305, 56
size: 28, 28
split: 6, 6, 6, 6
orig: 28, 28
offset: 0, 0
index: -1
-vis-check
- rotate: false
- xy: 588, 60
- size: 28, 28
- orig: 28, 28
- offset: 0, 0
- index: -1
textfield-over
rotate: false
- xy: 558, 64
+ xy: 275, 56
size: 28, 28
split: 2, 2, 2, 2
orig: 28, 28
offset: 0, 0
index: -1
-vis-check-over
- rotate: false
- xy: 558, 64
- size: 28, 28
- orig: 28, 28
- offset: 0, 0
- index: -1
tooltip-bg
rotate: false
- xy: 335, 81
+ xy: 908, 81
size: 3, 3
split: 1, 1, 1, 1
orig: 3, 3
@@ -928,85 +924,29 @@ touchpad-knob
index: -1
tree-minus
rotate: false
- xy: 664, 50
+ xy: 874, 62
size: 10, 10
orig: 10, 10
offset: 0, 0
index: -1
tree-plus
rotate: false
- xy: 205, 28
+ xy: 634, 74
size: 12, 16
orig: 12, 16
offset: 0, 0
index: -1
tree-selection
rotate: false
- xy: 645, 87
+ xy: 164, 32
size: 3, 3
split: 1, 1, 1, 1
orig: 3, 3
offset: 0, 0
index: -1
-vis-check-down
- rotate: false
- xy: 275, 56
- size: 28, 28
- orig: 28, 28
- offset: 0, 0
- index: -1
-vis-check-tick
- rotate: false
- xy: 245, 33
- size: 19, 19
- orig: 19, 19
- offset: 0, 0
- index: -1
-vis-check-tick-disabled
- rotate: false
- xy: 624, 71
- size: 19, 19
- orig: 19, 19
- offset: 0, 0
- index: -1
-vis-radio-down
- rotate: false
- xy: 305, 56
- size: 28, 28
- orig: 28, 28
- offset: 0, 0
- index: -1
-vis-radio-over
- rotate: false
- xy: 138, 12
- size: 28, 28
- orig: 28, 28
- offset: 0, 0
- index: -1
-vis-radio-tick
- rotate: false
- xy: 624, 55
- size: 14, 14
- orig: 14, 14
- offset: 0, 0
- index: -1
-vis-radio-tick-disabled
- rotate: false
- xy: 276, 40
- size: 14, 14
- orig: 14, 14
- offset: 0, 0
- index: -1
-vis-red
- rotate: false
- xy: 340, 80
- size: 1, 1
- orig: 1, 1
- offset: 0, 0
- index: -1
white
rotate: false
- xy: 969, 81
+ xy: 335, 78
size: 3, 3
orig: 3, 3
offset: 0, 0
@@ -1021,7 +961,7 @@ window
index: -1
window-border-bg
rotate: false
- xy: 676, 69
+ xy: 246, 41
size: 3, 3
split: 1, 1, 1, 1
orig: 3, 3
diff --git a/core/assets/ui/uiskin.json b/core/assets/ui/uiskin.json
index 1bd0487445..44a8adcd37 100644
--- a/core/assets/ui/uiskin.json
+++ b/core/assets/ui/uiskin.json
@@ -36,6 +36,7 @@ io.anuke.ucore.scene.ui.ImageButton$ImageButtonStyle: {
default: {down: button-down, up: button },
blue: {down: button-blue-down, up: button-blue },
toggle: {checked: button-down, down: button-down, up: button },
+ togglemap: {checked: button-map-down, down: button-map-down, up: button-map },
select: {checked: button-select, up: clear },
gray: {down: button-down, up: button-gray, over: button-gray-over, disabled: button},
close-window: {up: button, imageUp: icon-close, imageOver: icon-close-over, imageDown: icon-close-down, disabled: button }
diff --git a/core/assets/ui/uiskin.png b/core/assets/ui/uiskin.png
index 4b3f7798ab..21611d8d06 100644
Binary files a/core/assets/ui/uiskin.png and b/core/assets/ui/uiskin.png differ
diff --git a/core/lib/ucore.jar b/core/lib/ucore.jar
deleted file mode 100644
index ca49b4c0d6..0000000000
Binary files a/core/lib/ucore.jar and /dev/null differ
diff --git a/core/src/Moment.gwt.xml b/core/src/Mindustry.gwt.xml
similarity index 85%
rename from core/src/Moment.gwt.xml
rename to core/src/Mindustry.gwt.xml
index bf796234bc..d9e0d528c1 100644
--- a/core/src/Moment.gwt.xml
+++ b/core/src/Mindustry.gwt.xml
@@ -1,5 +1,5 @@
-
+
\ No newline at end of file
diff --git a/core/src/io/anuke/mindustry/Control.java b/core/src/io/anuke/mindustry/Control.java
index 0ddd37f34f..719555b177 100644
--- a/core/src/io/anuke/mindustry/Control.java
+++ b/core/src/io/anuke/mindustry/Control.java
@@ -1,425 +1,134 @@
package io.anuke.mindustry;
-import static io.anuke.mindustry.world.TileType.tilesize;
+import static io.anuke.mindustry.Vars.*;
-import com.badlogic.gdx.Application.ApplicationType;
import com.badlogic.gdx.Gdx;
-import com.badlogic.gdx.Input.Buttons;
import com.badlogic.gdx.Input.Keys;
-import com.badlogic.gdx.graphics.Color;
-import com.badlogic.gdx.graphics.GL20;
-import com.badlogic.gdx.math.MathUtils;
-import com.badlogic.gdx.math.Rectangle;
-import com.badlogic.gdx.math.Vector2;
-import io.anuke.mindustry.ai.Pathfind;
-import io.anuke.mindustry.entities.TileEntity;
-import io.anuke.mindustry.resource.ItemStack;
-import io.anuke.mindustry.world.Tile;
-import io.anuke.mindustry.world.TileType;
+import io.anuke.gif.GifRecorder;
+import io.anuke.mindustry.entities.Player;
+import io.anuke.mindustry.world.Generator;
+import io.anuke.mindustry.world.blocks.ProductionBlocks;
import io.anuke.ucore.core.*;
-import io.anuke.ucore.entities.*;
+import io.anuke.ucore.entities.Entities;
import io.anuke.ucore.graphics.Atlas;
-import io.anuke.ucore.graphics.Hue;
import io.anuke.ucore.modules.RendererModule;
-import io.anuke.ucore.scene.style.Styles;
-import io.anuke.ucore.scene.utils.Cursors;
-import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Timers;
-public class Control extends RendererModule{
- //GifRecorder recorder = new GifRecorder(batch);
- int rangex = 10, rangey = 10;
- float breaktime = 0;
- float breakdur = 50;
-
- public Control() {
- atlas = new Atlas("moment.atlas");
+public class Control extends RendererModule{
+ public int rangex = 10, rangey = 10;
+ GifRecorder recoder = new GifRecorder(batch);
+
+ public Control(){
cameraScale = 4f;
setPixelation();
buffers.add("shadow", (int) (Gdx.graphics.getWidth() / cameraScale), (int) (Gdx.graphics.getHeight() / cameraScale));
+ atlas = new Atlas("mindustry.atlas");
+
Sounds.load("shoot.wav", "place.wav", "explosion.wav", "enemyshoot.wav", "corexplode.wav", "break.wav", "spawn.wav", "flame.wav");
Musics.load("1.mp3", "2.mp3", "3.mp3");
-
+
+ Generator.loadMaps();
+
+ KeyBinds.defaults(
+ "up", Keys.W,
+ "left", Keys.A,
+ "down", Keys.S,
+ "right", Keys.D,
+ "rotate", Keys.R,
+ "menu", Keys.ESCAPE
+ );
+
+ Settings.loadAll("io.anuke.moment");
+
+ Sounds.setFalloff(9000f);
+
+ player = new Player();
}
-
+
@Override
public void init(){
Musics.shuffleAll();
- DrawContext.font = Styles.styles.font();
-
- Entities.initPhysics(0, 0, main.pixsize, main.pixsize);
-
- Effect.create("place", 16, e -> {
- Draw.thickness(3f - e.ifract() * 2f);
- Draw.square(e.x, e.y, TileType.tilesize / 2 + e.ifract() * 3f);
- Draw.clear();
- });
-
- Effect.create("spark", 10, e -> {
- Draw.thickness(1f);
- Draw.color(Hue.mix(Color.WHITE, Color.GRAY, e.ifract()));
- Draw.spikes(e.x, e.y, e.ifract() * 5f, 2, 8);
- Draw.clear();
- });
- Effect.create("smelt", 10, e -> {
- Draw.thickness(1f);
- Draw.color(Hue.mix(Color.YELLOW, Color.RED, e.ifract()));
- Draw.spikes(e.x, e.y, e.ifract() * 5f, 2, 8);
- Draw.clear();
- });
-
- Effect.create("break", 12, e -> {
- Draw.thickness(2f);
- Draw.color(Color.WHITE, Color.GRAY, e.ifract());
- Draw.spikes(e.x, e.y, e.ifract() * 5f, 2, 5);
- Draw.clear();
- });
-
- Effect.create("hit", 10, e -> {
- Draw.thickness(1f);
- Draw.color(Hue.mix(Color.WHITE, Color.ORANGE, e.ifract()));
- Draw.spikes(e.x, e.y, e.ifract() * 3f, 2, 8);
- Draw.clear();
- });
-
- Effect.create("explosion", 15, e -> {
- Draw.thickness(2f);
- Draw.color(Hue.mix(Color.ORANGE, Color.GRAY, e.ifract()));
- Draw.spikes(e.x, e.y, 2f + e.ifract() * 3f, 4, 6);
- Draw.circle(e.x, e.y, 3f + e.ifract() * 3f);
- Draw.clear();
- });
+ Entities.initPhysics(0, 0, pixsize, pixsize);
- Effect.create("coreexplosion", 13, e -> {
- Draw.thickness(3f-e.ifract()*2f);
- Draw.color(Hue.mix(Color.ORANGE, Color.WHITE, e.ifract()));
- Draw.spikes(e.x, e.y, 5f + e.ifract() * 40f, 6, 6);
- Draw.circle(e.x, e.y, 4f + e.ifract() * 40f);
- Draw.clear();
- });
-
- Effect.create("spawn", 23, e -> {
- Draw.thickness(2f);
- Draw.color(Hue.mix(Color.DARK_GRAY, Color.SCARLET, e.ifract()));
- Draw.circle(e.x, e.y, 7f - e.ifract() * 6f);
- Draw.clear();
+ Entities.setCollider(tilesize, (x, y)->{
+ return World.solid(x, y);
});
- Effect.create("ind", 100, e -> {
- Draw.thickness(3f);
- Draw.color("royal");
- Draw.circle(e.x, e.y, 3);
- Draw.clear();
- });
-
- Effect.create("respawn", main.respawntime, e -> {
- Draw.tcolor(Color.SCARLET);
- Draw.tscl(0.25f);
- Draw.text("Respawning in " + (int)((e.lifetime-e.time)/60), e.x, e.y);
- Draw.tscl(0.5f);
- Draw.clear();
- });
-
- Pathfind.updatePath();
+ EffectLoader.create();
}
-
- public void tryMove(SolidEntity e, float x, float y){
- e.getBoundingBox(Rectangle.tmp);
- Rectangle.tmp.setSize(4);
-
- if(!overlaps(Rectangle.tmp, e.x + x, e.y)){
- e.x += x;
- }
-
- if(!overlaps(Rectangle.tmp, e.x, e.y + y)){
- e.y += y;
- }
- }
-
- boolean overlaps(Rectangle rect, float x, float y){
- int r = 1;
- rect.setCenter(x, y);
- int tilex = Mathf.scl2(x, tilesize);
- int tiley = Mathf.scl2(y, tilesize);
-
- for(int dx = -r; dx <= r; dx++){
- for(int dy = -r; dy <= r; dy++){
- Tile tile = main.tile(tilex + dx, tiley + dy);
- if(tile != null && tile.block().solid && Rectangle.tmp2.setSize(tilesize).setCenter(tile.worldx(), tile.worldy()).overlaps(rect)){
- return true;
- }
- }
- }
- return false;
- }
-
- Rectangle getRect(int x, int y){
- return Rectangle.tmp2.setSize(tilesize).setCenter(x * tilesize, y * tilesize);
- }
-
- void input(){
-
- if(Inputs.keyUp("rotate"))
- main.rotation++;
-
- main.rotation %= 4;
-
- if(main.recipe != null && !main.hasItems(main.recipe.requirements)){
- main.recipe = null;
- Cursors.restoreCursor();
- }
-
- if(Inputs.buttonUp(Buttons.LEFT) && main.recipe != null && validPlace(tilex(), tiley(), main.recipe.result) && !get(UI.class).hasMouse()){
- Tile tile = main.tile(tilex(), tiley());
- if(tile == null)
- return; //just in ase
-
- tile.setBlock(main.recipe.result);
- tile.rotation = main.rotation;
-
- Pathfind.updatePath();
-
- Effects.effect("place", roundx(), roundy());
- Effects.shake(2f, 2f);
- Sounds.play("place");
-
- for(ItemStack stack : main.recipe.requirements){
- main.removeItem(stack);
- }
-
- if(!main.hasItems(main.recipe.requirements)){
- main.recipe = null;
- Cursors.restoreCursor();
- }
- }
-
- if(main.recipe != null && Inputs.buttonUp(Buttons.RIGHT)){
- main.recipe = null;
- Cursors.restoreCursor();
- }
-
- //block breaking
- if(Inputs.buttonDown(Buttons.RIGHT) && cursorNear() && main.tile(tilex(), tiley()).artifical()
- && main.tile(tilex(), tiley()).block() != TileType.core){
- Tile tile = main.tile(tilex(), tiley());
- breaktime += delta();
- if(breaktime >= breakdur){
- Effects.effect("break", tile.entity);
- Effects.shake(3f, 1f);
- tile.setBlock(TileType.air);
- Pathfind.updatePath();
- breaktime = 0f;
- Sounds.play("break");
- }
- }else{
- breaktime = 0f;
- }
-
- }
-
- float roundx(){
- return Mathf.round2(Graphics.mouseWorld().x, TileType.tilesize);
- }
-
- float roundy(){
- return Mathf.round2(Graphics.mouseWorld().y, TileType.tilesize);
- }
-
- int tilex(){
- return Mathf.scl2(Graphics.mouseWorld().x, TileType.tilesize);
- }
-
- int tiley(){
- return Mathf.scl2(Graphics.mouseWorld().y, TileType.tilesize);
- }
-
- boolean validPlace(int x, int y, TileType type){
-
- if(!cursorNear())
- return false;
-
- for(Tile spawn : main.spawnpoints){
- if(Vector2.dst(x * tilesize, y * tilesize, spawn.worldx(), spawn.worldy()) < main.spawnspace){
- return false;
- }
- }
-
- for(SolidEntity e : Entities.getNearby(x * tilesize, y * tilesize, tilesize * 2f)){
- Rectangle.tmp.setSize(e.hitsize);
- Rectangle.tmp.setCenter(e.x, e.y);
-
- if(getRect(x, y).overlaps(Rectangle.tmp)){
- return false;
- }
- }
- return main.tile(x, y).block() == TileType.air;
- }
-
- boolean cursorNear(){
- return Vector2.dst(main.player.x, main.player.y, tilex() * tilesize, tiley() * tilesize) <= main.placerange;
- }
-
+
@Override
public void update(){
- if(Gdx.input.isKeyJustPressed(Keys.ESCAPE) && Gdx.app.getType() == ApplicationType.Desktop)
+ if(Inputs.keyUp(Keys.ESCAPE) && debug)
Gdx.app.exit();
- if(!main.playing){
+ if(Inputs.keyUp(Keys.SPACE) && debug)
+ Effects.sound("shoot", core.worldx(), core.worldy());
+
+ if(!playing){
clearScreen();
- return;
+ }else{
+
+ if(Inputs.keyUp("menu")){
+ if(paused){
+ ui.hideMenu();
+ paused = false;
+ }else{
+ ui.showMenu();
+ paused = true;
+ }
+ }
+
+ if(!paused){
+
+ if(enemies <= 0)
+ wavetime -= delta();
+
+ if(wavetime <= 0){
+ GameState.runWave();
+ }
+
+ Entities.update();
+
+ Input.doInput();
+ }
+
+
+
+ if(core.block() == ProductionBlocks.core)
+ camera.position.set(player.x, player.y, 0f);
+ else
+ camera.position.set(core.worldx(), core.worldy(), 0f);
+
+ updateShake();
+ clampCamera(-tilesize / 2f, -tilesize / 2f, pixsize - tilesize / 2f, pixsize - tilesize / 2f);
+
+ drawDefault();
+
+ batch.setProjectionMatrix(control.camera.combined);
+ batch.begin();
+ Renderer.renderOverlay();
+ batch.end();
+
+ recoder.update();
}
- if(!main.paused)
- Entities.update();
-
- input();
-
- if(main.core.block() == TileType.core)
- camera.position.set(main.player.x, main.player.y, 0f);
- else
- camera.position.set(main.core.worldx(), main.core.worldy(), 0f);
-
- clampCamera(-tilesize / 2f, -tilesize / 2f, main.pixsize - tilesize / 2f, main.pixsize - tilesize / 2f);
-
- drawDefault();
-
- //recorder.update();
+ if(!paused){
+ Inputs.update();
+ Timers.update(Gdx.graphics.getDeltaTime()*60f);
+ }
}
-
+
@Override
public void draw(){
- Draw.clear();
-
- for(int l = 0; l < 4; l++){
- if(l == 1){
- batch.end();
- buffers.end("pixel");
-
- buffers.begin("shadow");
-
- batch.begin();
- Gdx.gl.glClearColor(0, 0, 0, 0);
- Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
- }
- for(int x = -rangex; x <= rangex; x++){
- for(int y = -rangey; y <= rangey; y++){
- int worldx = Mathf.scl(camera.position.x, tilesize) + x;
- int worldy = Mathf.scl(camera.position.y, tilesize) + y;
-
- if(Mathf.inBounds(worldx, worldy, main.tiles)){
- Tile tile = main.tiles[worldx][worldy];
- if(l == 1){
- if(tile.block() != TileType.air)
- Draw.rect("shadow", worldx * tilesize, worldy * tilesize);
- }else if(l == 0 || l == 2){
- (l == 0 ? tile.floor() : tile.block()).draw(tile);
- }else{
- tile.block().drawOver(tile);
- }
- }
- }
- }
-
- if(l == 1){
- batch.end();
- buffers.end("shadow");
- batch.setColor(0, 0, 0, 0.15f);
-
- buffers.begin("pixel");
-
- drawFull("shadow");
- batch.setColor(Color.WHITE);
- batch.setProjectionMatrix(camera.combined);
-
- batch.begin();
- }
- }
-
+ Renderer.renderTiles();
Entities.draw();
-
- if(main.recipe != null && !get(UI.class).hasMouse()){
- float x = Mathf.round2(Graphics.mouseWorld().x, tilesize);
- float y = Mathf.round2(Graphics.mouseWorld().y, tilesize);
-
- boolean valid = validPlace(tilex(), tiley(), main.recipe.result);
-
- Draw.color(valid ? Color.PURPLE : Color.SCARLET);
- Draw.thickness(2f);
- Draw.square(x, y, TileType.tilesize / 2 + MathUtils.sin(Timers.time() / 6f) + 1);
-
- if(main.recipe.result.rotate){
- Draw.color("orange");
- vector.set(7, 0).rotate(main.rotation * 90);
- Draw.line(x, y, x + vector.x, y + vector.y);
- }
-
- Draw.thickness(1f);
- Draw.color("scarlet");
- for(Tile spawn : main.spawnpoints){
- Draw.dashcircle(spawn.worldx(), spawn.worldy(), main.spawnspace);
- }
-
- if(valid)
- Cursors.setHand();
- else
- Cursors.restoreCursor();
-
- Draw.clear();
- }
-
- //block breaking
- if(Inputs.buttonDown(Buttons.RIGHT) && cursorNear()){
- Tile tile = main.tile(tilex(), tiley());
- if(tile.artifical() && tile.block() != TileType.core){
- Draw.color(Color.YELLOW, Color.SCARLET, breaktime / breakdur);
- Draw.square(tile.worldx(), tile.worldy(), 4);
- Draw.clear();
- }
- }
-
- if(main.recipe == null && !get(UI.class).hasMouse()){
- Tile tile = main.tiles[tilex()][tiley()];
-
- if(tile.block() != TileType.air){
- if(tile.block().name().contains("turret")){
- Draw.color("green");
- Draw.dashcircle(tile.worldx(), tile.worldy(), tile.block().range);
- Draw.clear();
- }
- if(tile.entity != null)
- drawHealth(tile.entity.x, tile.entity.y, tile.entity.health, tile.entity.maxhealth);
- }
- }
-
- for(Entity entity : Entities.all()){
- if(entity instanceof DestructibleEntity && !(entity instanceof TileEntity)){
- DestructibleEntity dest = ((DestructibleEntity) entity);
-
- drawHealth(dest.x, dest.y, dest.health, dest.maxhealth);
- }
- }
-
- //Draw.text(Gdx.graphics.getFramesPerSecond() + " FPS", main.player.x, main.player.y);
+ Renderer.renderPixelOverlay();
}
-
- void drawHealth(float x, float y, float health, float maxhealth){
- float len = 3;
- float offset = 7;
-
- Draw.thickness(3f);
- Draw.color(Color.GRAY);
- Draw.line(x - len + 1, y - offset, x + len + 1, y - offset);
- Draw.thickness(1f);
- Draw.color(Color.BLACK);
- Draw.line(x - len + 1, y - offset, x + len, y - offset);
- Draw.color(Color.RED);
- Draw.line(x - len + 1, y - offset, x - len + (int)(len * 2 * ((float) health / maxhealth)), y - offset);
- Draw.clear();
- }
-
+
@Override
public void resize(int width, int height){
super.resize(width, height);
diff --git a/core/src/io/anuke/mindustry/EffectLoader.java b/core/src/io/anuke/mindustry/EffectLoader.java
new file mode 100644
index 0000000000..35a7acdb17
--- /dev/null
+++ b/core/src/io/anuke/mindustry/EffectLoader.java
@@ -0,0 +1,87 @@
+package io.anuke.mindustry;
+
+import static io.anuke.mindustry.Vars.*;
+
+import com.badlogic.gdx.graphics.Color;
+
+import io.anuke.ucore.core.Draw;
+import io.anuke.ucore.entities.Effect;
+import io.anuke.ucore.graphics.Hue;
+
+public class EffectLoader{
+
+ public static void create(){
+
+ Effect.create("place", 16, e -> {
+ Draw.thickness(3f - e.ifract() * 2f);
+ Draw.square(e.x, e.y, tilesize / 2f + e.ifract() * 3f);
+ Draw.clear();
+ });
+
+ Effect.create("spark", 10, e -> {
+ Draw.thickness(1f);
+ Draw.color(Hue.mix(Color.WHITE, Color.GRAY, e.ifract()));
+ Draw.spikes(e.x, e.y, e.ifract() * 5f, 2, 8);
+ Draw.clear();
+ });
+
+ Effect.create("smelt", 10, e -> {
+ Draw.thickness(1f);
+ Draw.color(Hue.mix(Color.YELLOW, Color.RED, e.ifract()));
+ Draw.spikes(e.x, e.y, e.ifract() * 5f, 2, 8);
+ Draw.clear();
+ });
+
+ Effect.create("break", 12, e -> {
+ Draw.thickness(2f);
+ Draw.color(Color.WHITE, Color.GRAY, e.ifract());
+ Draw.spikes(e.x, e.y, e.ifract() * 5f, 2, 5);
+ Draw.clear();
+ });
+
+ Effect.create("hit", 10, e -> {
+ Draw.thickness(1f);
+ Draw.color(Hue.mix(Color.WHITE, Color.ORANGE, e.ifract()));
+ Draw.spikes(e.x, e.y, e.ifract() * 3f, 2, 8);
+ Draw.clear();
+ });
+
+ Effect.create("explosion", 15, e -> {
+ Draw.thickness(2f);
+ Draw.color(Hue.mix(Color.ORANGE, Color.GRAY, e.ifract()));
+ Draw.spikes(e.x, e.y, 2f + e.ifract() * 3f, 4, 6);
+ Draw.circle(e.x, e.y, 3f + e.ifract() * 3f);
+ Draw.clear();
+ });
+
+ Effect.create("coreexplosion", 13, e -> {
+ Draw.thickness(3f-e.ifract()*2f);
+ Draw.color(Hue.mix(Color.ORANGE, Color.WHITE, e.ifract()));
+ Draw.spikes(e.x, e.y, 5f + e.ifract() * 40f, 6, 6);
+ Draw.circle(e.x, e.y, 4f + e.ifract() * 40f);
+ Draw.clear();
+ });
+
+ Effect.create("spawn", 23, e -> {
+ Draw.thickness(2f);
+ Draw.color(Hue.mix(Color.DARK_GRAY, Color.SCARLET, e.ifract()));
+ Draw.circle(e.x, e.y, 7f - e.ifract() * 6f);
+ Draw.clear();
+ });
+
+ Effect.create("ind", 100, e -> {
+ Draw.thickness(3f);
+ Draw.color("royal");
+ Draw.circle(e.x, e.y, 3);
+ Draw.clear();
+ });
+
+ Effect.create("respawn", respawntime, e -> {
+ Draw.tcolor(Color.SCARLET);
+ Draw.tscl(0.25f);
+ Draw.text("Respawning in " + (int)((e.lifetime-e.time)/60), e.x, e.y);
+ Draw.tscl(0.5f);
+ Draw.clear();
+ });
+ }
+}
diff --git a/core/src/io/anuke/mindustry/GameState.java b/core/src/io/anuke/mindustry/GameState.java
new file mode 100644
index 0000000000..94ff7b532c
--- /dev/null
+++ b/core/src/io/anuke/mindustry/GameState.java
@@ -0,0 +1,106 @@
+package io.anuke.mindustry;
+
+import static io.anuke.mindustry.Vars.*;
+
+import io.anuke.mindustry.entities.*;
+import io.anuke.mindustry.world.Tile;
+import io.anuke.ucore.core.Effects;
+import io.anuke.ucore.core.Settings;
+import io.anuke.ucore.core.Sounds;
+import io.anuke.ucore.entities.Entities;
+import io.anuke.ucore.util.Mathf;
+import io.anuke.ucore.util.Timers;
+
+public class GameState{
+
+ public static void reset(){
+ wave = 1;
+ wavetime = waveSpacing();
+ Entities.clear();
+ enemies = 0;
+ player.add();
+ player.heal();
+ Inventory.clearItems();
+ spawnpoints.clear();
+
+ ui.updateItems();
+ }
+
+ public static void play(){
+ player.x = core.worldx();
+ player.y = core.worldy()-8;
+
+ wavetime = waveSpacing();
+
+ if(showedTutorial || !Settings.getBool("tutorial")){
+ playing = true;
+ paused = false;
+ }else{
+ playing = true;
+ paused = true;
+ ui.showTutorial();
+ showedTutorial = true;
+ }
+ }
+
+ public static void runWave(){
+ int amount = wave;
+ Sounds.play("spawn");
+
+ for(int i = 0; i < amount; i ++){
+ int pos = i;
+
+ for(int w = 0; w < spawnpoints.size; w ++){
+ int point = w;
+ Tile tile = spawnpoints.get(w);
+
+ Timers.run(i*30f, ()->{
+
+ Enemy enemy = null;
+
+ if(wave%5 == 0 /*&& point == 1 */&& pos == 0){
+ enemy = new BossEnemy(point);
+ }else if(wave > 3 && pos < amount/2){
+ enemy = new FastEnemy(point);
+ }else if(wave > 8 && pos % 3 == 0 && wave%2==1){
+ enemy = new FlameEnemy(point);
+ }else{
+ enemy = new Enemy(point);
+ }
+
+ enemy.set(tile.worldx(), tile.worldy());
+ Effects.effect("spawn", enemy);
+ enemy.add();
+ });
+
+ enemies ++;
+ }
+ }
+
+ wave ++;
+
+ wavetime = waveSpacing();
+ }
+
+ public static void coreDestroyed(){
+ Effects.shake(5, 6);
+ Sounds.play("corexplode");
+ for(int i = 0; i < 16; i ++){
+ Timers.run(i*2, ()->{
+ Effects.effect("explosion", core.worldx()+Mathf.range(40), core.worldy()+Mathf.range(40));
+ });
+
+ }
+ Effects.effect("coreexplosion", core.worldx(), core.worldy());
+
+ Timers.run(60, ()->{
+ ui.showRestart();
+ });
+ }
+
+ public static float waveSpacing(){
+ int scale = Settings.getInt("difficulty");
+ float out = (scale == 0 ? 2f : scale == 1f ? 1f : 0.5f);
+ return wavespace*out;
+ }
+}
diff --git a/core/src/io/anuke/mindustry/Input.java b/core/src/io/anuke/mindustry/Input.java
new file mode 100644
index 0000000000..7328a6349a
--- /dev/null
+++ b/core/src/io/anuke/mindustry/Input.java
@@ -0,0 +1,87 @@
+package io.anuke.mindustry;
+
+import static io.anuke.mindustry.Vars.*;
+
+import com.badlogic.gdx.Input.Buttons;
+
+import io.anuke.mindustry.ai.Pathfind;
+import io.anuke.mindustry.resource.ItemStack;
+import io.anuke.mindustry.world.Tile;
+import io.anuke.mindustry.world.blocks.Blocks;
+import io.anuke.mindustry.world.blocks.ProductionBlocks;
+import io.anuke.ucore.core.Effects;
+import io.anuke.ucore.core.Inputs;
+import io.anuke.ucore.core.Sounds;
+import io.anuke.ucore.scene.utils.Cursors;
+import io.anuke.ucore.util.Mathf;
+
+public class Input{
+
+ public static void doInput(){
+
+ //player is dead
+ if(player.health <= 0) return;
+
+ if(Inputs.keyUp("rotate"))
+ rotation++;
+
+ rotation %= 4;
+
+ if(recipe != null && !Inventory.hasItems(recipe.requirements)){
+ recipe = null;
+ Cursors.restoreCursor();
+ }
+
+
+ if(Inputs.buttonUp(Buttons.LEFT) && recipe != null &&
+ World.validPlace(World.tilex(), World.tiley(), recipe.result) && !ui.hasMouse()){
+ Tile tile = World.tile(World.tilex(), World.tiley());
+
+ if(tile == null)
+ return; //just in case
+
+ tile.setBlock(recipe.result);
+ tile.rotation = rotation;
+
+ Pathfind.updatePath();
+
+ Effects.effect("place", World.roundx(), World.roundy());
+ Effects.shake(2f, 2f);
+ Sounds.play("place");
+
+ for(ItemStack stack : recipe.requirements){
+ Inventory.removeItem(stack);
+ }
+
+ if(!Inventory.hasItems(recipe.requirements)){
+ recipe = null;
+ Cursors.restoreCursor();
+ }
+ }
+
+ if(recipe != null && Inputs.buttonUp(Buttons.RIGHT)){
+ recipe = null;
+ Cursors.restoreCursor();
+ }
+
+ Tile cursor = World.cursorTile();
+
+ //block breaking
+ if(Inputs.buttonDown(Buttons.RIGHT) && World.cursorNear() && cursor.artifical()
+ && cursor.block() != ProductionBlocks.core){
+ Tile tile = cursor;
+ breaktime += Mathf.delta();
+ if(breaktime >= breakduration){
+ Effects.effect("break", tile.entity);
+ Effects.shake(3f, 1f);
+ tile.setBlock(Blocks.air);
+ Pathfind.updatePath();
+ breaktime = 0f;
+ Sounds.play("break");
+ }
+ }else{
+ breaktime = 0f;
+ }
+
+ }
+}
diff --git a/core/src/io/anuke/mindustry/Inventory.java b/core/src/io/anuke/mindustry/Inventory.java
new file mode 100644
index 0000000000..c009d55a61
--- /dev/null
+++ b/core/src/io/anuke/mindustry/Inventory.java
@@ -0,0 +1,42 @@
+package io.anuke.mindustry;
+
+import static io.anuke.mindustry.Vars.*;
+
+import io.anuke.mindustry.resource.Item;
+import io.anuke.mindustry.resource.ItemStack;
+
+public class Inventory{
+
+ public static void clearItems(){
+ items.clear();
+ //TODO make this not hardcoded
+ items.put(Item.stone, 40);
+
+ if(debug){
+ items.put(Item.stone, 2000);
+ items.put(Item.iron, 2000);
+ items.put(Item.steel, 2000);
+ }
+ }
+
+ public static void addItem(Item item, int amount){
+ items.put(item, items.get(item, 0)+amount);
+ ui.updateItems();
+ }
+
+ public static boolean hasItems(ItemStack[] items){
+ for(ItemStack stack : items)
+ if(!hasItem(stack))
+ return false;
+ return true;
+ }
+
+ public static boolean hasItem(ItemStack req){
+ return items.get(req.item, 0) >= req.amount;
+ }
+
+ public static void removeItem(ItemStack req){
+ items.put(req.item, items.get(req.item, 0)-req.amount);
+ ui.updateItems();
+ }
+}
diff --git a/core/src/io/anuke/mindustry/Mindustry.java b/core/src/io/anuke/mindustry/Mindustry.java
new file mode 100644
index 0000000000..0ef84bef71
--- /dev/null
+++ b/core/src/io/anuke/mindustry/Mindustry.java
@@ -0,0 +1,17 @@
+package io.anuke.mindustry;
+
+import io.anuke.ucore.modules.Core;
+
+public class Mindustry extends Core {
+
+ @Override
+ public void init(){
+ add(Vars.control = new Control());
+ add(Vars.ui = new UI());
+ }
+
+ @Override
+ public void postInit(){
+ GameState.reset();
+ }
+}
diff --git a/core/src/io/anuke/mindustry/Moment.java b/core/src/io/anuke/mindustry/Moment.java
deleted file mode 100644
index 85e5a2ef5c..0000000000
--- a/core/src/io/anuke/mindustry/Moment.java
+++ /dev/null
@@ -1,252 +0,0 @@
-package io.anuke.mindustry;
-
-import com.badlogic.gdx.Input.Keys;
-import com.badlogic.gdx.utils.Array;
-import com.badlogic.gdx.utils.ObjectMap;
-
-import io.anuke.mindustry.ai.Pathfind;
-import io.anuke.mindustry.entities.*;
-import io.anuke.mindustry.resource.Item;
-import io.anuke.mindustry.resource.ItemStack;
-import io.anuke.mindustry.resource.Recipe;
-import io.anuke.mindustry.world.Generator;
-import io.anuke.mindustry.world.Tile;
-import io.anuke.mindustry.world.TileType;
-import io.anuke.ucore.core.*;
-import io.anuke.ucore.entities.Entities;
-import io.anuke.ucore.modules.ModuleController;
-import io.anuke.ucore.util.Mathf;
-import io.anuke.ucore.util.Timers;
-
-public class Moment extends ModuleController{
- public static Moment i;
- public Player player;
- public int size = 128;
- public int pixsize = size*TileType.tilesize;
- public Tile[][] tiles = new Tile[size][size];
- public ObjectMap- items = new ObjectMap<>();
- public Recipe recipe;
- public int rotation;
- public float placerange = 60;
- public float respawntime = 60*5;
-
- public int wave = 1;
- public float wavespace = 35*60;
- public float wavetime;
- public float spawnspace = 65;
- public Tile core;
- public Array spawnpoints = new Array();
-
- public boolean playing = false;
- public boolean paused = false;
- public boolean showedTutorial = false;
-
- @Override
- public void init(){
- i = this;
-
- addModule(new Control());
- addModule(new UI());
- }
-
- @Override
- public void preInit(){
- KeyBinds.defaults(
- "up", Keys.W,
- "left", Keys.A,
- "down", Keys.S,
- "right", Keys.D,
- "rotate", Keys.R,
- "menu", Keys.ESCAPE
- );
-
- Settings.loadAll("io.anuke.moment");
-
- for(int x = 0; x < size; x ++){
- for(int y = 0; y < size; y ++){
- tiles[x][y] = new Tile(x, y, TileType.grass);
- }
- }
-
- player = new Player();
-
- }
-
- @Override
- public void postInit(){
- restart();
- }
-
- @Override
- public void update(){
- if(!paused)
- super.update();
-
- if(!playing || paused) return;
-
- //if(UInput.keyUp(Keys.Q))
- // System.out.println("Enemies: " + Enemy.amount + " Wavetime: " + wavetime + " Wave: " + wave + " Wavespace: " + wavespace);
-
- //System.out.println(Enemy.amount);
- if(Enemy.amount <= 0)
- wavetime -= delta();
-
- if(wavetime <= 0/* || UInput.keyUp(Keys.Q)*/){
- runWave();
- }
- }
-
- public void play(){
- wavetime = waveSpacing();
-
- if(showedTutorial){
- playing = true;
- paused = false;
- }else{
- playing = true;
- paused = true;
- get(UI.class).tutorial.show(get(UI.class).scene);
- showedTutorial = true;
- }
- }
-
- public void restart(){
- wave = 1;
- wavetime = waveSpacing();
- Entities.clear();
- Enemy.amount = 0;
- player.add();
- player.heal();
- items.clear();
- generate();
-
- player.x = core.worldx();
- player.y = core.worldy()-8;
-
- items.put(Item.stone, 20);
-
- //items.put(Item.stone, 2000);
- //items.put(Item.iron, 2000);
- //items.put(Item.steel, 2000);
-
- if(get(UI.class).about != null)
- get(UI.class).updateItems();
- }
-
- public void coreDestroyed(){
- Effects.shake(5, 6);
- Sounds.play("corexplode");
- for(int i = 0; i < 16; i ++){
- Timers.run(i*2, ()->{
- Effects.effect("explosion", core.worldx()+Mathf.range(40), core.worldy()+Mathf.range(40));
- });
-
- }
- Effects.effect("coreexplosion", core.worldx(), core.worldy());
-
- Timers.run(60, ()->{
- getModule(UI.class).showRestart();
- });
- }
-
- void generate(){
- spawnpoints.clear();
- Pathfind.reset();
- Generator.generate(tiles, "map");
- Pathfind.updatePath();
- core.setBlock(TileType.core);
- int x = core.x, y = core.y;
-
- set(x, y-1, TileType.conveyor, 1);
- set(x, y-2, TileType.conveyor, 1);
- set(x, y-3, TileType.conveyor, 1);
- set(x, y-4, TileType.stonedrill, 0);
- //just in case
- tiles[x][y-4].setFloor(TileType.stone);
-
-
- tiles[x+2][y-2].setFloor(TileType.stone);
- set(x+2, y-2, TileType.stonedrill, 0);
- set(x+2, y-1, TileType.conveyor, 1);
- set(x+2, y, TileType.turret, 0);
-
- tiles[x-2][y-2].setFloor(TileType.stone);
- set(x-2, y-2, TileType.stonedrill, 0);
- set(x-2, y-1, TileType.conveyor, 1);
- set(x-2, y, TileType.turret, 0);
- }
-
- void set(int x, int y, TileType type, int rot){
- tiles[x][y].setBlock(type);
- tiles[x][y].rotation = rot;
- }
-
- public void runWave(){
- int amount = wave;
- Sounds.play("spawn");
-
- for(int i = 0; i < amount; i ++){
- int pos = i;
-
- for(int w = 0; w < spawnpoints.size; w ++){
- int point = w;
- Tile tile = spawnpoints.get(w);
-
- Timers.run(i*30f, ()->{
-
- Enemy enemy = null;
-
- if(wave%5 == 0 /*&& point == 1 */&& pos == 0){
- enemy = new BossEnemy(point);
- }else if(wave > 3 && pos < amount/2){
- enemy = new FastEnemy(point);
- }else if(wave > 8 && pos % 3 == 0 && wave%2==1){
- enemy = new FlameEnemy(point);
- }else{
- enemy = new Enemy(point);
- }
-
- enemy.set(tile.worldx(), tile.worldy());
- Effects.effect("spawn", enemy);
- enemy.add();
- });
- }
- }
-
- wave ++;
-
- wavetime = waveSpacing();
- }
-
- public float waveSpacing(){
- int scale = Settings.getInt("difficulty");
- float out = (scale == 0 ? 2f : scale == 1f ? 1f : 0.5f);
- return wavespace*out;
- }
-
- public Tile tile(int x, int y){
- if(!Mathf.inBounds(x, y, tiles)) return null;
- return tiles[x][y];
- }
-
- public void addItem(Item item, int amount){
- items.put(item, items.get(item, 0)+amount);
- get(UI.class).updateItems();
- }
-
- public boolean hasItems(ItemStack[] items){
- for(ItemStack stack : items)
- if(!hasItem(stack))
- return false;
- return true;
- }
-
- public boolean hasItem(ItemStack req){
- return items.get(req.item, 0) >= req.amount;
- }
-
- public void removeItem(ItemStack req){
- items.put(req.item, items.get(req.item, 0)-req.amount);
- get(UI.class).updateItems();
- }
-}
diff --git a/core/src/io/anuke/mindustry/Renderer.java b/core/src/io/anuke/mindustry/Renderer.java
new file mode 100644
index 0000000000..2d73f9b5e8
--- /dev/null
+++ b/core/src/io/anuke/mindustry/Renderer.java
@@ -0,0 +1,172 @@
+package io.anuke.mindustry;
+
+import static io.anuke.mindustry.Vars.*;
+
+import com.badlogic.gdx.Gdx;
+import com.badlogic.gdx.Input.Buttons;
+import com.badlogic.gdx.graphics.Color;
+import com.badlogic.gdx.graphics.GL20;
+import com.badlogic.gdx.graphics.OrthographicCamera;
+import com.badlogic.gdx.graphics.g2d.Batch;
+import com.badlogic.gdx.math.MathUtils;
+
+import io.anuke.mindustry.entities.TileEntity;
+import io.anuke.mindustry.world.Tile;
+import io.anuke.mindustry.world.blocks.Blocks;
+import io.anuke.mindustry.world.blocks.ProductionBlocks;
+import io.anuke.ucore.core.Draw;
+import io.anuke.ucore.core.Graphics;
+import io.anuke.ucore.core.Inputs;
+import io.anuke.ucore.entities.DestructibleEntity;
+import io.anuke.ucore.entities.Entities;
+import io.anuke.ucore.entities.Entity;
+import io.anuke.ucore.graphics.FrameBufferMap;
+import io.anuke.ucore.scene.utils.Cursors;
+import io.anuke.ucore.util.Mathf;
+import io.anuke.ucore.util.Timers;
+
+public class Renderer{
+
+ public static void renderTiles(){
+ Draw.clear();
+ Batch batch = control.batch;
+ FrameBufferMap buffers = control.buffers;
+ OrthographicCamera camera = control.camera;
+ int rangex = control.rangex, rangey = control.rangey;
+
+ for(int l = 0; l < 4; l++){
+ if(l == 1){
+ batch.end();
+ buffers.end("pixel");
+
+ buffers.begin("shadow");
+
+ batch.begin();
+ Gdx.gl.glClearColor(0, 0, 0, 0);
+ Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
+ }
+
+ for(int x = -rangex; x <= rangex; x++){
+ for(int y = -rangey; y <= rangey; y++){
+ int worldx = Mathf.scl(camera.position.x, tilesize) + x;
+ int worldy = Mathf.scl(camera.position.y, tilesize) + y;
+
+ if(Mathf.inBounds(worldx, worldy, tiles)){
+ Tile tile = tiles[worldx][worldy];
+ if(l == 1){
+ if(tile.block() != Blocks.air)
+ Draw.rect("shadow", worldx * tilesize, worldy * tilesize);
+ }else if(l == 0 || l == 2){
+ (l == 0 ? tile.floor() : tile.block()).draw(tile);
+ }else{
+ tile.block().drawOver(tile);
+ }
+ }
+ }
+ }
+
+ if(l == 1){
+ batch.end();
+ buffers.end("shadow");
+ batch.setColor(0, 0, 0, 0.15f);
+
+ buffers.begin("pixel");
+
+ control.drawFull("shadow");
+ batch.setColor(Color.WHITE);
+ batch.setProjectionMatrix(camera.combined);
+
+ batch.begin();
+ }
+ }
+ }
+
+ public static void renderPixelOverlay(){
+
+ if(recipe != null && !ui.hasMouse()){
+ float x = Mathf.round2(Graphics.mouseWorld().x, tilesize);
+ float y = Mathf.round2(Graphics.mouseWorld().y, tilesize);
+
+ boolean valid = World.validPlace(World.tilex(), World.tiley(), recipe.result);
+
+ Draw.color(valid ? Color.PURPLE : Color.SCARLET);
+ Draw.thickness(2f);
+ Draw.square(x, y, tilesize / 2 + MathUtils.sin(Timers.time() / 6f) + 1);
+
+ if(recipe.result.rotate){
+ Draw.color("orange");
+ vector.set(7, 0).rotate(rotation * 90);
+ Draw.line(x, y, x + vector.x, y + vector.y);
+ }
+
+ Draw.thickness(1f);
+ Draw.color("scarlet");
+ for(Tile spawn : spawnpoints){
+ Draw.dashcircle(spawn.worldx(), spawn.worldy(), enemyspawnspace);
+ }
+
+ if(valid)
+ Cursors.setHand();
+ else
+ Cursors.restoreCursor();
+
+ Draw.clear();
+ }
+
+ //block breaking
+ if(Inputs.buttonDown(Buttons.RIGHT) && World.cursorNear()){
+ Tile tile = World.cursorTile();
+ if(tile.artifical() && tile.block() != ProductionBlocks.core){
+ Draw.color(Color.YELLOW, Color.SCARLET, breaktime / breakduration);
+ Draw.square(tile.worldx(), tile.worldy(), 4);
+ Draw.clear();
+ }
+ }
+
+ if(recipe == null && !ui.hasMouse()){
+ Tile tile = World.cursorTile();
+
+ if(tile.block() != Blocks.air){
+ if(tile.entity != null)
+ drawHealth(tile.entity.x, tile.entity.y, tile.entity.health, tile.entity.maxhealth);
+
+ tile.block().drawPixelOverlay(tile);
+ }
+ }
+
+ for(Entity entity : Entities.all()){
+ if(entity instanceof DestructibleEntity && !(entity instanceof TileEntity)){
+ DestructibleEntity dest = ((DestructibleEntity) entity);
+
+ drawHealth(dest.x, dest.y, dest.health, dest.maxhealth);
+ }
+ }
+ }
+
+ public static void renderOverlay(){
+
+ Tile tile = World.cursorTile();
+
+ if(tile != null && tile.block() != Blocks.air){
+ tile.block().drawOverlay(tile);
+ }
+
+ }
+
+ public static void drawHealth(float x, float y, float health, float maxhealth){
+ float len = 3;
+ float offset = 7;
+
+ float fraction = Mathf.clamp((float) health / maxhealth);
+
+ Draw.thickness(3f);
+ Draw.color(Color.GRAY);
+ Draw.line(x - len + 1, y - offset, x + len + 1, y - offset);
+ Draw.thickness(1f);
+ Draw.color(Color.BLACK);
+ Draw.line(x - len + 1, y - offset, x + len, y - offset);
+ Draw.color(Color.RED);
+ Draw.line(x - len + 1, y - offset, x - len + (int)(len * 2 * fraction), y - offset);
+ Draw.clear();
+ }
+}
diff --git a/core/src/io/anuke/mindustry/UI.java b/core/src/io/anuke/mindustry/UI.java
index 6f0ac21f4e..fae3604a19 100644
--- a/core/src/io/anuke/mindustry/UI.java
+++ b/core/src/io/anuke/mindustry/UI.java
@@ -1,6 +1,6 @@
package io.anuke.mindustry;
-import static io.anuke.mindustry.world.TileType.tilesize;
+import static io.anuke.mindustry.Vars.*;
import java.util.function.BooleanSupplier;
@@ -9,13 +9,12 @@ import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.Texture.TextureWrap;
import com.badlogic.gdx.graphics.g2d.Batch;
+import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.utils.Array;
-import io.anuke.mindustry.entities.Enemy;
import io.anuke.mindustry.resource.*;
-import io.anuke.mindustry.world.Tile;
-import io.anuke.mindustry.world.TileType;
-import io.anuke.ucore.core.*;
+import io.anuke.ucore.core.Draw;
+import io.anuke.ucore.core.Settings;
import io.anuke.ucore.modules.SceneModule;
import io.anuke.ucore.scene.Scene;
import io.anuke.ucore.scene.builders.*;
@@ -23,22 +22,22 @@ import io.anuke.ucore.scene.style.Styles;
import io.anuke.ucore.scene.ui.*;
import io.anuke.ucore.scene.ui.layout.Stack;
import io.anuke.ucore.scene.ui.layout.Table;
-import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Timers;
-public class UI extends SceneModule{
+public class UI extends SceneModule{
Table itemtable;
SettingsDialog prefs;
KeybindDialog keys;
- Dialog about, menu, restart, tutorial;
+ Dialog about, menu, restart, tutorial, levels;
Texture conveyor = new Texture("sprites/conveyor.png"), conveyort = new Texture("sprites/conveyort.png");
+ int selectedMap = 0;
BooleanSupplier play = () -> {
- return main.playing;
+ return playing;
};
BooleanSupplier nplay = () -> {
- return !main.playing;
+ return !playing;
};
public UI() {
@@ -58,6 +57,8 @@ public class UI extends SceneModule{
int w = gwidth();
int h = gheight();
+ Draw.color("gray");
+
batch.draw(conveyor, 0, 0, (int)Timers.time(), 0, w, h);
int tw = w/64+1;//, th = h/64+1;
@@ -66,8 +67,9 @@ public class UI extends SceneModule{
batch.draw(conveyort, x*64, 0, 0, (int)Timers.time(), 32, h);
}
- Draw.tscl(1.5f);
+ Draw.color();
+ Draw.tscl(1.5f);
Draw.text("[DARK_GRAY]-( Mindustry )-", w/2, h-16);
Draw.text("[#f1de60]-( Mindustry )-", w/2, h-10);
@@ -78,39 +80,7 @@ public class UI extends SceneModule{
@Override
public void update(){
- if(main.playing){
- scene.getBatch().setProjectionMatrix(get(Control.class).camera.combined);
- scene.getBatch().begin();
- Tile tile = main.tiles[tilex()][tiley()];
- if(tile.block() != TileType.air){
- String error = tile.block().error(tile);
- if(error != null){
- Draw.tcolor(Color.SCARLET);
- Draw.tscl(1 / 8f);
- Draw.text(error, tile.worldx(), tile.worldy() + tilesize);
-
- }else if(tile.block().ammo != null){
- Draw.tscl(1 / 8f);
- Draw.tcolor(Color.GREEN);
- Draw.text("Ammo: " + tile.entity.shots, tile.worldx(), tile.worldy() - tilesize);
- }
-
- Draw.tscl(0.5f);
- Draw.clear();
- }
- scene.getBatch().end();
-
- if(Inputs.keyUp("menu")){
- if(menu.getScene() != null){
- menu.hide();
- main.paused = false;
- }else{
- main.paused = true;
- menu.show(scene);
- }
- }
-
- }else{
+ if(!playing){
scene.getBatch().getProjectionMatrix().setToOrtho2D(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
scene.getBatch().begin();
@@ -124,18 +94,43 @@ public class UI extends SceneModule{
@Override
public void init(){
-
- prefs = new SettingsDialog();
-
- prefs.sliderPref("screenshake", "Screen Shake", 4, 0, 12, i -> {
- return (i / 4f) + "x";
+ ButtonGroup mapgroup = new ButtonGroup<>();
+
+ levels = new Dialog("Level Select");
+ levels.addCloseButton();
+ levels.getButtonTable().addButton("Play", ()->{
+ levels.hide();
+ World.loadMap(selectedMap);
+ GameState.play();
});
+ for(int i = 0; i < maps.length; i ++){
+ levels.content().add(maps[i]);
+ }
+
+ levels.content().row();
+
+ for(int i = 0; i < maps.length; i ++){
+ int index = i;
+ ImageButton image = new ImageButton(new TextureRegion(mapTextures[i]), "togglemap");
+ mapgroup.add(image);
+ image.clicked(()->{
+ selectedMap = index;
+ });
+ image.getImageCell().size(150, 150);
+ levels.content().add(image).size(180);
+ }
+
+ prefs = new SettingsDialog();
+
prefs.sliderPref("difficulty", "Difficulty", 1, 0, 2, i -> {
return i == 0 ? "Easy" : i == 1 ? "Normal" : "Hard";
});
+ prefs.screenshakePref();
+ prefs.volumePrefs();
+ prefs.checkPref("tutorial", "Show tutorial Window", true);
prefs.checkPref("fps", "Show FPS", false);
keys = new KeybindDialog();
@@ -153,10 +148,11 @@ public class UI extends SceneModule{
@Override
public void hide(){
super.hide();
- main.playing = true;
- main.paused = false;
+ playing = true;
+ paused = false;
}
};
+
tutorial.addCloseButton();
tutorial.getButtonTable().addButton("OK", ()->{
tutorial.hide();
@@ -176,11 +172,16 @@ public class UI extends SceneModule{
tutorial.content().pad(8);
+ tutorial.content().row();
+ tutorial.content().addCheck("Don't show again", b->{
+ Settings.putBool("tutorial", !b);
+ }).padTop(4);
+
restart = new Dialog("The core was destroyed.", "dialog"){
public Dialog show(Scene scene){
super.show(scene);
restart.content().clearChildren();
- restart.content().add("You lasted until wave [GREEN]" + main.wave + "[].").pad(6);
+ restart.content().add("You lasted until wave [GREEN]" + wave + "[].").pad(6);
restart.pack();
return this;
}
@@ -188,14 +189,24 @@ public class UI extends SceneModule{
restart.getButtonTable().addButton("Back to menu", ()->{
restart.hide();
- main.playing = false;
- main.restart();
+ playing = false;
+ GameState.reset();
});
menu = new Dialog("Paused", "dialog");
menu.content().addButton("Back", ()->{
menu.hide();
- main.paused = false;
+ paused = false;
+ }).width(200);
+
+ menu.content().row();
+ menu.content().addButton("Settings", ()->{
+ prefs.show();
+ }).width(200);
+
+ menu.content().row();
+ menu.content().addButton("Controls", ()->{
+ keys.show();
}).width(200);
menu.content().row();
@@ -210,8 +221,8 @@ public class UI extends SceneModule{
protected void result(Object object){
if(object == Boolean.TRUE){
menu.hide();
- main.paused = false;
- main.playing = false;
+ paused = false;
+ playing = false;
}
}
}.show(scene);
@@ -260,8 +271,8 @@ public class UI extends SceneModule{
ImageButton image = new ImageButton(Draw.region(r.result.name()), "select");
image.clicked(()->{
- if(main.hasItems(r.requirements))
- main.recipe = r;
+ if(Inventory.hasItems(r.requirements))
+ recipe = r;
});
table.add(image).size(size+8).pad(4);
@@ -269,9 +280,9 @@ public class UI extends SceneModule{
image.update(()->{
- boolean has = main.hasItems(r.requirements);
+ boolean has = Inventory.hasItems(r.requirements);
image.setDisabled(!has);
- image.setChecked(main.recipe == r && has);
+ image.setChecked(recipe == r && has);
//image.setTouchable(has ? Touchable.enabled : Touchable.disabled);
image.getImage().setColor(has ? Color.WHITE : Color.GRAY);
});
@@ -287,10 +298,6 @@ public class UI extends SceneModule{
tiptable.clearChildren();
String description = r.result.description();
- if(r.result.ammo != null){
- description += "\n[SALMON]Ammo: " + r.result.ammo.name();
- }
-
tiptable.background("button");
tiptable.add("[PURPLE]" + r.result.name(), 0.75f).left().padBottom(2f);
@@ -298,7 +305,7 @@ public class UI extends SceneModule{
ItemStack[] req = r.requirements;
for(ItemStack s : req){
tiptable.row();
- int amount = Math.min(main.items.get(s.item, 0), s.amount);
+ int amount = Math.min(items.get(s.item, 0), s.amount);
tiptable.add(
(amount >= s.amount ? "[YELLOW]" : "[RED]")
+s.item + ": " + amount + " / " +s.amount, 0.5f).left();
@@ -378,7 +385,7 @@ public class UI extends SceneModule{
new label("Wave 1"){{
get().setFontScale(1f);
get().update(() -> {
- get().setText("[YELLOW]Wave " + Moment.i.wave);
+ get().setText("[YELLOW]Wave " + wave);
});
}}.left();
@@ -386,7 +393,8 @@ public class UI extends SceneModule{
new label("Time"){{
get().update(() -> {
- get().setText(Enemy.amount > 0 ? Enemy.amount + " Enemies remaining" : "New wave in " + (int) (main.wavetime / 60f));
+ get().setText(enemies > 0 ?
+ enemies + " Enemies remaining" : "New wave in " + (int) (wavetime / 60f));
});
}}.minWidth(150);
@@ -401,18 +409,17 @@ public class UI extends SceneModule{
new table(){{
aleft();
abottom();
- Control c = main.get(Control.class);
new button("+", ()->{
- if(c.cameraScale < 4f){
- c.cameraScale = 4f;
- c.resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
+ if(control.cameraScale < 4f){
+ control.cameraScale = 4f;
+ control.resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
}
}).size(40);
new button("-", ()->{
- if(c.cameraScale > 3f){
- c.cameraScale = 3f;
- c.resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
+ if(control.cameraScale > 3f){
+ control.cameraScale = 3f;
+ control.resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
}
}).size(40);
@@ -424,7 +431,7 @@ public class UI extends SceneModule{
float w = 200;
new button("Play", () -> {
- main.play();
+ levels.show();
}).width(w);
row();
@@ -453,36 +460,33 @@ public class UI extends SceneModule{
build.end();
}
+ public void showMenu(){
+ menu.show();
+ }
+
+ public void hideMenu(){
+ menu.hide();
+ }
+
+ public void showTutorial(){
+ tutorial.show();
+ }
+
public void showRestart(){
- restart.show(scene);
+ restart.show();
}
public void updateItems(){
itemtable.clear();
- for(Item stack : main.items.keys()){
+ for(Item stack : items.keys()){
Image image = new Image(Draw.region("icon-" + stack.name()));
- Label label = new Label("" + main.items.get(stack));
+ Label label = new Label("" + items.get(stack));
label.setFontScale(1f);
itemtable.add(image).size(32);
itemtable.add(label);
itemtable.row();
}
}
-
- float roundx(){
- return Mathf.round2(Graphics.mouseWorld().x, TileType.tilesize);
- }
-
- float roundy(){
- return Mathf.round2(Graphics.mouseWorld().y, TileType.tilesize);
- }
-
- int tilex(){
- return Mathf.scl2(Graphics.mouseWorld().x, TileType.tilesize);
- }
-
- int tiley(){
- return Mathf.scl2(Graphics.mouseWorld().y, TileType.tilesize);
- }
+
}
diff --git a/core/src/io/anuke/mindustry/Vars.java b/core/src/io/anuke/mindustry/Vars.java
new file mode 100644
index 0000000000..aea398704d
--- /dev/null
+++ b/core/src/io/anuke/mindustry/Vars.java
@@ -0,0 +1,55 @@
+package io.anuke.mindustry;
+
+import com.badlogic.gdx.graphics.Pixmap;
+import com.badlogic.gdx.graphics.Texture;
+import com.badlogic.gdx.math.Vector2;
+import com.badlogic.gdx.utils.Array;
+import com.badlogic.gdx.utils.ObjectMap;
+
+import io.anuke.mindustry.entities.Player;
+import io.anuke.mindustry.resource.Item;
+import io.anuke.mindustry.resource.Recipe;
+import io.anuke.mindustry.world.Tile;
+
+/**ick, global state*/
+public class Vars{
+ public static final float placerange = 66;
+ public static final float respawntime = 60*4;
+ public static final float wavespace = 20*60;
+ public static final float enemyspawnspace = 65;
+ public static final float breakduration = 40;
+ public static boolean debug = true;
+
+ public static final Vector2 vector = new Vector2();
+
+ public static final int tilesize = 8;
+
+ public static Control control;
+ public static UI ui;
+
+ public static final ObjectMap
- items = new ObjectMap<>();
+
+ public static Player player;
+
+ public static float breaktime = 0;
+
+ public static final String[] maps = {"delta", "canyon", "pit"};
+ public static Pixmap[] mapPixmaps;
+ public static Texture[] mapTextures;
+ public static int worldsize = 128;
+ public static int pixsize = worldsize*tilesize;
+ public static Tile[][] tiles = new Tile[worldsize][worldsize];
+ public static Recipe recipe;
+ public static int rotation;
+
+ public static int wave = 1;
+ public static float wavetime;
+ public static int enemies = 0;
+
+ public static Tile core;
+ public static Array spawnpoints = new Array();
+
+ public static boolean playing = false;
+ public static boolean paused = false;
+ public static boolean showedTutorial = false;
+}
diff --git a/core/src/io/anuke/mindustry/World.java b/core/src/io/anuke/mindustry/World.java
new file mode 100644
index 0000000000..efe9626ace
--- /dev/null
+++ b/core/src/io/anuke/mindustry/World.java
@@ -0,0 +1,170 @@
+package io.anuke.mindustry;
+
+import static io.anuke.mindustry.Vars.*;
+
+import com.badlogic.gdx.math.Rectangle;
+import com.badlogic.gdx.math.Vector2;
+
+import io.anuke.mindustry.ai.Pathfind;
+import io.anuke.mindustry.entities.TileEntity;
+import io.anuke.mindustry.world.Block;
+import io.anuke.mindustry.world.Generator;
+import io.anuke.mindustry.world.Tile;
+import io.anuke.mindustry.world.blocks.Blocks;
+import io.anuke.mindustry.world.blocks.ProductionBlocks;
+import io.anuke.mindustry.world.blocks.WeaponBlocks;
+import io.anuke.ucore.core.Graphics;
+import io.anuke.ucore.entities.Entities;
+import io.anuke.ucore.entities.Entity;
+import io.anuke.ucore.entities.SolidEntity;
+import io.anuke.ucore.util.Mathf;
+
+public class World{
+ private static Tile[] temptiles = new Tile[4];
+
+ public static boolean solid(int x, int y){
+ Tile tile = tile(x, y);
+
+ return tile == null || tile.block().solid;
+ }
+
+ public static Tile tile(int x, int y){
+ if(!Mathf.inBounds(x, y, tiles)) return null;
+ return tiles[x][y];
+ }
+
+ public static Tile cursorTile(){
+ return tile(tilex(), tiley());
+ }
+
+ public static Tile[] getNearby(int x, int y){
+ temptiles[0] = tile(x+1, y);
+ temptiles[1] = tile(x, y+1);
+ temptiles[2] = tile(x-1, y);
+ temptiles[3] = tile(x, y-1);
+ return temptiles;
+ }
+
+ public static void loadMap(int id){
+ spawnpoints.clear();
+
+ int size = mapPixmaps[id].getWidth();
+ worldsize = size;
+ pixsize = worldsize*tilesize;
+ tiles = new Tile[worldsize][worldsize];
+
+ for(int x = 0; x < worldsize; x ++){
+ for(int y = 0; y < worldsize; y ++){
+ tiles[x][y] = new Tile(x, y, Blocks.stone);
+ }
+ }
+
+ Generator.generate(id);
+
+ Pathfind.reset();
+
+ core.setBlock(ProductionBlocks.core);
+ int x = core.x, y = core.y;
+
+ set(x, y-1, ProductionBlocks.conveyor, 1);
+ set(x, y-2, ProductionBlocks.conveyor, 1);
+ set(x, y-3, ProductionBlocks.conveyor, 1);
+ set(x, y-4, ProductionBlocks.stonedrill, 0);
+ //just in case
+ tiles[x][y-4].setFloor(Blocks.stone);
+
+
+ tiles[x+2][y-2].setFloor(Blocks.stone);
+ set(x+2, y-2, ProductionBlocks.stonedrill, 0);
+ set(x+2, y-1, ProductionBlocks.conveyor, 1);
+ set(x+2, y, WeaponBlocks.turret, 0);
+
+ tiles[x-2][y-2].setFloor(Blocks.stone);
+ set(x-2, y-2, ProductionBlocks.stonedrill, 0);
+ set(x-2, y-1, ProductionBlocks.conveyor, 1);
+ set(x-2, y, WeaponBlocks.turret, 0);
+
+ Pathfind.updatePath();
+ }
+
+ static void set(int x, int y, Block type, int rot){
+ tiles[x][y].setBlock(type);
+ tiles[x][y].rotation = rot;
+ }
+
+ public static boolean validPlace(int x, int y, Block type){
+
+ if(!cursorNear())
+ return false;
+
+ for(Tile spawn : spawnpoints){
+ if(Vector2.dst(x * tilesize, y * tilesize, spawn.worldx(), spawn.worldy()) < enemyspawnspace){
+ return false;
+ }
+ }
+
+ for(SolidEntity e : Entities.getNearby(x * tilesize, y * tilesize, tilesize * 2f)){
+ Rectangle.tmp.setSize(e.hitsize);
+ Rectangle.tmp.setCenter(e.x, e.y);
+
+ if(getCollider(x, y).overlaps(Rectangle.tmp)){
+ return false;
+ }
+ }
+ return tile(x, y).block() == Blocks.air;
+ }
+
+ public static boolean cursorNear(){
+ return Vector2.dst(player.x, player.y, tilex() * tilesize, tiley() * tilesize) <= placerange;
+ }
+
+ public static Rectangle getCollider(int x, int y){
+ return Rectangle.tmp2.setSize(tilesize).setCenter(x * tilesize, y * tilesize);
+ }
+
+ public static TileEntity findTileTarget(float x, float y, Tile tile, float range, boolean damaged){
+ Entity closest = null;
+ float dst = 0;
+
+ int rad = (int)(range/tilesize)+1;
+ int tilex = Mathf.scl2(x, tilesize);
+ int tiley = Mathf.scl2(y, tilesize);
+
+ for(int rx = -rad; rx <= rad; rx ++){
+ for(int ry = -rad; ry <= rad; ry ++){
+ Tile other = tile(rx+tilex, ry+tiley);
+
+ if(other == null || other.entity == null ||(tile != null && other.entity == tile.entity)) continue;
+
+ TileEntity e = other.entity;
+
+ if(damaged && ((TileEntity) e).health >= ((TileEntity) e).tile.block().health)
+ continue;
+
+ float ndst = Vector2.dst(x, y, e.x, e.y);
+ if(ndst < range && (closest == null || ndst < dst)){
+ dst = ndst;
+ closest = e;
+ }
+ }
+ }
+
+ return (TileEntity) closest;
+ }
+
+ public static float roundx(){
+ return Mathf.round2(Graphics.mouseWorld().x, tilesize);
+ }
+
+ public static float roundy(){
+ return Mathf.round2(Graphics.mouseWorld().y, tilesize);
+ }
+
+ public static int tilex(){
+ return Mathf.scl2(Graphics.mouseWorld().x, tilesize);
+ }
+
+ public static int tiley(){
+ return Mathf.scl2(Graphics.mouseWorld().y, tilesize);
+ }
+}
diff --git a/core/src/io/anuke/mindustry/ai/MHueristic.java b/core/src/io/anuke/mindustry/ai/MHueristic.java
index edce7d57c3..793789d90e 100644
--- a/core/src/io/anuke/mindustry/ai/MHueristic.java
+++ b/core/src/io/anuke/mindustry/ai/MHueristic.java
@@ -2,8 +2,8 @@ package io.anuke.mindustry.ai;
import com.badlogic.gdx.ai.pfa.Heuristic;
+import io.anuke.mindustry.Vars;
import io.anuke.mindustry.world.Tile;
-import io.anuke.mindustry.world.TileType;
public class MHueristic implements Heuristic{
//so this means that the cost of going through solids is 10x going through non solids
@@ -14,8 +14,8 @@ public class MHueristic implements Heuristic{
float cost = Math.abs(node.worldx() - other.worldx()) + Math.abs(node.worldy() - other.worldy());
//TODO balance multiplier
- if(node.artifical() && node.block().solid) cost += TileType.tilesize*multiplier;
- if(other.artifical() && other.block().solid) cost += TileType.tilesize*multiplier;
+ if(node.artifical() && node.block().solid) cost += Vars.tilesize*multiplier;
+ if(other.artifical() && other.block().solid) cost += Vars.tilesize*multiplier;
return cost;
}
diff --git a/core/src/io/anuke/mindustry/ai/PassTileGraph.java b/core/src/io/anuke/mindustry/ai/PassTileGraph.java
index 8ba368d1d0..61a998b840 100644
--- a/core/src/io/anuke/mindustry/ai/PassTileGraph.java
+++ b/core/src/io/anuke/mindustry/ai/PassTileGraph.java
@@ -1,12 +1,12 @@
package io.anuke.mindustry.ai;
+import static io.anuke.mindustry.Vars.worldsize;
+
import com.badlogic.gdx.ai.pfa.Connection;
import com.badlogic.gdx.ai.pfa.indexed.IndexedGraph;
import com.badlogic.gdx.utils.Array;
-import io.anuke.mindustry.Moment;
import io.anuke.mindustry.world.Tile;
-
/**Tilegraph that ignores player-made tiles.*/
public class PassTileGraph implements IndexedGraph{
private Array> tempConnections = new Array>();
@@ -28,11 +28,11 @@ public class PassTileGraph implements IndexedGraph{
@Override
public int getIndex(Tile node){
- return node.x+node.y*Moment.i.size;
+ return node.x+node.y*worldsize;
}
@Override
public int getNodeCount(){
- return Moment.i.size*Moment.i.size;
+ return worldsize*worldsize;
}
}
diff --git a/core/src/io/anuke/mindustry/ai/Pathfind.java b/core/src/io/anuke/mindustry/ai/Pathfind.java
index a053a9f74f..0c466ef4d4 100644
--- a/core/src/io/anuke/mindustry/ai/Pathfind.java
+++ b/core/src/io/anuke/mindustry/ai/Pathfind.java
@@ -1,22 +1,20 @@
package io.anuke.mindustry.ai;
+import static io.anuke.mindustry.Vars.*;
+
import com.badlogic.gdx.ai.pfa.DefaultGraphPath;
import com.badlogic.gdx.ai.pfa.indexed.IndexedAStarPathFinder;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Array;
-import io.anuke.mindustry.Moment;
import io.anuke.mindustry.entities.Enemy;
import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.entities.Entities;
import io.anuke.ucore.entities.Entity;
-
public class Pathfind{
static MHueristic heuristic = new MHueristic();
- static TileGraph graph = new TileGraph();
static PassTileGraph passgraph = new PassTileGraph();
- static IndexedAStarPathFinder pathfinder = new IndexedAStarPathFinder(graph);
- static IndexedAStarPathFinder passpathfinder = new IndexedAStarPathFinder(passgraph);
+ static IndexedAStarPathFinder passpathfinder;
static Array> paths = new Array<>();
static Vector2 vector = new Vector2();
@@ -48,11 +46,12 @@ public class Pathfind{
static public void reset(){
paths.clear();
+ passpathfinder = new IndexedAStarPathFinder(passgraph);
}
static public void updatePath(){
if(paths.size == 0){
- for(int i = 0; i < Moment.i.spawnpoints.size; i ++){
+ for(int i = 0; i < spawnpoints.size; i ++){
DefaultGraphPath path = new DefaultGraphPath<>();
paths.add(path);
}
@@ -62,8 +61,8 @@ public class Pathfind{
for(DefaultGraphPath path : paths){
path.clear();
passpathfinder.searchNodePath(
- Moment.i.spawnpoints.get(i),
- Moment.i.core, heuristic, path);
+ spawnpoints.get(i),
+ core, heuristic, path);
//for(Tile tile : path){
// Effects.effect("ind", tile.worldx(), tile.worldy());
@@ -80,7 +79,6 @@ public class Pathfind{
static void findNode(Enemy enemy){
DefaultGraphPath path = paths.get(enemy.spawn);
-
Tile closest = null;
float ldst = 0f;
int cindex = -1;
diff --git a/core/src/io/anuke/mindustry/ai/TileGraph.java b/core/src/io/anuke/mindustry/ai/TileGraph.java
deleted file mode 100644
index b7ad189654..0000000000
--- a/core/src/io/anuke/mindustry/ai/TileGraph.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package io.anuke.mindustry.ai;
-
-import com.badlogic.gdx.ai.pfa.Connection;
-import com.badlogic.gdx.ai.pfa.indexed.IndexedGraph;
-import com.badlogic.gdx.utils.Array;
-
-import io.anuke.mindustry.Moment;
-import io.anuke.mindustry.world.Tile;
-
-public class TileGraph implements IndexedGraph{
- private Array> tempConnections = new Array>();
-
- @Override
- public Array> getConnections(Tile fromNode){
- tempConnections.clear();
-
- if(fromNode.block().solid && fromNode != Moment.i.core)
- return tempConnections;
-
- for(Tile tile : fromNode.getNearby()){
- if(tile != null && (!tile.block().solid || tile == Moment.i.core))
- tempConnections.add(new TileConnection(fromNode, tile));
- }
- return tempConnections;
- }
-
- @Override
- public int getIndex(Tile node){
- return node.x+node.y*Moment.i.size;
- }
-
- @Override
- public int getNodeCount(){
- return Moment.i.size*Moment.i.size;
- }
-}
diff --git a/core/src/io/anuke/mindustry/entities/Bullet.java b/core/src/io/anuke/mindustry/entities/Bullet.java
index 29203dd9e3..d130a8776e 100644
--- a/core/src/io/anuke/mindustry/entities/Bullet.java
+++ b/core/src/io/anuke/mindustry/entities/Bullet.java
@@ -1,8 +1,9 @@
package io.anuke.mindustry.entities;
-import io.anuke.mindustry.Moment;
+import static io.anuke.mindustry.Vars.tilesize;
+
+import io.anuke.mindustry.World;
import io.anuke.mindustry.world.Tile;
-import io.anuke.mindustry.world.TileType;
import io.anuke.ucore.entities.BulletEntity;
import io.anuke.ucore.entities.Entity;
import io.anuke.ucore.entities.SolidEntity;
@@ -24,9 +25,9 @@ public class Bullet extends BulletEntity{
@Override
public void update(){
- int tilex = Mathf.scl2(x, TileType.tilesize);
- int tiley = Mathf.scl2(y, TileType.tilesize);
- Tile tile = Moment.i.tile(tilex, tiley);
+ int tilex = Mathf.scl2(x, tilesize);
+ int tiley = Mathf.scl2(y, tilesize);
+ Tile tile = World.tile(tilex, tiley);
if(tile != null && tile.entity != null &&
tile.entity.collide(this) && !tile.entity.dead){
diff --git a/core/src/io/anuke/mindustry/entities/BulletType.java b/core/src/io/anuke/mindustry/entities/BulletType.java
index 318b2d4612..a6628d2982 100644
--- a/core/src/io/anuke/mindustry/entities/BulletType.java
+++ b/core/src/io/anuke/mindustry/entities/BulletType.java
@@ -25,7 +25,7 @@ public abstract class BulletType extends BaseBulletType{
},
sniper = new BulletType(3f, 17){
public void draw(Bullet b){
- Draw.color("light gray");
+ Draw.color("lightgray");
Draw.rect("bullet", b.x, b.y, b.angle());
Draw.clear();
}
diff --git a/core/src/io/anuke/mindustry/entities/Enemy.java b/core/src/io/anuke/mindustry/entities/Enemy.java
index 0c9f6d3881..26ee0b9315 100644
--- a/core/src/io/anuke/mindustry/entities/Enemy.java
+++ b/core/src/io/anuke/mindustry/entities/Enemy.java
@@ -2,19 +2,15 @@ package io.anuke.mindustry.entities;
import com.badlogic.gdx.math.Vector2;
-import io.anuke.mindustry.Control;
-import io.anuke.mindustry.Moment;
+import io.anuke.mindustry.Vars;
+import io.anuke.mindustry.World;
import io.anuke.mindustry.ai.Pathfind;
-import io.anuke.mindustry.world.TileType;
import io.anuke.ucore.core.Draw;
import io.anuke.ucore.core.Effects;
-import io.anuke.ucore.core.Sounds;
import io.anuke.ucore.entities.*;
import io.anuke.ucore.util.Timers;
public class Enemy extends DestructibleEntity{
- public static int amount = 0;
-
public Vector2 direction = new Vector2();
public float xvelocity, yvelocity;
public float speed = 0.3f;
@@ -27,6 +23,7 @@ public class Enemy extends DestructibleEntity{
public float length = 4;
public float rotatespeed = 8f;
public String shootsound = "enemyshoot";
+ public boolean dead = false;
public Enemy(int spawn){
this.spawn = spawn;
@@ -35,18 +32,16 @@ public class Enemy extends DestructibleEntity{
maxhealth = 30;
heal();
-
- amount ++;
}
void move(){
Vector2 vec = Pathfind.find(this);
vec.sub(x, y).setLength(speed);
- Moment.module(Control.class).tryMove(this, vec.x*delta, vec.y*delta);
+ move(vec.x*delta, vec.y*delta);
//if(Timers.get(this, 10))
- target = TileType.findTileTarget(x, y, null, range, false);
+ target = World.findTileTarget(x, y, null, range, false);
//no tile found
if(target == null)
@@ -57,7 +52,7 @@ public class Enemy extends DestructibleEntity{
if(target != null){
if(Timers.get(this, reload)){
shoot();
- Sounds.play(shootsound);
+ Effects.sound(shootsound, this);
}
}
@@ -78,13 +73,15 @@ public class Enemy extends DestructibleEntity{
public void onDeath(){
Effects.effect("explosion", this);
Effects.shake(3f, 4f);
- Sounds.play("explosion");
+ Effects.sound("explosion", this);
remove();
+ dead = true;
}
@Override
public void removed(){
- amount --;
+ if(!dead)
+ Vars.enemies --;
}
@Override
diff --git a/core/src/io/anuke/mindustry/entities/Player.java b/core/src/io/anuke/mindustry/entities/Player.java
index 0208162f64..80837b4ae0 100644
--- a/core/src/io/anuke/mindustry/entities/Player.java
+++ b/core/src/io/anuke/mindustry/entities/Player.java
@@ -1,11 +1,11 @@
package io.anuke.mindustry.entities;
+import static io.anuke.mindustry.Vars.*;
+
import com.badlogic.gdx.Input.Buttons;
import com.badlogic.gdx.math.Vector2;
-import io.anuke.mindustry.Control;
-import io.anuke.mindustry.Moment;
-import io.anuke.mindustry.UI;
+import io.anuke.mindustry.Vars;
import io.anuke.ucore.core.*;
import io.anuke.ucore.entities.DestructibleEntity;
import io.anuke.ucore.util.Angles;
@@ -32,8 +32,8 @@ public class Player extends DestructibleEntity{
Effects.shake(4f, 5f);
Effects.effect("respawn", this);
- Timers.run(Moment.i.respawntime, ()->{
- set(Moment.i.core.worldx(), Moment.i.core.worldy()-8);
+ Timers.run(respawntime, ()->{
+ set(core.worldx(), core.worldy()-8);
heal();
add();
});
@@ -50,6 +50,11 @@ public class Player extends DestructibleEntity{
@Override
public void update(){
+ float speed = this.speed;
+
+ if(Vars.debug)
+ speed = 3f;
+
if(health < maxhealth && Timers.get(this, 50))
health ++;
@@ -66,7 +71,7 @@ public class Player extends DestructibleEntity{
reload -= delta;
- boolean shooting = Inputs.buttonDown(Buttons.LEFT) && Moment.i.recipe == null && !Moment.module(UI.class).hasMouse();
+ boolean shooting = Inputs.buttonDown(Buttons.LEFT) && recipe == null && !ui.hasMouse();
if(shooting && reload <= 0){
weapon.shoot(this);
@@ -76,7 +81,7 @@ public class Player extends DestructibleEntity{
vector.limit(speed);
- Moment.module(Control.class).tryMove(this, vector.x*delta, vector.y*delta);
+ move(vector.x*delta, vector.y*delta);
if(!shooting){
direction.add(vector.scl(delta));
diff --git a/core/src/io/anuke/mindustry/entities/TileEntity.java b/core/src/io/anuke/mindustry/entities/TileEntity.java
index 7ee4e11811..3bf5fe730d 100644
--- a/core/src/io/anuke/mindustry/entities/TileEntity.java
+++ b/core/src/io/anuke/mindustry/entities/TileEntity.java
@@ -1,48 +1,47 @@
package io.anuke.mindustry.entities;
-import com.badlogic.gdx.utils.DelayedRemovalArray;
import com.badlogic.gdx.utils.ObjectMap;
-import io.anuke.mindustry.Moment;
+import io.anuke.mindustry.GameState;
import io.anuke.mindustry.ai.Pathfind;
import io.anuke.mindustry.resource.Item;
import io.anuke.mindustry.world.Tile;
-import io.anuke.mindustry.world.TileType;
+import io.anuke.mindustry.world.blocks.Blocks;
+import io.anuke.mindustry.world.blocks.ProductionBlocks;
import io.anuke.ucore.core.Effects;
-import io.anuke.ucore.core.Sounds;
import io.anuke.ucore.entities.Entity;
public class TileEntity extends Entity{
- public final Tile tile;
- public DelayedRemovalArray convey = new DelayedRemovalArray<>();
+ public Tile tile;
public ObjectMap
- items = new ObjectMap<>();
- public int shots;
- public TileEntity link;
- public float rotation;
public int maxhealth, health;
public boolean dead = false;
- public TileEntity(Tile tile){
+
+ public TileEntity init(Tile tile){
this.tile = tile;
x = tile.worldx();
y = tile.worldy();
maxhealth = tile.block().health;
health = maxhealth;
+
+ return this;
}
public void onDeath(){
dead = true;
- if(tile.block() == TileType.core){
- Moment.i.coreDestroyed();
+ if(tile.block() == ProductionBlocks.core){
+ GameState.coreDestroyed();
}
- tile.setBlock(TileType.air);
+
+ tile.setBlock(Blocks.air);
Pathfind.updatePath();
Effects.shake(4f, 4f);
Effects.effect("explosion", this);
- Sounds.play("break");
+ Effects.sound("break", this);
}
public void collision(Bullet other){
@@ -79,27 +78,4 @@ public class TileEntity extends Entity{
public void removeItem(Item item, int amount){
items.put(item, items.get(item, 0) - amount);
}
-
- public void addConvey(Item item){
- addConvey(item, 0);
- }
-
- public void addConvey(Item item, float pos){
- ItemPos posa = new ItemPos(item);
- posa.pos = pos;
- convey.add(posa);
- }
-
- public void removeConvey(ItemPos pos){
- convey.removeValue(pos, true);
- }
-
- static public class ItemPos{
- public Item item;
- public float pos;
-
- public ItemPos(Item item){
- this.item = item;
- }
- }
}
diff --git a/core/src/io/anuke/mindustry/resource/Recipe.java b/core/src/io/anuke/mindustry/resource/Recipe.java
index fcc7a9ce1c..23bc101529 100644
--- a/core/src/io/anuke/mindustry/resource/Recipe.java
+++ b/core/src/io/anuke/mindustry/resource/Recipe.java
@@ -4,37 +4,39 @@ import static io.anuke.mindustry.resource.Section.*;
import com.badlogic.gdx.utils.Array;
-import io.anuke.mindustry.world.TileType;
+import io.anuke.mindustry.world.Block;
+import io.anuke.mindustry.world.blocks.Blocks;
+import io.anuke.mindustry.world.blocks.ProductionBlocks;
+import io.anuke.mindustry.world.blocks.WeaponBlocks;
public enum Recipe{
- stonewall(distribution, TileType.stonewall, stack(Item.stone, 5)),
- ironwall(distribution, TileType.ironwall, stack(Item.iron, 5)),
- steelwall(distribution, TileType.steelwall, stack(Item.steel, 5)),
- conveyor(distribution, TileType.conveyor, stack(Item.stone, 1)),
- fastconveyor(distribution, TileType.steelconveyor, stack(Item.steel, 1)),
- router(distribution, TileType.router, stack(Item.stone, 3)),
+ stonewall(distribution, Blocks.stonewall, stack(Item.stone, 5)),
+ ironwall(distribution, Blocks.ironwall, stack(Item.iron, 5)),
+ steelwall(distribution, Blocks.steelwall, stack(Item.steel, 5)),
+ conveyor(distribution, ProductionBlocks.conveyor, stack(Item.stone, 1)),
+ fastconveyor(distribution, ProductionBlocks.steelconveyor, stack(Item.steel, 1)),
+ router(distribution, ProductionBlocks.router, stack(Item.stone, 3)),
+ turret(defense, WeaponBlocks.turret, stack(Item.stone, 6)),
+ dturret(defense, WeaponBlocks.doubleturret, stack(Item.stone, 12)),
+ machineturret(defense, WeaponBlocks.machineturret, stack(Item.iron, 15), stack(Item.stone, 20)),
+ shotgunturret(defense, WeaponBlocks.shotgunturret, stack(Item.iron, 15), stack(Item.iron, 20)),
+ flameturret(defense, WeaponBlocks.flameturret, stack(Item.iron, 25), stack(Item.steel, 18)),
+ sniperturret(defense, WeaponBlocks.sniperturret, stack(Item.iron, 30), stack(Item.steel, 20)),
- turret(defense, TileType.turret, stack(Item.stone, 8)),
- dturret(defense, TileType.doubleturret, stack(Item.stone, 12)),
- machineturret(defense, TileType.machineturret, stack(Item.iron, 15), stack(Item.stone, 20)),
- shotgunturret(defense, TileType.shotgunturret, stack(Item.iron, 15), stack(Item.steel, 24)),
- flameturret(defense, TileType.flameturret, stack(Item.iron, 25), stack(Item.steel, 18)),
- sniperturret(defense, TileType.sniperturret, stack(Item.iron, 30), stack(Item.steel, 20)),
+ healturret(defense, WeaponBlocks.repairturret, stack(Item.iron, 40)),
+ megahealturret(defense, WeaponBlocks.megarepairturret, stack(Item.iron, 30), stack(Item.steel, 40)),
- healturret(defense, TileType.repairturret, stack(Item.iron, 40)),
- megahealturret(defense, TileType.megarepairturret, stack(Item.iron, 30), stack(Item.steel, 40)),
+ drill(production, ProductionBlocks.stonedrill, stack(Item.stone, 6)),
+ irondrill(production, ProductionBlocks.irondrill, stack(Item.stone, 40)),
+ coaldrill(production, ProductionBlocks.coaldrill, stack(Item.stone, 40), stack(Item.iron, 40)),
+ smelter(production, ProductionBlocks.smelter, stack(Item.stone, 80), stack(Item.iron, 80));
- drill(production, TileType.stonedrill, stack(Item.stone, 6)),
- irondrill(production, TileType.irondrill, stack(Item.stone, 40)),
- coaldrill(production, TileType.coaldrill, stack(Item.stone, 40), stack(Item.iron, 40)),
- smelter(production, TileType.smelter, stack(Item.stone, 80), stack(Item.iron, 80));
-
- public TileType result;
+ public Block result;
public ItemStack[] requirements;
public Section section;
- private Recipe(Section section, TileType result, ItemStack... requirements){
+ private Recipe(Section section, Block result, ItemStack... requirements){
this.result = result;
this.requirements = requirements;
this.section = section;
diff --git a/core/src/io/anuke/mindustry/world/Block.java b/core/src/io/anuke/mindustry/world/Block.java
new file mode 100644
index 0000000000..ee8a09a0f4
--- /dev/null
+++ b/core/src/io/anuke/mindustry/world/Block.java
@@ -0,0 +1,139 @@
+package io.anuke.mindustry.world;
+
+import com.badlogic.gdx.math.MathUtils;
+import com.badlogic.gdx.math.Vector2;
+
+import io.anuke.mindustry.entities.TileEntity;
+import io.anuke.mindustry.resource.Item;
+import io.anuke.ucore.core.Draw;
+
+public class Block{
+ protected static Vector2 vector = new Vector2();
+ protected static Vector2 vector2 = new Vector2();
+
+ public final String name;
+ public boolean solid, update, rotate;
+ public int health = 40;
+
+ public Block(String name) {
+ this.name = name;
+ solid = false;
+ }
+
+ public void drawOver(Tile tile){}
+ public void drawPixelOverlay(Tile tile){}
+ public void drawOverlay(Tile tile){}
+
+ public String name(){
+ return name;
+ }
+
+ public String description(){
+ return "[no description]";
+ }
+
+ public String errorMessage(Tile tile){
+ return null;
+ }
+
+ protected void handleItem(Tile tile, Item item, Tile source){
+ tile.entity.addItem(item, 1);
+ }
+
+ public boolean accept(Item item){
+ return false;
+ }
+
+ public void update(Tile tile){}
+
+ public TileEntity getEntity(){
+ return new TileEntity();
+ }
+
+ /**
+ * Tries to put this item into a nearby container, if there are no available
+ * containers, it gets added to the block's inventory.
+ */
+ protected void offloadNear(Tile tile, Item item){
+ int i = tile.dump;
+ int pdump = tile.dump;
+
+ Tile[] tiles = tile.getNearby();
+
+ for(int j = 0; j < 4; j ++){
+ Tile other = tiles[i];
+ if(other != null && other.block().accept(item)
+ //don't output to things facing this thing
+ && !(other.block().rotate && (other.rotation + 2) % 4 == i)){
+
+ other.block().handleItem(other, item, tile);
+ tile.dump = (i+1)%4;
+ return;
+ }
+ i++;
+ i %= 4;
+ }
+ tile.dump = pdump;
+ handleItem(tile, item, tile);
+ }
+
+ /** Try dumping any item near the tile. */
+ protected boolean tryDump(Tile tile){
+ return tryDump(tile, -1, null);
+ }
+
+ /**
+ * Try dumping any item near the tile. -1 = any direction
+ */
+ protected boolean tryDump(Tile tile, int direction, Item todump){
+ int i = tile.dump;
+
+ Tile[] tiles = tile.getNearby();
+
+ for(int j = 0; j < 4; j ++){
+ Tile other = tiles[i];
+
+ if(i == direction || direction == -1)
+ for(Item item : Item.values()){
+
+ if(todump != null && item != todump) continue;
+
+ if(tile.entity.hasItem(item) && other != null && other.block().accept(item) &&
+ //don't output to things facing this thing
+ !(other.block().rotate && (other.rotation + 2) % 4 == i)){
+ other.block().handleItem(other, item, tile);
+ tile.entity.removeItem(item, 1);
+ tile.dump = (i+1)%4;
+ return true;
+ }
+ }
+ i++;
+ i %= 4;
+ }
+
+ return false;
+ }
+
+ /**
+ * Try offloading an item to a nearby container. Returns true if success.
+ */
+ protected boolean offloadDir(Tile tile, Item item){
+ Tile other = tile.getNearby()[tile.rotation];
+ if(other != null && other.block().accept(item)){
+ other.block().handleItem(other, item, tile);
+ //other.entity.addCovey(item, ch == 1 ? 0.5f : ch ==2 ? 1f : 0f);
+ return true;
+ }
+ return false;
+ }
+
+ public void draw(Tile tile){
+ if(tile.floor() == this){
+ MathUtils.random.setSeed(tile.id());
+ Draw.rect(name() + MathUtils.random(1, 3), tile.worldx(), tile.worldy(), rotate ? tile.rotation * 90 : 0);
+ }else{
+ Draw.rect(name(), tile.worldx(), tile.worldy(), rotate ? tile.rotation * 90 : 0);
+ }
+ }
+
+}
diff --git a/core/src/io/anuke/mindustry/world/Generator.java b/core/src/io/anuke/mindustry/world/Generator.java
index 78a33a24fd..f31e3177f3 100644
--- a/core/src/io/anuke/mindustry/world/Generator.java
+++ b/core/src/io/anuke/mindustry/world/Generator.java
@@ -1,53 +1,66 @@
package io.anuke.mindustry.world;
+import static io.anuke.mindustry.Vars.*;
+
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Pixmap;
+import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.math.MathUtils;
-import io.anuke.mindustry.Moment;
+import io.anuke.mindustry.world.blocks.Blocks;
+import io.anuke.ucore.graphics.Hue;
import io.anuke.ucore.noise.Noise;
public class Generator{
- static final int black = Color.rgba8888(Color.BLACK);
- static final int white = Color.rgba8888(Color.WHITE);
- static final int red = Color.rgba8888(Color.RED);
- static final int blue = Color.rgba8888(Color.BLUE);
+ static final int stonefloor = Color.rgba8888(Hue.rgb(54, 54, 54));
+ static final int stone = Color.rgba8888(Hue.rgb(128, 128, 128));
+ static final int spawn = Color.rgba8888(Color.RED);
+ static final int start = Color.rgba8888(Color.GREEN);
- public static void generate(Tile[][] tiles, String mapname){
- Pixmap pix = new Pixmap(Gdx.files.internal("maps/"+mapname+".png"));
+ /**Returns world size.*/
+ public static void generate(int map){
+ Pixmap pix = mapPixmaps[map];
+
Noise.setSeed(MathUtils.random(0, 99999));
for(int x = 0; x < tiles.length; x ++){
for(int y = 0; y < tiles.length; y ++){
- TileType floor = TileType.stone;
- TileType block = TileType.air;
+ Block floor = Blocks.stone;
+ Block block = Blocks.air;
int color = pix.getPixel(x, pix.getHeight()-1-y);
if(Noise.nnoise(x, y, 8, 1) > 0.22){
- floor = TileType.iron;
+ floor = Blocks.iron;
}
if(Noise.nnoise(x, y, 6, 1) > 0.245){
- floor = TileType.coal;
+ floor = Blocks.coal;
}
-
-
-
- if(color == white){
- block = TileType.stoneblock;
-
- }else if(color == blue){
- Moment.i.core = tiles[x][y];
- }else if(color == red){
- Moment.i.spawnpoints.add(tiles[x][y]);
+ if(color == stone && map == 1){
+ block = Blocks.dirtblock;
+ }else if(color == stone){
+ block = Blocks.stoneblock;
+ }else if(color == start){
+ core = tiles[x][y];
+ }else if(color == spawn){
+ spawnpoints.add(tiles[x][y]);
}
tiles[x][y].setBlock(block);
tiles[x][y].setFloor(floor);
}
}
+ }
+
+ public static void loadMaps(){
+ mapPixmaps = new Pixmap[maps.length];
+ mapTextures = new Texture[maps.length];
- pix.dispose();
+ for(int i = 0; i < maps.length; i ++){
+ Pixmap pix = new Pixmap(Gdx.files.internal("maps/"+maps[i]+".png"));
+ mapPixmaps[i] = pix;
+ mapTextures[i] = new Texture(pix);
+ }
}
}
diff --git a/core/src/io/anuke/mindustry/world/Tile.java b/core/src/io/anuke/mindustry/world/Tile.java
index 3fb7cfbeda..e5ad3ef9d2 100644
--- a/core/src/io/anuke/mindustry/world/Tile.java
+++ b/core/src/io/anuke/mindustry/world/Tile.java
@@ -1,51 +1,66 @@
package io.anuke.mindustry.world;
-import io.anuke.mindustry.Moment;
+import static io.anuke.mindustry.Vars.*;
+
+import io.anuke.mindustry.World;
import io.anuke.mindustry.entities.TileEntity;
+import io.anuke.mindustry.world.blocks.Blocks;
+
public class Tile{
- private static Tile[] tiles = new Tile[4];
- private TileType floor = TileType.air;
- private TileType block = TileType.air;
+ private Block floor = Blocks.air;
+ private Block block = Blocks.air;
public TileEntity entity;
- public int x, y, rotation;
+ public int x, y, rotation, dump;
public Tile(int x, int y){
this.x = x;
this.y = y;
}
- public Tile(int x, int y, TileType floor){
+ public Tile(int x, int y, Block floor){
this(x, y);
this.floor = floor;
}
+ public int relativeTo(int cx, int cy){
+ if(x == cx && y == cy - 1) return 1;
+ if(x == cx && y == cy + 1) return 3;
+ if(x == cx - 1 && y == cy) return 0;
+ if(x == cx + 1 && y == cy) return 2;
+ return -1;
+ }
+
+ public T entity(){
+ return (T)entity;
+ }
+
public int id(){
- return x + y * Moment.i.size;
+ return x + y * worldsize;
}
public float worldx(){
- return x * TileType.tilesize;
+ return x * tilesize;
}
public float worldy(){
- return y * TileType.tilesize;
+ return y * tilesize;
}
- public TileType floor(){
+ public Block floor(){
return floor;
}
- public TileType block(){
+ public Block block(){
return block;
}
- public void setBlock(TileType type){
+ public void setBlock(Block type){
this.block = type;
changed();
}
- public void setFloor(TileType type){
+ public void setFloor(Block type){
this.floor = type;
}
@@ -54,15 +69,9 @@ public class Tile{
}
public Tile[] getNearby(){
- tiles[0] = Moment.i.tile(x+1, y);
- tiles[1] = Moment.i.tile(x, y+1);
- tiles[2] = Moment.i.tile(x-1, y);
- tiles[3] = Moment.i.tile(x, y-1);
-
- return tiles;
+ return World.getNearby(x, y);
}
-
public void changed(){
if(entity != null){
entity.remove();
@@ -70,6 +79,11 @@ public class Tile{
}
if(block.update)
- entity = new TileEntity(this).add();
+ entity = block.getEntity().init(this).add();
+ }
+
+ @Override
+ public String toString(){
+ return floor.name() + ":" + block.name();
}
}
diff --git a/core/src/io/anuke/mindustry/world/TileType.java b/core/src/io/anuke/mindustry/world/TileType.java
deleted file mode 100644
index 13da58145f..0000000000
--- a/core/src/io/anuke/mindustry/world/TileType.java
+++ /dev/null
@@ -1,735 +0,0 @@
-package io.anuke.mindustry.world;
-
-import com.badlogic.gdx.Gdx;
-import com.badlogic.gdx.math.MathUtils;
-import com.badlogic.gdx.math.Vector2;
-import com.badlogic.gdx.utils.Array;
-
-import io.anuke.mindustry.Moment;
-import io.anuke.mindustry.entities.*;
-import io.anuke.mindustry.entities.TileEntity.ItemPos;
-import io.anuke.mindustry.resource.Item;
-import io.anuke.ucore.core.Draw;
-import io.anuke.ucore.core.Effects;
-import io.anuke.ucore.core.Sounds;
-import io.anuke.ucore.entities.*;
-import io.anuke.ucore.graphics.Hue;
-import io.anuke.ucore.util.Angles;
-import io.anuke.ucore.util.Mathf;
-import io.anuke.ucore.util.Timers;
-
-public enum TileType{
- air{
- //nothing gets drawn
- public void draw(Tile tile){
- }
- },
- grass,
- stone,
- dirt,
- iron,
- coal,
- dirtblock(true),
- stoneblock(true),
- stonewall(true, true){{health = 50;}},
- ironwall(true, true){{health = 80;}},
- steelwall(true, true){{health = 110;}},
- stonedrill(true, true){
- public void update(Tile tile){
-
- if(tile.floor() == TileType.stone && Timers.get(tile, 60 * 6)){
- offloadNear(tile, Item.stone);
- Effects.effect("spark", tile.x * tilesize, tile.y * tilesize);
- }
-
- if(Timers.get(tile.hashCode() + "dump", 30)){
- tryDump(tile);
- }
- }
-
- public String description(){
- return "Mines 1 stone every 6 seconds.";
- }
-
- public String error(Tile tile){
- if(tile.floor() != TileType.stone)
- return "Not on stone block!";
- return null;
- }
- },
- irondrill(true, true){
- public void update(Tile tile){
-
- if(tile.floor() == TileType.iron && Timers.get(tile, 60 * 6)){
- offloadNear(tile, Item.iron);
- Effects.effect("spark", tile.x * tilesize, tile.y * tilesize);
- }
-
- if(Timers.get(tile.hashCode() + "dump", 30)){
- tryDump(tile);
- }
- }
-
- public String description(){
- return "Mines 1 iron every 6 seconds.";
- }
-
- public String error(Tile tile){
- if(tile.floor() != TileType.iron)
- return "Not on iron ore block!";
- return null;
- }
- },
- coaldrill(true, true){
- public void update(Tile tile){
-
- if(tile.floor() == TileType.coal && Timers.get(tile, 60 * 6)){
- offloadNear(tile, Item.coal);
- Effects.effect("spark", tile.x * tilesize, tile.y * tilesize);
- }
-
- if(Timers.get(tile.hashCode() + "dump", 30)){
- tryDump(tile);
- }
- }
-
- public String description(){
- return "Mines 1 coal every 6 seconds.";
- }
-
- public String error(Tile tile){
- if(tile.floor() != TileType.coal)
- return "Not on coal block!";
- return null;
- }
- },
- conveyor(false, true, true){
- float speed = 0.02f;
-
- public void draw(Tile tile){
- Draw.rect(name() + (Timers.time() % ((20 / 100f) / speed) < (10 / 100f) / speed ? "" : "move"), tile.worldx(), tile.worldy(), tile.rotation * 90);
-
- vector.set(tilesize, 0).rotate(tile.rotation * 90);
- vector2.set(-tilesize / 2, 0).rotate(tile.rotation * 90);
-
- for(ItemPos pos : tile.entity.convey){
- Draw.rect("icon-" + pos.item.name(), tile.x * tilesize + vector.x * pos.pos + vector2.x, tile.y * tilesize + vector.y * pos.pos + vector2.y, 4, 4);
- }
- }
-
- public void update(Tile tile){
- tile.entity.convey.begin();
-
- for(ItemPos pos : tile.entity.convey){
- pos.pos += speed * Gdx.graphics.getDeltaTime() * 60f;
- if(pos.pos >= 1f && offloadDir(tile, pos.item)){
- tile.entity.removeConvey(pos);
- continue;
- }
- pos.pos = Mathf.clamp(pos.pos);
- }
-
- tile.entity.convey.end();
- }
-
- @Override
- public boolean accepts(Item item){
- return true;
- }
-
- public String description(){
- return "Moves Items";
- }
-
- @Override
- void handleItem(Tile tile, Item item, float f){
- tile.entity.addConvey(item, f);
- }
- },
- steelconveyor(false, true, true){
- float speed = 0.03f;
-
- public void draw(Tile tile){
- Draw.rect(name() + (Timers.time() % ((20 / 100f) / speed) < (10 / 100f) / speed ? "" : "move"), tile.worldx(), tile.worldy(), tile.rotation * 90);
-
- vector.set(tilesize, 0).rotate(tile.rotation * 90);
- vector2.set(-tilesize / 2, 0).rotate(tile.rotation * 90);
-
- for(ItemPos pos : tile.entity.convey){
- Draw.rect("icon-" + pos.item.name(), tile.x * tilesize + vector.x * pos.pos + vector2.x, tile.y * tilesize + vector.y * pos.pos + vector2.y, 4, 4);
- }
- }
-
- public void update(Tile tile){
- tile.entity.convey.begin();
-
- for(ItemPos pos : tile.entity.convey){
- pos.pos += speed * Gdx.graphics.getDeltaTime() * 60f;
- if(pos.pos >= 1f && offloadDir(tile, pos.item)){
- tile.entity.removeConvey(pos);
- continue;
- }
- pos.pos = Mathf.clamp(pos.pos);
- }
-
- tile.entity.convey.end();
- }
-
- @Override
- public boolean accepts(Item item){
- return true;
- }
-
- public String description(){
- return "Moves Items\nFaster than a normal conveyor";
- }
-
- @Override
- void handleItem(Tile tile, Item item, float f){
- tile.entity.addConvey(item, f);
- }
- },
- router(true, true, false){
-
- public void update(Tile tile){
- if(Timers.get(tile, 10) && tile.entity.totalItems() > 0){
- tryDump(tile, tile.rotation++);
- tile.rotation %= 4;
- }
- }
-
- @Override
- public boolean accepts(Item item){
- return true;
- }
-
- public String description(){
- return "Splits conveyor belt input";
- }
- },
- smelter(true, true, false){
- {health=70;}
-
- public void update(Tile tile){
-
- if(tile.entity.hasItem(Item.coal) && tile.entity.hasItem(Item.iron)){
- tile.entity.removeItem(Item.coal, 1);
- tile.entity.removeItem(Item.iron, 1);
- offloadNear(tile, Item.steel);
- Effects.effect("smelt", tile.entity);
- }
-
- if(Timers.get(tile, 20) && tile.entity.hasItem(Item.steel)){
- tryDump(tile);
- }
- }
-
- @Override
- public boolean accepts(Item item){
- return item == Item.iron || item == Item.coal;
- }
-
- public String description(){
- return "Smelts iron and coal into steel";
- }
- },
- core(true, true, false){
- {
- health = 300;
- }
-
- @Override
- void handleItem(Tile tile, Item item, float f){
- Moment.i.addItem(item, 1);
- }
-
- @Override
- public boolean accepts(Item item){
- return true;
- }
- },
- turret(true, true, false){
- {
- range = 40;
- reload = 10f;
- bullet = BulletType.stone;
- ammo = Item.stone;
- }
-
- public void update(Tile tile){
- updateTurret(tile);
- }
-
- public void draw(Tile tile){
- Draw.rect("block", tile.worldx(), tile.worldy());
- }
-
- public void drawOver(Tile tile){
- Draw.rect(name(), tile.worldx(), tile.worldy(), tile.entity.rotation - 90);
- }
-
- public String description(){
- return "Shoots things.";
- }
- },
- doubleturret(true, true, false){
- {
- range = 40;
- reload = 13f;
- bullet = BulletType.stone;
- ammo = Item.stone;
- health = 50;
- }
-
- public void update(Tile tile){
- updateTurret(tile);
- }
-
- public void draw(Tile tile){
- Draw.rect("block", tile.worldx(), tile.worldy());
- }
-
- public void drawOver(Tile tile){
- Draw.rect(name(), tile.worldx(), tile.worldy(), tile.entity.rotation - 90);
- }
-
- public String description(){
- return "Shoots things.";
- }
-
- @Override
- void shoot(Tile tile){
- vector.set(4, -2).rotate(tile.entity.rotation);
- bullet(tile, tile.entity.rotation);
- vector.set(4, 2).rotate(tile.entity.rotation);
- bullet(tile, tile.entity.rotation);
- }
- },
- machineturret(true, true, false){
- {
- range = 65;
- reload = 7f;
- bullet = BulletType.iron;
- ammo = Item.iron;
- health = 65;
- }
-
- public void update(Tile tile){
- updateTurret(tile);
- }
-
- public void draw(Tile tile){
- Draw.rect("block", tile.worldx(), tile.worldy());
- }
-
- public void drawOver(Tile tile){
- Draw.rect(name(), tile.worldx(), tile.worldy(), tile.entity.rotation - 90);
- }
-
- public String description(){
- return "Shoots things.";
- }
- },
- flameturret(true, true, false){
- {
- range = 35f;
- reload = 5f;
- bullet = BulletType.flame;
- ammo = Item.coal;
- health = 85;
- }
-
- public void update(Tile tile){
- updateTurret(tile);
- }
-
- public void draw(Tile tile){
- Draw.rect("block", tile.worldx(), tile.worldy());
- }
-
- public void drawOver(Tile tile){
- Draw.rect(name(), tile.worldx(), tile.worldy(), tile.entity.rotation - 90);
- }
-
- public String description(){
- return "Burns things.";
- }
- },
- sniperturret(true, true, false){
- {
- range = 100;
- reload = 60f;
- bullet = BulletType.sniper;
- ammo = Item.steel;
- health = 60;
- }
-
- public void update(Tile tile){
- updateTurret(tile);
- }
-
- public void draw(Tile tile){
- Draw.rect("block", tile.worldx(), tile.worldy());
- }
-
- public void drawOver(Tile tile){
- Draw.rect(name(), tile.worldx(), tile.worldy(), tile.entity.rotation - 90);
- }
-
- public String description(){
- return "Shoots things.";
- }
- },
- shotgunturret(true, true, false){
- {
- range = 50;
- reload = 40f;
- bullet = BulletType.iron;
- ammo = Item.iron;
- health = 70;
- }
-
- public void update(Tile tile){
- updateTurret(tile);
- }
-
- public void draw(Tile tile){
- Draw.rect("block", tile.worldx(), tile.worldy());
- }
-
- public void drawOver(Tile tile){
- Draw.rect(name(), tile.worldx(), tile.worldy(), tile.entity.rotation - 90);
- }
-
- public String description(){
- return "Shoots things.";
- }
-
- @Override
- void shoot(Tile tile){
-
- for(int i = 0; i < 6; i ++)
- Timers.run(i/1.5f, ()->{
- vector.set(4, 0).setAngle(tile.entity.rotation);
- bullet(tile, tile.entity.rotation + Mathf.range(16));
- });
-
- }
- },
- repairturret(true, true, false){
- {
- range = 30;
- reload = 40f;
- health = 50;
- }
-
- public void update(Tile tile){
- /*
- * if(tile.entity.hasItem(ammo)){ tile.entity.shots += 20;
- * tile.entity.removeItem(ammo, 1); }
- */
- //if(tile.entity.shots > 0){
- tile.entity.link = findTileTarget(tile.worldx(), tile.worldy(), tile, range, true);
-
- if(tile.entity.link != null){
- tile.entity.rotation = tile.entity.angleTo(tile.entity.link);
-
- if(Timers.get(tile, reload)){
- tile.entity.link.health++;
- }
- }
- //}
- }
-
- public void draw(Tile tile){
- Draw.rect("block", tile.worldx(), tile.worldy());
- }
-
- public void drawOver(Tile tile){
- if(tile.entity.link != null){
- float x = tile.worldx(), y = tile.worldy();
- float x2 = tile.entity.link.x, y2 = tile.entity.link.y;
-
- Draw.color(Hue.rgb(138, 244, 138, (MathUtils.sin(Timers.time()) + 1f) / 14f));
- Draw.alpha(0.3f);
- Draw.thickness(4f);
- Draw.line(x, y, x2, y2);
- Draw.thickness(2f);
- Draw.rect("circle", x2, y2, 7f, 7f);
- Draw.alpha(1f);
- Draw.thickness(2f);
- Draw.line(x, y, x2, y2);
- Draw.thickness(1f);
- Draw.rect("circle", x2, y2, 5f, 5f);
- Draw.clear();
- }
- Draw.rect(name(), tile.worldx(), tile.worldy(), tile.entity.rotation - 90);
- }
-
- public String description(){
- return "Heals nearby tiles.";
- }
- },
- megarepairturret(true, true, false){
- {
- range = 30;
- reload = 20f;
- health = 80;
- }
-
- public void update(Tile tile){
- tile.entity.link = findTileTarget(tile.worldx(), tile.worldy(), tile, range, true);
-
- if(tile.entity.link != null){
- tile.entity.rotation = tile.entity.angleTo(tile.entity.link);
-
- if(Timers.get(tile, reload)){
- tile.entity.link.health++;
- }
- }
- }
-
- public void draw(Tile tile){
- Draw.rect("block", tile.worldx(), tile.worldy());
- }
-
- public void drawOver(Tile tile){
- if(tile.entity.link != null){
- float x = tile.worldx(), y = tile.worldy();
- float x2 = tile.entity.link.x, y2 = tile.entity.link.y;
-
- Draw.color(Hue.rgb(132, 242, 242, (MathUtils.sin(Timers.time()) + 1f) / 13f));
- Draw.alpha(0.3f);
- Draw.thickness(4f);
- Draw.line(x, y, x2, y2);
- Draw.thickness(2f);
- Draw.rect("circle", x2, y2, 7f, 7f);
- Draw.alpha(1f);
- Draw.thickness(2f);
- Draw.line(x, y, x2, y2);
- Draw.thickness(1f);
- Draw.rect("circle", x2, y2, 5f, 5f);
- Draw.clear();
- }
- Draw.rect(name(), tile.worldx(), tile.worldy(), tile.entity.rotation - 90);
- }
-
- public String description(){
- return "Heals nearby tiles.";
- }
- };
- static Vector2 vector = new Vector2();
- static Vector2 vector2 = new Vector2();
-
- public boolean solid, update, rotate;
- public static final int tilesize = 8;
- public int health = 40;
-
- //turrets
- public float range = 50f;
- public float reload = 10f;
- public BulletType bullet;
- public Item ammo;
-
- private TileType() {
- solid = false;
- }
-
- private TileType(boolean solid) {
- this.solid = solid;
- }
-
- private TileType(boolean solid, boolean update) {
- this.solid = solid;
- this.update = update;
- }
-
- private TileType(boolean solid, boolean update, boolean rotate) {
- this.solid = solid;
- this.update = update;
- this.rotate = rotate;
- }
-
- public void init(TileEntity entity){
-
- }
-
- void updateTurret(Tile tile){
- if(tile.entity.hasItem(ammo)){
- tile.entity.shots += 20;
- tile.entity.removeItem(ammo, 1);
- }
-
- if(tile.entity.shots > 0){
- Enemy enemy = findTarget(tile, range);
- if(enemy != null){
- tile.entity.rotation = MathUtils.lerpAngleDeg(tile.entity.rotation, Angles.predictAngle(tile.worldx(), tile.worldy(), enemy.x, enemy.y, enemy.xvelocity, enemy.yvelocity, bullet.speed - 0.1f), 0.2f);
- if(Timers.get(tile, reload)){
- Sounds.play("shoot");
- shoot(tile);
- tile.entity.shots--;
- }
- }
- }
- }
-
- void shoot(Tile tile){
- vector.set(0, 4).setAngle(tile.entity.rotation);
- new Bullet(bullet, tile.entity, tile.worldx()+vector.x, tile.worldy()+vector.y, tile.entity.rotation).add();
- }
-
- void bullet(Tile tile, float angle){
- new Bullet(bullet, tile.entity, tile.worldx()+vector.x, tile.worldy()+vector.y, angle).add();
- }
-
- Enemy findTarget(Tile tile, float range){
- Entity closest = null;
- float dst = 0;
-
- Array array = Entities.getNearby(tile.worldx(), tile.worldy(), range*2);
-
- for(Entity e : array){
-
- if(e instanceof Enemy){
- float ndst = Vector2.dst(tile.worldx(), tile.worldy(), e.x, e.y);
- if(ndst < range && (closest == null || ndst < dst)){
- dst = ndst;
- closest = e;
- }
- }
- }
-
- return (Enemy) closest;
- }
-
- public static TileEntity findTileTarget(float x, float y, Tile tile, float range, boolean damaged){
- Entity closest = null;
- float dst = 0;
-
- int rad = (int)(range/tilesize)+1;
- int tilex = Mathf.scl2(x, tilesize);
- int tiley = Mathf.scl2(y, tilesize);
-
- for(int rx = -rad; rx <= rad; rx ++){
- for(int ry = -rad; ry <= rad; ry ++){
- Tile other = Moment.i.tile(rx+tilex, ry+tiley);
-
- if(other == null || other.entity == null ||(tile != null && other.entity == tile.entity)) continue;
-
- TileEntity e = other.entity;
-
- if(damaged && ((TileEntity) e).health >= ((TileEntity) e).tile.block().health)
- continue;
-
- float ndst = Vector2.dst(x, y, e.x, e.y);
- if(ndst < range && (closest == null || ndst < dst)){
- dst = ndst;
- closest = e;
- }
- }
- }
-
- return (TileEntity) closest;
- }
-
- void handleItem(Tile tile, Item item, float f){
- tile.entity.addItem(item, 1);
- }
-
- /**
- * Tries to put this item into a nearby container, if there are no available
- * containers, it gets added to the block's inventory.
- */
- void offloadNear(Tile tile, Item item){
- int i = 0;
- for(Tile other : tile.getNearby()){
- if(other != null && other.block().accepts(item)
- //don't output to things facing this thing
- && !(other.block().rotate && (other.rotation + 2) % 4 == i)){
-
- other.block().handleItem(other, item, 0);
- return;
- }
- i++;
- }
- handleItem(tile, item, 0);
- }
-
- /** Try dumping any item near the tile. */
- boolean tryDump(Tile tile){
- return tryDump(tile, -1);
- }
-
- /**
- * Try dumping any item near the tile. -1 = any direction
- */
- boolean tryDump(Tile tile, int direction){
- int i = 0;
-
- for(Tile other : tile.getNearby()){
- if(i == direction || direction == -1)
- for(Item item : Item.values()){
-
- if(tile.entity.hasItem(item) && other != null && other.block().accepts(item) &&
- //don't output to things facing this thing
- !(other.block().rotate && (other.rotation + 2) % 4 == i)){
- other.block().handleItem(other, item, 0);
- tile.entity.removeItem(item, 1);
- return true;
- }
- }
- i++;
- }
-
- return false;
- }
-
- /**
- * Try offloading an item to a nearby container. Returns true if success.
- */
- boolean offloadDir(Tile tile, Item item){
- Tile other = tile.getNearby()[tile.rotation];
- if(other != null && other.block().accepts(item)){
- int ch = Math.abs(other.rotation - tile.rotation);
- other.block().handleItem(other, item, ch == 1 ? 0.5f : ch == 2 ? 1f : 0f);
- //other.entity.addCovey(item, ch == 1 ? 0.5f : ch ==2 ? 1f : 0f);
- return true;
- }
- return false;
- }
-
- public boolean accepts(Item item){
- return item == ammo;
- }
-
- public String description(){
- return "[no description]";
- }
-
- public void draw(Tile tile){
- if(tile.floor() == this){
- MathUtils.random.setSeed(tile.id());
- Draw.rect(name() + MathUtils.random(1, 3), tile.worldx(), tile.worldy(), rotate ? tile.rotation * 90 : 0);
- }else{
- Draw.rect(name(), tile.worldx(), tile.worldy(), rotate ? tile.rotation * 90 : 0);
- }
- }
-
- public String error(Tile tile){
- if(ammo != null && !tile.entity.hasItem(ammo) && tile.entity.shots <= 0)
- return "No ammo!";
-
- return null;
- }
-
- public void drawOver(Tile tile){
- /*
- * String error = error(tile); if(error != null){ Draw.color("scarlet");
- * Draw.square(tile.worldx(), tile.worldy(), 6); Draw.clear(); }
- */
- }
-
- public void update(Tile tile){
-
- }
-}
diff --git a/core/src/io/anuke/mindustry/world/blocks/Blocks.java b/core/src/io/anuke/mindustry/world/blocks/Blocks.java
new file mode 100644
index 0000000000..91d855168b
--- /dev/null
+++ b/core/src/io/anuke/mindustry/world/blocks/Blocks.java
@@ -0,0 +1,49 @@
+package io.anuke.mindustry.world.blocks;
+
+import io.anuke.mindustry.world.Block;
+import io.anuke.mindustry.world.Tile;
+
+public class Blocks{
+ public static final Block
+
+ air = new Block("air"){
+ //no drawing here
+ public void draw(Tile tile){}
+ },
+
+ stone = new Block("stone"),
+
+ dirt = new Block("dirt"),
+
+ iron = new Block("iron"),
+
+ coal = new Block("coal"),
+
+ grass = new Block("grass"),
+
+ stoneblock = new Block("stoneblock"){{
+ solid = true;
+ }},
+
+ dirtblock = new Block("dirtblock"){{
+ solid = true;
+ }},
+
+ stonewall = new Block("stonewall"){{
+ solid = true;
+ update = true;
+ health = 50;
+ }},
+
+ ironwall = new Block("ironwall"){{
+ solid = true;
+ update = true;
+ health = 80;
+ }},
+
+ steelwall = new Block("steelwall"){{
+ solid = true;
+ update = true;
+ health = 100;
+ }};
+}
diff --git a/core/src/io/anuke/mindustry/world/blocks/Conveyor.java b/core/src/io/anuke/mindustry/world/blocks/Conveyor.java
new file mode 100644
index 0000000000..fe8ba32bcc
--- /dev/null
+++ b/core/src/io/anuke/mindustry/world/blocks/Conveyor.java
@@ -0,0 +1,103 @@
+package io.anuke.mindustry.world.blocks;
+
+import static io.anuke.mindustry.Vars.tilesize;
+
+import com.badlogic.gdx.math.MathUtils;
+import com.badlogic.gdx.utils.DelayedRemovalArray;
+
+import io.anuke.mindustry.entities.TileEntity;
+import io.anuke.mindustry.resource.Item;
+import io.anuke.mindustry.world.Block;
+import io.anuke.mindustry.world.Tile;
+import io.anuke.ucore.core.Draw;
+import io.anuke.ucore.util.Mathf;
+import io.anuke.ucore.util.Timers;
+
+public class Conveyor extends Block{
+ float speed = 0.02f;
+
+ protected Conveyor(String name) {
+ super(name);
+ rotate = true;
+ update = true;
+ }
+
+ @Override
+ public void draw(Tile tile){
+ ConveyorEntity entity = tile.entity();
+
+ Draw.rect(name() + (Timers.time() % ((20 / 100f) / speed) < (10 / 100f) / speed ? "" : "move"), tile.worldx(), tile.worldy(), tile.rotation * 90);
+
+ for(ItemPos pos : entity.convey){
+ vector.set(tilesize, 0).rotate(tile.rotation * 90);
+ vector2.set(-tilesize / 2, pos.y*tilesize/2).rotate(tile.rotation * 90);
+
+ Draw.rect("icon-" + pos.item.name(),
+ tile.x * tilesize + vector.x * pos.pos + vector2.x,
+ tile.y * tilesize + vector.y * pos.pos + vector2.y, 4, 4);
+ }
+ }
+
+ @Override
+ public void update(Tile tile){
+ ConveyorEntity entity = tile.entity();
+
+ entity.convey.begin();
+
+ for(ItemPos pos : entity.convey){
+ pos.pos += speed * Mathf.delta();
+ pos.y = MathUtils.lerp(pos.y, 0, 0.14f * Mathf.delta());
+
+ if(pos.pos >= 1f && offloadDir(tile, pos.item)){
+ entity.convey.removeValue(pos, true);
+ continue;
+ }
+ pos.pos = Mathf.clamp(pos.pos);
+ }
+
+ entity.convey.end();
+ }
+
+ @Override
+ public TileEntity getEntity(){
+ return new ConveyorEntity();
+ }
+
+ @Override
+ public boolean accept(Item item){
+ return true;
+ }
+
+ @Override
+ public String description(){
+ return "Moves Items";
+ }
+
+ @Override
+ protected void handleItem(Tile tile, Item item, Tile source){
+ int ch = Math.abs(source.relativeTo(tile.x, tile.y) - tile.rotation);
+ int ang = ((source.relativeTo(tile.x, tile.y) - tile.rotation));
+
+
+ float pos = ch == 0 ? 0 : ch%2 == 1 ? 0.5f : 1f;
+ float y = (ang == -1 || ang == 3) ? 1 : (ang == 1 || ang == -3) ? -1 : 0;
+
+ ConveyorEntity entity = tile.entity();
+ entity.convey.add(new ItemPos(item, pos, y*0.9f));
+ }
+
+ static class ConveyorEntity extends TileEntity{
+ DelayedRemovalArray convey = new DelayedRemovalArray<>();
+ }
+
+ static class ItemPos{
+ public Item item;
+ public float pos, y;
+
+ public ItemPos(Item item, float pos, float y){
+ this.item = item;
+ this.pos = pos;
+ this.y = y;
+ }
+ }
+}
diff --git a/core/src/io/anuke/mindustry/world/blocks/Crafter.java b/core/src/io/anuke/mindustry/world/blocks/Crafter.java
new file mode 100644
index 0000000000..4443feaced
--- /dev/null
+++ b/core/src/io/anuke/mindustry/world/blocks/Crafter.java
@@ -0,0 +1,46 @@
+package io.anuke.mindustry.world.blocks;
+
+import io.anuke.mindustry.resource.Item;
+import io.anuke.mindustry.world.Block;
+import io.anuke.mindustry.world.Tile;
+import io.anuke.ucore.core.Effects;
+import io.anuke.ucore.util.Timers;
+
+public class Crafter extends Block{
+ protected Item[] requirements;
+ protected Item result;
+
+ public Crafter(String name) {
+ super(name);
+ update = true;
+ solid = true;
+ }
+
+ @Override
+ public void update(Tile tile){
+
+ if(Timers.get(tile, 20) && tile.entity.hasItem(result)){
+ tryDump(tile, -1, result);
+ }
+
+ for(Item item : requirements){
+ if(!tile.entity.hasItem(item)){
+ return;
+ }
+ }
+
+ for(Item item : requirements){
+ tile.entity.removeItem(item, 1);
+ }
+
+ offloadNear(tile, result);
+ Effects.effect("smelt", tile.entity);
+
+
+ }
+
+ @Override
+ public boolean accept(Item item){
+ return item == Item.iron || item == Item.coal;
+ }
+}
diff --git a/core/src/io/anuke/mindustry/world/blocks/Drill.java b/core/src/io/anuke/mindustry/world/blocks/Drill.java
new file mode 100644
index 0000000000..c3c89ddd0f
--- /dev/null
+++ b/core/src/io/anuke/mindustry/world/blocks/Drill.java
@@ -0,0 +1,62 @@
+package io.anuke.mindustry.world.blocks;
+
+import static io.anuke.mindustry.Vars.tilesize;
+
+import com.badlogic.gdx.graphics.Color;
+
+import io.anuke.mindustry.resource.Item;
+import io.anuke.mindustry.world.Block;
+import io.anuke.mindustry.world.Tile;
+import io.anuke.ucore.core.Draw;
+import io.anuke.ucore.core.Effects;
+import io.anuke.ucore.util.Timers;
+
+public class Drill extends Block{
+ protected Block resource;
+ protected Item result;
+ protected int time = 6;
+
+ public Drill(String name) {
+ super(name);
+ update = true;
+ solid = true;
+ }
+
+ @Override
+ public void update(Tile tile){
+
+ if(tile.floor() == resource && Timers.get(tile, 60 * time)){
+ offloadNear(tile, result);
+ Effects.effect("spark", tile.worldx(), tile.worldy());
+ }
+
+ if(Timers.get(tile.hashCode() + "dump", 30)){
+ tryDump(tile);
+ }
+ }
+
+ @Override
+ public String description(){
+ return "Mines 1 "+resource.name+" every "+time+" seconds.";
+ }
+
+ @Override
+ public void drawOverlay(Tile tile){
+
+ if(tile.floor() != resource){
+ Draw.tcolor(Color.SCARLET);
+ Draw.tscl(1 / 8f);
+ Draw.text("Not on " + resource.name + " block!", tile.worldx(), tile.worldy() + tilesize);
+ }
+
+ Draw.tscl(0.5f);
+ }
+
+ //@Override
+ public String error(Tile tile){
+ if(tile.floor() != resource)
+ return "Not on iron ore block!";
+ return null;
+ }
+
+}
diff --git a/core/src/io/anuke/mindustry/world/blocks/ProductionBlocks.java b/core/src/io/anuke/mindustry/world/blocks/ProductionBlocks.java
new file mode 100644
index 0000000000..36619d0abb
--- /dev/null
+++ b/core/src/io/anuke/mindustry/world/blocks/ProductionBlocks.java
@@ -0,0 +1,86 @@
+package io.anuke.mindustry.world.blocks;
+
+import io.anuke.mindustry.Inventory;
+import io.anuke.mindustry.resource.Item;
+import io.anuke.mindustry.world.Block;
+import io.anuke.mindustry.world.Tile;
+import io.anuke.ucore.util.Timers;
+
+public class ProductionBlocks{
+ public static final Block
+
+ core = new Block("core"){
+ {
+ health = 300;
+ solid = true;
+ update = true;
+ }
+
+ @Override
+ protected void handleItem(Tile tile, Item item, Tile source){
+ Inventory.addItem(item, 1);
+ }
+
+ @Override
+ public boolean accept(Item item){
+ return true;
+ }
+ },
+
+ conveyor = new Conveyor("conveyor"){{
+ update = true;
+ }},
+
+ steelconveyor = new Conveyor("steelconveyor"){{
+ update = true;
+ speed = 0.04f;
+ }},
+
+ router = new Block("router"){
+ {
+ update = true;
+ solid = true;
+ }
+
+ @Override
+ public void update(Tile tile){
+ if(Timers.get(tile, 10) && tile.entity.totalItems() > 0){
+ tryDump(tile, tile.rotation++, null);
+ tile.rotation %= 4;
+ }
+ }
+
+ @Override
+ public boolean accept(Item item){
+ return true;
+ }
+
+ @Override
+ public String description(){
+ return "Split input materials into 3 directions.";
+ }
+ },
+
+ smelter = new Crafter("smelter"){{
+ health = 70;
+ requirements = new Item[]{Item.coal, Item.iron};
+ result = Item.steel;
+ }},
+
+ stonedrill = new Drill("stonedrill"){{
+ resource = Blocks.stone;
+ result = Item.stone;
+ }},
+
+ irondrill = new Drill("irondrill"){{
+ resource = Blocks.iron;
+ result = Item.iron;
+ }},
+
+ coaldrill = new Drill("coaldrill"){{
+ resource = Blocks.coal;
+ result = Item.coal;
+ }},
+
+ end = null;
+}
diff --git a/core/src/io/anuke/mindustry/world/blocks/RepairTurret.java b/core/src/io/anuke/mindustry/world/blocks/RepairTurret.java
new file mode 100644
index 0000000000..5437d64343
--- /dev/null
+++ b/core/src/io/anuke/mindustry/world/blocks/RepairTurret.java
@@ -0,0 +1,61 @@
+package io.anuke.mindustry.world.blocks;
+
+import com.badlogic.gdx.math.MathUtils;
+
+import io.anuke.mindustry.World;
+import io.anuke.mindustry.world.Tile;
+import io.anuke.ucore.core.Draw;
+import io.anuke.ucore.graphics.Hue;
+import io.anuke.ucore.util.Timers;
+
+public class RepairTurret extends Turret{
+
+ public RepairTurret(String name) {
+ super(name);
+ }
+
+ @Override
+ public void update(Tile tile){
+ TurretEntity entity = tile.entity();
+
+ entity.target = World.findTileTarget(tile.worldx(), tile.worldy(), tile, range, true);
+
+ if(entity.target != null){
+ entity.rotation = entity.angleTo(entity.target);
+
+ if(Timers.get(tile, reload)){
+ entity.target.health++;
+ }
+ }
+ }
+
+ @Override
+ public void drawOver(Tile tile){
+ TurretEntity entity = tile.entity();
+
+ if(entity.target != null){
+ float x = tile.worldx(), y = tile.worldy();
+ float x2 = entity.target.x, y2 = entity.target.y;
+
+ Draw.color(Hue.rgb(138, 244, 138, (MathUtils.sin(Timers.time()) + 1f) / 14f));
+ Draw.alpha(0.3f);
+ Draw.thickness(4f);
+ Draw.line(x, y, x2, y2);
+ Draw.thickness(2f);
+ Draw.rect("circle", x2, y2, 7f, 7f);
+ Draw.alpha(1f);
+ Draw.thickness(2f);
+ Draw.line(x, y, x2, y2);
+ Draw.thickness(1f);
+ Draw.rect("circle", x2, y2, 5f, 5f);
+ Draw.clear();
+ }
+
+ Draw.rect(name(), tile.worldx(), tile.worldy(), entity.rotation - 90);
+ }
+
+ @Override
+ public String description(){
+ return "Heals nearby tiles.";
+ }
+}
diff --git a/core/src/io/anuke/mindustry/world/blocks/Turret.java b/core/src/io/anuke/mindustry/world/blocks/Turret.java
new file mode 100644
index 0000000000..fbd538c513
--- /dev/null
+++ b/core/src/io/anuke/mindustry/world/blocks/Turret.java
@@ -0,0 +1,122 @@
+package io.anuke.mindustry.world.blocks;
+import static io.anuke.mindustry.Vars.tilesize;
+
+import com.badlogic.gdx.graphics.Color;
+import com.badlogic.gdx.math.MathUtils;
+
+import io.anuke.mindustry.entities.*;
+import io.anuke.mindustry.resource.Item;
+import io.anuke.mindustry.world.Block;
+import io.anuke.mindustry.world.Tile;
+import io.anuke.ucore.core.Draw;
+import io.anuke.ucore.core.Effects;
+import io.anuke.ucore.entities.Entities;
+import io.anuke.ucore.util.Angles;
+import io.anuke.ucore.util.Timers;
+
+public class Turret extends Block{
+ protected float range = 50f;
+ protected float reload = 10f;
+ protected String shootsound = "shoot";
+ protected BulletType bullet;
+ protected Item ammo;
+
+ public Turret(String name) {
+ super(name);
+ update = true;
+ solid = true;
+ }
+
+ @Override
+ public void draw(Tile tile){
+ Draw.rect("block", tile.worldx(), tile.worldy());
+ }
+
+ @Override
+ public void drawOver(Tile tile){
+ TurretEntity entity = tile.entity();
+ Draw.rect(name(), tile.worldx(), tile.worldy(), entity.rotation - 90);
+ }
+
+ @Override
+ public void drawPixelOverlay(Tile tile){
+ Draw.color("green");
+ Draw.dashcircle(tile.worldx(), tile.worldy(), range);
+ Draw.clear();
+ }
+
+ @Override
+ public void drawOverlay(Tile tile){
+ TurretEntity entity = tile.entity();
+
+ if(entity.ammo <= 0 && ammo != null){
+ Draw.tcolor(Color.SCARLET);
+ Draw.tscl(1 / 8f);
+ Draw.text("No ammo!", tile.worldx(), tile.worldy() + tilesize);
+
+ }else if(ammo != null){
+ Draw.tscl(1 / 8f);
+ Draw.tcolor(Color.GREEN);
+ Draw.text("Ammo: " + entity.ammo, tile.worldx(), tile.worldy() - tilesize);
+ }
+
+ Draw.tscl(0.5f);
+ }
+
+ @Override
+ public boolean accept(Item item){
+ return item == ammo;
+ }
+
+ @Override
+ public String description(){
+ return "Shoots things.";
+ }
+
+ @Override
+ public void update(Tile tile){
+ TurretEntity entity = tile.entity();
+
+ if(entity.hasItem(ammo)){
+ entity.ammo += 20;
+ entity.removeItem(ammo, 1);
+ }
+
+ if(entity.ammo > 0){
+ Enemy enemy = (Enemy)Entities.getClosest(tile.worldx(), tile.worldy(), range, e->{
+ return e instanceof Enemy;
+ });
+
+ if(enemy != null){
+ entity.rotation = MathUtils.lerpAngleDeg(entity.rotation, Angles.predictAngle(tile.worldx(), tile.worldy(), enemy.x, enemy.y, enemy.xvelocity, enemy.yvelocity, bullet.speed - 0.1f), 0.2f);
+ if(Timers.get(tile, reload)){
+ Effects.sound(shootsound, entity);
+ shoot(tile);
+ entity.ammo --;
+ }
+ }
+ }
+ }
+
+ @Override
+ public TileEntity getEntity(){
+ return new TurretEntity();
+ }
+
+ protected void shoot(Tile tile){
+ TurretEntity entity = tile.entity();
+
+ vector.set(0, 4).setAngle(entity.rotation);
+ new Bullet(bullet, tile.entity, tile.worldx()+vector.x, tile.worldy()+vector.y, entity.rotation).add();
+ }
+
+ protected void bullet(Tile tile, float angle){
+ new Bullet(bullet, tile.entity, tile.worldx()+vector.x, tile.worldy()+vector.y, angle).add();
+ }
+
+ static class TurretEntity extends TileEntity{
+ public TileEntity target;
+ public int ammo;
+ public float rotation;
+ }
+}
diff --git a/core/src/io/anuke/mindustry/world/blocks/WeaponBlocks.java b/core/src/io/anuke/mindustry/world/blocks/WeaponBlocks.java
new file mode 100644
index 0000000000..7f1f9c12e8
--- /dev/null
+++ b/core/src/io/anuke/mindustry/world/blocks/WeaponBlocks.java
@@ -0,0 +1,109 @@
+package io.anuke.mindustry.world.blocks;
+
+import io.anuke.mindustry.entities.BulletType;
+import io.anuke.mindustry.resource.Item;
+import io.anuke.mindustry.world.Block;
+import io.anuke.mindustry.world.Tile;
+import io.anuke.ucore.util.Mathf;
+import io.anuke.ucore.util.Timers;
+
+public class WeaponBlocks{
+ public static Block
+
+ turret = new Turret("turret"){
+ {
+ range = 50;
+ reload = 10f;
+ bullet = BulletType.stone;
+ ammo = Item.stone;
+ }
+ },
+
+ doubleturret = new Turret("doubleturret"){
+ {
+ range = 40;
+ reload = 13f;
+ bullet = BulletType.stone;
+ ammo = Item.stone;
+ health = 50;
+ }
+
+ @Override
+ protected void shoot(Tile tile){
+ TurretEntity entity = tile.entity();
+
+ vector.set(4, -2).rotate(entity.rotation);
+ bullet(tile, entity.rotation);
+
+ vector.set(4, 2).rotate(entity.rotation);
+ bullet(tile, entity.rotation);
+ }
+ },
+
+ machineturret = new Turret("machineturret"){
+ {
+ range = 65;
+ reload = 7f;
+ bullet = BulletType.iron;
+ ammo = Item.iron;
+ health = 65;
+ }
+ },
+
+ shotgunturret = new Turret("shotgunturret"){
+ {
+ range = 50;
+ reload = 40f;
+ bullet = BulletType.iron;
+ ammo = Item.iron;
+ health = 70;
+ }
+
+ @Override
+ protected void shoot(Tile tile){
+ TurretEntity entity = tile.entity();
+
+ for(int i = 0; i < 6; i ++)
+ Timers.run(i/1.5f, ()->{
+ vector.set(4, 0).setAngle(entity.rotation);
+ bullet(tile, entity.rotation + Mathf.range(16));
+ });
+ }
+ },
+
+ flameturret = new Turret("flameturret"){
+ {
+ range = 35f;
+ reload = 5f;
+ bullet = BulletType.flame;
+ ammo = Item.coal;
+ health = 85;
+ }
+ },
+
+ sniperturret = new Turret("sniperturret"){
+ {
+ range = 100;
+ reload = 60f;
+ bullet = BulletType.sniper;
+ ammo = Item.steel;
+ health = 60;
+ }
+ },
+
+ repairturret = new RepairTurret("repairturret"){
+ {
+ range = 30;
+ reload = 40f;
+ health = 60;
+ }
+ },
+
+ megarepairturret = new RepairTurret("megarepairturret"){
+ {
+ range = 50;
+ reload = 20f;
+ health = 90;
+ }
+ };
+}
diff --git a/core/src/uCore.gwt.xml b/core/src/uCore.gwt.xml
deleted file mode 100644
index 2388a04522..0000000000
--- a/core/src/uCore.gwt.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
-
-
-
-
-
diff --git a/desktop/build.gradle b/desktop/build.gradle
index a7ee24d25f..18189a0f6e 100644
--- a/desktop/build.gradle
+++ b/desktop/build.gradle
@@ -3,7 +3,7 @@ apply plugin: "java"
sourceCompatibility = 1.8
sourceSets.main.java.srcDirs = [ "src/" ]
-project.ext.mainClassName = "io.anuke.moment.desktop.DesktopLauncher"
+project.ext.mainClassName = "io.anuke.mindustry.desktop.DesktopLauncher"
project.ext.assetsDir = new File("../core/assets");
task run(dependsOn: classes, type: JavaExec) {
diff --git a/desktop/gifexport/recording1493769807.gif b/desktop/gifexport/recording1493769807.gif
new file mode 100644
index 0000000000..2599004947
Binary files /dev/null and b/desktop/gifexport/recording1493769807.gif differ
diff --git a/desktop/gifexport/recording1493777288.gif b/desktop/gifexport/recording1493777288.gif
new file mode 100644
index 0000000000..7b56bb911b
Binary files /dev/null and b/desktop/gifexport/recording1493777288.gif differ
diff --git a/desktop/gifexport/recording1493777471.gif b/desktop/gifexport/recording1493777471.gif
new file mode 100644
index 0000000000..f08b941246
Binary files /dev/null and b/desktop/gifexport/recording1493777471.gif differ
diff --git a/desktop/gifexport/recording1493777483.gif b/desktop/gifexport/recording1493777483.gif
new file mode 100644
index 0000000000..5ec133ce18
Binary files /dev/null and b/desktop/gifexport/recording1493777483.gif differ
diff --git a/desktop/gifexport/recording1493777703.gif b/desktop/gifexport/recording1493777703.gif
new file mode 100644
index 0000000000..3578a6b898
Binary files /dev/null and b/desktop/gifexport/recording1493777703.gif differ
diff --git a/desktop/src/io/anuke/moment/desktop/DesktopLauncher.java b/desktop/src/io/anuke/mindustry/desktop/DesktopLauncher.java
similarity index 60%
rename from desktop/src/io/anuke/moment/desktop/DesktopLauncher.java
rename to desktop/src/io/anuke/mindustry/desktop/DesktopLauncher.java
index 173398ae10..0c416136e6 100644
--- a/desktop/src/io/anuke/moment/desktop/DesktopLauncher.java
+++ b/desktop/src/io/anuke/mindustry/desktop/DesktopLauncher.java
@@ -1,17 +1,14 @@
-package io.anuke.moment.desktop;
+package io.anuke.mindustry.desktop;
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application;
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration;
-
-import io.anuke.mindustry.Moment;
+import io.anuke.mindustry.Mindustry;
public class DesktopLauncher {
public static void main (String[] arg) {
Lwjgl3ApplicationConfiguration config = new Lwjgl3ApplicationConfiguration();
- config.setTitle("Moment");
+ config.setTitle("Mindustry");
config.setMaximized(true);
- config.useVsync(false);
- config.setWindowedMode(800, 600);
- new Lwjgl3Application(new Moment(), config);
+ new Lwjgl3Application(new Mindustry(), config);
}
}
diff --git a/html/build.gradle b/html/build.gradle
index d04d6d63e6..aa1759083c 100644
--- a/html/build.gradle
+++ b/html/build.gradle
@@ -7,8 +7,8 @@ gwt {
minHeapSize="1G"
src = files(file("src/")) // Needs to be in front of "modules" below.
- modules 'io.anuke.moment.GdxDefinition'
- devModules 'io.anuke.moment.GdxDefinitionSuperdev'
+ modules 'io.anuke.mindustry.GdxDefinition'
+ devModules 'io.anuke.mindustry.GdxDefinitionSuperdev'
project.webAppDirName = 'webapp'
compiler {
diff --git a/html/src/io/anuke/moment/GdxDefinition.gwt.xml b/html/src/io/anuke/mindustry/GdxDefinition.gwt.xml
similarity index 74%
rename from html/src/io/anuke/moment/GdxDefinition.gwt.xml
rename to html/src/io/anuke/mindustry/GdxDefinition.gwt.xml
index 20ac9bda6a..c032402765 100644
--- a/html/src/io/anuke/moment/GdxDefinition.gwt.xml
+++ b/html/src/io/anuke/mindustry/GdxDefinition.gwt.xml
@@ -1,12 +1,12 @@
-
+
+
-
+
-
-
+
diff --git a/html/src/io/anuke/moment/GdxDefinitionSuperdev.gwt.xml b/html/src/io/anuke/mindustry/GdxDefinitionSuperdev.gwt.xml
similarity index 80%
rename from html/src/io/anuke/moment/GdxDefinitionSuperdev.gwt.xml
rename to html/src/io/anuke/mindustry/GdxDefinitionSuperdev.gwt.xml
index a93917b545..59fcbe6a4d 100644
--- a/html/src/io/anuke/moment/GdxDefinitionSuperdev.gwt.xml
+++ b/html/src/io/anuke/mindustry/GdxDefinitionSuperdev.gwt.xml
@@ -2,8 +2,9 @@
+
-
+
diff --git a/html/src/io/anuke/moment/client/HtmlLauncher.java b/html/src/io/anuke/mindustry/client/HtmlLauncher.java
similarity index 91%
rename from html/src/io/anuke/moment/client/HtmlLauncher.java
rename to html/src/io/anuke/mindustry/client/HtmlLauncher.java
index c7276f7435..ea532df17f 100644
--- a/html/src/io/anuke/moment/client/HtmlLauncher.java
+++ b/html/src/io/anuke/mindustry/client/HtmlLauncher.java
@@ -1,15 +1,14 @@
-package io.anuke.moment.client;
+package io.anuke.mindustry.client;
import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.backends.gwt.GwtApplication;
import com.badlogic.gdx.backends.gwt.GwtApplicationConfiguration;
+import io.anuke.mindustry.Mindustry;
import com.google.gwt.dom.client.*;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.VerticalPanel;
-import io.anuke.mindustry.Moment;
-
public class HtmlLauncher extends GwtApplication {
static final int WIDTH = 800;
static final int HEIGHT = 600;
@@ -49,7 +48,7 @@ public class HtmlLauncher extends GwtApplication {
setupResizeHook();
}
});
- return new Moment();
+ return new Mindustry();
}
void scaleCanvas() {
@@ -90,11 +89,11 @@ public class HtmlLauncher extends GwtApplication {
}-*/;
native void setupResizeHook() /*-{
- var htmlLauncher_onWindowResize = $entry(@io.anuke.moment.client.HtmlLauncher::handleResize());
+ var htmlLauncher_onWindowResize = $entry(@io.anuke.mindustry.client.HtmlLauncher::handleResize());
$wnd.addEventListener('resize', htmlLauncher_onWindowResize, false);
}-*/;
public static void handleResize() {
instance.scaleCanvas();
}
-}
\ No newline at end of file
+}
diff --git a/html/webapp/index.html b/html/webapp/index.html
index 38cd2ae995..bf0395e9fa 100644
--- a/html/webapp/index.html
+++ b/html/webapp/index.html
@@ -1,14 +1,14 @@
- Moment
+ Mindustry
-
+