Gather the gold

Game development specific discussions.
BasicCoder2
Posts: 3205
Joined: Jan 01, 2009 7:03

Gather the gold

Postby BasicCoder2 » Jun 05, 2018 3:10

This is a preliminary exploration of what might be involved in writing the mechanics of a Lode Runner like game. I haven't implemented much of the Lode Runner stuff like moving along monkey bars or zapping the ground tiles. And at this stage the guards just stand there without interaction mainly because I haven't figured out what kind of AI to give them.
It is different to the "Roll out the barrel" thread example in that the hot spots return the tile ID not a boolean on transparent color or not.
Thus the background is based on an array of tile images although the characters have pixel accurate positions.
You must run this code to generate the bitmaps used ...

Code: Select all

screenres 640,480,32
color rgb(0,0,0),rgb(255,255,255):cls
dim as any ptr image
image = imagecreate( 60, 100)
dim as ulong colors( 9)
colors( 0)=RGB(255,0,255)
colors( 1)=RGB(128,0,0)
colors( 2)=RGB(136,0,21)
colors( 3)=RGB(248,184,160)
colors( 4)=RGB(0,0,0)
colors( 5)=RGB(160,32,64)
colors( 6)=RGB(34,177,76)
colors( 7)=RGB(255,174,201)
colors( 8)=RGB(255,255,255)
    dim as integer n
    for j as integer = 0 to  99
        for i as integer = 0 to  59
            read n
            pset image,(i,j),colors(n)
        next i
    next j
bsave "littleGuysA.bmp",image
put (0,0),image,trans
sleep

dim shared as any ptr guards
guards = imagecreate(60,100)
bload "littleGuysA.bmp",guards
for j as integer = 0 to 99
    for i as integer = 0 to 59
        if point(i,j,guards)<>rgb(255,0,255) then
            pset guards,(i,j),rgb(255,0,0)
        end if
    next i
next j
bsave "littleGuards.bmp",guards

dim shared as any ptr tile1,tile2,tile3
tile1 = imagecreate(16,16)
tile2 = imagecreate(16,16)
tile3 = imagecreate(16,16)

for j as integer = 0 to 15
    for i as integer = 0 to 15
        read n
        if n = 0 then pset tile1,(i,j),rgb(255,255,255)
        if n = 1 then pset tile1,(i,j),rgb(0,0,255)
    next i
next j
bsave "tile1.bmp",tile1

for j as integer = 0 to 15
    for i as integer = 0 to 15
        read n
        if n = 0 then pset tile2,(i,j),rgb(100,100,100)
        if n = 1 then pset tile2,(i,j),rgb(255,100,0)
    next i
next j
bsave "tile2.bmp",tile2

for j as integer = 0 to 15
    for i as integer = 0 to 15
        read n
        if n = 0 then pset tile3,(i,j),rgb(255,0,255)
        if n = 1 then pset tile3,(i,j),rgb(255,200,15)
        if n = 2 then pset tile3,(i,j),rgb(0,0,0)
    next i
next j
bsave "tile3.bmp",tile3

DATA  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
DATA  0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0
DATA  0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0
DATA  0,0,0,0,0,2,3,3,3,2,0,0,0,0,0,0,0,0,0,0,2,3,3,3,2,0,0,0,0,0,0,0,0,0,0,2,3,3,3,2,0,0,0,0,0,0,0,0,0,0,2,3,3,3,2,0,0,0,0,0
DATA  0,0,0,0,0,2,4,3,4,2,0,0,0,0,0,0,0,0,0,0,2,4,3,4,2,0,0,0,0,0,0,0,0,0,0,2,4,3,4,2,0,0,0,0,0,0,0,0,0,0,2,4,3,4,2,0,0,0,0,0
DATA  0,0,0,0,0,3,3,3,3,3,0,0,0,0,0,0,0,0,0,0,3,3,3,3,3,0,0,0,0,0,0,0,0,0,0,3,3,3,3,3,0,0,0,0,0,0,0,0,0,0,3,3,3,3,3,0,0,0,0,0
DATA  0,0,0,0,0,3,3,3,3,3,0,0,0,0,0,0,0,0,0,0,3,3,3,3,3,0,0,0,0,0,0,0,0,0,0,3,3,3,3,3,0,0,0,0,0,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1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1
data 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
data 1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1
data 1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1
data 1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1
data 1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1
data 1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1
data 1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1
data 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
'gold

data 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,2,1,2,0,0,0,0,0,0
data 0,0,0,0,0,0,2,1,1,1,2,0,0,0,0,0
data 0,0,0,0,0,2,1,1,1,1,1,2,0,0,0,0
data 0,0,0,0,2,1,1,1,1,1,1,1,2,0,0,0
data 0,0,0,2,1,1,1,1,1,1,1,1,1,2,0,0
data 0,0,2,1,1,1,1,1,1,1,1,1,1,1,2,0
data 0,2,1,1,1,1,1,1,1,1,1,1,1,1,1,2
data 0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2


And this is the demo ...

Code: Select all

const SCRW = 450
const SCRH = 288

screenres SCRW,SCRH,32
color rgb(0,0,0),rgb(255,255,255)

dim shared as integer SCORE
dim shared as integer tileX,tileY

dim shared as any ptr tile1,tile2,tile3
tile1 = imagecreate(16,16)
tile2 = imagecreate(16,16)
tile3 = imagecreate(16,16)
bload "tile1.bmp",tile1
bload "tile2.bmp",tile2
bload "tile3.bmp",tile3

dim shared as integer world(0 to 27,0 to 17)   'hold tile ID

const TW = 16


    restore background
    for j as integer = 0 to 17
        for i as integer = 0 to 27
            read world(i,j)
        next i
    next j
   
type SPRITE
    as integer x
    as integer y
    as integer w    'width of sprite
    as integer h    'height of sprite
    as integer s    'current state eg. running, walking,climbing
    as integer a    'alive or dead
    as integer f    'current frame being displayed
    as integer fc   'total frames in animation
    as integer c    'delay between frames
    as any ptr img  'image sheet
end type

dim shared as SPRITE hero
dim shared as SPRITE guard(0 to 5)

hero.x = 33
hero.y = 215
hero.w = 15
hero.h = 25
hero.a = 1
hero.fc = 4
hero.img = imagecreate(60,100)
bload "littleGuysA.bmp",hero.img

dim shared as any ptr guardImage
guardImage = imagecreate(60,100)
bload "littleGuards.bmp",guardImage

restore GuardPositions
for i as integer = 0 to 4
    read guard(i).x,guard(i).y
    guard(i).w = 15
    guard(i).h = 25
    guard(i).a = 1
    guard(i).img = guardImage
next i

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

function onTile(b as SPRITE) as integer
    dim as integer ID
    tileX = (b.x+b.w\2) \TW
    tileY = (b.y+b.h  ) \TW
    return world(tileX,tileY)
end function

function inTile(b as SPRITE) as integer
    dim as integer ID
    tileX = (b.x+b.w\2) \TW
    tileY = (b.y+b.h-1  ) \TW
    return world(tileX,tileY)
end function


sub display()
   
    hero.c = hero.c + 1
    if hero.c > 10 then      'controls frame rate
        hero.c = 0           'reset counter
        hero.f = hero.f + 1  'next frame
        if hero.f = hero.fc then
            hero.f = 0
        end if
    end if
   
    dim as integer v
    screenlock
   
    cls
    for j as integer = 0 to 17
        for i as integer = 0 to 27
            v = world(i,j)
            if v = 32 then
                put (i*TW,j*TW),tile1,trans
            end if
            if v = 33 then
                put (i*TW,j*TW),tile2,trans
            end if
            if v = 22 then
                put (i*TW,j*TW),tile3,trans
            end if
        next i
    next
   
    'draw guards
    for i as integer = 0 to 4
        if guard(i).a = 1 then
            put (guard(i).x,guard(i).y),guard(i).img,(guard(i).f*guard(i).w,guard(i).s*guard(i).h)-(guard(i).f*guard(i).w + guard(i).w-1,guard(i).s * guard(i).h + guard(i).h-1),trans
        end if
    next i

    'draw hero
    if hero.a = 1 then
        put (hero.x,hero.y),hero.img,(hero.f*hero.w,hero.s*hero.h)-(hero.f*hero.w + hero.w-1,hero.s * hero.h + hero.h-1),trans
    end if

    locate 34,2
    print "SCORE =";SCORE
    screenunlock
