AndyRCM, HELP !!!
 
Notifications
Clear all

AndyRCM, HELP !!!

Page 1 / 2
Panther
(@panther)
Member Moderator

Hi Andy,

Just working through some of the code for the Starfield that you posted, one or two things I need some help with.

You've got these Dim statements towards the start

Dim shared as double r,g,b
Dim shared as integer a

Why are r, g & b as double and not as integers ?

Also with this line

#define pp(x,y,argb) sb(y*XRES+x)=argb

Where does argb come from ?

Cheers for any help  🙂

Quote
Topic starter Posted : 08/07/2009 4:50 pm
AndyRCM
(@andyrcm)
Member Admin

Hi matey,
erm - r,g,b don't need to be double - that is just me not thinking! 🙁

and argb = alpha, red, green and blue - it is created inside freabasic as far as I know! ??? Shockwave might be able to help a little more with that?

Hope that helps a little . . .

Andy

"I could see the faces of those who led pissing themselves laughing" - Funeral Pyre by The Jam

ReplyQuote
Posted : 08/07/2009 6:07 pm
Panther
(@panther)
Member Moderator

As they say on one of the adverts "Every little helps"  😀

ReplyQuote
Topic starter Posted : 08/07/2009 10:01 pm
Panther
(@panther)
Member Moderator

Had another dabble with Sin & Cos

Still not got used to tiny_ptc, but will give it a go (sometime)

ReplyQuote
Topic starter Posted : 10/07/2009 7:58 pm
Panther
(@panther)
Member Moderator

Andy,

Did you use Sprites when you did the pacman demo, and if so what did you use to design the sprites and how did you then insert these into FreeBasic ?

If you didn't use Sprites then what did you use to design the graphics and again how did you get them into FreeBasic ?

I'm trying to get some simple graphics in to have a play about with movement etc. but haven't got a clue where to start !!!  ::) ::)

Any ideas on collision detection ?

Perhaps I'm trying to get ahead of myself  😛

If I can get anything working I'll post the code, so you can tell me how to write it more efficiently  😉

ReplyQuote
Topic starter Posted : 14/07/2009 2:56 pm
AndyRCM
(@andyrcm)
Member Admin

When I get home I will send you the code or post it here . . .

I use data statements with binary . . . i.e.

0,0,1,1,1,1,0,0
0,1,1,1,1,1,1,0
1,1,1,1,1,1,1,1
1,1,1,1,1,1,1,1
1,1,1,1,1,1,1,1
1,1,1,1,1,1,1,1
0,1,1,1,1,1,1,0
0,0,1,1,1,1,0,0

would almost be a ball of sorts etc . . .

the pacman uses 2 x 8 pixel blocks across and down too!

because of this i can then add 2,3,4 etc into it and put further colours into it . . . does that make sense?

I will post the text later though . . .

Andy

"I could see the faces of those who led pissing themselves laughing" - Funeral Pyre by The Jam

ReplyQuote
Posted : 14/07/2009 3:02 pm
AndyRCM
(@andyrcm)
Member Admin

In fact here you go . . . just knocked this up . . .


#include once "tinyptc_ext.bi"
const xres = 640   
const yres = 480
    ptc_allowclose(0)
    ptc_setdialog(1,"Would you like to go Fullscreen?",0,1)
If( ptc_open( "ball . . .", XRES, YRES ) = 0 ) Then
End -1
End If

Dim Shared as Integer sb(xres*yres)
#define pp(x,y,argb) sb(y*XRES+x)=argb
Dim Shared as Integer a,b,c

WHILE(GETASYNCKEYSTATE(VK_ESCAPE)<> -32767 and PTC_GETLEFTBUTTON=FALSE)
    for a=0 to 7
        for b=0 to 7
            read c
            if c=1 then pp(100+a,xres*100+b,rgb(255,255,0))
        next b
    next a
    ptc_update @sb(0)
restore ball   
Wend

ptc_close()
end

ball:
data 0,0,1,1,1,1,0,0
data 0,1,1,1,1,1,1,0
data 1,1,1,1,1,1,1,1
data 1,1,1,1,1,1,1,1
data 1,1,1,1,1,1,1,1
data 1,1,1,1,1,1,1,1
data 0,1,1,1,1,1,1,0
data 0,0,1,1,1,1,0,0

this will simply put a ball on the screen . . .


#include once "tinyptc_ext.bi"
const xres = 640   
const yres = 480
    ptc_allowclose(0)
    ptc_setdialog(1,"Would you like to go Fullscreen?",0,1)
If( ptc_open( "ball . . .", XRES, YRES ) = 0 ) Then
End -1
End If

Dim Shared as Integer sb(xres*yres)
#define pp(x,y,argb) sb(y*XRES+x)=argb
Dim Shared as Integer a,b,c

