bitrunner

Game development specific discussions.
Post Reply
pr1mezr0
Posts: 6
Joined: Mar 16, 2023 2:42

bitrunner

Post by pr1mezr0 »

I made this game a few years ago and thought i lost the source code for it but i found it. It's called BitRunner.

Code: Select all

Const palegreen = rgb(150,250,150)
Const cream = rgb(225,225,150)
const gold = rgb(120,120,50)
Const black = rgb(0,0,0)
Const lightblue = rgb(200,200,255)
Const lightpink = rgb(200,150,150)
Const pi=3.1415926535
Const maxbits = 1000

Randomize Timer

type screentype
    as integer x,y,hx,hy
end type

type bitstype
    As single cycle, scycle  ,ecycle ,vigour, guard, spd
    As Byte sign
    As Single   x , y _
                , oldx , oldy
    as uinteger colour
End Type

Type contype
    As Integer x , y , b
    as ubyte sleepb
End Type

Type playertype
    As single x , y _
            , oldx , oldy ,oldx2 ,oldy2
    As Integer totrings, rings, bestrings
    as byte forcefield
    as contype con(2)
    as byte consel
End Type

Type appletype
    As Integer x , y , size
End Type

type gamemodetype
	as string *32 title
	as integer id_n
end type

type globaltype
	as integer ovalsize,totbits
	as byte restart,appleexist,quit, trails, gamespeed
	as single modlen,modspd
	as integer surcounter
	as gamemodetype gamemode
    as double start
	
end type

type movebitcalc
    as single mag , angle , vecx, vecy ,vecx2, vecy2
end type

dim as screentype scr

Dim As playertype player
dim as bitstype bitt(maxbits)
Dim As appletype apple
dim as movebitcalc mbc

Dim scoretable(2) As Any Ptr
dim highscore(2) as integer

dim shared as globaltype glob
dim as integer i

declare sub openhighscores(scoretable() as any ptr, highscore() as integer, i as integer)
Declare Sub alllogic(player as playertype ,scoretable() as any ptr,highscore() as integer,apple as appletype,scr as screentype, bitt() as bitstype, i as integer,  mbc as movebitcalc)

Declare Sub moveyourself(player as playertype,scr as screentype, speedx as single, speedy as single, tempmousex as integer, tempmousey as integer)
declare sub draw_cursor(player as playertype, colour as uinteger)

Declare Sub endsub(player as playertype,scoretable() as any ptr,highscore() as integer,scr as screentype,i as integer )

Declare Sub movebits(player as playertype, bitt() as bitstype, mbc as movebitcalc, scr as screentype)
declare sub tiltbits(player as playertype, bitt() as bitstype, mbc as movebitcalc)

Declare Sub plotbits(bitt() as bitstype, i as integer)
Declare Sub plotplayer(player as playertype)

Declare Sub setupbits(scr as screentype, bitt() as bitstype, i as integer)
Declare Sub reinit(player as playertype,scr as screentype, bitt() as bitstype, i as integer)
declare sub resetbittcount()

Declare Sub apples(player as playertype, apple as appletype,scr as screentype,  mbc as movebitcalc)
declare sub drawapple (apple as appletype)

Declare Sub bsavehigh(i As Integer,player as playertype, highscore() as integer , scoretable() as any ptr,scr as screentype)

Declare Function checkcollision(plyrx as integer,plyry as integer, bitt() as bitstype) As Byte
Declare Function checkescape (plyrx as single,plyry as single,scrhx as integer,scrhy as integer) As Byte
declare function gtky (conx as integer,cony as integer,conb as integer) as byte
declare sub splashscreen
declare sub initial_screen (player as playertype, scr as screentype, scoretable() as any ptr, i as integer)
declare sub options(player as playertype, scr as screentype, i as integer)
declare sub optionsgraphics(scr as screentype, fullscreen as byte)


scr.x=640:scr.y=480
screeninfo scr.x,scr.y
scr.hx=scr.x*.5:scr.hy=scr.y*.5
screenres scr.x,scr.y,32,,1

For i = 0 To 2
    scoretable(i) = ImageCreate(scr.x/4,scr.y/4,black )
