Initial commit: labirynt 3D pseudo-raycasting game

This commit is contained in:
lukasz@orzechowski.eu
2026-02-07 10:20:50 +01:00
commit a7f14c010f
132 changed files with 5319 additions and 0 deletions

50
lib/player.dart Normal file
View File

@@ -0,0 +1,50 @@
import 'dart:math';
import 'maze.dart';
class Player {
double x;
double y;
double angle;
static const double moveSpeed = 0.05;
static const double rotSpeed = 0.04;
Player({required this.x, required this.y, this.angle = 0});
void moveForward(Maze maze) {
_tryMove(maze, cos(angle) * moveSpeed, sin(angle) * moveSpeed);
}
void moveBackward(Maze maze) {
_tryMove(maze, -cos(angle) * moveSpeed, -sin(angle) * moveSpeed);
}
void strafeLeft(Maze maze) {
_tryMove(maze, cos(angle - pi / 2) * moveSpeed, sin(angle - pi / 2) * moveSpeed);
}
void strafeRight(Maze maze) {
_tryMove(maze, cos(angle + pi / 2) * moveSpeed, sin(angle + pi / 2) * moveSpeed);
}
void rotateLeft() {
angle -= rotSpeed;
}
void rotateRight() {
angle += rotSpeed;
}
void _tryMove(Maze maze, double dx, double dy) {
const margin = 0.2;
final nx = x + dx;
final ny = y + dy;
if (!maze.isWall((nx + margin).toInt(), y.toInt()) &&
!maze.isWall((nx - margin).toInt(), y.toInt())) {
x = nx;
}
if (!maze.isWall(x.toInt(), (ny + margin).toInt()) &&
!maze.isWall(x.toInt(), (ny - margin).toInt())) {
y = ny;
}
}
}