WHILE(GETASYNCKEYSTATE(VK_ESCAPE)<> -32767 and PTC_GETLEFTBUTTON=FALSE)
    for a=0 to 7
        for b=0 to 7
            read c
            if c=1 then pp(100+a,xres*100+b,rgb(255,255,0))
            if c=2 then pp(100+a,xres*100+b,rgb(255,0,0))
        next b
    next a
    ptc_update @sb(0)
restore ball   
Wend

ptc_close()
end

ball:
data 0,0,1,1,1,1,0,0
data 0,1,1,1,1,1,1,0
data 1,1,2,2,2,2,1,1
data 1,1,2,2,2,2,1,1
data 1,1,2,2,2,2,1,1
data 1,1,2,2,2,2,1,1
data 0,1,1,1,1,1,1,0
data 0,0,1,1,1,1,0,0

this will put a ball in the middle of the screen but give it a red middle . . . 😉

Okay?

"I could see the faces of those who led pissing themselves laughing" - Funeral Pyre by The Jam

ReplyQuote
Posted : 14/07/2009 3:12 pm
Panther
(@panther)
Member Moderator

Cheers for taking the time Andy, I do appreciate it..........but  😉

I understand the ball & colour thing I think, but if you want to move the ball around do you do the whole read/data every time it moves ?

And what if you wanted two different balls, different colours (A_ball and Z_ball for example), how do you get it to read the data for the ball each ball  ?

ReplyQuote
Topic starter Posted : 14/07/2009 4:49 pm
AndyRCM
(@andyrcm)
Member Admin

what you would do then is . . . create an array and store the ball in that

i will knock something up and show you the code - be easier that way i think?

it would be good for me too so . . . 😉

Andy

"I could see the faces of those who led pissing themselves laughing" - Funeral Pyre by The Jam

ReplyQuote
Posted : 14/07/2009 6:04 pm
AndyRCM
(@andyrcm)
Member Admin

Here you go . . .


#include once "tinyptc_ext.bi"
const xres = 640   
const yres = 480
    ptc_allowclose(0)
    ptc_setdialog(1,"Would you like to go Fullscreen?",0,1)
If( ptc_open( "ball . . .", XRES, YRES ) = 0 ) Then
End -1
End If

Dim Shared as Integer sb(xres*yres)
#define pp(x,y,argb) sb(y*XRES+x)=argb
Dim Shared as Integer a,b,c,rdx,rdy
Dim Shared as Integer nb,lp
nb=256 'number of balls is 100
Dim Shared as Integer x(nb),y(nb),x1(nb),y1(nb)
Dim Shared as Integer rr(nb),gg(nb),bb(nb)

for lp=0 to nb-1 ' set up the ball(s) positions
    x(lp)=int(rnd(1)*xres-1)
    y(lp)=int(rnd(1)*yres-1)
    rdx=int(rnd(1)*11)
    rdy=int(rnd(1)*11)
    if rdx<=5 then x1(lp)=1
    if rdx>=6 then x1(lp)=-1
    if rdy>=6 then y1(lp)=-1
    if rdy<=5 then y1(lp)=1
    rr(lp)=int(rnd(1)*255)
    gg(lp)=int(rnd(1)*255)
    bb(lp)=int(rnd(1)*255)
next lp

WHILE(GETASYNCKEYSTATE(VK_ESCAPE)<> -32767 and PTC_GETLEFTBUTTON=FALSE)
   
    for lp=0 to nb-1 ' draw the balls . . .

    for a=0 to 7
        for b=0 to 7
            read c
            if c=1 and x(lp)<=xres-8 and y(lp)<=yres-8 and x(lp)>=1 and y(lp)>=1 then pp(x(lp)+b,xres*y(lp)+a,rgb(rr(lp),gg(lp),bb(lp)))
        next b
    next a
    restore ball
    next lp

    for lp=0 to nb-1 ' move the ball(s)
    x(lp)=x(lp)+x1(lp)
    y(lp)=y(lp)+y1(lp)
        if x(lp)>=xres-8 then x1(lp)=-1
        if x(lp)<=1 then x1(lp)=1
        if y(lp)>=yres-8 then y1(lp)=-1
        if y(lp)<=1 then y1(lp)=1
    next lp
   
    ptc_update @sb(0)
   
    for a=0 to xres-1
        for b=0 to yres-1
            pp(a,b,rgb(0,0,0)) ' clear the screen
        next b
    next a
   
Wend

ptc_close()
end

ball:
data 0,0,1,1,1,1,0,0
data 0,1,1,1,1,1,1,0
data 1,1,1,1,1,1,1,1
data 1,1,1,1,1,1,1,1
data 1,1,1,1,1,1,1,1
data 1,1,1,1,1,1,1,1
data 0,1,1,1,1,1,1,0
data 0,0,1,1,1,1,0,0