Next
openhighscores(scoretable(),highscore(),i)

glob.ovalsize = scr.hy
glob.modspd = 1
glob.modlen = glob.ovalsize*.4 '.41025

apple.size=cint((glob.ovalsize/240)*10)
glob.gamespeed=10

glob.gamemode.title="SURVIVAL"
glob.gamemode.id_n=1


do

initial_screen (player, scr, scoretable(), i)

player.rings=0:player.totrings=0:player.bestrings=0

    Do
        getmouse player.con(0).x , player.con(0).y , , player.con(0).b
        gtky( player.con(1).x,player.con(1).y,player.con(1).b ) 
        	                
        for i = 0 to 2
		    If player.con(i).y < 50 And player.con(i).b <> 0 Then
		    
		    	player.consel=i
		    	
		        Select Case player.con(player.consel).b
		        Case 1
		            glob.gamemode.title="ESCAPE"
		            glob.gamemode.id_n=0
		        Case 2
		            glob.gamemode.title="MAXRUN"
		            glob.gamemode.id_n=2
		        Case 4
		            glob.gamemode.title="SURVIVAL"
		            glob.gamemode.id_n=1
		        End Select
                
                Line (1,17)-(scr.x,24),rgb(0,0,0),bf
                draw string (scr.x/2 - len("GAME MODE:"& glob.gamemode.title)*8/2, 17),"GAME MODE:"& glob.gamemode.title,cream
                
		    End If
            
            if player.con(0).y<scr.hy*.5 and player.con(0).y>scr.hy*.4 and player.con(0).x<scr.hx+len("options")*8/2 and player.con(0).x>scr.hx-len("options")*8/2 and player.con(0).b= 1 then 
                options(player, scr, i)
                initial_screen (player, scr, scoretable(), i)
                glob.modlen = glob.ovalsize*.4
                apple.size=cint((glob.ovalsize/240)*10)
            end if
            
            if player.con(0).y<scr.hy*.6 and player.con(0).y>scr.hy*.5 and player.con(0).x<scr.hx+len("play game")*8/2 and player.con(0).x>scr.hx-len("play game")*8/2 and player.con(0).b= 1 then 
                glob.restart=-4
            end if
            

        NEXT
        
        Sleep 20
    
    Loop Until glob.restart=-4 Or multikey(1)

    
    resetbittcount()
		
    If player.con(0).b = 2 Then splashscreen
    
   Do
       
        setmouse scr.hx,scr.hy,0
		
        alllogic(player,scoretable(),highscore(),apple,scr, bitt(), i, mbc)
        
        setmouse scr.hx,scr.hy,1
       
    Loop Until glob.restart=0 Or multikey(1) Or glob.quit=-1 or glob.restart=-2

Loop Until glob.restart=0 Or multikey(1) Or glob.quit=-1
       
For i = 0 To 2
    ImageDestroy( scoretable(i) )
Next



Sub alllogic(player as playertype,scoretable() as any ptr,highscore() as integer, apple as appletype, scr as screentype, bitt() as bitstype, i as integer, mbc as movebitcalc)
dim as single speedx,speedy
dim as integer tempmousex, tempmousey
    glob.restart = 0
   
    glob.appleexist=0

    glob.surcounter=0
    
    reinit(player,scr, bitt(), i)

   Do
       
	glob.start=timer
    line (scr.x-len(glob.totbits & " bitts")*8,scr.y-9)-(scr.x,scr.y),black,bf
	draw string(scr.x-len(glob.totbits & " bitts")*8,scr.y-9),glob.totbits & " bitts", rgb(255,255,150)
    
			draw_cursor(player,0)
        moveyourself(player,scr,speedx,speedy, tempmousex, tempmousey)
			draw_cursor(player,rgb(100,250,100))
   
        movebits(player, bitt(), mbc, scr)
        
        if player.forcefield=-1 then
        	if glob.surcounter >0 then tiltbits(player, bitt(), mbc)
			player.forcefield=0
    	end if
                
        If checkcollision(player.x , player.y, bitt()) Then endsub(player,scoretable(),highscore(),scr,i) 
        
        If checkescape(player.x,player.y,scr.hx,scr.hy) = -1 Then endsub(player,scoretable(),highscore(),scr,i)
       
        plotbits (bitt(), i)
       
        plotplayer (player)
       
        apples (player, apple,scr, mbc)
       
        glob.surcounter+=1
        if glob.surcounter>250 then
            glob.surcounter=0
            if glob.appleexist=-1 then drawapple(apple)
            If glob.gamemode.id_n=1 Then
                glob.totbits+=1
            End If
        End If
        
        sleep 21-glob.gamespeed
        i=int(1/(timer-glob.start))
        line (scr.x-len(i & " fps")*8,1)-(scr.x,9),black,bf
        draw string (scr.x-len(i & " fps")*8,1),i & " fps",rgb(255,150,255)
    Loop Until multikey(1) Or glob.restart

