The island - An RTS game

New to FreeBASIC? Post your questions here.
Post Reply
ITomi
Posts: 154
Joined: Jul 31, 2015 11:23
Location: Hungary

Re: The island - An RTS game

Post by ITomi »

Oh, big thanks for you, SARG!
I corrected these values and now the game starts well. I hope, not so many errors still remains, and in this case I will find these with help of -exx command, as you advised.
ITomi
Posts: 154
Joined: Jul 31, 2015 11:23
Location: Hungary

Re: The island - An RTS game

Post by ITomi »

Okay, I think, this is my last question before I build in the sounds and musics, and publish the finished game (because it seems work well already):
How can I check whether a button released? Because I would like use the <Esc> button to exit from the setup screen to title screen and from there exit from the game. But when I press the <Esc> button on the setup screen, the title screen just flash and the game exit immediately. Now I use the Multikey function on both of that two screens to detect whether <Esc> is pressed and I tried to use with this the "While Inkey <> "": Wend" trick, but the result is the same. Therefore I would like check released state of <Esc> on one of that screens and the pressed state on the other screen. But how can I realize it in FB? Or can you advise me a better solution?
SARG
Posts: 1763
Joined: May 27, 2005 7:15
Location: FRANCE

Re: The island - An RTS game

Post by SARG »

Hi ITomi,


Try by adding a sleep statement inside the inkey loop like this :

Code: Select all

While Inkey <> "":Sleep 100: Wend
Obviously if ESC key is pressed a long time it doesn't work. In this case more code is needed to check if the program is returned in the main menu and so on.

I tried with the example code given in the help file, changed a bit to handle 2 followed esc keys and it works.

Code: Select all

#Include "fbgfx.bi"
#if __FB_LANG__ = "fb"
Using FB '' Scan code constants are stored in the FB namespace in lang FB
#endif

Dim As Integer x, y

ScreenRes 640, 480

Color 2, 15

x = 320: y = 240
Do
    ' Check arrow keys and update the (x, y) position accordingly
    If MultiKey(SC_LEFT ) And x >   0 Then x = x - 1
    If MultiKey(SC_RIGHT) And x < 639 Then x = x + 1
    If MultiKey(SC_UP   ) And y >   0 Then y = y - 1
    If MultiKey(SC_DOWN ) And y < 479 Then y = y + 1
    
    ' Lock the page while we work on it
    ScreenLock
        ' Clear the screen and draw a circle at the position (x, y)
        Cls
        Circle(x, y), 30, , , , ,F
    ScreenUnlock
    
    Sleep 15, 1
    
    ' Run loop until user presses Escape
Loop Until MultiKey(SC_ESCAPE)


' Clear Inkey buffer
While Inkey <> "":Sleep 100: Wend    <----------------

Print "Press ESC exit..."

Do
    Sleep 25
    
    '' Stay in loop until user holds down CTRL and H at the same time
    If MultiKey(SC_ESCAPE) Then Exit Do
Loop
ITomi
Posts: 154
Joined: Jul 31, 2015 11:23
Location: Hungary

Re: The island - An RTS game

Post by ITomi »

I did a working solution. I publish it; maybe useful for somebody:

Code: Select all

dim as ubyte escpressed=0
if multikey(sc_escape) then escpressed=1
if escpressed=1 then
        while multikey(sc_escape)<>0
        wend
        ...do something here, e.g. jump to an other game state...
end if
Well, only sounds and musics are still left, then I can publish here my little RTS in FB!
Dr_D
Posts: 2451
Joined: May 27, 2005 4:59
Contact:

Re: The island - An RTS game

Post by Dr_D »

ITomi wrote:Well, only sounds and musics are still left, then I can publish here my little RTS in FB!
Hey there. I love writing music for games, if you're interested.
Here's one of the songs I've been working on. See if you like it. :)
ITomi
Posts: 154
Joined: Jul 31, 2015 11:23
Location: Hungary

Re: The island - An RTS game

Post by ITomi »

Dr_D wrote:Hey there. I love writing music for games, if you're interested.
Here's one of the songs I've been working on. See if you like it. :)
Hello!

I listened it just now; quite good melody! I already built musics in the game, but I develop an other game too in Game Maker Studio, and I will show your music the person to whom I make that game, because we still looking for musics.
ITomi
Posts: 154
Joined: Jul 31, 2015 11:23
Location: Hungary

Re: The island - An RTS game

Post by ITomi »

Well, ladies and gentlemen, here is the game, my first little RTS in FB:
http://www.programozzunk.ucoz.hu/fbjatekok/sziget.zip
Once I gave up that I ever finish it, but I got down to work again. Unfortunately the game sometimes exits, and I don't know whether is it error of the game, the FB or the Windows 10, because all three of these does strange things on my computer.
And unfortunately again, some things aren't to be found in the game, because I still don't know how I realize these: the fog of war and game save possibility. Ah, and I still can't change the volume of musics. But maybe in the future, when I will be a skilled FB programmer...
Meanwhile I wait your critiques, comments about the game.
Dr_D
Posts: 2451
Joined: May 27, 2005 4:59
Contact:

Re: The island - An RTS game

Post by Dr_D »

ITomi wrote:
Dr_D wrote:Hey there. I love writing music for games, if you're interested.
Here's one of the songs I've been working on. See if you like it. :)
Hello!

I listened it just now; quite good melody! I already built musics in the game, but I develop an other game too in Game Maker Studio, and I will show your music the person to whom I make that game, because we still looking for musics.
Ok. Cool. :)
Dr_D
Posts: 2451
Joined: May 27, 2005 4:59
Contact:

