Author Topic: My YaBASIC Game - Green Boxcopter  (Read 16187 times)

0 Members and 1 Guest are viewing this topic.

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17412
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: My YaBASIC Game - Green Boxcopter
« Reply #20 on: October 14, 2006 »
Inexplicable slowdown was my favourite :)
Probably caused by memory leaks everywhere.
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Clanky

  • Laser Guided Memories
  • Amiga 1200
  • ****
  • Posts: 340
  • Karma: 16
  • kiss that sound that pounds your senses
    • View Profile
Re: My YaBASIC Game - Green Boxcopter
« Reply #21 on: October 15, 2006 »
haha yea... esspecially when you compile the programs on a fast computer, and your using variables suitable for that computer - like speed... and then you try it on the slow computer and its not good!!! bummer it depends on your computer how fast it processes the screens!  :||

well, im gonna finish the game... without the good collision... just cant understand enough to fix the problem. i will post it up when its complete.

thanx for all your help Jim, and your comments Shock!
He tilts, and his eyes are focused on the ground far below.. Wind? Angels? Men..

Offline Clanky

  • Laser Guided Memories
  • Amiga 1200
  • ****
  • Posts: 340
  • Karma: 16
  • kiss that sound that pounds your senses
    • View Profile
Re: My YaBASIC Game - Green Boxcopter
« Reply #22 on: October 17, 2006 »
hmm... i was wondering, as i had already asked Slinking at Ezboard whether it was possible to make the scrolling blocks turn around on itself?
confused?
well... imagine the scrolling block... with points 'A' and 'B', and radius'x'

                       A
                       |
there>>>         | x
                       |
                       B

--> with 'point B' the stationary point, which does not move/rotate... rather, you can consider it as the Centre of the 'wanted' circle.
--> 'point A' will be the point which will move around 'point B'... rotating in a circle.

i dont know how this would be done... but i think i have seen codes using COS or SIN as the co-efficient which turns 'point A'...

'point B' would be (ex1,ey1), while 'point A' would be moved with (ex1+rotateX,ey1+rotateY)
where 'rotateX/Y' is the value for the turning sum - either the COS or SIN

hope you can understand... and if it is actually possible... Slinking said that it was nearly impossible... but i dunno?.............. "Is It?"  :-[
He tilts, and his eyes are focused on the ground far below.. Wind? Angels? Men..

Offline taj

  • Bytes hurt
  • DBF Aficionado
  • ******
  • Posts: 4810
  • Karma: 189
  • Scene there, done that.
    • View Profile
Re: My YaBASIC Game - Green Boxcopter
« Reply #23 on: October 18, 2006 »
You need
A is (ex1 + x*sin(angle), ey1 + x*cos(angle))

angle is obvious in the sense that it represents the angle through which you wish to rotate. Its non obvious because you may need the value in radians not degrees, I dont know your sin function. To convert degrees to radians (if you need to) use:

angle = degrees * 3.14159/180.0

So check your sin function. If you dont have a sin function, we can come up with something else...
Challenge Trophies Won:

Offline taj

  • Bytes hurt
  • DBF Aficionado
  • ******
  • Posts: 4810
  • Karma: 189
  • Scene there, done that.
    • View Profile
Re: My YaBASIC Game - Green Boxcopter
« Reply #24 on: October 18, 2006 »
Intersection of two AXIS ALIGNED boxes can be done like this.

Two boxes, b1,b2.

if (b1.minx<b2.maxx) && (b1.maxx>b2.minx) &&
   (b1.miny<b2.maxy) && (b1.maxy>b2.miny)

&& is AND in C. This is complete and robust, no other tests needed. Its hard to see why it works, but basically the problem is decomposed into the problem of two 1d problems (known as spans). Only if both the 1d solutions are true, can the 2d problem (two boxes intersect) be true.

Extending to 3d is obvious, even 4d... :-)  Here is code to check if two hypercubes intersect ...

if (b1.minx<b2.maxx) && (b1.maxx>b2.minx) &&
   (b1.miny<b2.maxy) && (b1.maxy>b2.miny) &&
   (b1.minz<b2.maxz) && (b1.maxz>b2.minz) &&
   (b1.minw<b2.maxw) && (b1.maxw>b2.minw)

Of course why you'd ever want to do that is beyond me.

Sorry for rambling, I cant sleep.
« Last Edit: October 18, 2006 by taj »
Challenge Trophies Won:

Offline Clanky

  • Laser Guided Memories
  • Amiga 1200
  • ****
  • Posts: 340
  • Karma: 16
  • kiss that sound that pounds your senses
    • View Profile
Re: My YaBASIC Game - Green Boxcopter
« Reply #25 on: October 18, 2006 »
i dont have a rotation code - as i dont know how it works using sin or cos...
but, i tried you examples, but it didnt work... well, at least the way i interpereted it and implemented it in a sample code! it just moves the X point down the screen? not rotating the triangle...
using YaBASIC:

Code: [Select]
open window 640,512

ex=500
ey=200

label loop
x=x+1
  setdrawbuf db
  db=1-db
  setdispbuf db
  clear window
angle=degrees*3.14159/180.0
triangle (ex+(x*sin(angle))),(ey+(x*cos(angle))) to ex,ey+20 to ex+5,ey+20
triangle (ex+(x*sin(angle))),(ey+(x*cos(angle))) to (ex+(x*sin(angle))+5),(ey+(x*cos(angle))) to ex+5,ey+20
goto loop

is that how you ment the code to be used? as you didn't define X, or change its value???
Thanx for you help!

ok.. i went through the old codes at Ezboard - memories... good ol' games!!! haha... and i have found a bit of code which rotates triangles through 2 points!!! OMG! i will try and put it onto my game... hopefully the collision detection will be fixed by my theroy!
i had to change some of it so that it rotated a triangle rather than the original circle.
with a bit of modification, i think that it will work!

heres the rotation code:

Code: [Select]
open window 640,512

label loop
  setdrawbuf d
  d=1-d
  setdispbuf d
  clear window
mm=mm+.025
x=100*sin(mm)+320
y=100*cos(mm)+256
x2=320
y2=256
setrgb 1,250,250,250
fill triangle x-5,y-10 to x2-5,y2+10 to x+5,y-10
fill triangle x+5,y-10 to x2-5,y2+10 to x2+5,y2+10
goto loop
« Last Edit: October 18, 2006 by Clanky »
He tilts, and his eyes are focused on the ground far below.. Wind? Angels? Men..

Offline taj

  • Bytes hurt
  • DBF Aficionado
  • ******
  • Posts: 4810
  • Karma: 189
  • Scene there, done that.
    • View Profile
Re: My YaBASIC Game - Green Boxcopter
« Reply #26 on: October 18, 2006 »
i dont have a rotation code - as i dont know how it works using sin or cos...
but, i tried you examples, but it didnt work... well, at least the way i interpereted it and implemented it in a sample code! it just moves the X point down the screen? not rotating the triangle...
using YaBASIC:

Code: [Select]
open window 640,512

ex=500
ey=200

label loop
x=x+1
  setdrawbuf db
  db=1-db
  setdispbuf db
  clear window
angle=degrees*3.14159/180.0
triangle (ex+(x*sin(angle))),(ey+(x*cos(angle))) to ex,ey+20 to ex+5,ey+20
triangle (ex+(x*sin(angle))),(ey+(x*cos(angle))) to (ex+(x*sin(angle))+5),(ey+(x*cos(angle))) to ex+5,ey+20
goto loop

is that how you ment the code to be used? as you didn't define X, or change its value???
Thanx for you help!

No :-) If I read your basic right (I dont program in it so Im guessing a little), you are incrementing x. X is the radius of the circle that would be drawn. You should be increasing the angle, not x. In your case this is the variable degrees. However you havent set degrees to any value...I guess basic allows this and defaults to zero or something? In which case your code cant work at all. I clearly dont understand what you are trying to do. Your description seemed to be to rotate point A around point B with a radius of x, which is just drawing a circle, but now you have a triangle in there and you are changing the radius so I dont know what it is you are trying to do I'm afarid. Sorry.



Challenge Trophies Won:

Offline Clanky

  • Laser Guided Memories
  • Amiga 1200
  • ****
  • Posts: 340
  • Karma: 16
  • kiss that sound that pounds your senses
    • View Profile
Re: My YaBASIC Game - Green Boxcopter
« Reply #27 on: October 22, 2006 »
OK... i have kind of fixed the collision error... it still occurs sometimes... its the best i can do. i have taken out the boss level - and have made it scroll from Level One Design after level 13, 26 ect.
i wont add the rotating blocks, becuase i think it will be too hard to code esspecially with the collision detection ??? wouldnt have a clue if it went wrong@ - and too hard to pass the level...
well. heres the final version. Hope You Guys and Lovely Gurls Enjoy The Game