End Sub


Sub moveyourself( player as playertype, scr as screentype, speedx as single,speedy as single, tempmousex as integer, tempmousey as integer)

	if player.con(player.consel).sleepb>0 then player.con(player.consel).sleepb-=1
   
    player.oldx2 = player.oldx
    player.oldy2 = player.oldy
    player.oldx = player.x
    player.oldy = player.y
   
    getmouse tempmousex, tempmousey
    if tempmousex>=0 and tempmousex<=scr.x and tempmousey>=0 and tempmousey<=scr.y then
        select case player.consel
        case 0
            getmouse player.con(0).x , player.con(0).y ,, player.con(0).b
        case 1
            gtky (player.con(1).x, player.con(1).y, player.con(1).b)
        end select
    end if
	if player.con(player.consel).b=2 then			'speed 1 rmb
        speedx=cos(atan2(player.con(player.consel).y-scr.hy, player.con(player.consel).x-scr.hx))
        speedy=sin(atan2(player.con(player.consel).y-scr.hy, player.con(player.consel).x-scr.hx))
	else
	
		speedx=abs(player.con(player.consel).x-scr.hx)
        if speedx > glob.ovalsize then speedx=glob.ovalsize
        speedx=(speedx/glob.ovalsize)*3+.1
		speedx=speedx*sgn(player.con(player.consel).x-scr.hx)

        speedy=abs(player.con(player.consel).y-scr.hy)
        if speedy > glob.ovalsize then speedy=glob.ovalsize
        speedy=(speedy/glob.ovalsize)*3+.1
		speedy=speedy*sgn(player.con(player.consel).y-scr.hy)

	end if
	    
    if speedx<>0 then player.x+= speedx
    if speedy<>0 then player.y+= speedy
    
    if player.con(player.consel).b=1 then
    	if player.con(player.consel).sleepb<1 then
	    	player.forcefield=-1
	    	player.con(player.consel).sleepb=2
	    else
	    	player.con(player.consel).sleepb+=1
	    end if
    end if
    
End Sub


Function checkescape (plyrx as single,plyry as single,scrhx as integer,scrhy as integer) As Byte
    Return Sqr( (plyrx-scrhx)^2 + (plyry-scrhy)^2 ) > glob.ovalsize
End Function


Sub endsub(player as playertype ,scoretable() as any ptr,highscore() as integer,scr as screentype, i as integer )
dim as integer x,y
    
    Sleep 200 , 1
   
        Locate 9,36
        If not checkescape (player.x , player.y, scr.hx, scr.hy) Then
            Color rgb(200,150,200)
            ? "CAPTURED"
            player.rings=0
            player.totrings=0
            resetbittcount()
        else
            Color palegreen
            ? "ESCAPE!"
        end if
   
    if checkescape (player.x , player.y, scr.hx, scr.hy) then 
                
        player.totrings+=player.rings
        if player.totrings>player.bestrings then player.bestrings=player.totrings
        
        color gold
        x=0:y=0
        for i = 1 to player.bestrings
            y+=20
            x=20*int(y/600)
            circle (x+10,(y mod 600)+10),5
        next
        color cream
        x=0:y=0
        for i = 1 to player.totrings
            y+=20
            x=20*int(y/600)
            circle (x+10,(y mod 600)+10),5
        next
        
        Select Case glob.gamemode.id_n
        Case 0 '"FREEPLAY"
            i = 0
        Case 1 '"SURVIVAL"
            i = 1
        Case 2 '"MAXRUN"
            i = 2
        End Select
        
        If player.totrings > highscore(i) Then bsavehigh(i,player,highscore(),scoretable(),scr)
		

    END IF

    Do
		
		select case player.consel
		case 0
			getmouse player.con(0).x , player.con(0).y ,, player.con(0).b
		case 1
			gtky (player.con(1).x, player.con(1).y, player.con(1).b)
		end select
       
        If multikey(1) Then glob.quit=-1
       
        Sleep 1
    Loop Until player.con(player.consel).b=1 Or glob.quit=-1 or player.con(player.consel).b=2
   
   glob.restart =-1
   if player.con(player.consel).b=2 then glob.restart=-2
   