end sub

do
    display()
    hero.s = 0   'not moving
   
    if multikey(&H4B) then
        hero.x = hero.x - 1
        hero.s  = 2                  'move left
    end if
    if multikey(&H4D) then
        hero.x = hero.x + 1
        hero.s  = 1                  'move right
    end if
   
    if inTile(hero) = 32 or onTile(hero) = 32 then   'if onLadder than you can move up or down
        if multikey(&H48) then  'UP
            hero.y = hero.y - 1
            hero.s  = 3
        end if
   
        if multikey(&H50) then  'DOWN
            hero.y = hero.y + 1
            hero.s  = 3
        end if
    end if
   
    if inTile(hero)=0 then
        hero.y = hero.y + 1  'gravity
    end if
   
    while inTile(hero)=33
        hero.y = hero.y - 1  'pull out of ground
    wend
   
    if inTile(hero)=22 then
        SCORE = SCORE + 1     'pick up gold
        world(tileX,tileY)= 0     'remove gold tile
        print ((hero.x+hero.w\2)\TW),((hero.y+hero.h)\TW)
        sleep
    end if
   
    'adjust for left/right border
    if hero.x < 0 then hero.x = 0
    if hero.x > SCRW - hero.w then hero.x = SCRW - hero.w
    sleep 2
loop until multikey(&H01)


background:
data  0, 0, 0, 0, 0, 0, 0, 0, 0,32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
data  0, 0, 0, 0, 0, 0, 0, 0, 0,32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
data 33,33,33, 0, 0, 0, 0, 0, 0,32, 0, 0, 0, 0, 0,33,33,33,33,32,33,33,33,33,33,33,33,33
data  0, 0,33,33, 0, 0, 0, 0, 0,32, 0, 0, 0, 0, 0,33,33, 0, 0,32, 0, 0, 0, 0, 0, 0, 0, 0
data  0, 0, 0,33,33, 0, 0, 0, 0,32, 0, 0, 0, 0,33,33, 0, 0, 0,32, 0, 0, 0, 0, 0, 0, 0, 0
data  0, 22, 0,33,33,33, 0, 0, 0,32, 0, 0, 0,33,33,33, 0, 0, 0,32, 0, 0, 0, 0, 0,22, 0, 0
data 32,33,32,33,33,33,33, 0, 0,32, 0, 0,33,33,33,33,32,33,33,32,33,33,33,33,33,33,33,33
data 32, 0,32, 0, 0, 0,33,33, 0,32, 0,33,33, 0, 0, 0,32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
data 32, 0,32, 0, 0, 0, 0,33,33,32,33,33,33, 0, 0, 0,32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
data 32,33,33,33,32, 0, 0, 0, 0,32, 0, 0, 0, 0, 0,33,32,33,33,32,33,33, 0, 0, 0, 0, 0, 0
data 32, 0, 0, 0,32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,32, 0, 0, 0, 0, 0, 0, 0, 0
data 32, 0, 0, 0,32, 0, 0, 0,22, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,32, 0, 0, 0, 0, 0, 0, 0, 0
data 32, 0, 0, 0,32,33,33,33,33,33,33,33,32,33,33,33,33,33,33,32,33,33,33,33,33,32,33,33
data 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,32, 0, 0
data 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,32, 0, 0, 0, 0, 0, 0,22, 0, 0, 0, 0, 0,32, 0, 0
data 33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33
data  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
data  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0

GuardPositions:
data 18,7,  355,7,  355,71,  99,167,  353,167
dafhi
Posts: 1040
Joined: Jun 04, 2005 9:51

Re: Gather the gold

Postby dafhi » Jun 05, 2018 4:14

Here's my physics loop. You can change the fps to anything and the action will remain consistent.

Had to swap the order of things near the bottom

Code: Select all

var   iphys_fps = 1/193, phys_t = 0f
var   ianim_fps = 1/57, anim_t = 0f
var   tp = timer

do
    if anim_t <= 0 then
      display()
      while anim_t < 0
        anim_t += ianim_fps
      wend
    endif
    hero.s = 0   'not moving
   
    var t=timer, dt=t-tp
    tp=t
   
    anim_t -= dt
    phys_t += dt

    var frames=0
    while phys_t>0
      frames += 1
      phys_t -= iphys_fps
    wend
   
    'var rate = pi*iphys_fps*frames
    for i as integer = 1 to frames
        if multikey(&H4B) then
            hero.x = hero.x - 1
            hero.s  = 2                  'move left
        end if
        if multikey(&H4D) then
            hero.x = hero.x + 1
            hero.s  = 1                  'move right
        end if
       
        if inTile(hero) = 32 or onTile(hero) = 32 then   'if onLadder than you can move up or down
            if multikey(&H48) then  'UP
                hero.y = hero.y - 1
                hero.s  = 3
            end if
       
            if multikey(&H50) then  'DOWN
                hero.y = hero.y + 1
                hero.s  = 3
            end if
        end if
       
        if inTile(hero)=0 then
            hero.y = hero.y + 1  'gravity
        end if
       
        while inTile(hero)=33
            hero.y = hero.y - 1  'pull out of ground
        wend
       
        'adjust for left/right border
        if hero.x < 0 then hero.x = 0
        if hero.x > SCRW - hero.w then hero.x = SCRW - hero.w
    next
   
    if inTile(hero)=22 then
        SCORE = SCORE + 1     'pick up gold
        world(tileX,tileY)= 0     'remove gold tile
        print ((hero.x+hero.w\2)\TW),((hero.y+hero.h)\TW)
        sleep
    end if
   
    sleep 2
loop until multikey(&H01)
lizard
Posts: 406
Joined: Oct 17, 2017 11:35
Location: Germany

Re: Gather the gold

Postby lizard » Jun 05, 2018 4:24

Works all here on Mint 18.3 64 bit (i suppose you are on windows). Yes, thats the game! As far i remember, the enemies always moved towards player. Player could dig holes to stop them. But the holes closed after some time. Climbing the upper ladder to top leaded to next level.

But these days it would possible to add further elements. Frankensteins, mummys and the best: electricity!
BasicCoder2
Posts: 3205
Joined: Jan 01, 2009 7:03

Re: Gather the gold

Postby BasicCoder2 » Jun 05, 2018 22:56

dafhi wrote:Here's my physics loop. You can change the fps to anything and the action will remain consistent.

Can you explain how it works and indeed what it does exactly?
In this example I notice the little guy moves really fast, indeed too fast.
For example where do the numbers come from in these two lines?

Code: Select all

var   iphys_fps = 1/193, phys_t = 0f
var   ianim_fps = 1/57, anim_t = 0f
dafhi
Posts: 1040
Joined: Jun 04, 2005 9:51

Re: Gather the gold

Postby dafhi » Jun 06, 2018 3:54

You could actually use your original dispaly code and remove ianim_fps and anim_t

Code: Select all

    display()
    hero.s = 0   'not moving

this increments the physics time

Code: Select all

    phys_t += dt

physics frame count

Code: Select all

    var frames=0
    while phys_t>0
      frames += 1
      phys_t -= iphys_fps
    wend
 

Return to “Game Dev”

Who is online

Users browsing this forum: No registered users and 2 guests