In freeBASIC, is it possible to do two calculations at once or close? I have been testing it with the draw string command as well as the circle command but when I draw two of each, I only control the first mentioned in the code.
Thank you for any help I receive!
- Ivan
Controlling two characters at once
-
- Posts: 44
- Joined: Nov 07, 2019 21:57
Re: Controlling two characters at once
Not sure I understand the question.
With FreeBASIC you can make anything form your own OS to your own World of Craft. (if you have the time and motivation, both years of work for a group of developers).
The limit to your question seems input hardware. How are the players going to control the characters? Sharing the same keyboard is technically[1] and piratically inconvenient. Like a game computers (e.g. xbox) you probably need multiple joysticks or game-pads. (I never tried this with a normal PC). Another option is link computers via network, but building network code into your game is not trivial.
[1]There is maximum numbers of keys that can be pressed (and detected) at ounce.
With FreeBASIC you can make anything form your own OS to your own World of Craft. (if you have the time and motivation, both years of work for a group of developers).
The limit to your question seems input hardware. How are the players going to control the characters? Sharing the same keyboard is technically[1] and piratically inconvenient. Like a game computers (e.g. xbox) you probably need multiple joysticks or game-pads. (I never tried this with a normal PC). Another option is link computers via network, but building network code into your game is not trivial.
[1]There is maximum numbers of keys that can be pressed (and detected) at ounce.
-
- Posts: 862
- Joined: May 05, 2015 5:35
- Location: Germany
Re: Controlling two characters at once
If using a multi-core-processor, it could help to do every calculation in an own thread.
Re: Controlling two characters at once
Would help immensely (and resolve the issue faster) if you showed us a code snippet with your intent...IvanisIvan wrote:In freeBASIC, is it possible to do two calculations at once or close? I have been testing it with the draw string command as well as the circle command but when I draw two of each, I only control the first mentioned in the code.
...
For example:
Code: Select all
#include once "fbgfx.bi"
type as long _
Control
type Player
as integer _
x, y, _
radius
as double _
speed
as ulong _
color
as Control _
up, _
down, _
left, _
right
end type
type _
Bounds
as integer _
width, _
height
end type
sub _
renderAsCircle( _
aPlayer as Player )
circle _
( aPlayer.x, aPlayer.y ), _
aPlayer.radius, _
aPlayer.color, , , , f
end sub
sub _
updateFrame( _
byref extents as Bounds, _
players() as Player, _
byval dT as double )
for _
i as integer => 0 _
to ubound( players )
with players( i )
if( multiKey( .up ) ) then
.y => iif( .y > 0, _
.y - .speed * dT, 0 )
end if
if( multiKey( .down ) ) then
.y => iif( .y < extents.height, _
.y + .speed * dT, extents.height )
end if
if( multiKey( .left ) ) then
.x => iif( .x > 0, _
.x - .speed * dT, 0 )
end if
if( multiKey( .right ) ) then
.x => iif( .x < extents.width, _
.x + .speed * dT, extents.width )
end if
end with
next
end sub
sub _
renderFrame( _
byref extents as Bounds, _
players() as Player )
screenLock()
cls()
for _
i as integer => 0 _
to ubound( players )
renderAsCircle( players( i ) )
next
screenUnlock()
end sub
var _
displayBounds => type <Bounds> ( _
800, 600 )
dim as Player _
players( ... ) => { _
type <Player> ( _
50, displayBounds.height \ 2 , _
25, 1.0, rgb( 255, 0, 0 ), _
Fb.SC_W, _
Fb.SC_S, _
Fb.SC_A, _
Fb.SC_D ), _
type <Player> ( _
displayBounds.width - 50, displayBounds.height \ 2 , _
25, 1.0, rgb( 0, 0, 255 ), _
Fb.SC_UP, _
Fb.SC_DOWN, _
Fb.SC_LEFT, _
Fb.SC_RIGHT ) }
screenRes( _
displayBounds.width, _
displayBounds.height, _
32 )
dim as double _
dT
do
dT => timer()
renderFrame( _
displayBounds, _
players() )
sleep( 1, 1 )
dT => timer() - dT
/'
The delta time here is expressed in milliseconds, so the speed of a
player is interpreted as pixels/second. Thus, if you specify a speed
of 1.0, it will move at a rate of 1000 pixels/second.
'/
updateFrame( _
displayBounds, _
players(), _
dT * 1000.0 )
loop until( multiKey( Fb.SC_ESCAPE ) )