End Sub


Function checkcollision(plyrx as integer,plyry as integer, bitt() as bitstype) As Byte

    For checkcol As Integer = 1 To glob.totbits-1
       With bitt(checkcol)
          If Sqr((plyry - .y)^2 + (plyrx - .x)^2 ) < 2 Then Return -1
       End With
    Next
   
    Return 0
   
End Function

Sub movebits(player as playertype, bitt() as bitstype, mbc as movebitcalc, scr as screentype)
    
    For i as integer = 1 To glob.totbits
		With bitt(i)
            
		    .cycle+= glob.modspd * .sign
		    If .cycle>.scycle and .cycle<.ecycle Then 
		        else
		            .sign *=-1
		    end if
		    
	        mbc.vecx=0:mbc.vecy=0:mbc.vecx2=0:mbc.vecy2=0
			
			mbc.vecx = player.x-.x + (player.x-player.oldx)*.guard
			mbc.vecy = player.y-.y + (player.y-player.oldy)*.guard
				
		    mbc.angle = atan2( mbc.vecy , mbc.vecx )
		    .vigour = .cycle/glob.modlen
		    mbc.vecx2 = Cos(mbc.angle) * .vigour
		    mbc.vecy2 = Sin(mbc.angle) * .vigour
            mbc.mag=sqr(mbc.vecx2^2+mbc.vecy2^2) *.spd
            if abs(player.x-.x) < (glob.ovalsize) then 
                mbc.vecx = cos(mbc.angle) * (((glob.ovalsize-abs(player.x-.x))/glob.ovalsize)^2)*(1-mbc.mag)
            else
                mbc.vecx = 0
            end if
            if abs(player.y-.y) < (glob.ovalsize) then 
                mbc.vecy = sin(mbc.angle) * (((glob.ovalsize-abs(player.y-.y))/glob.ovalsize)^2)*(1-mbc.mag)
            else
                mbc.vecy=0
            end if
		    
'		    if abs(mbc.vecx2) > abs(.x-player.x) then mbc.vecx2 = (player.x-.x) 
'		    if abs(mbc.vecy2) > abs(.y-player.y) then mbc.vecy2 = (player.y-.y)
		    
		    .oldx = .x
		    .oldy = .y
            mbc.mag=sqr((.x-scr.hx)^2+(.y-scr.hy)^2)
            if (sqr(((.x-scr.hx)+mbc.vecx2*.spd+mbc.vecx)^2+((.y-scr.hy)+mbc.vecy2*.spd+mbc.vecy)^2)<glob.ovalsize) or _
                sqr(((.x-scr.hx)+mbc.vecx2*.spd+mbc.vecx)^2+((.y-scr.hy)+mbc.vecy2*.spd+mbc.vecy)^2)< mbc.mag then
                .x+=mbc.vecx2*.spd+mbc.vecx
                .y+=mbc.vecy2*.spd+mbc.vecy
                
            end if
		End With
	Next

end sub
        
