93 lines
3.4 KiB
Markdown
93 lines
3.4 KiB
Markdown
# CLAUDE.md
|
|
|
|
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
|
|
## Project Overview
|
|
|
|
This is an Asteroids-style game originally written in Turbo Pascal 7 for DOS, now being converted to modern C++ with SDL2. The game features a spaceship that must avoid and destroy enemies ("cosinus mesisinus" mounted in UFOs/ORNIs). The codebase contains both the original Pascal implementation and the in-progress C++ port.
|
|
|
|
**Language**: The code and comments are in Catalan/Valencian.
|
|
|
|
## Build Commands
|
|
|
|
**macOS**:
|
|
```bash
|
|
make macos
|
|
./bin/asteroids_macos
|
|
```
|
|
|
|
**Linux**:
|
|
```bash
|
|
make linux
|
|
./bin/asteroids_linux
|
|
```
|
|
|
|
Both commands compile from `source/*.cpp` with `-std=c++11 -Wall -O2` and link against SDL2.
|
|
|
|
## Architecture
|
|
|
|
### Code Structure
|
|
|
|
- `source/ASTEROID.PAS` - Original Turbo Pascal 7 implementation (DOS)
|
|
- `source/asteroids.cpp` - C++ port using SDL2 (in progress)
|
|
|
|
### Core Data Structures
|
|
|
|
The game uses polar coordinates (`ipunt`) for geometric objects:
|
|
- `ipunt` - Polar coordinate point (radius `r`, angle `angle`)
|
|
- `punt` - Cartesian coordinate point (x, y)
|
|
- `triangle` - The player's ship (3 polar points + center + angle + velocity)
|
|
- `poligon` - Generic polygon for enemies and bullets (vector of polar points + center + angle + velocity + rotation)
|
|
|
|
### Key Game Constants
|
|
|
|
Defined in `asteroids.cpp`:
|
|
- Screen bounds: `MARGE_DALT` (20), `MARGE_BAIX` (460), `MARGE_ESQ` (20), `MARGE_DRET` (620)
|
|
- `MAX_ORNIS` (15) - Maximum enemies
|
|
- `MAX_BALES` (3) - Maximum bullets
|
|
- `VELOCITAT` (2), `VELOCITAT_MAX` (6) - Speed constraints
|
|
|
|
### Rendering System
|
|
|
|
The original Pascal code used VGA Mode 13h (320x200, 256 colors) with custom bit-packed framebuffer:
|
|
- `pvirt` - Virtual screen buffer (38400 bytes)
|
|
- `posa(x,y,color)` - Set pixel in virtual buffer (bit-packed)
|
|
- `llig(x,y)` - Read pixel from virtual buffer
|
|
- `volca()` - Flip virtual buffer to VGA memory
|
|
- Line drawing using Bresenham algorithm
|
|
|
|
The C++ port uses SDL2 for rendering.
|
|
|
|
### Game Mechanics
|
|
|
|
- **Movement**: Ship uses polar velocity - angle determines direction, velocity determines speed
|
|
- **Collision**: Line drawing returns collision state; `rota_tri()` returns 1 on pixel collision
|
|
- **Death sequence**: Ship shrinks (`nau.p*.r` decreases), explodes into debris (`chatarra_cosmica`), then respawns after 250 frames
|
|
- **Enemies**: `orni[]` array of polygons with autonomous movement, random angle adjustments
|
|
- **Bullets**: Only one bullet active at a time (`bales[1].esta` flag)
|
|
|
|
### Pascal-to-C++ Conversion Notes
|
|
|
|
The C++ file contains hybrid Pascal/C++ syntax that needs completion:
|
|
- Lines 63-450 are uncommented Pascal code
|
|
- Pascal procedures/functions need conversion to C++ equivalents
|
|
- Assembly blocks (`waitretrace`, VGA mode setting) need SDL2 replacements
|
|
- Turbo Pascal keyboard handling (`teclapuls`, `instalarkb`) needs SDL event system
|
|
- Memory management (`getmem`, pointer segments) needs modern C++ approach
|
|
|
|
### Game Controls (from README)
|
|
|
|
- Up Arrow: Accelerate
|
|
- Down Arrow: Brake
|
|
- Right Arrow: Rotate clockwise
|
|
- Left Arrow: Rotate counterclockwise
|
|
- Space: Fire
|
|
- Esc: Exit
|
|
|
|
## Development Notes
|
|
|
|
- The conversion is incomplete - much Pascal code remains in comments
|
|
- Focus on SDL2 for cross-platform graphics/input instead of DOS VGA/keyboard
|
|
- Original used bit-packed monochrome framebuffer; consider SDL surfaces or textures
|
|
- Preserve the polar coordinate geometry system - it's core to the game's physics
|