FreeBASIC Community produced game

General discussion for topics related to the FreeBASIC project or its community.
Post Reply
paul doe
Moderator
Posts: 1730
Joined: Jul 25, 2017 17:22
Location: Argentina

Re: FreeBASIC Community produced game

Post by paul doe »

coderJeff wrote:For a case study, and the only game I have ever helped with: Space Fight AI Tournament Idea. I know it is an old post, but it has the elements of what we are talking about.
I missed that thread, back in the day! (yeah, I was a lurker at that time =D). That's a pretty neat idea, indeed, and looks like a lot of fun! The concept of 'AI battles' has always fascinated me, moreso if they're simple ones like this -a dogfight in space, reminds me a lot to the battle sequences of Star Control II, only without the human component.

I think a 'community driven' AI competition can encourage more people to participate in the forum, even if they don't like games, just the intelectual challenge of coding an autonomous AI. Do you have something in mind?
coderJeff
Site Admin
Posts: 4313
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: FreeBASIC Community produced game

Post by coderJeff »

BasicCoder2 wrote:Have done lots of tile/sprite based game demos but again it is coming up with an original idea.
BasicCoder2, I tried your demo, and feels like could be a fun game. Must it be a new idea? What is the road block that is stopping you from taking it to the next step? What is the problem that you need to solve or get help with from others that will allow you to proceed?

I usually get stuck when I have no plan for what I want to achieve next, and the project gets shelved.
coderJeff
Site Admin
Posts: 4313
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: FreeBASIC Community produced game

Post by coderJeff »

paul doe wrote:I think a 'community driven' AI competition can encourage more people to participate in the forum, even if they don't like games, just the intelectual challenge of coding an autonomous AI. Do you have something in mind?
yes, I think the most interesting part of the project for contributors was writing the AI logic. I think that's the key part to keep.

What I would have in mind:
1) Minimally fix the (possibly only known) last version of the game so it compiles with current fbc and let this be our reference prototype (even though the structure and modularity of the original program is fragile). Overall, the original concept is good, we don't need a new idea.
2) Rewrite in the style of your framework to give it a robust implementation. (Actually, this game/AI simulation could be test case for some portion of your framework, but I would not make that a requirement, so this either project can proceed independently, regardless).
3) Run the AI challenge on the forum just as before. I think it would be successful.

And, if I were to do a sequel, it would be with tanks. The overall implementation of the program would be almost the same. Difference would be in writing the AI, having already left, right, back, forward, & fire, then adding turret left, turret right, new for responses.

---
Case study follow up:
There are 3 things that made this AI challenge project successful as a community collaborative effort:
1) leader to keep the project moving
2) simple design (main loop enforces the rules of the simulation and calls the AI)
3) modular components (AI) written in FB, that have a simple and uniform API

In contrast, the reboot, (which I think was going to be called "Atto"), had ambitious changes: new physics, destructible ship pieces, ship designer, openGL, assembler like virtual machine AI, multiple ships, and so on.
badidea
Posts: 2586
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: FreeBASIC Community produced game

Post by badidea »

coderJeff wrote:And, if I were to do a sequel, it would be with tanks. The overall implementation of the program would be almost the same. Difference would be in writing the AI, having already left, right, back, forward, & fire, then adding turret left, turret right, new for responses.
Tanks, awesome! I'm in.
Can we add (to make it more difficult):
* A double forward facing machine gun?
* A set of rocket launchers?
* Mine laying ability?
* Limited ammo for the bullet, shells and rockets?
* Limited fuel?

One of my unfinished projects:
https://nr100.home.xs4all.nl/badidea/tank_game_01.png
Last edited by badidea on Aug 26, 2018 22:22, edited 1 time in total.
coderJeff
Site Admin
Posts: 4313
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: FreeBASIC Community produced game

Post by coderJeff »

badidea wrote:Tanks, awesome! I'm in.
Can we add...
@badidea,
ha, seeing that AI challenge version 1: spaceships is not written yet, then sure, what the heck, totally possible for AI challenge version 2: tanks. Actually, if the core program was written with an OOP framework, I can see the possibly of adding the features you are talking about without having to do a compete rewrite. But, one step at a time, because I'm sure we brainstorm the next 10 versions we'd like to see, but then we'd all want the 10th version that is nearly impossible to write, and it would never happen all.