sub tiltbits(player as playertype, bitt() as bitstype, mbc as movebitcalc)

    for i as integer = 1 to glob.totbits
        
        mbc.mag=sqr((bitt(i).x-player.x)^2+(bitt(i).y-player.y)^2)
        mbc.vecx=(player.oldx2-player.oldx)
        mbc.vecx2=(player.oldx-player.x)
        mbc.vecy=(player.oldy2-player.oldy)
        mbc.vecy2=(player.oldy-player.y)
        mbc.angle=((mbc.vecx-mbc.vecx2)/(abs(mbc.vecx)+abs(mbc.vecx2)))*mbc.mag
        if abs(mbc.angle)<>0 then bitt(i).x-=mbc.angle
        mbc.angle=((mbc.vecy-mbc.vecy2)/(abs(mbc.vecy)+abs(mbc.vecy2)))*mbc.mag
        if abs(mbc.angle)<>0 then bitt(i).y-=mbc.angle
      
    next

End Sub


Sub plotbits(bitt() as bitstype, i as integer)
    
screenlock
    
    For i = 1 To glob.totbits
        if glob.trails=-1 then 
            circle( bitt(i).oldx , bitt(i).oldy ) ,1, black
            pset( bitt(i).oldx , bitt(i).oldy ),bitt(i).colour
        else
            circle( bitt(i).oldx , bitt(i).oldy ) ,1, black,,,,f 
        end if
    Next
 
    For i = 1 To glob.totbits-1
            circle ( bitt(i).x , bitt(i).y ), 1,  bitt(i).colour
    Next
    Pset ( bitt(glob.totbits).x , bitt(glob.totbits).y ) , rgb(250,250,250)
screenunlock

End Sub
   

Sub plotplayer(player as playertype)
  
    Circle(player.oldx , player.oldy) , 2 , black,,,,f
    Circle(player.x , player.y) , 2 , lightblue,,,,f
 
End Sub

sub resetbittcount()
    Select Case glob.gamemode.id_n
    Case 0 '"FREEPLAY"
        glob.totbits=50*(glob.ovalsize/240)^2
    Case 1 '"SURVIVAL"
        glob.totbits=25*(glob.ovalsize/240)^2
    Case 2 '"MAXRUN"
        glob.totbits=5*(glob.ovalsize/240)^2
    End Select
end sub

Sub setupbits(scr as screentype, bitt() as bitstype, i as integer)
dim as single distance , angle

    For i = 1 To maxbits
        With bitt(i)
            angle = (Rnd*6.282)
            distance = Int(Rnd * (glob.ovalsize*.5)) + .48 * glob.ovalsize
            .x = scr.hx - (Sin(angle) * distance)
            .y = scr.hy - (Cos(angle) * distance)
            
	        .scycle = -glob.modlen
	        .ecycle = glob.modlen
            .cycle = .scycle + rnd*.ecycle*2
	        .guard=rnd
	        .spd=rnd*.5+.5
	        
            if .sign=0 then .sign = 1+(2*(rnd>.5))
	        
	        .colour=rgb(125+int(rnd*125),125+int(rnd*125),50+int(rnd*150))
	        
        End With
    Next
   
End Sub

Sub reinit(player as playertype,scr as screentype, bitt() as bitstype, i as integer)
       
    player.rings=0
    
    player.x = scr.hx : player.y = scr.hy
    player.oldx = scr.hx : player.oldy = scr.hy
    
    Cls
   
    Circle (scr.hx,scr.hy), glob.ovalsize, rgb(0,255,0)
   
    setupbits (scr, bitt(), i)

End Sub


Sub apples(player as playertype,apple as appletype,scr as screentype, mbc as movebitcalc)

    If Sqr((player.x-apple.x)^2+(player.y-apple.y)^2) < apple.size+1 and glob.appleexist = -1 Then
        glob.appleexist = 0
        if glob.gamemode.id_n=0 then glob.appleexist = -2
        Circle (apple.x,apple.y),apple.size+3,black,,,,f
        player.rings+=1
        If glob.gamemode.id_n<>1 Then glob.totbits+=1
    End If
    
    If glob.appleexist = 0 Then
        do
            mbc.angle = Rnd * pi*2
            mbc.mag = (Rnd*glob.ovalsize)-glob.ovalsize*.1
            apple.x = scr.hx-Sin(mbc.angle)*mbc.mag
            apple.y = scr.hy-Cos(mbc.angle)*mbc.mag
        loop until sqr((apple.x-player.x)^2+(apple.y-player.y)^2) > apple.size or multikey(1)
        glob.appleexist = -1

        drawapple(apple)
    End If