- have a look and see what you think

"I could see the faces of those who led pissing themselves laughing" - Funeral Pyre by The Jam

ReplyQuote
Posted : 14/07/2009 6:36 pm
AndyRCM
(@andyrcm)
Member Admin

for those of you who don't have freebasic - this is what it looks like . . .

"I could see the faces of those who led pissing themselves laughing" - Funeral Pyre by The Jam

ReplyQuote
Posted : 14/07/2009 6:37 pm
AndyRCM
(@andyrcm)
Member Admin

meant to say - put the nb=256 up to something larger - try 1000 and up . . .

please note that this code doesn't have any delta timing in at all - so on some machines it will run very slow and others very fast! 🙂

Andy

"I could see the faces of those who led pissing themselves laughing" - Funeral Pyre by The Jam

ReplyQuote
Posted : 14/07/2009 6:45 pm
AndyRCM
(@andyrcm)
Member Admin

also - as you see from the speed - you can read the data in every time! 🙂

or you can store it in an array - same way we store the x and y co-ordinates for each ball! 😉

"I could see the faces of those who led pissing themselves laughing" - Funeral Pyre by The Jam

ReplyQuote
Posted : 14/07/2009 7:21 pm
Panther
(@panther)
Member Moderator

Does the 'restore Ball' command make it read from the beginning of the ball data ?

If so could you have something like

ball:
data 0,0,1,1,1,1,0,0
data 0,1,1,1,1,1,1,0
data 1,1,1,1,1,1,1,1
data 1,1,1,1,1,1,1,1
data 1,1,1,1,1,1,1,1
data 1,1,1,1,1,1,1,1
data 0,1,1,1,1,1,1,0
data 0,0,1,1,1,1,0,0


ball2:
data 0,0,1,1,1,1,0,0
data 0,1,1,0,0,1,1,0
data 1,1,0,0,0,0,1,1
data 1,0,0,0,0,0,0,1
data 1,0,0,0,0,0,0,1
data 1,1,0,0,0,0,1,1
data 0,1,1,0,0,1,1,0
data 0,0,1,1,1,1,0,0

And send it to each set of Data or doesn't it work that way ?

ReplyQuote
Topic starter Posted : 14/07/2009 9:09 pm
AndyRCM
(@andyrcm)
Member Admin

yes mate that is exactly how it works . . . that is how i did the pacman graphics . . . here is the code . . .


'  Pacman Test by Andy'09 v3

#include once "tinyptc_ext.bi"

const xres = 640
const yres = 480

    ptc_allowclose(0)
    ptc_setdialog(0,"Would you like to go Fullscreen?",0,0)
    If( ptc_open( "PacMan Test", XRES, YRES ) = 0 ) Then
    End -1
    End If

Dim Shared as Integer nopm
nopm=32
Dim Shared as Integer sb(xres*yres)
#define pp(x,y,argb) sb(y*XRES+x)=argb
Dim Shared as Integer x,y,c,an,fc(nopm)
x=16an=0
Dim shared as Integer pac1(x,y),pac2(x,y),pac3(x,y)

Dim Shared As LARGE_INTEGER Frequency
Dim Shared As LARGE_INTEGER LiStart
Dim Shared As LARGE_INTEGER LiStop
Dim Shared As LONGLONG LlTimeDiff
Dim Shared As Double MDuration

Declare Sub Clr
Declare Sub SetupPac
Declare Sub DrawPac
Declare Sub MovePac

Dim Shared as Integer posix(nopm),posiy(nopm),speed(nopm),pcolr(nopm),pcolg(nopm),pcolb(nopm)

SetupPac
   
QueryPerformanceFrequency( @Frequency )

WHILE(GETASYNCKEYSTATE(VK_SPACE)<> -32767 and PTC_GETLEFTBUTTON=FALSE)
    QueryPerformanceCounter( @LiStart )
   
    DrawPac
    MovePac
   
    ptc_update @sb(0)
    clr
    an=an+1
    if an>22 then an=1
    do
        QueryPerformanceCounter( @LiStop )
        LlTimeDiff = LiStop.QuadPart - LiStart.QuadPart
        MDuration = Cast( Double, LlTimeDiff ) * 1000.0 / Cast( Double , Frequency.QuadPart )
    Loop While (  MDuration <= 1000.0/60.0 )
   
Wend

Sub Clr
    for b=0 to yres-1
        for a=0 to xres-1
            pp(a,b,rgb(0,0,0))
        next a
    next b
End Sub

Sub SetupPac
   
restore pac1
for a=0 to 15
    for b=0 to 15
            read pac1(b,a)
    next b
next a

restore pac2
for a=0 to 15
    for b=0 to 15
            read pac2(b,a)
    next b
next a