Code: [Select]
'Green Boxcopter
'Coded by Sir Johnah
'Rel-Ver: 15.09.06
'Add_Rel-Ver: 20.09.06, CCX: Slinking Shadow
'Fin_Rel-Ver: 22.10.06, CCX: SLinking Shadow, Jim Shaw

'INTRODUCTION     
'============
'Avoid the blocks scrolling across the screen
'or else you will crash!!! Do not hit the roof
'or the ground, or, again, you will crash.
'NB// ROOF REFERS TO THE top white bit.
'NB// GROUND REFERS TO THE bottom white bit.

'CONTROLS
'========
'D-PAD UP: Fly Helicopter Up
'D-PAD DOWN: Fly Helicopter Down
'START: Pause Game
'X (while paused): Unpause Game

'Add_Rel-Ver: 20.09.06
'=====================
' All Bugs and Errors Have Been Fixed^
' Improved Visuals
' Improved Controls
' Enhanced Menu
' Level 10-New Block Formation, Chatter Motion
' Level 15-New Block Formation, Up/Down Motion
' New Visual: Smoke OnTrail
'^90% True, the Collision Detection System is still down.

'Fin_Rel-Ver: 22.10.06
'=====================
' Went through the code... and decided to change the
' way things worked! Things I changed:
'  Level Changes: Now @ 5, 8 and 13
'  Like to see if you can cheat? Can you?
'  Fixed smoke.gfx
'  New smoke.gfx code
'  New Menu Themes: Green for Good, Red for Bad
'  Scrapped Boss Level - couldn't see why the game needed
'    it? The game restarts scrolling through levels after
'    Level 13.
' NB// Fixed the Collision Bug... Still goes through some
'      blocks some of the times... Cant help that!

'Thank you to Slinking Shadow @ Ezboard - bummer we didn't
'get the game further.
'Jim @ DBF - helpful support as per usual!
'Shocky... never really knew you @ Ezboard as I came when
'the YaBASIC seasons were becomming short - but I had a
'chance to see your programs... you should be Really Proud!
'Tank Zone... mmm
'And to DBF Forums for having the abandoned crew from Ezboard!
'Cheers... <Vision YaBASIC>

'Hope you enjoy the game.
'Cheers,
'       Sir Johnah    >_<

'--CODE--

open window 640,512

high_score=1000

title()

'TITLE PAGE
sub title()
xp=80
yp=256
spd=3
smoke1=0
smoke2=2
smoke3=2
repeat
  setdrawbuf db
  db=1-db
  setdispbuf db
  clear window
setrgb 1,100,200,100
text 245,100,"Green Boxcopter"
text 230,120,"Coded by Sir Johnah"
text 235,200,"Hit X to Play Game"
text 230,300,"        >_<        "
text 245,330,"{execute trance}"
text 235,350,"Dance To My Trance"
draw()
clear fill rect 0,475,640,500
until (peek("port1")=16384)
setup()
end sub

'SET VARIABLES
sub setup()
score=0
hi=0
level=1
levels=1
stage=0
grav=0
xp=80
yp=256
spd=3
ex1=650
ey1=int(ran(382)+100)
size1=int(ran(50)+50)
ex1s=1
ex2=960
ey2=int(ran(382)+100)
size2=int(ran(50)+50)
ex2s=2
smoke1=0
smoke2=2
smoke3=2
s1_exe=0
s2_exe=0
s3_exe=0
main()
end sub

'GAME LOOP
sub main()
s1_exe=0
s2_exe=0
s3_exe=0
label loop
  setdrawbuf db
  db=1-db
  setdispbuf db
  clear window
  if levels<5 level()
  if (levels>=5 and levels<8) level_b8()
  if (levels>=8 and levels<13) level_b13()
  if (levels=13 and stage=100) levels=1
stage=stage+0.1
score=score+0.1+(level/100)
'GET LEVEL VARS
  if stage>=100 then
    stage=0
    score=score+50
    spd=spd+0.2
    level=level+1
    levels=levels+1
  fi
rise=0
'CALL ROUTINES
controls()
level()
chk_sum()
draw()
'GRAVITY
  if rise=0 then
    grav=grav+.69
    up=0
  fi
  if rise=1 then
    grav=0
    up=up+.69
  fi
yp=yp+grav
goto loop
end sub

sub draw()
'DRAW SMOKE
  if smoke1=0 then
  sx1=xp-30
  sy1=yp
  smoke1=1
  elsif smoke1=1 then
  sx1=sx1-(spd+1.5)
