Dark Bit Factory & Gravity
PROGRAMMING => Other languages => Yabasic => Topic started by: Clanky on September 20, 2006
-
well, this code uses win32yabasic, from ezboard homebrew forums...
hope you guys and lovely guys enjoy! you'll need the emulator to run the game!
one problem.... the collision in the game does not work properly! for some reason, it lets some of the helicopter pass through the blocks...
and, the boss level at the end has not been coded, but all else works.
levels 1-9 are easy!
levels 10-14 are intermediate!!!
and, levels 15-19 are extreme!
if someone thinks that the game is too hard, then i will make it easier when i code the boss and fix the collision!
Cheers,
   Sir Johnah (Clanky)
>_<
THIS IS UPDATED!!! NEWER VERSION... NEW BITS OF CODE IMPLEMENTED!!!
Hope you enjoy
'Green Boxcopter
'Coded by Sir Johnah
'Rel-Ver: 15.09.06
'Add_Rel-Ver: 20.09.06, CCX: Slinking Shadow
'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
'NB// NO OTHER BUTTONS ARE USED IN-GAME,
' EXCEPT FOR MENU SELECTIONS.
'Add_Rel-Ver: 20.09.06
'=====================
'New Code:
' Level 10-New Block Formation, Chatter Motion
' Level 15-New Block Formation, Up/Down Motion
' Level 20-Boss Level!!!
'Hope you enjoy the game.
'Cheers, Sir Johnah
'>_<
open window 640,512
high_score=1000
title()
'TITLE PAGE
sub title()
xp=80
yp=256
spd=3
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 225,380,"{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
stage=0
level=1
stage=0
grav=0
xp=80
yp=256
spd=5
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=0
smoke3=0
main()
end sub
'GAME LOOP
sub main()
label loop
setdrawbuf db
db=1-db
setdispbuf db
clear window
score=score+0.1
if level<10 level()
if (level>=10 and level<15) level_b10()
if (level>=15 and level<20) level_b15()
if level=20 boss()
if level<20 stage=stage+0.1
'GET LEVEL VARS
if stage>=100 then
stage=0
score=score+50
spd=spd+0.25
level=level+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
setrgb 1,100,100,100
fill circle sx1-10,sy1,5
setrgb 1,140,140,140
fill circle sx1-3,sy1-3,5
setrgb 1,120,120,120
fill circle sx1-3,sy1+3,5
if sx1<=0 smoke1=0
if sx1<=10 smoke2=0
fi
if smoke2=0 then
sx2=xp-30
sy2=yp
smoke2=1
elsif smoke2=1 then
sx2=sx2-spd
setrgb 1,100,100,100
fill circle sx2-10,sy2,5
setrgb 1,140,140,140
fill circle sx2-3,sy2-3,5
setrgb 1,120,120,120
fill circle sx2-3,sy2+3,5
if sx2<=5 smoke2=0
if sx2<=10 smoke3=0
fi
if smoke3=0 then
sx3=xp-30
sy3=yp
smoke3=1
elsif smoke3=1 then
sx3=sx3-spd
setrgb 1,100,100,100
fill circle sx3-10,sy3,5
setrgb 1,140,140,140
fill circle sx3-3,sy3-3,5
setrgb 1,120,120,120
fill circle sx2-3,sy3+3,5
if sx3<=5 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
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)
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)
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_b10()
'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_b15()
'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 boss()
'WELL....
'I CHALLENGE YOU TO A DUEL!!!
'FIGHT ME AND WIN, AND I SHALL LET YOU LIVE... BUT,
'FIGHT AND LOSE! THEN I SHALL TEAR YOU APART!!!
end sub
sub chk_sum()
'CHECK SYSTEM
if yp<=40 crash()
if yp>=402 crash()
'=============
'=PROBLEMS!!!=
'=============
'COLLISION FIRST BLOCK
if (yp-15>=(ey1-size1) and yp+15<=(ey1+size1) and xp+30>=(ex1-5) and xp-42<=(ex1+5)) crash()
'COLLISION SECOND BLOCK
if (yp-15>=(ey2-size2) and yp+15<=(ey2+size2) and xp+30>=(ex2-5) and xp-42<=(ex2+5)) crash()
end sub
sub crash()
label crash
setdrawbuf db
db=1-db
setdispbuf db
smoke1=3
smoke2=3
smoke3=3
draw()
setrgb 1,200,10,10
clear fill circle xp,yp,53
fill circle xp,yp,50
setrgb 1,100,200,100
clear fill rect 190,185,415,270
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,100,200,100
line 190,227,415,227
setrgb 1,int(ran(250)+120),int(ran(250)+120),int(ran(250)+120)
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()
if peek("port1")=4096 error"Thank you for playing Green Boxcopter, coded by Sir Johnah.\nHope you enjoyed this installment!\nCheers, Sir Johnah\n>_<\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()
ex1p=ex1
ey1p=ey1
ex2p=ex2
ey2p=ey2
smoke1=3
smoke2=3
smoke3=3
label pausing
ex1=ex1p
ey1=ey1p
ex2=ex2p
ey2=ey2p
setdrawbuf db
db=1-db
setdispbuf db
draw()
level()
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=0
smoke3=0
main()
fi
goto pausing
end sub
Edit- Added Code Tags To Source Listing
-
Hey Clanky! Great to see you over here! Happy 18th brithday!
For folks who want to try this, you can download the PC yabasic player here
http://members.iinet.net.au/~jimshaw/Yabasic/ps2yabasic1.6b3.zip
or, if you're feeling more adventurous, you can try it on your PSP too
http://members.iinet.net.au/~jimshaw/PSP/pspyabasic1.0a.zip
Jim
-
:hi: And I am just going to create a Yabasic area.
-
Sorted.
Happy birthday by the way :) I need to download the Yabasic emulator now ( I don't have it any more!! Ooops! ) I still have some of my demos though so I should be able to help populate this board.
-
Might find some old friends here
http://members.iinet.net.au/~jimshaw/Yabasic/yabres/yabres.html
Jim
-
Excellent! I'll look through them. Maybe we'll even drum up a little interest in Yabasic again!
-
excellent link there jim!
but when i tried downloading your chess it said the page you tried to access has been moved or something like that.
back on topic nice stuff clanky.
-
Yes, I am going to sort out a copy of the emulator and play this game tomorrow :) I'll leave feedback.
-
@Jim - is there a macintosh version of the YaBasic player? although i could try running it on my psp . . . ;)
Drew
-
i have started to try and finish the code. coding the boss! but i still cant understand why the collision isnt working properly??? making me real angry!!! :whack:
well, if any YaBASIC knowhow people can help, then please do!!!!
Cheers!
-
->DrewPee - sorry, there's no Mac version of the player.
->Clanky, if you post the bit of the code with the collision problem I'll have a look.
This code collides a point with a rectangle
open window 640,512
b0x=220
b0y=256
b1x=320
b1y=256
b1w=40
b1h=30
repeat
setdispbuf d
d=1-d
setdrawbuf d
clear window
p=peek("port1")
if and(p,32)<>0 then b0x=b0x+1 fi
if and(p,128)<>0 then b0x=b0x-1 fi
if and(p,64)<>0 then b0y=b0y+1 fi
if and(p,16)<>0 then b0y=b0y-1 fi
setrgb 1,255,255,255
if b0x>b1x and b0x<b1x+b1w then
if b0y>b1y and b0y<b1y+b1h then
setrgb 1,255,0,0
fi
fi
fill rect b0x-1,b0y-1 to b0x+1,b0y+1
rect b1x,b1y to b1x+b1w,b1y+b1h
until (and(p,16384)<>0)
end
If that's any use?
Jim
-
thanx. yea, i know the basics for collision... but i can't seem to figure out why this collision is stuffing up :(
heres the code for the game - only the bit which detects the collision...
WHERE:
since the helicopter doesnt change X position, i have just stated the back of the helicopter as 38, and the front of the helicopter as 110... hope you understand?
yp is the players Y co-ordinant
ex1 is the current Block 1 X co-ordinant
ex2 is the current Block 2 X co-ordinant
ey1c1 is the current Block 1 top co-ordinant (ex1-size1)
ey1c2 is the current Block 1 bottom co-ordinant (ex1+size1)
ey2c1 is the current Block 2 top co-ordinant (ex2-size1)
ey2c2 is the current Block 2 bottom co-ordinant (ex2+size1)
'COLLISION FIRST BLOCK
if (yp-15>=ey1c1 and yp+15<=ey1c2 and ex1+5<=110 and ex1-5>=38) crash()
'COLLISION SECOND BLOCK
if (yp-15>=ey2c1 and yp+15<=ey2c2 and ex2+5<=110 and ex2-5>=38) crash()
heres a bit of code which can simulate the collision for my game:
i have added visual aids to help with the positions of the collision! hopefully you can understand what is happening - and what is going wrong.
open window 640,512
xp=80
yp=256
spd=3
main()
sub main()
repeat
setdispbuf db
db=1-db
setdrawbuf db
clear window
setrgb 1,250,250,250
rect 38,yp-15,110,yp+15
line 111,yp-15,640,yp-15
line 111,yp+15,640,yp+15
get_blocks()
con()
collision()
until (peek("port1")=16384)
end sub
sub get_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 con()
c=peek("port1")
if and(c,64)<>0 yp=yp+4
if and(c,16)<>0 yp=yp-4
end sub
sub collision()
if (yp-15>=ey1c1 and yp+15<=ey1c2) O_o()
if (yp-15>=ey2c1 and yp+15<=ey2c2) o_O()
'COLLISION FIRST BLOCK
if (yp-15>=ey1c1 and yp+15<=ey1c2 and ex1+5<=110 and ex1-5>=38) collide()
'COLLISION SECOND BLOCK
if (yp-15>=ey2c1 and yp+15<=ey2c2 and ex2+5<=110 and ex2-5>=38) collide()
end sub
sub O_o()
setrgb 1,0,250,0
fill rect ex1-5,ey1-size1,ex1+5,ey1+size1
line 111,yp-15,ex1,yp-15
line 111,yp+15,ex1,yp+15
end sub
sub o_O()
setrgb 1,0,0,250
fill rect ex2-5,ey2-size2,ex2+5,ey2+size2
line 111,yp-15,ex2,yp-15
line 111,yp+15,ex2,yp+15
end sub
sub collide()
setrgb 1,250,0,0
fill rect 38,yp-15,110,yp+15
fill rect ex1-5,ey1-size1,ex1+5,ey1+size1
fill rect ex2-5,ey2-size2,ex2+5,ey2+size2
end sub
hopefully you can see whats going wrong? and help with the bug!!! lol
thanx for you help
Cheers,
Sir Johnah
>_<
-
I'm not sure what I'm looking at.
The basis of this is one rectangle colliding with another rectangle, right?
algorithm:
To check if two rectangles A and B intersect, once you've thrown away the obvious stuff of A being completely to one side/above/below B, you need to check each of A's corners to see if they lie in B, *and* you need to check each of B's corners to see if they lie within A.
Jim
-
basically!
the main thing is the rectangle at the left side of the screen: your helicopter block
the blocks scrolling across the screen are the blocks for the game - there are 2.
the lines across the screen indicate where your Y position is relative to the blocks... if you are in line with the collision the line will change colour to either blue or green - block one, block two. this tells you that it has detected the collision, but since both X positions (you and block) are not equal or smaller than, then it will no calculate the hit.
if you hit the block... you turn red.
i think the problem is that all the helicopter has to be completely in line with the block to detect a collison.... i will give it a shot at fixing it, and see where i get!
-
I've been meaning to come back in here and add that the algorithm I posted isn't sufficient. If two boxes cross each other in a plus shape + then no corners of either box are inside any of the points of the other box. You need to check at least one edge as well.
Jim
-
not sure whats ment by the algorithm bit?
-
I was trying to give you a recipe for making code that detects reliably if two rectangles overlap, but I failed. I should probably just write the code as a subroutine and post it up.
Jim
-
thanx... i knew what you ment to do, but i just couldnt understand what you were saying? if you could rite the routine, that would clear things up! :cheers:
thanx again, i have tried to write the collision properly, but i just cant understand why it stuffs up!
-
Yabasic has a habit of strange happenings like that Clanky :)
-
yea bummer
-
Inexplicable slowdown was my favourite :)
Probably caused by memory leaks everywhere.
-
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!
-
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?" :-[
-
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...
-
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.
-
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:
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:
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
-
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:
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.
-
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
'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
-
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)
-
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