-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsketch.js
More file actions
147 lines (123 loc) · 3.43 KB
/
Copy pathsketch.js
File metadata and controls
147 lines (123 loc) · 3.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
let CANVAS_X = 800; // Default 800
let CANVAS_Y = 800; // Default 800
const TILE_SIZE = 32; // Default 35
const NONE = '\0';
let SEED;
let MAP;
let GRIDMAP;
let COORDSY;
let font;
let recordingPath
function preload(){
test_stats();
terrainPreloader()
Ants_Preloader()
Resources_Preloader();
font = loadFont("Images/Assets/Terraria.TTF");
}
// MOUSE INTERACTIONS
function mousePressed() {
if (isInGame()) { // only allow ant interactions in game
if (typeof handleMousePressed === 'function') {
handleMousePressed(
ants,
mouseX,
mouseY,
Ant_Click_Control,
selectedAnt,
moveSelectedAntToTile,
TILE_SIZE,
mouseButton
);
}
}
// Handle menu button clicks
handleMenuClick();
}
function mouseDragged() {
if (isInGame() && typeof handleMouseDragged === 'function') {
handleMouseDragged(mouseX, mouseY, ants);
}
}
function mouseReleased() {
if (isInGame() && typeof handleMouseReleased === 'function') {
handleMouseReleased(ants);
}
}
// KEYBOARD INTERACTIONS
function keyPressed() {
if (keyCode === ESCAPE) {
if (typeof deselectAllEntities === 'function') {
deselectAllEntities();
}
}
}
////// MAIN
function setup() {
CANVAS_X = windowWidth;
CANVAS_Y = windowHeight;
createCanvas(CANVAS_X, CANVAS_Y);
SEED = hour()*minute()*floor(second()/10);
MAP = new Terrain(CANVAS_X,CANVAS_Y,TILE_SIZE);
MAP.randomize(SEED);
COORDSY = MAP.getCoordinateSystem();
COORDSY.setViewCornerBC(0,0);
GRIDMAP = new PathMap(MAP);
COORDSY = MAP.getCoordinateSystem(); // Get Backing canvas coordinate system
COORDSY.setViewCornerBC(0,0); // Top left corner of VIEWING canvas on BACKING canvas, (0,0) by default. Included to demonstrate use. Update as needed with camera
////
initializeMenu(); // Initialize the menu system
Ants_Spawn(50);
Resources_Spawn(20);
}
function draw() {
MAP.render();
Ants_Update();
Resources_Update();
if (typeof drawSelectionBox === 'function') {
drawSelectionBox();
}
drawDebugGrid(tileSize, GRIDMAP.width, GRIDMAP.height);
if(recordingPath){
}
}
function drawDebugGrid(tileSize, gridWidth, gridHeight) {
stroke(100, 100, 100, 100); // light gray grid lines
strokeWeight(1);
noFill();
for (let x = 0; x < gridWidth; x++) {
for (let y = 0; y < gridHeight; y++) {
rect(x * tileSize, y * tileSize, tileSize, tileSize);
}
}
// Highlight tile under mouse
const tileX = Math.floor(mouseX / tileSize);
const tileY = Math.floor(mouseY / tileSize);
fill(255, 255, 0, 50); // transparent yellow
noStroke();
rect(tileX * tileSize, tileY * tileSize, tileSize, tileSize);
// Highlight selected ant's current tile
if (selectedAnt) {
const antTileX = Math.floor(selectedAnt.posX / tileSize);
const antTileY = Math.floor(selectedAnt.posY / tileSize);
fill(0, 255, 0, 80); // transparent green
noStroke();
rect(antTileX * tileSize, antTileY * tileSize, tileSize, tileSize);
}
}
function draw() {
// Update menu state and handle transitions
updateMenu();
// Render menu if active, otherwise render game
if (renderMenu()) {
return; // Menu rendered, stop here
}
// --- GAMEPLAY RENDERING ---
MAP.render();
Ants_Update();
Resources_Update();
if (typeof drawSelectionBox === 'function') drawSelectionBox();
drawDebugGrid(TILE_SIZE, GRIDMAP.width, GRIDMAP.height);
// Draw fade overlay if transitioning
drawFadeOverlay();
}