mirror of
https://github.com/ynerant/Level-Editor.git
synced 2024-12-17 21:22:19 +00:00
Fixed collisions in editor and sample map
This commit is contained in:
parent
e50d485e4b
commit
37f0b663fc
Binary file not shown.
@ -66,7 +66,7 @@ object EditorAPI {
|
||||
implicit val formats: DefaultFormats.type = DefaultFormats
|
||||
val json = Serialization.writePretty(map)
|
||||
try {
|
||||
assert(file.createNewFile)
|
||||
assert(file.exists() || file.createNewFile)
|
||||
val bos = new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream(file)))
|
||||
bos.write(json.getBytes(StandardCharsets.UTF_8))
|
||||
bos.close()
|
||||
|
@ -31,26 +31,21 @@ class CollidPanel(val frame: EditorFrame) extends JPanel {
|
||||
val height = img.getHeight * 2
|
||||
g.drawImage(getMap.getFont, x, y, width, height, null)
|
||||
getMap.getAllCases.foreach(c => {
|
||||
if (!CollidPanel.isEmpty(c.getCoucheOne.getImage)) {
|
||||
g.drawImage(c.getCoucheOne.getImage, x + c.getPosX * 34 + 2, y + c.getPosY * 34 + 2, 32, 32, null)
|
||||
if (!CollidPanel.isEmpty(c.getCoucheTwo.getImage)) {
|
||||
g.drawImage(c.getCoucheTwo.getImage, x + c.getPosX * 34 + 2, y + c.getPosY * 34 + 2, 32, 32, null)
|
||||
if (!CollidPanel.isEmpty(c.getCoucheThree.getImage))
|
||||
g.drawImage(c.getCoucheThree.getImage, x + c.getPosX * 34 + 2, y + c.getPosY * 34 + 2, 32, 32, null)
|
||||
}
|
||||
}
|
||||
if (!CollidPanel.isEmpty(c.getCoucheOne.getImage)) g.drawImage(c.getCoucheOne.getImage, x + c.getPosX * 34 + 2, y + c.getPosY * 34 + 2, 32, 32, null)
|
||||
if (!CollidPanel.isEmpty(c.getCoucheTwo.getImage)) g.drawImage(c.getCoucheTwo.getImage, x + c.getPosX * 34 + 2, y + c.getPosY * 34 + 2, 32, 32, null)
|
||||
if (!CollidPanel.isEmpty(c.getCoucheThree.getImage)) g.drawImage(c.getCoucheThree.getImage, x + c.getPosX * 34 + 2, y + c.getPosY * 34 + 2, 32, 32, null)
|
||||
})
|
||||
|
||||
getMap.getAllCases.foreach(c => {
|
||||
if (c.getCollision.equals(Collision.ANY)) {
|
||||
if (!c.getCollision.equals(Collision.ANY)) {
|
||||
val alpha = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB)
|
||||
if (c.getCollision eq Collision.FULL) {
|
||||
if (c.getCollision.equals(Collision.FULL)) {
|
||||
val grap = alpha.createGraphics
|
||||
grap.setColor(new Color(0, 0, 0, 100))
|
||||
grap.fillRect(0, 0, 16, 16)
|
||||
grap.dispose()
|
||||
}
|
||||
else if (c.getCollision eq Collision.PARTIAL) {
|
||||
else if (c.getCollision.equals(Collision.PARTIAL)) {
|
||||
val grap = alpha.createGraphics
|
||||
grap.setColor(new Color(255, 0, 255, 70))
|
||||
grap.fillRect(0, 0, 16, 16)
|
||||
|
@ -18,21 +18,8 @@ class MapPanel(val frame: EditorFrame) extends JPanel {
|
||||
g.drawImage(getMap.getFont, x, y, width, height, null)
|
||||
getMap.getAllCases.foreach(c => { // BufferedImage image;
|
||||
if (!isEmpty(c.getCoucheOne.getImage)) g.drawImage(c.getCoucheOne.getImage, x + c.getPosX * 34 + 2, y + c.getPosY * 34 + 2, 32, 32, null)
|
||||
/* if (frame.getSelectedLayerIndex() != 0)
|
||||
{
|
||||
image = recalculateAplha(c.getCoucheOne().getImage(), 0);
|
||||
g.drawImage(image, x + c.getPosX() * 34 + 2, y + c.getPosY() * 34 + 2, 32, 32, null);
|
||||
}*/ if (!isEmpty(c.getCoucheTwo.getImage) && frame.getSelectedLayerIndex >= 1) g.drawImage(c.getCoucheTwo.getImage, x + c.getPosX * 34 + 2, y + c.getPosY * 34 + 2, 32, 32, null)
|
||||
/* if (frame.getSelectedLayerIndex() != 1)
|
||||
{
|
||||
image = recalculateAplha(c.getCoucheTwo().getImage(), 1);
|
||||
g.drawImage(image, x + c.getPosX() * 34 + 2, y + c.getPosY() * 34 + 2, 32, 32, null);
|
||||
}*/ if (!isEmpty(c.getCoucheThree.getImage) && frame.getSelectedLayerIndex == 2) g.drawImage(c.getCoucheThree.getImage, x + c.getPosX * 34 + 2, y + c.getPosY * 34 + 2, 32, 32, null)
|
||||
/* if (frame.getSelectedLayerIndex() != 2)
|
||||
{
|
||||
image = recalculateAplha(c.getCoucheThree().getImage(), 2);
|
||||
g.drawImage(image, x + c.getPosX() * 34 + 2, y + c.getPosY() * 34 + 2, 32, 32, null);
|
||||
}*/
|
||||
if (!isEmpty(c.getCoucheTwo.getImage) && frame.getSelectedLayerIndex >= 1) g.drawImage(c.getCoucheTwo.getImage, x + c.getPosX * 34 + 2, y + c.getPosY * 34 + 2, 32, 32, null)
|
||||
if (!isEmpty(c.getCoucheThree.getImage) && frame.getSelectedLayerIndex == 2) g.drawImage(c.getCoucheThree.getImage, x + c.getPosX * 34 + 2, y + c.getPosY * 34 + 2, 32, 32, null)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@ package fr.ynerant.leveleditor.frame.listeners
|
||||
|
||||
import java.awt.event.{MouseAdapter, MouseEvent}
|
||||
|
||||
import fr.ynerant.leveleditor.api.editor.Case
|
||||
import fr.ynerant.leveleditor.api.editor.{Case, Collision}
|
||||
import fr.ynerant.leveleditor.editor.{CollidPanel, EditorFrame}
|
||||
|
||||
|
||||
@ -15,7 +15,12 @@ class CollidMapMouseListener(val panel: CollidPanel, val frame: EditorFrame) ext
|
||||
val y = panel.getHeight / 2 - map.getFont.getHeight
|
||||
val c = map.getCase((event.getX - x + 2) / 34, (event.getY - y + 2) / 34)
|
||||
if (c != null && event.getX - x >= 2 && event.getY - y >= 2) {
|
||||
val n = Case.create(c.getPosX, c.getPosY, c.getCoucheOne, c.getCoucheTwo, c.getCoucheThree, c.getCollision)
|
||||
val col = c.getCollision match {
|
||||
case Collision.ANY => Collision.PARTIAL
|
||||
case Collision.PARTIAL => Collision.FULL
|
||||
case Collision.FULL => Collision.ANY
|
||||
}
|
||||
val n = Case.create(c.getPosX, c.getPosY, c.getCoucheOne, c.getCoucheTwo, c.getCoucheThree, col)
|
||||
map.setCase((event.getX - x + 2) / 34, (event.getY - y + 2) / 34, n)
|
||||
panel.repaint()
|
||||
}
|
||||
|
@ -161,8 +161,6 @@ class GameFrame(val map: RawMap) extends JFrame("Jeu") {
|
||||
|
||||
val accessible = getMap.getCases.filter(c => !Collision.FULL.equals(c.getCollision))
|
||||
if (accessible.exists(c => c.getPosX > 0 && pathFinder.nextPos(c.getPosX, c.getPosY) == null) || !accessible.exists(c => c.getPosX == 0 && !c.getCollision.equals(Collision.FULL))) {
|
||||
println(accessible.exists(c => c.getPosX > 0 && pathFinder.nextPos(c.getPosX, c.getPosY) == null))
|
||||
println(!accessible.exists(c => c.getPosX == 0 && pathFinder.nextPos(c.getPosX, c.getPosY) != null))
|
||||
// We ensure that the end of the game is accessible from everywhere, the tower should not block the game
|
||||
c.setCollision(Collision.ANY)
|
||||
pathFinder.invalidate()
|
||||
|
Loading…
Reference in New Issue
Block a user