163 lines
14 KiB
Plaintext
163 lines
14 KiB
Plaintext
|
|
Episode: 2693
|
||
|
|
Title: HPR2693: Getting started with web based game in Haskell and Elm
|
||
|
|
Source: https://hub.hackerpublicradio.org/ccdn.php?filename=/eps/hpr2693/hpr2693.mp3
|
||
|
|
Transcribed: 2025-10-19 07:36:39
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
This is HPR Episode 2693 entitled Getting Started With Web Based Game in Hakell & Elm.
|
||
|
|
It is hosted by Tuku Toroto and in about 19 minutes long and Karima Clean Flag.
|
||
|
|
The summary is first steps in writing for X-Pace Exploration Game.
|
||
|
|
This episode of HPR is brought to you by An Anastos.com.
|
||
|
|
Get 15% discount on all shared hosting with the offer code HPR15, that's HPR15.
|
||
|
|
Better web hosting that's honest and fair at An Anastos.com.
|
||
|
|
Hello listeners of the Hackerfather Radio, this is Tuku and today I'm going to
|
||
|
|
talk a little bit about the game programming with Hacker and Elm.
|
||
|
|
I have been working on a small game, the taste game for a bit now and thought that it might
|
||
|
|
be a fun idea to record sort of an audio diary until what I have learned and what my
|
||
|
|
plans have been and what kind of problems I have had to share with you with the listeners
|
||
|
|
of the Hackerfather Radio.
|
||
|
|
I'm doing this because I don't have a plan to make a complete game, it is more of an
|
||
|
|
learning experience, I'm a person who learns by doing and making simple games has always
|
||
|
|
been my preferred way of learning new things about programming, I started that when I was
|
||
|
|
tiny, tiny kid, I think 7 or so when I self-prod writing text adventures and I have been
|
||
|
|
doing it since then.
|
||
|
|
So the game I have been working on is a browser based multiplayer, space exploration
|
||
|
|
game, that's a mouthful but the idea is that there's a game that is running constantly,
|
||
|
|
it's a turn-based, in a sense, but that turns don't wait the players, they are automatically
|
||
|
|
done every, for example, every 24 hours or so and the recordless of what you have done
|
||
|
|
or recordless of if the player has given his input or not on a certain turn that turns
|
||
|
|
are evaluated, and I'm writing this with a hospital, yes or mainly, and a little bit
|
||
|
|
of error, and I was really lucky in a sense that it's easier to change things than to
|
||
|
|
create from nothing, and yes or comes with a stack template, stack instead, a hospital
|
||
|
|
built tool, configuration tool, but the stack comes with a yes or template, I can just
|
||
|
|
call a stack, I think it was a stack template, something, something, I checked it, put it on
|
||
|
|
the show notes, but it will create a scaffold, yes or correct, that's a fully fledged, yes
|
||
|
|
or website that has a, it doesn't have much of content, but it has a menu, it has a breadcrumbs,
|
||
|
|
it has a out-and-dickation, authorization, things like these basic things are in place,
|
||
|
|
so it was easy for me to just create a project from there, then start adding on that, just delete
|
||
|
|
the demo pages and start adding there, and the plan is basically just to keep changing
|
||
|
|
that demo pages that came with the yes or until the game ready or only I lose the interest
|
||
|
|
or decide that there's something else I'd rather do, so the idea is that the players can
|
||
|
|
change their orders any time, so at any given moment they can look at the page, they can
|
||
|
|
see what's the current situation for them, they can give orders to the, for example, planets
|
||
|
|
or the ships or whatever I end up adding in the game, and they can revert those orders and
|
||
|
|
give new orders, but when they turn in, the system will simulate what would happen or
|
||
|
|
rather what will happen when all these orders are taken into account, and it will create
|
||
|
|
a new, sort of a new state of the world, and then the players can again, you won't see
|
||
|
|
what's the state and how things have been progressing with the news and stuff, and keep
|
||
|
|
giving orders, or maybe they just decided that some seven orders are still valid, let's not
|
||
|
|
change this, for example, some planets have been ordered to scientific research and they
|
||
|
|
have failed to fill that this is a good idea, so let's keep doing no need to change that.
|
||
|
|
And I wanted to, originally I wanted to make this holding to wrong completely on the, on
|
||
|
|
the plane HTML, and just a tiny amount of client-side scripting, just, just as an, as
|
||
|
|
a challenge, basically, but I, at some point I realized that this is not going to cut it,
|
||
|
|
and I will need to write the client completely on the element, but at the start, the client
|
||
|
|
was basically just a dumb HTML, HTML, H's, a little bit more here, but yeah, and that's,
|
||
|
|
that's an act of, as of the moment I'm recording that, that's still working progress thing,
|
||
|
|
still writing the client on the, with the element, and so, let's talk a little bit about
|
||
|
|
the idea of the HTML more, I wanted to add a little twist into the game, in a way that
|
||
|
|
each player belongs to a factor, they have their own group, and one factor can have more
|
||
|
|
than one player, I haven't figured out how, how, how players are divided between like
|
||
|
|
fractions, and how can they move between them, and if they can move between them, and then,
|
||
|
|
and then, planets and ships, and basically everything don't belong to the players, but they
|
||
|
|
belong to the, the, the, the, the, the, the, at least that's the current, current idea,
|
||
|
|
and this hopefully gives an interesting dynamic in the game, in a sense that there's a group
|
||
|
|
of, there's always a group of people, sometimes there's a group of people, there's a one, sometimes
|
||
|
|
there's a bigger, that are managing this, whatever you want to call it, space, empire, space,
|
||
|
|
republic, space, something that has the planet, and they have, they, in between themselves
|
||
|
|
have to somehow decide what needs to be researched, research is going to be a big part of the
|
||
|
|
game, because in the beginning you can barely fly a spaceship, and you have to start researching
|
||
|
|
a bigger space ships, and better technologies, and better sensors, and do some basic research,
|
||
|
|
and then do some applied research, and then decide where to spend all the resources, and
|
||
|
|
at the same time you have to also have to manage your planet, you have to give the population
|
||
|
|
effect, give them reasonably happy, maybe have them to, some meaningful things to do, maybe
|
||
|
|
do some planet-based exploration instead of space exploration, because planets are huge,
|
||
|
|
like that, but if you look around and see that, how big Earth for example is, and how in the
|
||
|
|
space game it's usually just a one hex, and there's a couple numbers, and there isn't much to do
|
||
|
|
on a planet on a space game, I kind of want to change this a little bit solely, if you find a new planet,
|
||
|
|
and you land there, and you set an outpost, and start, we start living there, obviously you need to
|
||
|
|
have a planet-based exploration, that you can go around and roam on the planet and try to see if
|
||
|
|
there's anything interesting to find there, and all this needs to be managed that group of people
|
||
|
|
on single planet, but group of players, if I ever have a group of players, and if I ever have a
|
||
|
|
playable game that is, that's a couple big ifs, but that might give an interesting dynamic if there's
|
||
|
|
some planet-based exploration, who has decided that I want to explore the planet, I don't want to spend
|
||
|
|
my, meager resources to go to the space, and in the same fraction, the, some, another, another
|
||
|
|
guide who's in charge of the solar system, star system, and it's thinking that we do planets
|
||
|
|
on, and his opinion is that we need to explore the space, so why don't you help me with this goal?
|
||
|
|
So it might create nice, nice dynamic there, or not, I don't know, it's a, it's just an idea,
|
||
|
|
basically, but that's basically the idea of the game, and so back in, written,
|
||
|
|
Haskell-Fundent, HTML, later, are, even called, some resting phase in between, and all the data,
|
||
|
|
of course, all that stuff needs to be stored somewhere, so I'm just thinking all kinds of ideas
|
||
|
|
here, but then I decided that probably is the easiest, easiest, if I call it a simple relational
|
||
|
|
database, because that's the things that I know fairly well, that probably isn't going to give me
|
||
|
|
any big surprises, although they're already a surprise, and I talked about that a little bit later,
|
||
|
|
but I didn't want to do any Cosmos DB or MongoDB or other things, because while I have an
|
||
|
|
idea about those technologies, I'm not that familiar with them, and I didn't want to, I didn't want to
|
||
|
|
have too many new things to learn, because this Haskell-Fundent is going to be blending in
|
||
|
|
after, because I've been playing a little bit with them, but I haven't ever written anything big,
|
||
|
|
and sometimes it's really frustrating to work with the Haskell, because while it's a really
|
||
|
|
fun language, it's not too complicated, they say, but concepts are sometimes
|
||
|
|
completely different, but I have what I'm used to, so it's really hard to work around some
|
||
|
|
things, and sometimes it's really interesting, surprises, like I'm using a yes or comes with a
|
||
|
|
persistent for the database access, which is really nice, nice library, and I thought that
|
||
|
|
that would be enough for me, but then through and I learned that the persistent can't through
|
||
|
|
joins, you cannot join two tables and query data from both in a one query, there's some
|
||
|
|
good reason behind that, I think that's a good fact that persistent supports various different
|
||
|
|
kinds of back-ends, so they have to go with the minimum set of features that is available for all
|
||
|
|
of those, and then this I worked around by learning the sql, which is another
|
||
|
|
library for accessing databases, but sql is not in the stack yet, the stack is like I mentioned,
|
||
|
|
that build management tool that also comes with a curated package, so if you
|
||
|
|
all the packages that are available in the stack are currently to some degree to work together,
|
||
|
|
so you can, it's easy to pick the version from the stack because you know that if I use this
|
||
|
|
version of the library, all these other libraries will work together, together with it, but sql
|
||
|
|
is not the stack, so that I had to get from the GitHub directly, basically in my configuration
|
||
|
|
said that this library doesn't come from the stack, but it comes from the GitHub or GitHub repository,
|
||
|
|
and it's a specific commit that you need to make, and how did I think that specific commit
|
||
|
|
I would do the latest version from the master, and if this compiles it's probably good enough,
|
||
|
|
and so far it has been good enough, but yeah, so data starting the database,
|
||
|
|
Haskell, no sorry, yes or no, this is a good first approach on the database, there's a
|
||
|
|
model.config file where you write up, where you describe what kind of entities you have,
|
||
|
|
and yes or no, based on that information generate your database for you, it even has some
|
||
|
|
automatic migration tools, they are very rudimentary, they are good enough for the development,
|
||
|
|
but you cannot use those in the little real production, and you will commit you have to do the,
|
||
|
|
you have to do the migration by hand, if and then your database changes, you have to do those
|
||
|
|
changes by hand, and I think your specific case is how to data needs to change, if it needs to change.
|
||
|
|
Some data I have, well I don't know if I have to, but I came to a conclusion that I have to
|
||
|
|
spell as a JSON in the database, it's not optimal, you're going to do meaningful searches into
|
||
|
|
JSON data that is passed in some way in the database, but that that's into, when I was doing this,
|
||
|
|
seem to be the approach that gave me this, this is related to the algebraic data files,
|
||
|
|
so I don't have a data type that has very different looking data, like I don't have a,
|
||
|
|
it's all in the, it's all the same type in the Haskell, but it can be looked really different,
|
||
|
|
and if you were to map it into the, into the relational database, the rows, rows, and columns,
|
||
|
|
you could end up with multiple tables making queries for your heart, so I just decided to
|
||
|
|
serialize that, that those things into the JSON, sort them into the database, we done with that,
|
||
|
|
I cannot query that data, I cannot change that data easily, I believe it's always a different
|
||
|
|
operation, I take this data and replace it with this version of the data, but I'm happy with that,
|
||
|
|
so this is, this is basically the state, state of the database stuff for myself,
|
||
|
|
and like I said, the JSON comes with the authentication out of the box, I'm using the,
|
||
|
|
in the development environment, the very simple version we have, it's just a simple text box,
|
||
|
|
we are going to write that, it asks, and you go through the page, who are you, and you just type
|
||
|
|
your user ID, the first login, and then you log in, that's the user, no password, no, but,
|
||
|
|
no security whatsoever, but that's good enough for me for the development, I didn't want,
|
||
|
|
I haven't looked into the email password combination,
|
||
|
|
authentication, or into the, into the, or, or any, any of those,
|
||
|
|
what, what people are more used to, but, I know that yes, I can do that, so I don't have to
|
||
|
|
worry about that, now, I'm just concentrating now on getting the very basic blocks
|
||
|
|
into place, and get the whole thing off the ground, so I can, like I said, it's easier to change
|
||
|
|
something than it is to create something from the mapping, so I can, my goal currently is to
|
||
|
|
just create something that I can later start changing, as long as there's a song, right,
|
||
|
|
first, first step is to have a player, a person for the player, a planet, where they can be,
|
||
|
|
planet of course needs to be a solar system, solar system, star system, and star system,
|
||
|
|
has to have one or more stars, and on a planet there can be buildings, like farms for producing food,
|
||
|
|
and maybe some research stations producing research points, and so on, but that's the,
|
||
|
|
first step I want to concentrate, okay, I'm going to call this off now, and
|
||
|
|
going to start coding a little bit, and I'll get back to this, when I have some more to talk about,
|
||
|
|
so, have a good one, cheers.
|
||
|
|
If you ever thought of recording a podcast, then click on our contribute link to find out how easy
|
||
|
|
it really is. HECCA Public Radio was founded by the Digital Dove Pound and the Infonomicon
|
||
|
|
Computer Club, and it's part of the binary revolution at binrev.com. If you have comments on
|
||
|
|
today's show, please email the host directly, leave a comment on the website or record a follow-up
|
||
|
|
episode yourself, unless otherwise status, today's show is released on the create of comments,
|
||
|
|
attribution, share, light, free, dot, olisons.
|