End Sub

sub drawapple (apple as appletype)
    Circle (apple.x,apple.y),apple.size+2,rgb(100,100,0),,,,f
    Circle (apple.x,apple.y),apple.size-2,black,,,,f
    for i as integer = 1 to 5
        Circle (apple.x,apple.y),apple.size-3+i,rgb(200-abs(3-i)*50,200-abs(3-i)*50,0)
    next
end sub

Sub bsavehigh(i As Integer, player as playertype, highscore() as integer,scoretable() as any ptr,scr as screentype)
dim as uinteger colour
dim as uinteger rint,gint,bint
dim as ubyte red,green,blue
dim as integer setx , sety
dim as integer x,y
dim as integer f

    highscore(i)=player.totrings
    f = Freefile
    Open "high.dat" For Random As #f
        Put #f, i*4 , highscore(i)
    Close
    
    do
        do
            x=0
            do
                Colour =Point(setx+x,sety+y)
                rint += (Colour Shr 16) And &hFF
                gint += (Colour Shr 8) And &hFF
                bint += Colour And &hFF       
                x+=1
            loop until x>1
            x=0
            y+=1
        loop until y>1
        y=0
        sety+=2
        
        red =(rint*.25)
        green =(gint*.25)
        blue =(bint*.25)
        rint = 0
        gint = 0
        bint = 0
        pset scoretable(i), (setx*.25,sety*.25), rgb(red,green,blue)
        
        
        if sety>scr.y then 
            sety=0
            setx+=2
        end if
    loop until setx > scr.x or multikey(1)
    Bsave "high"&i &".bmp", scoretable(i)
            
    ? "saving.."
    sleep 35
    ? "press button to continue"

End Sub

sub openhighscores(scoretable() as any ptr,highscore() as integer, i as integer)
Dim As Integer f
f=Freefile
Open "high.dat" For Random As #f
    For i = 0 To 2
        Get #f, i*4 , highscore(i)
    Next
Close
For i = 0 To 2
    Bload "high"&i &".bmp", scoretable(i)
Next
end sub


sub draw_cursor(player as playertype,colour as uinteger)

    pset (player.con(player.consel).x+5,player.con(player.consel).y),colour
    pset (player.con(player.consel).x-5,player.con(player.consel).y),colour
    pset (player.con(player.consel).x,player.con(player.consel).y+5),colour
    pset (player.con(player.consel).x,player.con(player.consel).y-5),colour

end sub

function gtky(conx as integer,cony as integer,conb as integer) as byte
dim as byte oconx,ocony,oconb
oconx=conx:ocony=cony:oconb=conb

	conx+=multikey(&h4b)*-1 or multikey(&h4D)
	cony+=multikey(&h48)*-1 or multikey(&h50)
	conb=multikey(&h39)

if oconx<>conx or ocony<>cony or oconb<>conb then return 1
end function


sub splashscreen
cls
    Color lightpink
    Locate 1,1
    print "PrimeZeros"
    color gold
    locate 1,12 
    print "BitRunner"
    sleep 1000
    
end sub

sub initial_screen (player as playertype, scr as screentype, scoretable() as any ptr, i as integer)
	sleep 200,1
	cls
    
    player.con(1).x=scr.hx:player.con(1).y=scr.hy:player.con(1).b=0
    
    draw string (scr.x/2 - len("Bitrunner")*8/2, 1),"BitRunner",lightblue
    draw string (scr.x/2 - len("collect and escape with as many rings as possible")*8/2, 9),"collect and escape with as many rings as possible",palegreen
   
    Line (1,25)-(scr.x,50),rgb(255,0,0),b
    draw string (scr.x/2 - len("GAME MODE:"& glob.gamemode.title)*8/2, 17),"GAME MODE:"& glob.gamemode.title,cream
    Color rgb(150,150,150)
    draw string (scr.x/2 - len("use the mouse buttons in this box to change game mode")*8/2, 36),"use the mouse buttons in this box to change game mode",rgb(250,250,250)

    line (scr.hx - len("options")*8/2,scr.hy*.4)-(scr.hx + len("options")*8/2,scr.hy*.5),rgb(0,0,200),bf
    draw string (scr.hx - len("options")*8/2,scr.hy*.45 -4 ), "options", rgb(255,255,255)
    
    line (scr.hx - len("play game")*8/2,scr.hy*.5)-(scr.hx + len("play game")*8/2,scr.hy*.6),rgb(0,200,0),bf
    draw string (scr.hx - len("play game")*8/2,scr.hy*.55 -4 ), "play game", rgb(255,255,255)
    
    For i = 0 To 2
        Put (scr.x/6+i*scr.x/4, scr.y-1/3*scr.y), scoretable(i)
    Next

