Skip to content

Commit

Permalink
Simplified
Browse files Browse the repository at this point in the history
  • Loading branch information
armin-reichert committed Jan 6, 2025
1 parent 590cd88 commit f4c9264
Showing 1 changed file with 10 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
import javafx.scene.image.ImageView;
import javafx.scene.input.KeyCode;
import javafx.scene.paint.Color;
import javafx.scene.paint.PhongMaterial;
import javafx.scene.shape.Box;

import static de.amr.games.pacman.lib.Globals.HTS;
import static de.amr.games.pacman.lib.Globals.TS;
Expand All @@ -46,31 +44,25 @@ protected void replaceGameLevel3D() {

private void addGameOptionsArea(MsPacManGameTengen game) {
TileMap terrain = context.level().world().map().terrain();
float scale = 6;
int unscaledWidth = terrain.numCols() * TS;
int unscaledHeight = TS;

float scale = 5; // for better quality
var canvas = new Canvas(scale * unscaledWidth, scale * unscaledHeight);
canvas.getGraphicsContext2D().setImageSmoothing(false); // important!

var renderer = (TengenMsPacMan_Renderer2D) context.gameConfiguration().createRenderer(context.assets(), canvas);
renderer.ctx().setImageSmoothing(false);
renderer.fillCanvas(level3D.floorColor());
renderer.setScaling(scale);
renderer.fillCanvas(level3D.floorColor());
renderer.drawGameOptionsInfoCenteredAt(0.5 * unscaledWidth, HTS, game);

ImageView snap = new ImageView(canvas.snapshot(null, null));
snap.setFitWidth(unscaledWidth);
snap.setFitHeight(unscaledHeight);

Box surface = new Box(unscaledWidth, unscaledHeight, 0.05);
var texture = new PhongMaterial();
texture.setDiffuseMap(snap.getImage());
surface.setMaterial(texture);

surface.setTranslateX(unscaledWidth * 0.5);
surface.setTranslateY(terrain.numRows() * TS - 1.5 * TS);
surface.setTranslateZ(-level3D.floorThickness());
ImageView infoView = new ImageView(canvas.snapshot(null, null));
infoView.setFitWidth(unscaledWidth);
infoView.setFitHeight(unscaledHeight);
infoView.setTranslateY(terrain.numRows() * TS - 1.5 * TS);
infoView.setTranslateZ(-level3D.floorThickness());

level3D.getChildren().add(surface);
level3D.getChildren().add(infoView);
}

@Override
Expand Down

0 comments on commit f4c9264

Please sign in to comment.