-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrldev-6.html
410 lines (307 loc) · 16.4 KB
/
rldev-6.html
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="/assets/styles/styles.css">
<link rel="stylesheet" href="https://indestructibletype.com/fonts/Jost.css" type="text/css" charset="utf-8" />
<script src="https://kit.fontawesome.com/79c31398dc.js" crossorigin="anonymous"></script>
<!-- favicon -->
<link rel="apple-touch-icon" sizes="180x180" href="/assets/img/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/assets/img/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/assets/img/favicon-16x16.png">
<link rel="manifest" href="/assets/img/site.webmanifest">
<link rel="mask-icon" href="/assets/img/safari-pinned-tab.svg" color="#5bbad5">
<link rel="shortcut icon" href="/assets/img/favicon.ico">
<meta name="msapplication-TileColor" content="#da532c">
<meta name="msapplication-config" content="/assets/img/browserconfig.xml">
<meta name="theme-color" content="#ffffff">
<!-- feed -->
<link type="application/atom+xml" rel="alternate" href="https://efredericks.github.io/feed.xml" title="erik fredericks" />
<!-- Begin Jekyll SEO tag v2.8.0 -->
<title>fredericks does the roguelikedev tutorial - 6 | erik fredericks</title>
<meta name="generator" content="Jekyll v3.9.5" />
<meta property="og:title" content="fredericks does the roguelikedev tutorial - 6" />
<meta name="author" content="efredericks" />
<meta property="og:locale" content="en_US" />
<meta name="description" content="bugfixes, big maps, cellular automata" />
<meta property="og:description" content="bugfixes, big maps, cellular automata" />
<meta property="twitter:description" content="bugfixes, big maps, cellular automata" />
<link rel="canonical" href="https://efredericks.github.io/rldev-6.html" />
<meta property="og:url" content="https://efredericks.github.io/rldev-6.html" />
<meta property="og:site_name" content="erik fredericks" />
<meta property="og:type" content="article" />
<meta property="article:published_time" content="2023-08-09T00:00:00-04:00" />
<meta name="twitter:card" content="summary" />
<meta property="twitter:title" content="fredericks does the roguelikedev tutorial - 6" />
<meta name="twitter:site" content="@efredericks" />
<meta name="twitter:creator" content="@efredericks" />
<script type="application/ld+json">
{"@context":"https://schema.org","@type":"BlogPosting","author":{"@type":"Person","name":"efredericks"},"dateModified":"2023-08-09T00:00:00-04:00","datePublished":"2023-08-09T00:00:00-04:00","description":"bugfixes, big maps, cellular automata","headline":"fredericks does the roguelikedev tutorial - 6","mainEntityOfPage":{"@type":"WebPage","@id":"https://efredericks.github.io/rldev-6.html"},"url":"https://efredericks.github.io/rldev-6.html"}</script>
<!-- End Jekyll SEO tag -->
</head>
<body>
<aside class="menu">
<div class="menu-top">
<div class="menu-top_logo">
<a href="/" >
<img src="/assets/img/Fredericks-Small.jpg" alt="Logo" onerror="this.style.display='none'">
</a>
</div>
<div class="menu-top_expand" onclick="toggleExpander(this)">
<div class="bar_top"></div>
<div class="bar_middle"></div>
<div class="bar_bottom"></div>
</div>
<ul class="navigation">
<li>
<a href="/" category="home" title=""
>
<span>home</span>
</a>
</li>
<li>
<a href="/students.html" category="students" title="students tooltip"
>
<span>students</span>
</a>
</li>
<li>
<a href="/teaching.html" category="teaching" title="teaching tooltip"
>
<span>teaching</span>
</a>
</li>
<li>
<a href="/publications.html" category="publications" title="publications tooltip"
>
<span>publications</span>
</a>
</li>
<li>
<a href="/activities.html" category="activities" title="activities tooltip"
>
<span>activities</span>
</a>
</li>
<li>
<a href="/posts/" category="" title=""
class="selected"
>
<span>posts</span>
</a>
</li>
</ul>
</div>
<div class="menu-contact">
<a href="https://github.com/efredericks" target="_blank">
<i class="fa fa-github"></i>
</a>
<a href="https://scholar.google.com/citations?user=wpdiGa0AAAAJ" target="_blank">
<i class="fa fa-toilet-paper"></i>
</a>
<a href="https://youtube.com/@erikfredericks" target="_blank">
<i class="fa fa-youtube-play"></i>
</a>
<a href="https://twitch.tv/mrdoktorprofessor" target="_blank">
<i class="fa fa-twitch"></i>
</a>
<a href="https://twitter.com/erik_fredericks" target="_blank">
<i class="fab fa-twitter"></i>
</a>
<a href="mailto:[email protected]" target="">
<i class="fas fa-envelope"></i>
</a>
</div>
</aside>
<main class="content-layout">
<div class="post">
<div class="content-container ">
<header>
<h1>fredericks does the roguelikedev tutorial - 6</h1>
</header>
<div class="post-content">
<hr size="1" />
<ul>
<li>
<p><a href="https://www.reddit.com/r/roguelikedev/comments/15lnxy2/roguelikedev_does_the_complete_roguelike_tutorial/jvfnwkh/" target="_blank">Week 6 post</a></p>
</li>
<li>
<p><a href="https://github.com/efredericks/RL-MMO" target="\_blank">Project repo</a></p>
</li>
</ul>
<hr size="1" />
<p>This week involved a bit of navel gazing - what do I want this game to eventually be? What is fun and what is not?</p>
<p>Given that I started this as an homage to RotMG I wanted to start moving in that direction for the actual design and balance. The main concepts will (eventually) be large maps, loot, items that progressively get more and more useful based on enemy difficulty, etc. Spoiler warning - I didn’t get to the whole items bit, but it is good for future updates to consider.</p>
<p>Also some bugfixing and basic animation. Lets start there, shall we?</p>
<hr />
<h2 id="animation">Animation</h2>
<p>The animation was actually a lot easier to implement than I had thought. I’ve done this in the past in terms of client-side-only JS games, however receiving positional information from the server was going to be tricky (I thought).</p>
<p>It wasn’t really.</p>
<p>I always go back to the <a href="https://nluqo.github.io/broughlike-tutorial/stage7.html" target="\_blank">Broughlike tutorial</a> for JS roguelikes. It involves adding an <code class="language-plaintext highlighter-rouge">offset</code> attribute for the x/y coordinates and nicely degrading it as we animate in. I was able to do something similar.</p>
<p>Each <code class="language-plaintext highlighter-rouge">MoveableEntity</code> gets an <code class="language-plaintext highlighter-rouge">offsetX</code>/<code class="language-plaintext highlighter-rouge">offsetY</code> attribute on instantiation.</p>
<p>Drawing is as simple as tacking that onto my existing drawing function:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>let _x = player.offsetX + (player.pos.c - startx) * tileSize;
let _y = player.offsetY + (player.pos.r - starty) * tileSize + tileSize;
player.offsetX -= Math.sign(player.offsetX) * (1/8);
player.offsetY -= Math.sign(player.offsetY) * (1/8);
</code></pre></div></div>
<p>This gets applied to all <code class="language-plaintext highlighter-rouge">MoveableEntity</code> objects. The <code class="language-plaintext highlighter-rouge">Math.sign</code> helps to lerp things a bit so the animation is smoother.</p>
<p><code class="language-plaintext highlighter-rouge">offsetX</code> and <code class="language-plaintext highlighter-rouge">offsetY</code> get set whenever the player presses a movement key. The nice thing here is that if the movement is invalid (wall, enemy, deep water, etc.) then the player’s position will revert back. The offset will give a mild stutter and look like the player is bumping into something.</p>
<p><img src="https://i.imgur.com/ZtI90n8.gif" alt="player animation" /></p>
<p>(Right now enemies don’t make use of this field, but it is there for future updates).</p>
<h2 id="bugfixes">Bugfixes</h2>
<p>One of the more egregious bugs I came across was that, in reworking enemy AI, I neglected to remove a targeted player if they become inactive.</p>
<p>That was a simple fix - right now I remove a target from an enemy if the player leaves the level. The fix was to also check if they were active.</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code># update the enemies
for e in self.enemies:
# (basic follower):
# 1 if no target, set target
# 2 if target, follow
# 3 if target out of range, forget
tgt = e.getTarget()
if tgt is not None and tgt in self.players: # we have a target
# same level test / meditating test
if self.players[tgt].pos['level'] != e.pos['level'] or not self.players[tgt].active:
e.removeTarget()
else:
# do the follow thing
</code></pre></div></div>
<p>Easy enough. Also highly abusable in a production environment, but we’ll save that for when it is time to balance this monstrosity.</p>
<hr />
<h2 id="gameplay">Gameplay</h2>
<p>As a fun aside, I fully anticipate that a large number of performance bugs will be cropping up, now that I’m going “to scale,” so to speak.</p>
<p>Let’s start with bumping the number of rows/columns to 2500 each. This image became necessary in the canvas as it takes longer to receive the whole map now:</p>
<div align="center">
<img src="https://i.imgur.com/HJqJ3ax.png" alt="loader" title="loader" />
</div>
<p>I also started adding in a cellular automata for cave generation, but didn’t <em>quite</em> get it done in time for this post. There are a significant amount of tweaks needed as well, but at least it is something!</p>
<p>I based the implementation off of my favorite blog post for making CAs - they outline the algorithm quite nicely: <a href="https://abitawake.com/news/articles/procedural-generation-with-godot-creating-caves-with-cellular-automata" target="_blank">A Bit Awake - Cellular Automata</a>.</p>
<p>This was made while watching my kids playing outside so I gave 0 thought to tweaks and balance on all the parameters, but the skeleton is in place.</p>
<div align="center">
<img src="https://imgur.com/iXYU6N6.png" alt="ca" title="ca" />
</div>
<p>As you can see here, the maps are very stringy. I added a dev minimap to get a feel for what it looks like and clearly some optimizations need to be made.</p>
<hr />
<p>That’s it for this week - next week I’m thinking game balancing, items, and bugfixes.</p>
<hr />
<p><a href="/rldev-5.html">Last post</a></p>
<p><a href="/rldev-8.html">Next post</a></p>
</div>
<div class="post-metadata">
<p class="discography-album_release-date">
date: 09 August 2023
</p>
<p class="discography-album_type">
post type: blog
</p>
</div>
</div>
</div>
<script>
window.addEventListener("load", () => {
document.getElementsByClassName("copyrights")[0].innerHTML =
`Copyrights © ${new Date().getFullYear()} erik fredericks | template c/o <a href='https://github.com/ItsPatrq/minimal-music-project' target='_blank'>minimal-music-project</a>`;
});
</script>
<footer>
<p class="copyrights">
</p>
</footer>
</main>
<script>
(function () {
window.toggleExpander = function toggleExpander(x) {
const menu = document.getElementsByClassName("menu")[0];
const navigation = document.getElementsByClassName("navigation")[0];
if (menu.classList.contains('expanded--visible')) {
menu.classList.toggle('expanded--visible');
navigation.addEventListener('transitionend', function(e) {
menu.classList.toggle("expanded");
}, {
capture: false,
once: true,
passive: false
});
} else {
menu.classList.toggle("expanded");
setTimeout(() => menu.classList.toggle('expanded--visible'), 20);
}
};
window.addEventListener("load", () => {
// #region click to enlarge images
const imageWrappers = document.querySelectorAll(".click-to-enlarge");
imageWrappers.forEach(imageWrapper => {
imageWrapper.addEventListener("click", () => {
const img = imageWrapper.getElementsByTagName("img")[0];
const src = img.attributes.getNamedItem("src");
const modal = document.createElement("div");
const removeModal = function() {
modal.classList.add("hidden");
setTimeout(() => {
document.body.removeChild(modal);
}, 200);
};
const newImage = document.createElement("img");
newImage.classList.add("modal__picture-zoomed--image");
newImage.setAttribute("src", src.value);
modal.classList.add("modal__picture-zoomed", "hidden");
// modal.style.backgroundImage = `URL("${src.value}")`;
modal.addEventListener("click", removeModal);
modal.append(newImage);
document.body.append(modal);
document.body.addEventListener("keyup", e => {
if (e.key === 'Escape') {
removeModal();
}
}, {once : true});
setTimeout(() => {
modal.classList.remove("hidden");
}, 0);
});
});
// #endregion click to enlarge images
// #region embedded audio players
const players = document.querySelectorAll("iframe.embedded-player");
const getParamsByPlayerType = (src, type) => {
const rt = (src, height) => ({
src: src,
height: height
});
switch (type.toLocaleLowerCase()) {
case "soundcloud":
return rt(`https://w.soundcloud.com/player/?url=${src}`, 125);
case "bandcamp":
return rt(`https://bandcamp.com/EmbeddedPlayer/${src}`, 125);
case "spotify":
return rt(`https://open.spotify.com/embed/track/${src}`, 80);
case "spotifyalbum":
return rt(`https://open.spotify.com/embed/album/${src}`, 80);
case "spotifyplaylist":
return rt(`https://open.spotify.com/embed/playlist/${src}`, 80);
case "spotifyepisode":
return rt(`https://open.spotify.com/embed/episode/${src}`, 152);
case "spotifyshow":
return rt(`https://open.spotify.com/embed/show/${src}`, 152);
case "youtube":
return rt(`https://www.youtube.com/embed/${src}`, 350);
case "anchor.fm":
return rt(`https://anchor.fm/sucias/embed/episodes/${src}`,102);
default:
return rt(src, 125);
}
};
players.forEach(player => {
const givenSrc = player.getAttribute("givenSrc");
const type = player.getAttribute("type");
const { src, height } = getParamsByPlayerType(givenSrc, type);
player.setAttribute("src", src);
player.setAttribute("height", height);
player.classList.remove("hidden");
});
// #endregion embedded audio players
});
})();
</script>
</body>
</html>