end sub

sub options(player as playertype, scr as screentype, i as integer)
Dim As Integer mode, w, h, screenarray(50), ii
dim as byte fullscreen, klicker
    fullscreen=1
    i=0
    
    cls
    
    do
        getmouse player.con(0).x,player.con(0).y,,player.con(0).b
        sleep 1
    loop until player.con(0).b=0 or multikey(1)
    
    mode = ScreenList(32)
    While (mode)
        screenarray(i)=mode
        i+=1
        w = HiWord(mode)
        h = LoWord(mode)
        mode = ScreenList    
    Wend
    
    optionsgraphics(scr,fullscreen)
    
    do
        if player.con(0).b=0 then if klicker>0 then klicker-=1
        getmouse player.con(0).x,player.con(0).y,,player.con(0).b
        for ii = 0 to i-1
            w = HiWord(screenarray(ii))
            h = LoWord(screenarray(ii))
            draw string (1,ii*8+1), Str(w) + "x" + Str(h), rgb (155,155,155)
            if player.con(0).x < 80 then
                if player.con(0).y > (ii*8+1) and player.con(0).y < (ii*8+10) then
                    draw string (1,ii*8+1), Str(w) + "x" + Str(h), rgb (255,255,255)
                    if player.con(0).b = 1 and klicker < 1 then 
                        screenres w,h,32,,fullscreen
                        scr.x=w
                        scr.y=h
                        scr.hx=scr.x/2
                        scr.hy=scr.y/2
                        glob.ovalsize=scr.hy
                        optionsgraphics(scr, fullscreen)
                        klicker=1
                    end if
                end if
            end if
        next
        if player.con(0).x > 120 and player.con(0).x < 130 and player.con(0).y < 10 and player.con(0).b = 1 and klicker<1 then 
            fullscreen = abs(fullscreen=0)
            circle (125,5),4,rgb(0,0,0),,,,f
            if fullscreen=0 then circle (125,5),4,rgb(100,100,255),,,,f
            klicker=1
        end if
        if player.con(0).x>scr.x/2 and player.con(0).x<scr.x/2+scr.x*.05 and player.con(0).b=1 then
            glob.gamespeed=20-cbyte(player.con(0).y/scr.y*20)
            if glob.gamespeed< 1 then glob.gamespeed=1
            optionsgraphics(scr,fullscreen)
        end if
        if player.con(0).x>scr.x/1.5 and player.con(0).x<scr.x/1.5+scr.x*.05 and player.con(0).b=1 then
            glob.ovalsize=scr.hy- (scr.hy * (player.con(0).y/scr.y))
            if glob.ovalsize<240 then glob.ovalsize=240
            optionsgraphics(scr,fullscreen)
        end if
        if sqr((player.con(0).x-scr.x/1.25)^2 + (player.con(0).y-scr.hy)^2) < 10 and player.con(0).b=1 and klicker=0 then 
            glob.trails=(glob.trails=0)
            klicker=1
            optionsgraphics(scr,fullscreen)
        end if
        
        sleep 20
        
        if (player.con(0).b <>0 and player.con(0).x > (scr.x-32) and player.con(0).y > (scr.y-32)) or player.con(0).b=2 then glob.restart=-3
    loop until glob.restart=-3 or multikey(1)
    glob.restart=-1

end sub