Re: The island - An RTS game

Post by Dr_D »

I'm not sure if I made a mistake somewhere, but I picked English language... and the names of the constructs were still in another language. I probably could have fought through the language barrier... but I gave up. You may think about printing the names of the buildings and such in another way... not imprinted on the sprite itself. Maybe choose the language and print in real time. A lot of work... or another DLL. lol... I know. ;)
ITomi
Posts: 154
Joined: Jul 31, 2015 11:23
Location: Hungary

Re: The island - An RTS game

Post by ITomi »

Yes, because the names are parts of the building sprites, and not separated printouts. I was foolish enough to do so at the beginning of developing, I'm sorry. But in FreeBasic I still can't use hungarian diacritic letters, therefore I thought, write these names onto the sprites. Then I forgot make these english versions.
But here is the list in english and hungarian: Kőfejtő - Quarry, Favágó - Tree cutter, Laktanya - Barracks, Halász - Fisher, Lakóház - House, Őrtorony - Watch tower, Tanya - Farm.
Ah, and press Alt+Enter to switch fullscreen mode.
BasicCoder2
Posts: 3906
Joined: Jan 01, 2009 7:03
Location: Australia

Re: The island - An RTS game

Post by BasicCoder2 »

ITomi wrote:But in FreeBasic I still can't use Hungarian diacritic letters, therefore I thought, write these names onto the sprites.
Maybe use draw string and your own fonts?
Not sure exactly what your game does. It seems to involve making paths and placing buildings near them. There is a delay while a settler does some "building" animation and then along comes some little blue guy to burn it down and dispose of any settler?
There have been some other started attempts at such "settler" games but the programmers seem to burn out before they can finish anything.
At the moment your game seems to have a glitch. It just suddenly closes during play.
ITomi
Posts: 154
Joined: Jul 31, 2015 11:23
Location: Hungary

Re: The island - An RTS game

Post by ITomi »

BasicCoder2 wrote:
ITomi wrote:But in FreeBasic I still can't use Hungarian diacritic letters, therefore I thought, write these names onto the sprites.
Maybe use draw string and your own fonts?
Hello BasicCoder2!

The problem is that I don't know how to use own fonts in FB. I'm still so "green" with this programming language.
Not sure exactly what your game does. It seems to involve making paths and placing buildings near them. There is a delay while a settler does some "building" animation and then along comes some little blue guy to burn it down and dispose of any settler?
In the game, if you build a barrack, then you can train warriors in that, just click on that building and the popup icon. Then you can control your warriors by the mouse, just click on them with left button and select a target with right button.
There have been some other started attempts at such "settler" games but the programmers seem to burn out before they can finish anything.
Are these written in FB? And can I find these on the internet? I also almost became grey while I was working on this game :-).
At the moment your game seems to have a glitch. It just suddenly closes during play.
Yes, it's true, but interestingly enough, if I use an other IDE than FBide, I could play with it without it produce closing glitch.
badidea
Posts: 2591
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: The island - An RTS game

Post by badidea »

0.5 MB bas file, that's a lot of code.

A nice open source (not in FreeBASIC) settlers like game is Widelands
BasicCoder2
Posts: 3906
Joined: Jan 01, 2009 7:03
Location: Australia

Re: The island - An RTS game

Post by BasicCoder2 »

ITomi wrote:
BasicCoder2 wrote:
There have been some other started attempts at such "settler" games but the programmers seem to burn out before they can finish anything.
Are these written in FB? And can I find these on the internet?
Both Boromir and Leopardpm have worked on the start of Settler like game mechanics.
viewtopic.php?f=8&t=25457

I have also played with different ideas without actually attempting an actual game or adding user input to control the simulation.
This is just one of the threads covering the subject matter.
viewtopic.php?f=8&t=24615&hilit
I have also worked on isometric examples. Although you are using isometric buildings and characters your actual display layout is like that used in Toad on Fire. My view is you keep the mechanics of the game separate from the display and in the above forum thread I give examples of the top down view along with a simultaneous isometric view.

It is hard to work as a lone programmer on such a project and thus the need for a popular language to involve other people along with people with skills beyond programming. Also you would all have to agree on how it is to be implemented as you can't have conflicting coding techniques. For example I see Widelands uses C++ and OpenGL.

I did not compile your example from FBIDE, which is the one I use, instead I just ran the .exe that came with your download and still got the closing glitch.
ITomi
Posts: 154
Joined: Jul 31, 2015 11:23
Location: Hungary

Re: The island - An RTS game

Post by ITomi »

badidea:
"0.5 MB bas file, that's a lot of code."

Perhaps. But I can't really compare to other similar FB games, because I don't know so much.

"A nice open source (not in FreeBASIC) settlers like game is Widelands"

Oh, I didn't know this game, but looks like very good! My work isn't to be compared with that, because my game is just a first attempt. It's started a few years ago as a Game Maker project, but the result was unplayable because of its slowness. Then I tried to make it with FreeBasic and the game became much better. Although my FreeBasic games are slow down on an older computer: I tried these on an old laptop (1.6GHz CPU with 1GB RAM) and my games were visibly slower. I don't know, how can I achieve the same fps on different systems. For example, on a slower computer I should use bigger speed value to a unit to move to achieve the same move than on a modern computer - but it's impossible, because I don't know everybody's computer system in advance. Is the Timer function the solving to this question in FreeBasic?

BasicCoder2:
Thanks; I will look over those topics.
The .exe beside the .bas is compiled by FBIDE, therefore would close unexpectedly. Maybe I will upload its compiled version by other IDE.
Post Reply