restore pac3
for a=0 to 15
    for b=0 to 15
            read pac3(b,a)
    next b
next a

restore positions
For c=0 to nopm
    read posix(c),posiy(c)
next c

restore speeds
for c=0 to nopm
    read speed(c)
next c

restore pacol
for c=0 to nopm
    read pcolr(c),pcolg(c),pcolb(c)
    fc(c)=1
next c

End Sub

Sub DrawPac
for c=0 to nopm
for a=0 to 15
    for b=0 to 15
        if an>=1 and an<=8 and fc(c)=1 and pac1(b,a)=1 then pp(posix(c)+b,posiy(c)*xres+a,rgb(pcolr(c),pcolg(c),pcolb(c)))
        if an>=8 and an<=15 and fc(c)=1 and pac2(b,a)=1 then pp(posix(c)+b,posiy(c)*xres+a,rgb(pcolr(c),pcolg(c),pcolb(c)))
        if an>=15 and fc(c)=1 and pac3(b,a)=1 then pp(posix(c)+b,posiy(c)*xres+a,rgb(pcolr(c),pcolg(c),pcolb(c)))
        if an>=1 and an<=8 and fc(c)=2 and pac1(b,a)=1 then pp(posix(c)+(15-b),posiy(c)*xres+a,rgb(pcolr(c),pcolg(c),pcolb(c)))
        if an>=8 and an<=15 and fc(c)=2 and pac2(b,a)=1 then pp(posix(c)+(15-b),posiy(c)*xres+a,rgb(pcolr(c),pcolg(c),pcolb(c)))
        if an>=15 and fc(c)=2 and pac3(b,a)=1 then pp(posix(c)+(15-b),posiy(c)*xres+a,rgb(pcolr(c),pcolg(c),pcolb(c)))
    next b
next a
next c
End Sub

Sub MovePac
for c=0 to nopm
    posix(c)=posix(c)+speed(c)
    if posix(c)>xres-25 then speed(c)=-speed(c):fc(c)=2
    if posix(c)<8 then speed(c)=-speed(c):fc(c)=1
next c
End Sub

pac1:
'      1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8
data    0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0
data    0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0
data    0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0
data    0,0,1,1,1,1,1,1,1,1,0,1,1,1,0,0
data    0,1,1,1,1,1,1,1,1,0,0,1,1,1,1,0
data    0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0
data    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
data    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
data    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
data    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
data    0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0
data    0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0
data    0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0
data    0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0
data    0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0
data    0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0

pac2:
'      1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8
data    0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0
data    0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0
data    0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0
data    0,0,1,1,1,1,1,1,1,1,0,1,1,1,0,0
data    0,1,1,1,1,1,1,1,1,0,0,1,1,1,1,1
data    0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0
data    1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0
data    1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0
data    1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0
data    1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0
data    0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0
data    0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
data    0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0
data    0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0
data    0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0
data    0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0

pac3:
'      1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8
data    0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0
data    0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0
data    0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0
data    0,0,1,1,1,1,1,1,1,1,0,1,1,1,1,1
data    0,1,1,1,1,1,1,1,1,0,0,1,1,1,1,0
data    0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0
data    1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0
data    1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0
data    1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0
data    1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0
data    0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0
data    0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0
data    0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1
data    0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0
data    0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0
data    0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0

positions:
'starting positions of pacmen
data    10,10,40,40,70,70,100,100,130,130,160,160,190,190,220,220,250,250,280,280,310,310,340,340,370,370,400,400,430,430,460,460
data    10,26,40,56,70,86,100,116,130,146,160,176,190,206,220,236,250,266,280,296,310,326,340,356,370,386,400,416,430,446,460,300
data    50,50

speeds:
'speeds of pacmen
data    1,2,3,4,5,6,7,8,9,8,7,6,5,4,3,2,3
data    3,4,5,6,7,8,4,6,5,4,3,2,1,2,4,5,4

pacol:
'colors of pacmen
data    255,255,0
data    255,0,255
data    0,255,255
data    255,0,0
data    0,255,0
data    0,0,255
data    255,192,0
data    192,255,0
data    0,255,192
data    0,192,255
data    128,128,64
data    64,128,128
data    128,64,128
data    64,64,128
data    128,64,64
data    255,255,255
data    255,255,0
data    255,0,255
data    0,255,255
data    255,0,0
data    0,255,0
data    0,0,255
data    255,192,0
data    192,255,0
data    0,255,192
data    0,192,255
data    128,128,64
data    64,128,128
data    128,64,128
data    64,64,128
data    128,64,64
data    255,255,255
data    255,255,0

okay?

"I could see the faces of those who led pissing themselves laughing" - Funeral Pyre by The Jam

ReplyQuote
Posted : 14/07/2009 9:12 pm
Page 1 / 2
Share: