Author Topic: card fan problem  (Read 1268 times)

Yommy

• Mc. Print
• Posts: 14
card fan problem
« on: 2009-Sep-06 »
im having alot of problems trying to fan some cards in an arc style
my current code is -
Code: (glbasic) [Select]
`count = LEN(p1cards#[])start = 380 - (count/2)*40 // x of first cardstepangle = 60/countangle = 30FOR i = 0 TO count -1ROTOSPRITE p1cards#[i], i*40+start, 500-COS(angle)*100, angleangle = angle - stepangleIF angle < 0angle = angle + 360ENDIFNEXT`which makes it look like

please can someone spot my mistake and explain what i am doing wrong
thanks

Yommy x

• Guest
Re: card fan problem
« Reply #1 on: 2009-Sep-06 »
I propose :

Code: (glbasic) [Select]
`LOADSPRITE "c:/test/test.bmp",1LOADSPRITE "c:/test/test2.bmp",2LOADSPRITE "c:/test/test3.bmp",3maxCard=9stepAngle=180.0/maxCardstartAngle=270.0angle2=180.0s%=1WHILE TRUE angle2=180.0 startAngle=270.0 FOR loop%=0 TO maxCard-1 ROTOSPRITE s%,100+(50.0*COS(angle2)),100+(50.0*SIN(angle2)),startAngle DEC startAngle,stepAngle INC angle2,stepAngle INC s% IF s%>3 s%=1 ENDIF NEXT SHOWSCREENWEND`
Which results in :

Kitty Hello

• code monkey
`LOCAL p1cards#[]DIM p1cards[4]LOADSPRITE "card.bmp", 0LOCAL count, start, angle,fullangleLOCAL screenwidth, screenheight GETSCREENSIZE screenwidth, screenheightcount = LEN(p1cards#[])fullangle = 30LOCAL yy=0FOR i = 0 TO count -1 LOCAL saggita = 500 LOCAL x, y LOCAL proc = i; proc = proc / (count-1) // float from 0..1 for each card angle = fullangle/2-fullangle*proc // the 300 is the width from 1st to last card -> you can make that count * width_of_card if you like x = (proc-0.5) * 300.0 + screenwidth/2 y = 400-(COS(angle)-1)*saggita// ROTOSPRITE 0, x, y, angle PickCard(0, x,y, angle, TRUE) PRINT INTEGER(angle), x,y PRINT x, 0,yy INC yy,25NEXTSHOWSCREENMOUSEWAITFUNCTION PickCard%: index%, x, y, angle, bDraw%LOCAL px[], py[] DIM px[4] DIM py[4]LOCAL w, h // card dimensionsLOCAL spx, spy GETSPRITESIZE index, spx, spy w=spx/2 h=spy/2 // for example - you can scale if you want px[0] = -w; py[0] = -h px[1] = -w; py[1] =  h px[2] =  w; py[2] =  h px[3] =  w; py[3] = -h // now rotate that points around the center TransformPoint(px[0], py[0], x,y, angle) TransformPoint(px[1], py[1], x,y, angle) TransformPoint(px[2], py[2], x,y, angle) TransformPoint(px[3], py[3], x,y, angle) // Draw a polyvvector LOCAL c%=RGB(255,255,255) STARTPOLY index POLYVECTOR px[0], py[0], 0,  0,  c% POLYVECTOR px[1], py[1], 0,  spy,c% POLYVECTOR px[2], py[2], spx,spy,c% POLYVECTOR px[3], py[3], spx,  0,c% ENDPOLY ENDFUNCTIONFUNCTION TransformPoint: BYREF x, BYREF y, dx, dy, angleLOCAL px, py px =  x*COS(angle)+y*SIN(angle) py = -x*SIN(angle)+y*COS(angle) x=px+dx y=py+dyENDFUNCTION`Tadaa.