### Author Topic: Online Gorillas / Tanks  (Read 1822 times)

#### B+

• Full Member
• Posts: 215
##### Re: Online Gorillas / Tanks
« Reply #15 on: September 10, 2016 »
Code: [Select]
`' Banana throwing.'mod 2016-09-09 [B+=MGA] give it a banana to toss!constant:XMAX = 800YMAX = 600hidden:set window 100, 40, 800, 600set redraw off' Forward difference gravity effect.gravity# = 0.02' Starting position.startX = 64startY = 520' Power, should be controlled.power# = 3.5' Set state to 0 (aim and fire).state = 0do ' State 0: Aim and fire. if state = 0 ' Calculate angle. dx = mousex() - startX dy = mousey() - startY if not (dx = 0 and dy = 0) angle# = atan2(float(dy), float(dx)) endif ' Fire? if mousebutton(0, true) state = 1 projX# = float(startX) projY# = float(startY) projDX# = cos(angle)*power projDY# = sin(angle)*power bAng# = 0.0 endif ' State 1: Projectile in the air. elseif state = 1 projX = projX + projDX projY = projY + projDY projDY = projDY + gravity ' Out of bounds? if projX < 0.0 or projX >= float(width(primary)) or projY < 0.0 or projY >= float(height(primary)) state = 0 endif endif set color 0, 0, 0 cls set color 255, 255, 255 set caret width(primary)/2, 8 center "Move mouse cursor to aim, click to fire!" ' State 0: Draw aim. if state = 0 ' Arrow. endX = startX + int(int(cos(angle)*40.0)) endY = startY + int(sin(angle)*40.0) draw line startX, startY, endX, endY draw line endX, endY, endX + int(cos(angle - 160.0)*16.0), endY + int(sin(angle - 160.0)*16.0) draw line endX, endY, endX + int(cos(angle + 160.0)*16.0), endY + int(sin(angle + 160.0)*16.0) ' State 1: Draw projectile. else k# = 1.0/sqr(projDX*projDX + projDY*projDY) dxf# = 8.0*k*projDX dyf# = 8.0*k*projDY 'draw line int(projX - dxf), int(projY - dyf), int(projX), int(projY) _drawBanana int(projX - dxf), int(projY - dyf), bAng# bAng# = bAng# + 5.0 + rndF#(5.0) endif redraw wait 17until keydown(27, true)function quad(pStart, r1#, ang#, lng#, r2#)'solid fill circles at both ends, use polygon 4 points to fill middle area'draws from pStart at radius r1 down angle ang for length of leg'with r2 being the radius at end point 'returns the x, y end point in P form for further pendage drawing'constants XMAX, YMAX'needs fcirc(x, y, r)'needs xy2P(x, y) 'extract x, y start line of circles  fx# = float(pStart % (XMAX + 1)) fy# = float(pStart) / float(XMAX) x1# = fx# + r1# * cos(ang# + 90.0) y1# = fy# + r1# * sin(ang# + 90.0) x2# = fx# + r1# * cos(ang# - 90.0) y2# = fy# + r1# * sin(ang# - 90.0)  xe# = fx# + lng# * cos(ang#)  ye# = fy# + lng# * sin(ang#) x3# = xe# + r2# * cos(ang# + 90.0) y3# = ye# + r2# * sin(ang# + 90.0) x4# = xe# + r2# * cos(ang# - 90.0) y4# = ye# + r2# * sin(ang# - 90.0) _fcirc int(fx#), int(fy#), int(r1#)  _fcirc int(xe#), int(ye#), int(r2#) 'draw quad fill draw poly[int(x1#), int(y1#), int(x2#), int(y2#), int(x4#), int(y4#), int(x3#), int(y3#)], true return xy2P(int(xe#), int(ye#))endfuncprocedure fcirc(x, y, r) rsq = r * r for a = 0 to r b = int(sqr(float(rsq - a * a))) x1 = x + a; x2 = x - a; y1 = y - b; y2 = y + b draw line x1, y1, x1, y2 draw line x2, y1, x2, y2 nextendprocfunction xy2P(x, y) 'note uses constants XMAX screen width return y * (XMAX + 1) + xendfuncfunction rndF#(maxFloat#) 'note can't go up to 100,000 maybe 32000? return maxFloat# * float(rnd(16000)) / 16000.0endfuncprocedure drawBanana(x, y, ang#) set colori 0xffff00 startP = xy2P(x, y) Ang1# = ang# + 45.0 Ang2# = Ang1# + 45.0 midRadius# = 3.0 eRadius# = 1.5 nextP = quad(startP, eRadius#, ang#, 7.0, midRadius#) nextP = quad(nextP, midRadius#, Ang1#, 7.0, midRadius#) nextP = quad(nextP, midRadius#, Ang2#, 6.0, eRadius#) endproc`
B+

#### Marcus

• Hero Member
• Posts: 549
##### Re: Online Gorillas / Tanks
« Reply #16 on: September 10, 2016 »
Haha, awesome

Forget the time limit I set in my original post. Haven't had time to do much myself yet, but I'll post some p2p stuff here soon.
.\\\opz

#### Rick3137

• Sr. Member
• Posts: 347
• May the Force be with You
##### Re: Online Gorillas / Tanks
« Reply #17 on: September 10, 2016 »
Nice work, Mark

#### Marcus

• Hero Member
• Posts: 549
##### Re: Online Gorillas / Tanks
« Reply #18 on: September 11, 2016 »
Same thing as B+ posted but with a banana image
.\\\opz

#### B+

• Full Member
• Posts: 215
##### Re: Online Gorillas / Tanks
« Reply #19 on: September 11, 2016 »
Oh this is excellent image rotation example!    (and great banana too!)
B+

#### B+

• Full Member
• Posts: 215
##### Re: Online Gorillas / Tanks
« Reply #20 on: September 12, 2016 »
Combining Marcus code, a game.

B+