'   THESE SETRGB'S ARE USED TO FADE THE SMOKE...
'   SMART THINKIN SJ!
  setrgb 1,100-((1/sx1)*1000),100-((1/sx1)*1000),100-((1/sx1)*1000)
  fill circle sx1-10,sy1,5
  setrgb 1,140-((1/sx1)*1000),140-((1/sx1)*1000),140-((1/sx1)*1000)
  fill circle sx1-4,sy1-4,5
  setrgb 1,120-((1/sx1)*1000),120-((1/sx1)*1000),120-((1/sx1)*1000)
  fill circle sx1-3,sy1+3,5
  if sx1<=0 smoke1=0
  if (s2_exe=0 and sx1<=20) smoke2=0
  fi
  if smoke2=0 then
    s2_exe=1
  sx2=xp-30
  sy2=yp
  smoke2=1
  elsif smoke2=1 then
  sx2=sx2-(spd+1.5)
  setrgb 1,120-((1/sx2)*800),120-((1/sx2)*800),120-((1/sx2)*800)
  fill circle sx2-9,sy2,5
  setrgb 1,140-((1/sx2)*800),140-((1/sx2)*800),140-((1/sx2)*800)
  fill circle sx2-3,sy2-3,5
  setrgb 1,100-((1/sx2)*800),100-((1/sx2)*800),100-((1/sx2)*800)
  fill circle sx2-2,sy2+2,5
  if sx2<=0 smoke2=0
  if (s3_exe=0 and sx2<=10) smoke3=0
  fi
  if smoke3=0 then
    s3_exe=1
  sx3=xp-30
  sy3=yp
  smoke3=1
  elsif smoke3=1 then
  sx3=sx3-(spd+1.5)
  setrgb 1,100-((1/sx3)*500),100-((1/sx3)*500),100-((1/sx3)*500)
  fill circle sx3-8,sy3,5
  setrgb 1,120-((1/sx3)*500),120-((1/sx3)*500),120-((1/sx3)*500)
  fill circle sx3-3,sy3-2,5
    setrgb 1,140-((1/sx3)*500),140-((1/sx3)*500),140-((1/sx3)*500)
  fill circle sx3-4,sy3+4,5
  if sx3<=0 smoke3=0
  fi
'PLAYER HELICOPTER
setrgb 1,100,200,100
rect xp-10,yp-10,xp+10,yp+10
rect xp-10,yp-2.5,xp-35,yp+2.5
rect xp-35,yp-6,xp-42,yp+3
line xp-8,yp+10,xp-8,yp+15
line xp+8,yp+10,xp+8,yp+15
line xp-12,yp+15,xp+12,yp+15
rect xp-2,yp-10,xp+2,yp-15
rect xp+10,yp-10,xp+3,yp+3
dot xp-42,yp+3
dot xp+3,yp+3
  if rotated=0 rotate=rotate+5
  if rotated=1 rotate=rotate-5
  if rotate=30 or rotate=0 rotated=1-rotated
line xp-rotate,yp-15,xp+rotate,yp-15
'DRAW GROUND/ROOF
setrgb 1,250,250,250
fill rect 0,0,640,24
fill rect 0,417,640,512
'DRAW TABLE
clear fill rect 0,475,640,500
'SCORE
setrgb 1,100,200,100
text 10,490,"SCORE: "+str$(int(score))
  if score>high_score then
    high_score=int(score)
    hi=1
   fi
text 200,490,"HIGH SCORE: "+str$(high_score)
'DRAW LEVEL VARS
text 520,490,"LEVEL: "+str$(level)+"."+str$(int(stage/10))
setrgb 1,0,90,0
setrgb 2,0,90,0
setrgb 3,100,200,100
gtriangle 410,482 to 410+stage,482 to 410+stage,493
setrgb 2,100,200,100
gtriangle 410,482 to 410,493 to 410+stage,493
setrgb 1,0,0,0
line 420,482,420,493
line 430,482,430,493
line 440,482,440,493
line 450,482,450,493
line 460,482,460,493
line 470,482,470,493
line 480,482,480,493
line 490,482,490,493
line 500,482,500,493
setrgb 1,250,250,250
rect 410,482,510,493
dot 510,482
  if boss_level=1 then
    clear fill rect 409,438,511,451
    setrgb 1,200,0,0
    fill rect 410,440,410+boss_health,450
    setrgb 1,250,250,250
    rect 410,440,510,450
  fi