sub optionsgraphics(scr as screentype, fullscreen as byte)
    
    line (120,1)-(130,10),rgb(255,255,255),b
    circle (125,5),4,rgb(0,0,0),,,,f
    if fullscreen=0 then circle (125,5),4,rgb(0,0,200),,,,f
    draw string (132,1), "Windowed", rgb (100,255,255)
    
    line (scr.x-32, scr.y-32)-(scr.x-1,scr.y-1),rgb(0,200,0),bf
    draw string (scr.x-20, scr.y-20), "OK",rgb(255,255,255)
    
    line (scr.x/2,scr.y)-(scr.x/2+scr.x*.05,0),rgb(0,0,0),bf
    line (scr.x/2,scr.y)-(scr.x/2+scr.x*.05,scr.y-scr.y*(glob.gamespeed/20)),rgb(100,100,255),bf
    draw string (scr.x/2,scr.y*.05), "gamespeed", rgb(100,255,255)
    
    line (scr.x/1.5,scr.y)-(scr.x/1.5+scr.x*.05,0),rgb(0,0,0),bf
    line (scr.x/1.5,scr.y)-(scr.x/1.5+scr.x*.05,scr.y-scr.y*(glob.ovalsize/scr.hy)),rgb(100,255,100),bf
    draw string (scr.x/1.5,scr.y*.05), "play area", rgb(255,255,100)
    
    circle (scr.x/1.25,scr.hy),10,black,,,,f
    circle (scr.x/1.25,scr.hy),10,rgb(255,255,255)
    if glob.trails=-1 then circle (scr.x/1.25,scr.hy),9,rgb(255,255,150),,,,f
    draw string (scr.x/1.2,scr.hy-4), "bitt trails", rgb(255,255,150)
    
end sub
Last edited by pr1mezr0 on Mar 22, 2023 8:02, edited 1 time in total.
dafhi
Posts: 1640
Joined: Jun 04, 2005 9:51

Re: bitrunner

Post by dafhi »

quick few issues on my system

1. my xfce scaling results in seeing only a portion of the play area.
don't know how to fix this myself other than by going windowed

2. you might go with a delta time variable, probably add to your globals udt

my high single-threaded perf. 1165g7 makes the action near-invisible
pr1mezr0
Posts: 6
Joined: Mar 16, 2023 2:42

Re: bitrunner

Post by pr1mezr0 »

I don't know how to fix your scaling problem, maybe if I set the screen resolution to desktop resolution. I'll look into a fps limiter but you can try increasing the sleep time in the alllogic sub to 20 or more. I found sleep 5 and sleep 1 don't change the speed on my computer probably most of the lag is in the logic.
dafhi
Posts: 1640
Joined: Jun 04, 2005 9:51

Re: bitrunner

Post by dafhi »

sleep 10 here seems realistic. speed reminds me of waves at the edge of a lake.
pr1mezr0
Posts: 6
Joined: Mar 16, 2023 2:42

Re: bitrunner

Post by pr1mezr0 »

I get the same problem as you when I use screeninfo to set the screenres to the OS resolution, the play area isn't centred. I saw this problem in another game I made but I can't remember how I fixed it, probably just set a fixed screensize. It's a bummer playing in windowed mode. By the way did you compile with fbc32? There's problems when you compile with fbc64, like you get captured next initialisation if you're not holding the mouse button down when you escape.
dafhi
Posts: 1640
Joined: Jun 04, 2005 9:51

Re: bitrunner

Post by dafhi »

im 64 bit. i wouldn't know b/c i never play long enough.

you can replace all integer with long, which might fix that. i changed sleep to 15 it's starting to feel kinda peaceful. maybe i should go 20
pr1mezr0
Posts: 6
Joined: Mar 16, 2023 2:42

Re: bitrunner

Post by pr1mezr0 »

I tried replacing with longs didn't help. I fixed my centering problem by changing my display scale from 125% to 100%. But if you used the desktop resolution with screeninfo scr.x, scr.y instead of scr.x=640:scr.y=480 you'd want to increase the enemy count and the player speed. And it's not supposed to be peaceful :P
pr1mezr0
Posts: 6
Joined: Mar 16, 2023 2:42

Re: bitrunner

Post by pr1mezr0 »

I updated the code. Now there's an options menu where you can change the screenres and windowed mode, and change game speed. Also tweaked the mechanics.
Post Reply