This AI challenge concept really interests me. I think I would enjoy working on it. And I think it would engage the community, which is beneficial for the FreeBASIC project overall.

----
On a serious and somewhat personal note: the consequence of expending my time on this activity requires that I expend less time or no time on fbc compiler development. Top of my TODO list is the next FreeBASIC release. Most things I have worked on are steps that I think will lead me towards having the confidence to actually make a release. Over the last year I've done my best to encourage users to contribute to fbc directly, but honestly, I think the cost of investment for most users is just too high and there is no paycheck at the end of the week to motivate. There have been a few contributions, for example this patch, but it needs more attention to get it completed. And, if i don't do it, then who?. So, that's what I am weighing against when I consider my level of involvement with the AI challenge. On the other hand, if anyone complains about lack of fbc development, I could just respond, no apologies; too busy doing something fun, thank you very much.
BasicCoder2
Posts: 3906
Joined: Jan 01, 2009 7:03
Location: Australia

Re: FreeBASIC Community produced game

Post by BasicCoder2 »

coderJeff wrote: BasicCoder2, I tried your demo, and feels like could be a fun game.
Which demo? I have posted a lot of them.

Once the "game engine" is written the hard part starts and that may involve artists and the construction of worlds. Even the simple platform game needs a world for the character to traverse while it battles enemies and collects rewards. This last part takes 99% of time required to write a game which is why lone coders rarely if ever get beyond the beginnings of such games unless they work on the same game for many years.

The idea should be original enough not to be an obvious clone of another game although all new ideas evolve out of combinations, extensions or inspirations from older ones. Tetris was apparently inspired by pentomino puzzles which in turn is just about fitting together different shaped tiles which go all the way back to tiling floors and walls.
And, if I were to do a sequel, it would be with tanks. The overall implementation of the program would be almost the same. Difference would be in writing the AI, having already left, right, back, forward, & fire, then adding turret left, turret right, new for responses.
Like badidea that was another demo game where I worked on my own version of controlling a tank in "yet another tank game". But this illustrates a conflict in that many cowboy coders like to write their own code not fit in with other people's coding methods. It would be like two people working on the same painting.

So what would the first steps be in starting such a project?

This was an experiment in using the mouse to aim the turret and firing using the left mouse button.

Code: Select all

'some useful defines
Const Pi = 4 * Atn(1)
Dim Shared As Double TwoPi = 8 * Atn(1)
Dim Shared As Double RtoD = 180 / Pi   ' radians * RtoD = degrees
Dim Shared As Double DtoR = Pi / 180   ' degrees * DtoR = radians

screenres 640,480,32
color rgb(0,0,0),rgb(255,255,255):cls

dim shared as integer mx,my,mb        'mouse variable
dim shared as any ptr target
target = imagecreate(16,16,rgb(255,0,255))
circle target,(7,7),7,rgb(0,0,0)
line target,(7,0)-(7,15),rgb(0,0,0)
line target,(0,7)-(15,7),rgb(0,0,0)

setmouse ,,0  'turn off mouse cursor

dim shared as any ptr imgExplosion
imgExplosion = imagecreate(300,50)

dim shared as any ptr imgBullet
imgBullet = imagecreate(5,5,rgb(255,0,255))
line imgBullet,(0,0)-(4,4),rgb(255,0,255),bf
circle imgBullet,(2,2),2,rgb(255,255,0),,,,f

dim shared as any ptr imgTank,imgTurret,rotTank,rotTurret
imgTank = imagecreate(49,49,rgb(255,0,255))
'create 
line imgTank,(9,11)-(9+29,11+26),rgb(100,100,250),bf
line imgTank,(9,11)-(9+29,11+26),rgb(0,0,0),b
line imgTank,(10,5)-(10+27,5+7),rgb(100,100,250),bf
line imgTank,(10,5)-(10+27,5+7),rgb(0,0,0),b
line imgTank,(10,36)-(10+27,36+7),rgb(100,100,250),bf
line imgTank,(10,36)-(10+27,36+7),rgb(0,0,0),b
line imgTank,(37,15)-(37+4,15+18),rgb(200,100,0),bf
line imgTank,(37,15)-(37+4,15+18),rgb(0,0,0),b

imgTurret = imagecreate(49,49,rgb(255,0,255))
line imgTurret,(18,18)-(18+13,18+12),rgb(100,200,150),bf
line imgTurret,(18,18)-(18+13,18+12),rgb(0,0,0),b
line imgTurret,(1,22)-(1+17,22+4),rgb(100,200,150),bf
line imgTurret,(1,22)-(1+17,22+4),rgb(0,0,0),b

rotTank   = imagecreate(49,49)  'rotated version of tank
rotTurret = imagecreate(49,49)  'rotated version of turret

'create explosion graphics
for i as integer = 0 to 5
    circle imgExplosion,(i*50+25,25),(i+1)*4,rgb(200,155,0),,,,f
    circle imgExplosion,(i*50+25,25),(i+1)*2,rgb(255,255,0),,,,f
next i

type SPRITE
    as single  x
    as single  y
    as integer w
    as integer h
    as single  dx
    as single  dy
    as integer d        'direct 0=UP, 1=DOWN, 2=LEFT, 3=RIGHT
    as single  mv       'speed
    as single  tAngle   'turret angle
    as single  Angle    'tank direction
    as integer alive
end type

function testCollision(s1 as SPRITE,s2 as SPRITE) as boolean
    return (s1.y+s1.h) > (s2.y) and (s1.y) < (s2.y+s2.h) and (s1.x) < (s2.x+s2.w) and (s1.x + s1.w) > (s2.x)
end function

dim shared as SPRITE tank

tank.x = 320
tank.y = 240
tank.w = 49
tank.h = 49
tank.mv = 0
tank.Angle = 0
tank.tAngle = 0


dim shared as SPRITE bullet
bullet.x = 0
bullet.y = 0
bullet.w = 5
bullet.h = 5
bullet.mv = 0
bullet.angle = 0

dim shared as SPRITE explosion
explosion.x = 0
explosion.y = 0
explosion.w = 50
explosion.h = 50
explosion.alive = 0


sub rotateImage(img1 as any ptr,img2 as any ptr,ww as double)
    dim as double tx,ty,nx,ny,vx,vy,angle
    angle = (ww+180)*DtoR    
    dim as uinteger c
    for yp as double = 0 to 48 step .5
        for xp as double = 0 to 48 step .5      
            c = point(xp,yp,img1):'get color
            'select centre of image as centre of rotation
            vx = xp-(48\2)
            vy = yp-(48\2)     
            'equations to compute new x,y coordinates for rotation of ww degrees
            tx = cos(angle) * vx - sin(angle) * vy
            ty = cos(angle) * vy + sin(angle) * vx      
            nx = tx+(48\2)
            ny = ty+(48\2)
            pset img2,(nx,ny),c      
         next xp
    next yp
end sub

sub update()
    screenlock
    cls
    put (tank.x,tank.y),rotTank,trans
    put (tank.x,tank.y),rotTurret,trans
    
    if bullet.alive > 0 then
        circle (bullet.x,bullet.y),5,rgb(255,0,0),,,,f
        put (bullet.x,bullet.y),imgBullet,trans
    end if
    
    dim as integer frame
    if explosion.alive > 0 then
        frame = int(explosion.alive\10)
        frame = 5-(frame-1)
        put (explosion.x-25,explosion.y-25),imgExplosion,(frame*50,0)-(frame*50+explosion.w,explosion.h),trans
        explosion.alive = explosion.alive - 1
    end if
    
    put (mx,my),target,trans  'show target
    line ((tank.x+24),(tank.y+24))-((mx+8),(my+8)),rgb(0,0,255)
    
    screenunlock

end sub

sub moveTank()
    tank.x = tank.x + tank.dx  'make move
    tank.y = tank.y + tank.dy

        
    'boundary check
    if tank.x < 0 or tank.y < 0 or tank.x+tank.w > 639 or tank.y + tank.h > 479 then
        tank.x = tank.x - tank.dx 'undo move
        tank.y = tank.y - tank.dy
        tank.dx = 0
        tank.dy = 0
        tank.mv = 0
    end if
    
end sub

dim as double time1
time1 = timer
update()


do
    if timer > time1 + 0.01 then
        time1 = timer
        
        getmouse mx,my,,mb
        'show rotated version of image
        rotateImage(imgTank,rotTank,tank.Angle)
        rotateImage(imgTurret,rotTurret,tank.tAngle)
        
        tank.mv = 0
        if multikey(&H4D) then   'RIGHT
            tank.d = 0
            tank.angle = 0
            tank.mv = 1
        end if
        
        if multikey(&H4B) then   'LEFT
            tank.d = 1
            tank.Angle = 180
            tank.mv = 1
        end if
        
        'just rotates turret by itself
        if multikey(&H50) then   'DOWN
            tank.d = 2
            tank.Angle = 90
            tank.mv = 1
        end if
        
        if multikey(&H48) then   'UP
            tank.d = 2
            tank.angle = 270 
            tank.mv = 1
        end if

        'use mouse to get tAngle

        mx = mx + 8
        my = my + 8
        tank.tAngle = atan2((my+8)-(tank.y+24),(mx+8)-(tank.x+24))*57.2958 'get slope angle from x1,y1
        if tank.tAngle < 0 then tank.tAngle = tank.tAngle + 360


        tank.dx = cos(tank.angle * DtoR) * tank.mv
        tank.dy = sin(tank.angle * DtoR) * tank.mv
        
        if mb=1 and bullet.alive = 0 then
            bullet.alive = 100
            bullet.x  = Cos(tank.tAngle*DtoR)*25 + tank.x+24
            bullet.y  = Sin(tank.tAngle*DtoR)*25 + tank.y+24
            bullet.angle = tank.tAngle
            bullet.dx = cos(bullet.angle * DtoR) * 2
            bullet.dy = sin(bullet.angle * DtoR) * 2
        end if
        
        if bullet.alive > 0 then
            bullet.alive = bullet.alive - 1
            bullet.x = bullet.x + bullet.dx
            bullet.y = bullet.y + bullet.dy
            if bullet.alive = 0 then
                explosion.x = bullet.x
                explosion.y = bullet.y
                explosion.alive = 50
            end if
        end if

        moveTank()
        
        update()
        
    end if
loop until multikey(&H01)
paul doe
Moderator
Posts: 1730
Joined: Jul 25, 2017 17:22
Location: Argentina

Re: FreeBASIC Community produced game

Post by paul doe »

coderJeff wrote:yes, I think the most interesting part of the project for contributors was writing the AI logic. I think that's the key part to keep.
Definitely. That's the entire point of the simulation =D
coderJeff wrote:What I would have in mind:
1) Minimally fix the (possibly only known) last version of the game so it compiles with current fbc and let this be our reference prototype (even though the structure and modularity of the original program is fragile). Overall, the original concept is good, we don't need a new idea.
Agreed, the original concept is very good. It can get better, I'll draft some of my ideas and publish them here later, so make sure that you (and you guys, too!) tell me what you think. However, I wouldn't conserve the old code. I'll also show you what I have in mind in this respect, preparing a pretty barebones 'framework' to demonstrate it.
coderJeff wrote:2) Rewrite in the style of your framework to give it a robust implementation. (Actually, this game/AI simulation could be test case for some portion of your framework, but I would not make that a requirement, so this either project can proceed independently, regardless).
That's not a problem. I'm busy with some things now (which, incidentally, will also be useful in this context, too), so as soon as I'm finish I'll publish a first draft of the code.
coderJeff wrote:3) Run the AI challenge on the forum just as before. I think it would be successful.
Yes, I think so too. We shall see ;)
coderJeff wrote:And, if I were to do a sequel, it would be with tanks. The overall implementation of the program would be almost the same. Difference would be in writing the AI, having already left, right, back, forward, & fire, then adding turret left, turret right, new for responses.
I'd say that we stick to the original idea first, and implement a running framework for it. Once that is in place, we can easily modify it to accomodate anything else.
coderJeff wrote:Case study follow up:
There are 3 things that made this AI challenge project successful as a community collaborative effort:
1) leader to keep the project moving
I'd say that you take that role, as you were there when the original was released and know the mechanics. I can provide the code support, if you agree.
coderJeff wrote:2) simple design (main loop enforces the rules of the simulation and calls the AI)
Yes, that's not very hard to achieve. I can post a simple implementation of a cooperative multitasker, that should be our preferred method of implementing the loop. And also, provides an interesting frame for some cool stuff ;)
coderJeff wrote:3) modular components (AI) written in FB, that have a simple and uniform API
This is also easy to achieve using an ECS framework. I'm currently working on a class library to do serialization, since this approach is entirely data-driven. It does have, however, some pretty important security vulnerabilities (as we're injecting code into the process, and that could be potentially dangerous).
As for the rest:
coderJeff wrote:In contrast, the reboot, (which I think was going to be called "Atto"), had ambitious changes: new physics, destructible ship pieces, ship designer, openGL, assembler like virtual machine AI, multiple ships, and so on.
I'd say that we should stick to the simple, asteroids-like physics of the original. After all, this is about coding an AI, the rest is purely eye-candy.
OpenGL: we can consider it at a later stage. Eventually, it should be done in OpenGL however.
Multiple ships: trivial. This could give rise to very interesting and hectic battles, indeed!
Destructible ships, ship designer: Some of my ideas go in this direction. We'll discuss them later.
ASM-like VM: I definitely think that this is the approach we should take. A simple DSL could be implemented to interface with the game code. Scripting-like languages like LUA are out ot the question, as we need it to be as sandboxed as possible. I have a Forth implementation that runs on top of FreeBasic (to use as an internal tool for scripting) that can be modified and used for this purpose, and makes interfacing with the underlying framework trivial (no need for an interfacing layer; we can simply push the needed parameters and data to the VM stack).

Give me a little time, and I'll prepare a draft with several ideas that we can use. Everybody can contribute to this project, so make sure that you make your voice heard =D
coderJeff
Site Admin
Posts: 4313
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: FreeBASIC Community produced game

Post by coderJeff »

BasicCoder2 wrote:
coderJeff wrote: BasicCoder2, I tried your demo, and feels like could be a fun game.
Which demo? I have posted a lot of them.
The one with the bricks and ladders, it looked like loderunner. But you you deleted your post. That one. That's the post I quoted from.
badidea
Posts: 2586
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: FreeBASIC Community produced game

Post by badidea »

@coderJeff
I understand, the start should be simple. Just saying that I like the idea.
What if you try to finish the next fbc release first and with it an announcement that you switch to fun stuff for a while? Getting into fbc development does not seem attractive to me (as well).
About the game, I am in no hurry to start today. Next to other freebasic projects and normal work, I'm still working on my house. Need to get heating installed again before winter starts, and other minor things like a missing kitchen.

@BasicCoder2
If the goal isn't a best seller on steam, we can keep the artwork minimal, like your tank demo (line drawings), and still have fun with the AI stuff. Maybe someone later joins who likes to improve the artwork.
In my game, both the tank and the turret had a limited rotation speed. Where the turret rotates slowly to the mouse position. Not sure if I ever posted the code. Probably seeds some updates to run with the latest fbc and fbsound. I'll have a look.
BasicCoder2
Posts: 3906
Joined: Jan 01, 2009 7:03
Location: Australia

Re: FreeBASIC Community produced game

Post by BasicCoder2 »

coderJeff wrote:
BasicCoder2 wrote:
coderJeff wrote: BasicCoder2, I tried your demo, and feels like could be a fun game.
Which demo? I have posted a lot of them.
The one with the bricks and ladders, it looked like loderunner. But you you deleted your post. That one. That's the post I quoted from.
Ok. Sorry. I deleted it because I thought it was a distraction from the subject of the thread.
I had also posted an image of a Wolfenstein style ray caster world game engine I had written and had intended turning into a game.
I deleted that also for the same reason.
It was a lode runner clone as a coding exercise and for that reason I didn't pursue it further.
coderJeff
Site Admin
Posts: 4313
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: FreeBASIC Community produced game

Post by coderJeff »

paul doe wrote:I'd say that we should stick to the simple, asteroids-like physics of the original. After all, this is about coding an AI, the rest is
purely eye-candy.
perfect, I think we are agreed on the primary goal.
ASM-like VM: I definitely think that this is the approach we should take.
Interesting for some, most likely. I will definitely disagree on this point because then the AI is no longer FreeBASIC. However, you can convince me otherwise another time, while we work towards a first version. :)

Overall, I think this sounds very promising. Cool.
paul doe
Moderator
Posts: 1730
Joined: Jul 25, 2017 17:22
Location: Argentina

Re: FreeBASIC Community produced game

Post by paul doe »

badidea wrote:@coderJeff
I understand, the start should be simple. Just saying that I like the idea.
What if you try to finish the next fbc release first and with it an announcement that you switch to fun stuff for a while? Getting into fbc development does not seem attractive to me (as well).
Indeed, that's what I was thinking too.

@coderJeff: a little fun can't hurt, no? ;)
badidea wrote:@BasicCoder2
If the goal isn't a best seller on steam, we can keep the artwork minimal, like your tank demo (line drawings), and still have fun with the AI stuff. Maybe someone later joins who likes to improve the artwork.
I agree with this one too. The artwork is of lesser importance (at least in the first releases). Once we get something flexible and extensible up and running, we can start adding/changing/removing things as we see fit. Your tank game looks cool! =D
BasicCoder2 wrote:Ok. Sorry. I deleted it because I thought it was a distraction from the subject of the thread.
I had also posted an image of a Wolfenstein style ray caster world game engine I had written and had intended turning into a game.
I deleted that also for the same reason.
It was a lode runner clone as a coding exercise and for that reason I didn't pursue it further.
The snippets/project looks good. No need to delete them, BC2. Keep them coming =D
paul doe
Moderator
Posts: 1730
Joined: Jul 25, 2017 17:22
Location: Argentina

Re: FreeBASIC Community produced game

Post by paul doe »

coderJeff wrote:perfect, I think we are agreed on the primary goal.
Excellent. I'll start working on it as soon as I can.
coderJeff wrote:Interesting for some, most likely. I will definitely disagree on this point because then the AI is no longer FreeBASIC. However, you can convince me otherwise another time, while we work towards a first version. :)

Overall, I think this sounds very promising. Cool.
There's no problem on using FreeBasic itself, either. You can interface with the application layer and pass it the source code of the AI, which then goes through a validation layer (to sandbox the code and avoid injecting malicious and/or potentially harmful stuff), and if it passes the validation then gets compiled and injected into the application. The drawback is that you can't submit precompiled binaries, but this isn't necessarily a problem. I don't know, guys. What do you think?
coderJeff
Site Admin
Posts: 4313
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: FreeBASIC Community produced game

Post by coderJeff »

paul doe wrote:pass it the source code of the AI, which then goes through a validation layer (to sandbox the code and avoid injecting malicious and/or potentially harmful stuff)
Ah, I see where you are going with this, to protect the the host computer.
- a valid concern that can't be ignored, however,
- it seems to me, counterproductive, to create a FB challenge that asks the entrant to program in some other language, and,
- the entrant will be a member from the forum, they will have to have their name on it

My opinion on this is that entrants to the challenge should be able to submit FreeBASIC source code. I had no expectation to allow binaries. Your framework may allow other methods of scripting, that's up to you of course. But for the AI challenge it makes sense to me that it be fbc source. An included header plus a derived class for example.
RockTheSchock
Posts: 252
Joined: Mar 12, 2006 16:25

Re: FreeBASIC Community produced game

Post by RockTheSchock »

Whenever I see a new ai programming contest framework thread, i remember RealTimeBattle.
coderJeff wrote:Ah, I see where you are going with this, to protect the the host computer.
- a valid concern that can't be ignored, however,
- it seems to me, counterproductive, to create a FB challenge that asks the entrant to program in some other language, and,
- the entrant will be a member from the forum, they will have to have their name on it
Lets borrow some ideas from realtimebattle. It has a simple interface with bidirectional pipes. So you can programm your bot in any language. Adding a network socket interface would allow more flexibility. If you are paranoid, you could even run the guest robot in a virtual machine enviroment. Separating of GUI and Core is another good point.
Post Reply