end sub

sub level()
'GET LEVEL BLOCKS
'FIRST BLOCK
  if ex1<=0 ex1s=1
  if ex1s=1 then
    ex1=650
    ey1=int(ran(382)+100)
    size1=int(ran(50)+50)
    ey1c1=ey1-size1
    ey1c2=ey1+size1
    ex1s=2
  elsif ex1s=2 then
    ex1=ex1-spd
  fi
'SECOND BLOCK
  if ex2<=0 ex2s=1
  if ex2s=1 then
    ex2=650
    ey2=int(ran(382)+100)
    size2=int(ran(50)+50)
    ey2c1=ey2-size2
    ey2c2=ey2+size2
    ex2s=2
  elsif ex2s=2 then
    ex2=ex2-spd
  fi
'DRAW LEVEL BLOCKS
setrgb 1,250,250,250
fill rect ex1-5,ey1-size1,ex1+5,ey1+size1
fill rect ex2-5,ey2-size2,ex2+5,ey2+size2
end sub

sub level_b8()
'GETTING GOOD HEY? MUST THINK TO BEAT YOU!!!
'GET LEVEL BLOCKS
'FIRST BLOCK
  if ex1<=0 ex1s=1
  if ex1s=1 then
    ex1=650
    ey1=int(ran(382)+100)
    size1=int(ran(50)+50)
    ex1s=2
  elsif ex1s=2 then
    dirx1=int(ran(2))
    if dirx1=0 drx1=spd
    if dirx1=1 drx1=-spd
    ex1=ex1-spd
    ey1=ey1-drx1
  fi
'SECOND BLOCK
  if ex2<=0 ex2s=1
  if ex2s=1 then
    ex2=650
    ey2=int(ran(382)+100)
    size2=int(ran(50)+50)
    ex2s=2
  elsif ex2s=2 then
    dirx2=int(ran(2))
    if dirx2=0 drx2=spd
    if dirx2=1 drx2=-spd
    ex2=ex2-spd
    ey2=ey2-drx2
  fi
'DRAW LEVEL BLOCKS
setrgb 1,250,250,250
fill rect ex1-5,ey1-size1,ex1+5,ey1+size1
fill rect ex2-5,ey2-size2,ex2+5,ey2+size2
end sub

sub level_b13()
'DAMN, SMART GUY EY'? YOU WONT BEAT ME ANYMORE
'GET LEVEL BLOCKS
'FIRST BLOCK
  if ex1<=0 ex1s=1
  if ex1s=1 then
    ex1=650
    ey1=int(ran(382)+100)
    size1=int(ran(50)+50)
    ex1s=2
    dirx1=int(ran(2))
  elsif ex1s=2 then
    if dirx1=0 drx1=spd
    if dirx1=1 drx1=-spd
    ex1=ex1-spd
    ey1=ey1-drx1
    if (ey1-size1)<=24 dirx1=1
    if (ey1+size1)>=417 dirx1=0
  fi
'SECOND BLOCK
  if ex2<=0 ex2s=1
  if ex2s=1 then
    ex2=650
    ey2=int(ran(382)+100)
    size2=int(ran(50)+50)
    ex2s=2
    dirx2=int(ran(2))
  elsif ex2s=2 then
    if dirx2=0 drx2=spd
    if dirx2=1 drx2=-spd
    ex2=ex2-spd
    ey2=ey2-drx2
    if (ey2-size2)<=24 dirx2=1
    if (ey2+size2)>=417 dirx2=0
  fi
'DRAW LEVEL BLOCKS
setrgb 1,250,250,250
fill rect ex1-5,ey1-size1,ex1+5,ey1+size1
fill rect ex2-5,ey2-size2,ex2+5,ey2+size2
end sub

sub chk_sum()
'CHECK SYSTEM
  if yp<=40 crash()
  if yp>=402 crash()
'COLLISION FIRST BLOCK
  if ((ey1-size1)<(yp-15) and (ey1+size1)>(yp+15) and ex1<110 and ex1>38) crash()
'COLLISION SECOND BLOCK
  if ((ey2-size2)<(yp-15) and (ey2+size2)>(yp+15) and ex2<110 and ex2>38) crash()
end sub

sub crash()
label crash
  setdrawbuf db
  db=1-db
  setdispbuf db
