|
Post by Grishenko on Jul 4, 2004 13:49:50 GMT -5
I found these on a backup cd when b4g was still called glbasic . I found this great program on nehe's site, and decided to try it out since I was still was (and still am) a beginner with the opengl api and general programming. Somehow I lost some of my other b4g programs, but here are 2 working ones: pong and snake (that I eventually ported to c). Since then, I have just downloaded the new version, and was glad to see all the new features . Tips and comments will be appreciated! p.s. is there a way to dont have the display "freeze" when you do the run command?
|
|
|
Post by Grishenko on Jul 4, 2004 13:50:29 GMT -5
Snakes
dim direction, speed dim tx1(1006), ty1(1006) 'How many do we need?? dim first dim nowx1, nowy1 dim tailloop, comboloop, down dim plength, checktail dim point, pt dim main, good, bug, bx, by dim bNorth, bSouth, bEast, bWest
gosub goclear 'Clear Screen And Depth Buffer glShadeModel(GL_SMOOTH) 'Enable Smooth Shading glClearColor(0.0, 0.0, 0.0, 0.0) 'Black Background glClearDepth(1.0) 'Depth Buffer Setup glEnable(GL_DEPTH_TEST) 'Enables Depth Testing glDepthFunc(GL_LEQUAL) 'The Type Of Depth Testing To Do glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST) 'Really Nice Perspective Calculations glPushMatrix ()
gosub goinit TextMode(TEXT_OVERLAID) resizetext(80,40) locate 15,23 printr("Welcome to Grishenko"+ Chr$(164) +"s GLBasic Demo!")
while not first locate 1,0 print("Press SPACEBAR or ENTER to continue!")
glLoadIdentity() glTranslatef(0, 0 ,-4) glColor3f(0.1,0.2,0.9) glBegin(GL_QUADS) glVertex3f(-0.4, 0.4, 0) glVertex3f( 0.4, 0.4, 0) glVertex3f( 0.4,-0.4, 0) glVertex3f(-0.4,-0.4, 0) glEnd() glBegin(GL_QUADS) glVertex3f(0.6, 0.6, 3) glVertex3f( 0.4, 0.4, 0) glVertex3f( 0.4,-0.4, 0) glColor3f(0.8,0.8,0.8):glVertex3f(-0.4,-0.4, 0) glEnd() DrawText()
if ScanKeyDown(VK_SPACE) or ScanKeyDown(VK_RETURN) then first = TRUE gosub goclear endif wend
bug = false
while not main gosub goclear
' Is there a bug? if bug = FALSE then bx = ((rnd()%60)-30) ' Original is ((rnd()%62)-31) by = ((rnd()%44)-22) ' Original is ((rnd()%46)-23) bug = TRUE endif
' Moving - 5th direction is dead? if direction = 1 then nowy1 = (nowy1 + 1) endif if direction = 2 then nowy1 = (nowy1 - 1) endif if direction = 3 then nowx1 = (nowx1 + 1) endif if direction = 4 then nowx1 = (nowx1 - 1) endif ' Draw the Head glLoadIdentity() glTranslatef(nowx1, nowy1 , -40) glBegin(GL_QUADS) glVertex3f(-0.5, 0.5, 0) glVertex3f( 0.5, 0.5, 0) glVertex3f( 0.5,-0.5, 0) glVertex3f(-0.5,-0.5, 0) glEnd()
' Did you get the bug? if ( ( (nowx1<(bx+0.5)) and (nowx1>(bx-0.5)) )AND( (nowy1<(by+0.5)) and (nowy1>(by-0.5)) ) ) then 'old if (nowx1 = bx) and (nowy1 = by) then bug = false plength = plength + 1 'Make the tail longer if not (speed < 1) then speed = speed - 1 endif 'Make the speed faster beep() gosub goclear endif
gosub combotx
For tailloop = 1 to plength glLoadIdentity() glTranslatef(tx1(tailloop), ty1(tailloop) , -40) glBegin(GL_QUADS) glVertex3f(-0.5, 0.5, 0) glVertex3f( 0.5, 0.5, 0) glVertex3f( 0.5,-0.5, 0) glVertex3f(-0.5,-0.5, 0) glEnd() Next
'draw the bug glLoadIdentity() glTranslatef(bx, by, -40.02) glColor3f( ((rnd()%95)+4.001)/100, ((rnd()%95)+4.001)/100 , ((rnd()%100)+0.001)/100 ) glBegin(GL_QUADS) glVertex3f(-0.18, 0.18, 0) glVertex3f( 0.18, 0.18, 0) glVertex3f( 0.18,-0.18, 0) glVertex3f(-0.18,-0.18, 0) glEnd() glColor3f(0.8,0.8,0.8)
cls locate 1,1 ResizeText(60,30) print ("Use: Arrow Keys; Enter/Return to continue; Esc") locate 52,0 print(nowx1 + ", " + nowy1) locate 1,2 print("Points: " + (plength - 6)*2 +" Speed: "+(101-speed) +" Bug: "+bx +", "+by) DrawText()
if pt=TRUE then gosub point: gosub point: gosub point endif
gosub check
for checktail = 2 to plength if (nowx1 = tx1(checktail) AND nowy1 = ty1(checktail)) then run endif next
glPopMatrix() SwapBuffers() '////////////keys/////////////
if ScanKeyDown(VK_RIGHT) and not bWest=TRUE then gosub falsify: bEast = TRUE endif if ScanKeyDown(VK_LEFT) and not bEast=TRUE then gosub falsify: bWest = TRUE endif if ScanKeyDown(VK_UP) and not bSouth=TRUE then gosub falsify: bNorth = TRUE endif if ScanKeyDown(VK_DOWN) and not bNorth=TRUE then gosub falsify: bSouth = TRUE endif
if ScanKeyDown(VK_NUMPAD0) then plength = plength + 1 if not (speed < 1) then speed = speed - 1 endif endif if ScanKeyDown(VK_NUMPAD1) then pt=TRUE endif
if bNorth then gosub gonorth endif if bSouth then gosub gosouth endif if bEast then gosub goeast endif if bWest then gosub gowest endif
WaitTimer(speed) 'Best at 25 or around 100? [speed!]
wend
combotx: for comboloop = 1 to plength down = ((plength + 1) - comboloop) if (plength < 6) then plength = plength + 1 endif ty1(down) = ty1(down - 1) tx1(down) = tx1(down - 1) ty1(0) = nowy1 tx1(0) = nowx1 next
Return
goeast:
direction = 3 return
gowest: direction = 4 return
gosouth: direction = 2 return
gonorth: direction = 1 return
falsify: bNorth = False: bSouth = False: bEast = False: bWest = False return
point: glLoadIdentity() glTranslatef((rnd()%100)-50,(rnd()%100)-50, -38) glColor3f(0,0.3,0.6) glBegin(GL_QUADS) glVertex3f(-0.5, 0.5, 0) glVertex3f( 0.5, 0.5, 0) glVertex3f( 0.5,-0.5, 0) glVertex3f(-0.5,-0.5, 0) glEnd() glColor3f(1,1,1) return
goclear: glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT) return
goinit: bNorth = TRUE: bSouth = False: bEast = False: bWest = False first = false: direction = 1: plength = 2: nowx1 = 0.5: nowy1 = 0.5: pt=FALSE: speed = 100 return
check: if (nowx1 > 30) or (nowx1 < -30) or (nowy1 > 22.5) or (nowy1 < -22.5) then main = True ResizeText(80,40) locate 15,15 print("Game Over") DrawText() ' while not good ' if ScanKeyDown(VK_RETURN) then good=TRUE endif ' wend run endif return
|
|
|
Post by Grishenko on Jul 4, 2004 13:53:37 GMT -5
Pong
dim main, first dim p1y, p2y, p1x, p2x, p1length, p2length dim p1y1, p1y2, p1y3, p1y4, p1xc dim p2y1, p2y2, p2y3, p2y4, p2xc dim bx#, by#, b#, m# dim Random, r2#, GoRight: GoRight = TRUE
gosub goclear 'Clear Screen And Depth Buffer glShadeModel(GL_SMOOTH) 'Enable Smooth Shading glClearColor(0.0, 0.0, 0.0, 0.0) 'Black Background glClearDepth(1.0) 'Depth Buffer Setup glEnable(GL_DEPTH_TEST) 'Enables Depth Testing glDepthFunc(GL_LEQUAL) 'The Type Of Depth Testing To Do glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST) 'Really Nice Perspective Calculations glPushMatrix ()
gosub goinit TextMode(TEXT_OVERLAID) resizetext(80,40) locate 15,23 printr("Welcome to Grishenko"+ Chr$(164) +"s GLBasic Demo! P4OING")
while not first locate 1,0 print("Press SPACEBAR or ENTER to continue!")
glLoadIdentity() glTranslatef(0, 0 ,-4) glColor3f(0.1,0.2,0.9) glBegin(GL_QUADS) glVertex3f(-0.4, 0.4, 0) glVertex3f( 0.4, 0.4, 0) glVertex3f( 0.4,-0.4, 0) glVertex3f(-0.4,-0.4, 0) glEnd() glBegin(GL_QUADS) glVertex3f(0.6, 0.6, 3) glVertex3f( 0.4, 0.4, 0) glVertex3f( 0.4,-0.4, 0) glColor3f(0.8,0.8,0.8):glVertex3f(-0.4,-0.4, 0) glEnd() DrawText()
if ScanKeyDown(VK_SPACE) or ScanKeyDown(VK_RETURN) then first = TRUE gosub goclear endif wend Random = rnd()%10 'old r2 = ((rnd()%95)+4.001)/100 r2# = ( ((rnd()%399)) + 1.001 ) / 100 m# = r2# if (Random>=5) then GoRight = TRUE endif if (Random<5) then GoRight = FALSE endif
while not main gosub goclear
if (GoRight=TRUE) then bx# = bx# + 0.5 endif '0.1 is slow, 1 is fast if (GoRight=FALSE) then bx# = bx# - 0.5 endif
by# = (m# * bx#) + b#
gosub playerone: gosub playertwo
if ( ((bx#>=p2x) and (bx#<=(p2x+0.01))) AND ((by#>=p2y2) and (by#<=p2y3)) ) then GoRight = FALSE gosub bounceball endif if ( ((bx#<=(p1x)) and (bx#<=(p1x-0.01))) AND ((by#>=p1y2) and (by#<=p1y3)) ) then GoRight = TRUE gosub bounceball endif
if ( ((bx#>=p2x) and (bx#<=(p2x+0.01))) AND ((by#>=p2y1) and (by#<=p2y2)) ) then GoRight = FALSE gosub bounceball2 endif if ( ((bx#<=(p1x)) and (bx#<=(p1x-0.01))) AND ((by#>=p1y1) and (by#<=p1y2)) ) then GoRight = TRUE gosub bounceball2 endif
if ( ((bx#>=p2x) and (bx#<=(p2x+0.01))) AND ((by#>=p2y3) and (by#<=p2y4)) ) then GoRight = FALSE gosub bounceball2 endif if ( ((bx#<=(p1x)) and (bx#<=(p1x-0.01))) AND ((by#>=p1y3) and (by#<=p1y4)) ) then GoRight = TRUE gosub bounceball2 endif
if (bx#>=75) then run endif if (bx#<=-75) then run endif
if (by#>=50) then gosub bounceball endif if (by#<=(-50)) then gosub bounceball endif
glLoadIdentity() glTranslatef(bx#, by# , -100) 'old z-40 glColor3f(1,0,0.8) glBegin(GL_QUADS) glVertex3f(-0.5, 0.5, 0) glVertex3f( 0.5, 0.5, 0) glVertex3f( 0.5,-0.5, 0) glVertex3f(-0.5,-0.5, 0) glEnd()
glLoadIdentity() glTranslatef(p1x, p1y ,-99) glColor3f(0.8,0.8,0.8) 'old glColor3f(0.1,0.2,0.9) glBegin(GL_QUADS) glVertex3f(-1, p1length, 0) glVertex3f( 1, p1length, 0) glVertex3f( 1,-p1length, 0) glVertex3f(-1,-p1length, 0) glEnd()
glLoadIdentity() glTranslatef(p2x, p2y ,-99) 'old glColor3f(0.1,0.2,0.9) glBegin(GL_QUADS) glVertex3f(-1, p2length, 0) glVertex3f( 1, p2length, 0) glVertex3f( 1,-p2length, 0) glVertex3f(-1,-p2length, 0) glEnd()
cls locate 1,1 ResizeText(60,30) print ("Use: Arrow Keys; Enter/Return to continue; Esc") locate 1,2 print("Ball: " + bx# +", " + by#) locate 5, 28 print(" P1: "+p1y1+", "+p1y2+", "+p1y3+", "+p1y4) locate 33, 28 print(" P2: "+p2y1+", "+p2y2+", "+p2y3+", "+p2y4) DrawText() glPopMatrix() SwapBuffers() '////////////keys/////////////
if ScanKeyDown(VK_UP) and (p1y<=47) then p1y = p1y + 3 endif if ScanKeyDown(VK_DOWN) and (p1y>=-47) then p1y = p1y - 3 endif if ScanKeyDown(VK_NUMPAD6) and (p2y<=47) then p2y = p2y + 3 endif if ScanKeyDown(VK_NUMPAD3) and (p2y>=-47) then p2y = p2y - 3 endif
if ScanKeyDown(VK_NUMPAD7) then GoRight = FALSE endif if ScanKeyDown(VK_NUMPAD8) then GoRight = TRUE endif
WaitTimer(10) '30/50??
wend
goclear: glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT) return
goinit: p1x = -70 p2x = 70 p1length = 8 p2length = 8 return
bounceball: m# = m# * -1 b# = (m# * (-1 * bx#)) + by# by# = (m# * bx#) + b# return
bounceball2: m# = m# * -1.2 b# = (m# * (-1 * bx#)) + by# by# = (m# * bx#) + b# return
playerone: p1xc = p1x + 1
p1y1 = p1y - p1length p1y4 = p1y + p1length
p1y2 = ((p1y4 * 2) / 3) + p1y1 p1y3 = ((p1y1 * 2) / 3) + p1y4 return
playertwo: p2xc = p2x - 1
p2y1 = p2y - p2length p2y4 = p2y + p2length
p2y2 = ((p2y4 * 2) / 3) + p2y1 p2y3 = ((p2y1 * 2) / 3) + p2y4 return
|
|
|
Post by Ranger1800 on Jul 4, 2004 14:05:43 GMT -5
Snakes and Pong are already on the program... lol
|
|
|
Post by Grishenko on Jul 4, 2004 14:12:14 GMT -5
yes (i didnt check the new pong demos lol) but it is a different way of seeing/coding it for other ppl. but ill see if i can find my other stuff then.
|
|
|
Post by Ranger1800 on Jul 4, 2004 14:22:58 GMT -5
Hey i have a question how would like to assist me in a game?
|
|
|
Post by Grishenko on Jul 4, 2004 14:32:01 GMT -5
uhh I can try to help but im still not very good at programming. What kind of game would this be? (in b4g?)
|
|
|
Post by Ranger1800 on Jul 4, 2004 15:06:59 GMT -5
Yeah, it will be in b4gl, do you have Yahoo Instant Messanger? i'm starting out with a simple 2d game because i think starting with 2d games is easier so it's basically getting people ready for 3d programming what say you?
|
|
|
Post by Grishenko on Jul 4, 2004 21:40:47 GMT -5
i fixed the 'run' problem by adding the swap buffer stuff in the start of the file.
ranger: sure, i think i added you now.
|
|
|
Post by Trooper on Sept 5, 2004 22:09:49 GMT -5
i fixed the 'run' problem by adding the swap buffer stuff in the start of the file. Grishenko, When I first started programming BASIC back on the Apple IIe, I loved GOTO's, and all the other spaghetti code style. After some time doing programming in a professional environment, I have become a big fan of having one starting point, and one ending point in a program/script. Somehow, restarting a program in the middle of execution doesn't seem right... but that's just me... it obviously works. I like the idea of using a big while loop that loops the entire program until such time as the program should end, then it exists. Like I said, just my thoughts. I just like the way the code seems a little cleaner. Trooper
|
|