flat assembler
Message board for the users of flat assembler.

Index > Windows > My first Win32 console game prototype

Author
Thread Post new topic Reply to topic
MatQuasar



Joined: 25 Oct 2023
Posts: 105
MatQuasar 28 Apr 2024, 08:43
Hi all, although not my first game (as I have written simple game for DOS and EPOC), this is my first Win32 attempt to sketch a shooting game prototype.

Currently it only allow moving of spaceship (a "^" symbol), no weapon firing, and no enemies yet.

I still don't know how to keep track each of the bullet (can be more than one) and moving it simulateneously.....

My code use ANSI escape sequence, and currently it is only prototype. Looking for your feedback!


Description: Screenshot
Filesize: 6.83 KB
Viewed: 3097 Time(s)

Capture.PNG


Description: v0.01 - Moving spaceship only, no weapon, no enemies
Download
Filename: shooter.asm
Filesize: 6.1 KB
Downloaded: 190 Time(s)

Post 28 Apr 2024, 08:43
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4079
Location: vpcmpistri
bitRAKE 28 Apr 2024, 10:05
It is working well here. I tried to break it with too many keys, changing direction, etc. Yet, it remained responsive.
Post 28 Apr 2024, 10:05
View user's profile Send private message Visit poster's website Reply with quote
MatQuasar



Joined: 25 Oct 2023
Posts: 105
MatQuasar 28 Apr 2024, 10:11
bitRAKE wrote:
It is working well here. I tried to break it with too many keys, changing direction, etc. Yet, it remained responsive.


This is good feedback!! Very much appreciated, especially from expert like you.

Next I will work on bullet firing.... Laughing
Post 28 Apr 2024, 10:11
View user's profile Send private message Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1671
Location: Toronto, Canada
AsmGuru62 28 Apr 2024, 21:47
I think the way it should work is that you have your objects coordinates in a 2D array -- which is modeled after the console X rows and Y columns.
Then during the game you move the objects: gun is moving, bullets flying, enemies moving according to some AI.
When objects move -- you write it all into a memory buffer -- your model.
Then, finally, you dump the whole buffer into console in one operation -- Console API has a function for that.
Now, you do that dumping often, like 40 times per second or so.
Post 28 Apr 2024, 21:47
View user's profile Send private message Send e-mail Reply with quote
MatQuasar



Joined: 25 Oct 2023
Posts: 105
MatQuasar 29 Apr 2024, 07:00
AsmGuru62 wrote:
When objects move -- you write it all into a memory buffer -- your model.
Then, finally, you dump the whole buffer into console in one operation -- Console API has a function for that.


I have never thought of this, and am not sure if I will be able to use Console API to achieve that, I just looked at WriteConsoleOutput.

AsmGuru62 wrote:

Then during the game you move the objects: gun is moving, bullets flying, enemies moving according to some AI.


I think for gun (spaceship) and bullet, don't need AI. But for enemies (alien invasion), maybe will use random number generator (I have the code from @resolution years ago, make use of functions in ADVAPI32.DLL).

Thank you for the suggestion.
Post 29 Apr 2024, 07:00
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4079
Location: vpcmpistri
bitRAKE 29 Apr 2024, 12:14
My thoughts were similar to AsmGuru62 - reducing API calls, because API is very slow. There is a number of techniques.

Configuring console to remove processing: Modern console is very complex. It can do UTF-8 and ANSI codes with legacy terminal emulation.

Cache operations by building up strings with periodic console update.

Someone has actually made a console game engine, lol.
https://github.com/ural89/ConsoleCraftEngine
Post 29 Apr 2024, 12:14
View user's profile Send private message Visit poster's website Reply with quote
MatQuasar



Joined: 25 Oct 2023
Posts: 105
MatQuasar 29 Apr 2024, 12:54
bitRAKE wrote:

Someone has actually made a console game engine, lol.
https://github.com/ural89/ConsoleCraftEngine


I checked, it uses ncurses, and ncurses used ANSI , like VT 220/320/420/520 (no idea what are they).... So is my approach correct in using ANSI escape code to move cursor and draw sprite?
(Maybe I should reread your post Embarassed )

I know what AsmGuru62 meant, draw in the background first then move it to screen buffer.
Post 29 Apr 2024, 12:54
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4079
Location: vpcmpistri
bitRAKE 29 Apr 2024, 14:47
MatQuasar wrote:
VT 220/320/420/520 (no idea what are they)
Oh, you don't want to know. CRTs integrated into a desk-like furniture - the heavy steel and pressed wood terminals were hard on the back. This one skyscraper had a freight ramp that zigzagged down eight floors. Built to such a standard that they looked new at the end of their life - powered up to some CP/M based software system. My adolescent self thought they should have just pitched them out the window - to be dismantled by gravity.

_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup
Post 29 Apr 2024, 14:47
View user's profile Send private message Visit poster's website Reply with quote
Hrstka



Joined: 05 May 2008
Posts: 61
Location: Czech republic
Hrstka 30 Apr 2024, 12:25
Quote:
My adolescent self thought they should have just pitched them out the window - to be dismantled by gravity.

We call it "hardware acceleration by free fall" Very Happy
Post 30 Apr 2024, 12:25
View user's profile Send private message Reply with quote
MatQuasar3



Joined: 04 Nov 2024
Posts: 44
MatQuasar3 12 Nov 2024, 10:43
I am learning GUI window programming in Windows.

This version is also a shooting game prototype, like post #1, but in GUI, using GDI function "TextOutA".

If want to continue developing the game, I might consider using this GUI version as template, instead of the console version.

As usual, press left or right key to move the "^" symbol, Esc to quit. Maybe I need to fix the window size (no resize allowed).

----

shooter
My shooting game prototype (WIP)

What is this about?
This is a game prototype (work in progress) that was written in Assembly language.

There are two versions: Console (CUI) and GUI, both are 32-bit code for Windows.

Currently only moving of "^" symbol (a spaceship, or gun) to the left and to the right is allowed.

No weapon, no enemies.

Tell me about the difference between Console and GUI
Console version uses ANSI escape code to move the caret, clear the screen, while GUI version uses GDI TextOutA function to draw text in window.

In Console version, there are normally about 80 columns by 20 rows or more, and each cell is formed by 8x16 or 8x8 pixels.

In GUI, I can draw as small as 1 pixel, or move the "^" symbol by 1 pixel or 10 pixels depending on how fast to move.

In GUI, the window message loop and events such as paint event and keydown event are part of the standard coding.

But in Console, I had to set up the loop and invoke GetKeyState function to read the key myself. The amount of code in Console version is expected to be longer than GUI version.

When will you come up with full functioning game?
Not certain. As I have yet to figure out how to move multiple bullets simulteneously on screen. In Console, it is easier, just use Sleep function, but I am not decisive on GUI version.

Also, to put the enemies (kind of alien invasion) moving around, I need random number generator, so maybe will use Win32 API functions found in ADVAPI32.DLL.

Until then, check out my game prototype!

But wait, how to run your programs?
Just download FASM for Windows from flatassembler.net Download section.

Run FASMW.EXE and open my shooter.asm (Console) or shoot2.asm (GUI) and click Run. The program is now running with executables also produced in the background.

Next time you can just run shooter.exe or shoot2.exe, no need to open the source file from within FASM IDE anymore.

Once in the game, press Left or Right arrow key to move the caret, and when you're done, press Esc to quit.


Description:
Filesize: 3.16 KB
Viewed: 1384 Time(s)

Capture.PNG


Description: GUI version of shooting game prototype
Download
Filename: shoot2.ASM
Filesize: 3.56 KB
Downloaded: 64 Time(s)

Post 12 Nov 2024, 10:43
View user's profile Send private message Reply with quote
MatQuasar3



Joined: 04 Nov 2024
Posts: 44
MatQuasar3 22 Nov 2024, 09:05
I am about to do the second part of my shooting game, currently I have finished the first part, which is moving the "gun" (or spaceship in "^" symbol) to left or to right:

Image

The second part is moving the enemies (alien spaceship, maybe in "==" symbol"), but no weapon firing yet.

AsmGuru62 said simple AI is needed. I think that "AI" is actually random number generator.
I already have the code to generate random number (given by revolution) from ADVAPI32.DLL using CryptGenRandom Win32 API function.

It can supports long random data, for example, a few random bytes returned:
Image

So, do you think my logic OK?
I plan to generate 4KB random data, then put 5 alien spaceship, each alien spaceship moving direction will be determined by the next random byte (maybe 2 bits at one time), depending on this table:

00 - move up
01 - move left
10 - move right
11 - move down

And repeat for 5 alien spaceship, and repeat the 4KB from head to tail again (i.e. no more fresh new random data generated).
It will appear like the 5 alien spaceship is moving randomly, but I don't know how random.

Is this sound feasible?
Post 22 Nov 2024, 09:05
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20459
Location: In your JS exploiting you and your system
revolution 22 Nov 2024, 09:13
Code it up and see how you like it.

I personally find pure random walks to be not fun for enemy movement, and prefer some kind of goal orientated algorithm. The goal can be randomly selected and then use some deterministic code to aim for the goal.
Post 22 Nov 2024, 09:13
View user's profile Send private message Visit poster's website Reply with quote
MatQuasar3



Joined: 04 Nov 2024
Posts: 44
MatQuasar3 22 Nov 2024, 09:28
revolution wrote:
Code it up and see how you like it.

I personally find pure random walks to be not fun for enemy movement, and prefer some kind of goal orientated algorithm. The goal can be randomly selected and then use some deterministic code to aim for the goal.


Goal-oriented algorithm , aha, inspired me.

So instead of simple move left / right /up / down, 2 random bits will select a random "path", or a series of direction.

I can think of, example:
00 - move left, move left, move up
01 - move right, move up, move up
02......

But I need to synchronize with timer (am not decisive yet how to implement this).
Post 22 Nov 2024, 09:28
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20459
Location: In your JS exploiting you and your system
revolution 22 Nov 2024, 12:00
I was thinking that the goals could be at a higher abstraction.

Goal 1: Chase the player.
Goal 2: Run away from player
Goal 3: Aim for top-left corner
Goal 4: Hide from player behind obstacles
Goal 5: Choose a random x,y and go there
Goal 6: Follow a predetermined path
etc.
Post 22 Nov 2024, 12:00
View user's profile Send private message Visit poster's website Reply with quote
Mat Quasar



Joined: 15 Dec 2024
Posts: 57
Mat Quasar 18 Dec 2024, 09:34
....


Description:
Filesize: 141.12 KB
Viewed: 834 Time(s)

3.gif


Description: Game in action!
Filesize: 13.13 KB
Viewed: 861 Time(s)

shoot.png


Description: v0.04
Download
Filename: SHOOT.ASM
Filesize: 10.15 KB
Downloaded: 27 Time(s)



Last edited by Mat Quasar on 07 Jan 2025, 17:14; edited 2 times in total
Post 18 Dec 2024, 09:34
View user's profile Send private message Reply with quote
Mat Quasar



Joined: 15 Dec 2024
Posts: 57
Mat Quasar 19 Dec 2024, 17:16
....


Description: My shooting game prototype running on Windows XP
Filesize: 7.94 KB
Viewed: 308 Time(s)

xp_shoot.PNG


Description:
Filesize: 256.77 KB
Viewed: 792 Time(s)

rand.gif


Description:
Download
Filename: crypt.ASM
Filesize: 2.91 KB
Downloaded: 22 Time(s)

Post 19 Dec 2024, 17:16
View user's profile Send private message Reply with quote
Mat Quasar



Joined: 15 Dec 2024
Posts: 57
Mat Quasar 08 Jan 2025, 21:33
I have updated the shoot.asm to v0.04 about two days ago. I fixed the randomness of moving direction of enemies, because I used "bt" instruction wrongly, causing it to move to the left only.
A crypt.asm is attached above that analyzes the probablility of moving to the left / right & no move (stalled), from 1KB random data, exactly like what is being used in the shooting game prototype.

Sorry for my deleted comments in two posts above, as a result of having bad mood two days ago.
Post 08 Jan 2025, 21:33
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.