smoke1=2
smoke2=2
smoke3=2
draw()
setrgb 1,100,200,100
clear fill rect 190,185,415,270
setrgb 1,200,10,10
clear fill circle xp,yp,53
fill circle xp,yp,50
rect 190,185,415,270
text 225,200,"Hit X to Restart"
text 200,220,"Hit TRIANGLE to Quit"
text 200,240,"SCORE: "+str$(int(score))
text 200,260,"LEVEL: "+str$(level)+"."+str$(int(stage/10))
setrgb 1,200,200,200
rect 192,187,413,268
setrgb 1,200,10,10
line 190,227,415,227
setrgb 1,int(ran(250)+120),int(ran(250)+120),int(ran(250)+120)
'NEW HIGH SCORE? YAY... CONGRADULATIONS
  if hi=1 then
    clear fill rect 140,305,470,330
    rect 140,305,470,330
    text 150,320,"CONGRADULATIONS! NEW HIGH SCORE"
  fi
  if peek("port1")=16384 title()
'LEAVING SO SOON? WELL, THANX FOR PLAYING
  if peek("port1")=4096 error"Thank you for playing Green Boxcopter, coded by Sir Johnah.\nHope you enjoyed this installment!\nCheers,\n            Sir Johnah   >_<\n"
goto crash
end sub

sub controls()
'GET PLAYER CONTROLS
c=peek("port1")
  if and(c,64)<>0 then
    yp=yp+(4+up)
    rise=1
  fi
  if and(c,16)<>0 then
    yp=yp-(4+up)
    rise=1
  fi
  if and(c,8)<>0 pausing()
end sub

sub pausing()
'FREEZE GAME VALUES
ex1p=ex1
ey1p=ey1
ex2p=ex2
ey2p=ey2
smoke1=2
smoke2=2
smoke3=2
label pausing
ex1=ex1p
ey1=ey1p
ex2=ex2p
ey2=ey2p
  setdrawbuf db
  db=1-db
  setdispbuf db
level()
draw()
setrgb 1,100,200,100
clear fill rect 190,185,415,230
rect 190,185,415,230
text 218,210,"Hit X to Continue"
setrgb 1,200,200,200
rect 192,187,413,228
  if peek("port1")=16384 then
    smoke1=0
    smoke2=2
    smoke3=2
    main()
  fi
  if peek("port1")=16 sch=1
  if (sch=1 and peek("port1")=4096) sch=2
  if (sch=2 and peek("port1")=64) sch=3
  if sch=3 then:score=score+1000:sch=0:fi
  if peek("port1")=8 lch=1
  if (lch=1 and peek("port1")=1) lch=2
  if (lch=2 and peek("port1")=128) lch=3
  if (level<12 and lch=3) then:level=level+1:lch=0:fi
goto pausing
end sub

He tilts, and his eyes are focused on the ground far below.. Wind? Angels? Men..

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: My YaBASIC Game - Green Boxcopter
« Reply #28 on: January 26, 2007 »
1402 level 8 is a b4st4rd I had a real good run at it and all those walls were aiming for me.
Clanky why dont you try using a few cross-product calculations it works for rotating boxes I will explain -

crossproduct = (x1 - x2)*(y3 - y2) - (y1 - y2)*(x3 - x2)

x2 = posx (or a corner of the chopper)
y2 = posy

x1,y1 & x3,y3 are two points on one single edge the calculation checks to see if point x2,y2 is on one side of that line or the other. Now if you check this against two paralell edges (and you keep the orientation the same, y1 above y3) they will either return a positive or negative value. If one is positive and the other is negative then you will have to check the other edges if the other edges are also at odds you have yourself a collision with a rotating box. (note this will have to be repeated with all corners of copter)

Challenge Trophies Won:

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: My YaBASIC Game - Green Boxcopter
« Reply #29 on: January 26, 2007 »
Here is a working example i also included the program that I ripped it out of, I used this to calculate if an NPC could see a charictor by checking the charictor against both extremes of the feild of view it worked beautifully I have adapted it to suit the problem of calculating collisions with a rotating box. I hope you include this feature in the game I love these little touches, keep it real my friend.

Edit -

You can even use cross product to make an NPC turn to face another charictor like so

turnangle =  (NPCX - TargetX)*(sine - TargetY) - (NPCY - TargetY)*(cosine - TargetX)

where -
 sine = posy + sin(current_angle)
 cosine = posx + cos(current_angle)

the NPC will always turn towards the charictor cool little trick for avoiding if statements
« Last Edit: January 26, 2007 by rain_storm »

Challenge Trophies Won: