Another freebasic miner
Re: Another freebasic miner
Not near a computer at the moment, but that last picture looks good.
Infinite map may be unneeded complication indeed. Left / right direction, I while probably loop, to hide borders. At lower depth lava and unbreakable rock to hide the fixed borders.
Infinite map may be unneeded complication indeed. Left / right direction, I while probably loop, to hide borders. At lower depth lava and unbreakable rock to hide the fixed borders.
Re: Another freebasic miner
Here's the techique I was talking about before (perturbing a Worley map with a Perlin one):
So you can either threshold them for your resources, or generate a (perhaps subtler) separate map for each one of them, combine (by multiplying), and then threshold them. The possibilities using noise maps are endless ;)
PS: perhaps I should pull out the code into a separate project, and post some examples of what you can achieve by using such functions. Might prove to be quite fun and useful.
Code: Select all
/'
-1 .. 1 range
'/
function _
noise1( _
byval x as integer ) _
as single
x => ( x shl 13 ) xor x
return( ( 1.0! - ( ( x * ( x * x * 15731 + 789221) + 1376312589) and &h7fffffff) / 1073741824.0! ) )
end function
/'
0 .. 1 range
'/
function _
noise1n( _
byval x as integer ) _
as single
return( ( noise1( x ) / 2.0! ) + 0.5! )
end function
/'
-1 .. 1 range
'/
function _
noise2( _
byval x as integer, _
byval y as integer ) _
as single
dim as integer _
n => x + y * 57
n => ( n shl 13 ) xor n
return( ( 1.0! - ( ( n * ( n * n * 15731 + 789221 ) + 1376312589 ) and &h7fffffff ) / 1073741824.0! ) )
end function
/'
0 .. 1 range
'/
function _
noise2n( _
byval x as integer, _
byval y as integer ) _
as single
return( ( noise2( x, y ) / 2.0! ) + 0.5! )
end function
/'
Smooths the noise with bilinear interpolation.
-1 .. 1 range
'/
function _
smoothedNoise( _
byval x as single, _
byval y as single ) _
as single
dim as single _
fractX => x - int( x ), _
fractY => y - int( y )
dim as integer _
x1 => int( x ), _
y1 => int( y ), _
x2 => int( x - 1 ), _
y2 => int( y - 1 )
dim as single _
value => _
fractX * fractY * noise2( x1, y1 ) + _
fractX * ( 1.0! - fractY ) * noise2( x1, y2 ) + _
( 1.0! - fractX ) * fractY * noise2( x2, y1 ) + _
( 1.0! - fractX ) * ( 1.0! - fractY ) * noise2( x2, y2 )
return( value )
end function
/'
Creates a turbulence texture (aka Perlin Noise).
-1 .. 1 range
'/
function _
turbulence( _
byval x as single, _
byval y as single, _
byval size as single ) _
as single
dim as single _
value => 0.0!, _
initialSize => size
do while( size >= 1.0! )
value +=> smoothedNoise( x / size, y / size ) * size
size /=> 2.0!
loop
value => value / initialSize
return( iif( value < -1.0, -1.0, _
iif( value > 1.0, 1.0, value ) ) )
end function
function _
maxV( _
byval a as single, _
byval b as single ) _
as single
return( iif( a > b, a, b ) )
end function
function _
wn_dist_euclidean( _
byval x1 as single, _
byval y1 as single, _
byval x2 as single, _
byval y2 as single ) _
as single
return( sqr( ( x1 - x2 ) ^ 2 + ( y1 - y2 ) ^ 2 ) )
end function
function _
wn_dist_manhattan( _
byval x1 as single, _
byval y1 as single, _
byval x2 as single, _
byval y2 as single ) _
as single
return( abs( x1 - x2 ) + abs( y1 - y2 ) )
end function
function _
wn_dist_squared( _
byval x1 as single, _
byval y1 as single, _
byval x2 as single, _
byval y2 as single ) _
as single
return( maxV( abs( ( x1 - x2 ) ), abs( ( y1 - y2 ) ) ) )
end function
function _
wn_result_1( _
byval F as single, _
byval S as single, _
byval T as single, _
byval bias as single ) _
as single
return( ( F ^ 2 ) / ( S * T ) )
end function
function _
wn_result_2( _
byval F as single, _
byval S as single, _
byval T as single, _
byval bias as single ) _
as single
return( F / bias )
end function
function _
wn_result_3( _
byval F as single, _
byval S as single, _
byval T as single, _
byval bias as single ) _
as single
return( S / bias )
end function
function _
wn_result_4( _
byval F as single, _
byval S as single, _
byval T as single, _
byval bias as single ) _
as single
return( T / bias )
end function
function _
wn_result_5( _
byval F as single, _
byval S as single, _
byval T as single, _
byval bias as single ) _
as single
return( 2.0! * F / ( S + T ) )
end function
function _
wn_result_6( _
byval F as single, _
byval S as single, _
byval T as single, _
byval bias as single ) _
as single
return( F / S )
end function
function _
wn_result_7( _
byval F as single, _
byval S as single, _
byval T as single, _
byval bias as single ) _
as single
return( ( S - F ) / bias )
end function
function _
wn_result_8( _
byval F as single, _
byval S as single, _
byval T as single, _
byval bias as single ) _
as single
return( ( T - F ) / bias )
end function
function _
wn_result_9( _
byval F as single, _
byval S as single, _
byval T as single, _
byval bias as single ) _
as single
return( ( T - S ) / bias )
end function
/'
Worley noise (aka 'Cellular noise')
0 .. 1 range
'/
function _
worley( _
byval x as integer, _
byval y as integer, _
byval size as integer, _
byval cellSize as single, _
byval distanceFunc as function( _
byval as single, _
byval as single, _
byval as single, _
byval as single ) as single => _
@wn_dist_euclidean, _
byval resultFunc as function( _
byval as single, _
byval as single, _
byval as single, _
byval as single ) as single => _
@wn_result_1, _
byval bias as single => 1.0 ) _
as single
dim as single _
firstPoint => 2.0! * cellSize, _
secondPoint => 2.0! * cellSize, _
thirdPoint => 2.0! * cellSize, _
dist, xp, yp
dim as integer _
numCells => int( size / cellSize ) + 1, _
cellX => int( x / cellSize ), _
cellY => int( y / cellSize ), _
cell => numCells * cellY + cellX, _
cellPoint
for _
j as integer => -1 to 1
for _
i as integer => -1 to 1
cellPoint => cell + i + j * numCells
xp => _
( cellX + i ) * cellSize + _
noise1n( cellPoint ) * cellSize
yp => _
( cellY + j ) * cellSize + _
noise1n( cellPoint + 10 ) * cellSize
dist => distanceFunc( x, y, xp, yp )
if( firstPoint > dist ) then
thirdPoint => secondPoint
secondPoint => firstPoint
firstPoint => dist
elseif( secondPoint > dist ) then
thirdPoint => secondPoint
secondPoint => dist
elseif( thirdPoint > dist ) then
thirdPoint => dist
end if
next
next
dim as single _
result => resultFunc( _
firstPoint, secondPoint, thirdPoint, bias )
return( iif( result > 1.0!, 1.0!, result ) )
end function
dim as integer _
w => 256, _
h => 256, _
seed => 123456
screenRes( w, h, 32 )
windowTitle( "Noise playground" )
for _
y as integer => 0 _
to h - 1
for _
x as integer => 0 _
to w - 1
dim as single _
n => worley( _
x + 30.0! * turbulence( x, y, 32 ), _
y + 20.0! * turbulence( x, y, 16 ), _
w, 64 )
dim as ubyte _
c => n * 255
/'
Remap the texture to colors
'/
pset _
( x, y ), _
rgba( c, c, c, 255 )
next
next
sleep()
So you can either threshold them for your resources, or generate a (perhaps subtler) separate map for each one of them, combine (by multiplying), and then threshold them. The possibilities using noise maps are endless ;)
PS: perhaps I should pull out the code into a separate project, and post some examples of what you can achieve by using such functions. Might prove to be quite fun and useful.
Re: Another freebasic miner
Yes, can be useful. I don't mind the code here, but it might get lost here.paul doe wrote:PS: perhaps I should pull out the code into a separate project, and post some examples of what you can achieve by using such functions. Might prove to be quite fun and useful.
Meanwhile, I experimented a bit with a random walk with some preferred direction:
Code: Select all
const PIX_SIZE = 5
const SW = 800, SH = 600
screenres SW, SH, 32
width SW \ 8, SH \ 16
function rndRange(min as single, max as single) as single
return rnd() * (max - min) + min
end function
sub pset_big(x as integer, y as integer, c as ulong)
line(x * PIX_SIZE, y * PIX_SIZE)-step(PIX_SIZE - 2, PIX_SIZE - 2), c, bf
end sub
function isOnScreen(x as integer, y as integer) as boolean
if x < 0 or x > SW \ PIX_SIZE then return false
if y < 0 or y > SH \ PIX_SIZE then return false
return true
end function
dim as integer count = 0
dim as single x, y, xOffset, yOffset
dim as ulong c 'color
randomize timer
while inkey <> chr(27)
if count <= 0 then
if c <> 0 then sleep 500 'don't wait on first run
cls
count = 500
x = rndRange(0, SW \ PIX_SIZE)
y = rndRange(0, SH \ PIX_SIZE)
xOffset = rndRange(-0.015, +0.15)
yOffset = rndRange(-0.010, +0.10)
c = rgb(rndRange(63, 255), rndRange(63, 255), rndRange(63, 255))
end if
pset_big(x, y, c)
x += rndRange(-0.5, +0.5) + xOffset
y += rndRange(-0.5, +0.5) + yOffset
if isOnScreen(x, y) = false then count = 0
count -= 1
'sleep 10
wend
print "End"
sleep
Not the most efficient code, going to try a bit different one.
Something like this:
Code: Select all
const PIX_SIZE = 5
const SW = 800, SH = 600
screenres SW, SH, 32
width SW \ 8, SH \ 16
type int2d
dim as integer x, y
end type
function rndRange(min as single, max as single) as single
return rnd() * (max - min) + min
end function
sub pset_big(x as integer, y as integer, c as ulong)
line(x * PIX_SIZE, y * PIX_SIZE)-step(PIX_SIZE - 2, PIX_SIZE - 2), c, bf
end sub
function isOnScreen(x as integer, y as integer) as boolean
if x < 0 or x > SW \ PIX_SIZE then return false
if y < 0 or y > SH \ PIX_SIZE then return false
return true
end function
'right, left, down, up
dim as int2d move(0 to 3) = {(0, +1), (0, -1), (+1, 0), (-1, 0)}
dim as integer badMove
dim as ulong rockColor(0 to 6) = _
{&hffffff, &hff0000, &h00ff00, &h0000ff, &hffff00, &hff00ff, &h00ffff}
dim as integer count = 0
dim as integer x, y, i
dim as ulong c 'color
randomize timer
while inkey <> chr(27)
if count <= 0 then
count = 50
x = rndRange(0, SW \ PIX_SIZE)
y = rndRange(0, SH \ PIX_SIZE)
i = cint((y / (SH \ PIX_SIZE)) * 7 - 0.5)
if i < 0 then i = 0
if i > 6 then i = 6
c = rockColor(i)
badMove = int(rnd * 4)
end if
pset_big(x, y, c)
do
i = int(rnd * 4)
loop while i = badMove
x += move(i).x
y += move(i).y
if isOnScreen(x, y) = false then count = 0
count -= 1
sleep 10
wend
print "End"
sleep
Re: Another freebasic miner
Just made the game map here 150 blocks deep. Now I need a 'quick view' mode, because drilling down 150 blocks takes a while :-)
Quite amazing that these days you can just say make a map 10,000 blocks wide and 10,000 blocks deep and the computer does not complain at all.
Just a bit of time to fill the map with random blocks. Digging to the bottom would take a few hours however.
Quite amazing that these days you can just say make a map 10,000 blocks wide and 10,000 blocks deep and the computer does not complain at all.
Just a bit of time to fill the map with random blocks. Digging to the bottom would take a few hours however.
-
- Posts: 1002
- Joined: Nov 24, 2011 19:49
- Location: France
- Contact:
Re: Another freebasic miner
Hello!
I can't compile the latest version from the GitHub repository. I get this error:
miner.c:529:8: error: redéfinition de « struct $8FBARRAY1IlE »
struct $8FBARRAY1IlE {
^~~~~~~~~~~~~
miner.c:518:8: note: défini initialement ici
struct $8FBARRAY1IlE {
^~~~~~~~~~~~~
Here is my compiler version:
FreeBASIC Compiler - Version 1.07.1 (2019-09-27), built for linux-x86_64 (64bit)
Copyright (C) 2004-2019 The FreeBASIC development team.
No idea of what happens.
I can't compile the latest version from the GitHub repository. I get this error:
miner.c:529:8: error: redéfinition de « struct $8FBARRAY1IlE »
struct $8FBARRAY1IlE {
^~~~~~~~~~~~~
miner.c:518:8: note: défini initialement ici
struct $8FBARRAY1IlE {
^~~~~~~~~~~~~
Here is my compiler version:
FreeBASIC Compiler - Version 1.07.1 (2019-09-27), built for linux-x86_64 (64bit)
Copyright (C) 2004-2019 The FreeBASIC development team.
No idea of what happens.
Re: Another freebasic miner
Yes, I ran into this problem yesterday (late), see: https://freebasic.net/forum/viewtopic.php?f=3&t=28364Roland Chastain wrote:I can't compile the latest version from the GitHub repository. I get this error: ...
I'll try to fix it today (coming hours).
Quick fix: In miner.bas, change flowerArray(...) to flowerArray(0 to 4)
-
- Posts: 3906
- Joined: Jan 01, 2009 7:03
- Location: Australia
Re: Another freebasic miner
Another example of a game using the same graphics.
https://www.youtube.com/watch?v=_tUl1ezLgFQ
In your demos so far the the little miner gets stuck. It would be nice to have demo of even a simple working version to which you can add more game play later. I notice that in the above game the miner can build the ladders as he goes.
Your efforts have inspired me to spend some time refining some code to make another demo of a miner game.
https://www.youtube.com/watch?v=_tUl1ezLgFQ
In your demos so far the the little miner gets stuck. It would be nice to have demo of even a simple working version to which you can add more game play later. I notice that in the above game the miner can build the ladders as he goes.
Your efforts have inspired me to spend some time refining some code to make another demo of a miner game.
Re: Another freebasic miner
Redirected from https://freebasic.net/forum/viewtopic.p ... 57#p269359
Using a complete class for 4 numbers seems overkill to me. (2 lines of code vs your 40 lines).
However, I have more flower related stuff in my 'map_type' class which already marked with "'move this flower stuff elsewhere?"
So I will probably move all this to a new 'flower_type' class.
But I have also planned trees and fruit plants which may behave similarly, but maybe not.
I will wait for these plans to settle before I start making a new class.
flowerArray() contains image ID's of images (or sprites) containing flowers (each time the first ID of 3 images in row for animation),paul doe wrote:However, I tried to convey a different idea:This is a telltale sign that you have unwanted coupling between classes. What you do in those cases is simply make the arrays into their own classes. What do they represent in your code? Bitmaps? Tiles (bitmaps with some other associated data)?badidea wrote: ...
You are right, I was using that stuff in 1 class only, moved there now.
Edit: Still not optimal. In a class, I cannot use flowerArray(...).
...
Besides, you can use it even when encapsulated. Just expose appropriately:But, again, if they're used by more than one other class, it means that they need their own abstraction.Code: Select all
type _ SomeClass public: declare constructor( _ a() as integer ) declare destructor() declare property _ flowerArray() as integer ptr declare property _ flowerArrayCount() as integer private: declare constructor() as integer ptr _ _flowerArray as integer _ _flowerArrayCount end type constructor _ SomeClass() end constructor constructor _ SomeClass( _ a() as integer ) _flowerArray => @a( 0 ) _flowerArrayCount => ubound( a ) - lbound( a ) + 1 end constructor destructor _ SomeClass() end destructor property _ SomeClass.flowerArray() _ as integer ptr return( _flowerArray ) end property property _ SomeClass.flowerArrayCount() _ as integer return( _flowerArrayCount ) end property dim as integer _ flowerArray( ... ) => { 1, 2, 3, 4 } var _ c => SomeClass( flowerArray() ) for _ i as integer => 0 _ to c.flowerArrayCount - 1 ? c.flowerArray[ i ] next sleep()
Using a complete class for 4 numbers seems overkill to me. (2 lines of code vs your 40 lines).
However, I have more flower related stuff in my 'map_type' class which already marked with "'move this flower stuff elsewhere?"
So I will probably move all this to a new 'flower_type' class.
But I have also planned trees and fruit plants which may behave similarly, but maybe not.
I will wait for these plans to settle before I start making a new class.
Re: Another freebasic miner
Yes, I have seen that one as well. Unfortunately, I don't have the sounds and music. I wonder what the use of the space-shuttle is. I have the image and I plan to use it as well, but the combination mining and space travel seems odd.BasicCoder2 wrote:Another example of a game using the same graphics.
https://www.youtube.com/watch?v=_tUl1ezLgFQ
In your demos so far the the little miner gets stuck. It would be nice to have demo of even a simple working version to which you can add more game play later. I notice that in the above game the miner can build the ladders as he goes.
Your efforts have inspired me to spend some time refining some code to make another demo of a miner game.
And yes, my miner is a bit slow compared to that. I will put "build ladders while climbing" on my list, but I will continue with other stuff first. Like collecting resources. I want to keep a certain progress in the development and not spend weeks perfecting one functionality and then getting bored with the project.
Re: Another freebasic miner
After some structural changes to the code, I can continue implementing game functionality.
First goal: Collect a resource / mineral. But how should the miner pick up the resource?
1) Walk over it, then add to inventory? But what to do with a 'freed' resource hanging mid air? Drop it? What if another one drops in the same place?
2) Or move the resource automatically to the inventory? With some movement to miner animation. The no need to worry about dropping resources.
But, should there be a limit on the amount of collected resources that the miner can carry? Then option 2 is a problem.
The game 'treasure miner 2' (using the same graphics) seems to use option 1 + limited carrying capacity. I tend to go with option 2 with unlimited capacity. If you die, you lose your resources. So still a need to visit the surface regularly to store stuff safely, and recover from damage.
Problem illustration:
First goal: Collect a resource / mineral. But how should the miner pick up the resource?
1) Walk over it, then add to inventory? But what to do with a 'freed' resource hanging mid air? Drop it? What if another one drops in the same place?
2) Or move the resource automatically to the inventory? With some movement to miner animation. The no need to worry about dropping resources.
But, should there be a limit on the amount of collected resources that the miner can carry? Then option 2 is a problem.
The game 'treasure miner 2' (using the same graphics) seems to use option 1 + limited carrying capacity. I tend to go with option 2 with unlimited capacity. If you die, you lose your resources. So still a need to visit the surface regularly to store stuff safely, and recover from damage.
Problem illustration:
-
- Posts: 3906
- Joined: Jan 01, 2009 7:03
- Location: Australia
Re: Another freebasic miner
As I mentioned before I am also working on a simple miner game. I would just add gold and so on to the inventory. Depends how "realistic" you want it to look. For example in real mining you have to use carts, buckets and so on to physically remove rocks and soil as you dig. I am using separate animations when the miner is using different tools. No need to complicate it however as these games are symbolic and game play is the most important aspect to consider although I guess visuals do add to game play.
Re: Another freebasic miner
Are you using the same graphics? That would be funny, 2 different games using the same graphics. One can even make a jump-and-run Mario-like game with these graphics.BasicCoder2 wrote:As I mentioned before I am also working on a simple miner game.
I have a plan, not yet ready. Resources will fly to the miner once 'extracted'. Using similar code like here: https://freebasic.net/forum/viewtopic.p ... 88#p269760BasicCoder2 wrote:I would just add gold and so on to the inventory. Depends how "realistic" you want it to look.
If I get to use dynamite for mining (there are images), it will be multiple resources flying to the miner at once.
There are elevators/lifts in the graphics set which I might use later, but no carts. And I don't want to draw a single pixel for this game.BasicCoder2 wrote:For example in real mining you have to use carts, buckets and so on to physically remove rocks and soil as you dig.
Yes, a bit of animation makes he game more lively. That is why I also added the waving flowers. Totally useless, but nice. It was easy to do since the animation frames were already made.BasicCoder2 wrote:I am using separate animations when the miner is using different tools. No need to complicate it however as these games are symbolic and game play is the most important aspect to consider although I guess visuals do add to game play.
Re: Another freebasic miner
Resource collection finally implemented (code a bit messy).
https://github.com/verybadidea/Another-freebasic-miner
https://github.com/verybadidea/Another-freebasic-miner