Need help with code
BlitzMax Forums/BlitzMax Tutorials/Need help with code
| ||
'demo01-01.bmx - A Complete game of KONG--A Pong Clone 'Author: Maneesh Sethi, http://www.maneeshsethi.com 'Set up graphics mode Graphics 800,600 'Seed the random generator (make random numbers actually random) SeedRnd(MilliSecs()) 'Create a back buffer 'SetBuffer BackBuffer() 'Set the handle to the center of images AutoMidHandle True Const HUMAN_SPEED = 7 'The human's max speed Const COMPUTER_SPEED = 6 'The computer's max speed Const X_RANDOM_FACTOR = 2 'The variance of the x speed after colliding with something Const Y_RANDOM_FACTOR = 1 'The variance of the y speed after colliding with something 'The ball's speed at the beginning of a level Const LEVEL_START_XV_MIN = 3 Const LEVEL_START_XV_MAX = 6 Const LEVEL_START_YV_MIN = -8 Const LEVEL_START_YV_MAX = 8 'TYPES 'The player type: both the human and the opponent Type Tplayer Field y:Int 'The vertical position of the player Field score:Int End Type 'The ball type: for the ball Type Tball Field x:Int Field y:Int 'xv and yv are the velocity variables Field xv:Int Field yv:Int End Type 'IMAGES 'The picture of the human player Global player1image = LoadImage("paddle_blue.png") 'The picture of the computer player Global player2image = LoadImage("paddle_green.png") 'The picture of the ball Global ballimage = LoadImage("ball.png") 'Load the ball image 'TYPE INITIALIZATION 'Create a ball Global ball:Tball = New Tball 'Create the human Global player1:Tplayer = New Tplayer 'Create the computer Global player2:Tplayer = New Tplayer 'INITIALIZATION DrawText "Ready...Set",400,300 'Wait for one second Flip Delay(1000) DrawText "GO!!!", 420,330 Flip 'Delay for 1/5 of a second Delay(200) 'Initialize the level InitializeLevel() 'Set inital scores player1.score = 0 player2.score = 0 'MAIN LOOP While Not KeyHit(KEY_ESCAPE) 'Clear the screen Cls 'Draw the ball DrawImage (ballimage,ball.x,ball.y) 'Draw the human DrawImage (player1image, 60, player1.y) 'Draw the computer DrawImage (player2image, 740, player2.y) 'Test what user pressed TestKeyboard() 'What should AI do? TestAI() 'Draw the HUD DrawScore() Flip Delay 20 Wend 'END OF MAIN LOOP 'FUNCTIONS 'INITIALIZELEVEL() 'Sets up starting values Function InitializeLevel() 'Put ball in center of the screen ball.x = 400 ball.y = 300 'Make the ball move in a random direction ball.xv = Rand(LEVEL_START_XV_MIN, LEVEL_START_XV_MAX) ball.yv = Rand(LEVEL_START_YV_MIN, LEVEL_START_YV_MAX) 'Place the players in their correct position player2.y = 300 player1.y = 300 End Function 'DRAWSCORE() 'Draws the HUD in the top right Function DrawScore() 'Write the human score DrawText "Player 1: " + player1.score, 700, 0 'Write the computer's score DrawText "Player 2: " + player2.score, 700, 30 End Function 'TESTKEYBOARD() 'Moves player up and down based on keyboard Function TestKeyboard() 'If player presses up, move him up If KeyDown(KEY_UP) player1.y = player1.y - HUMAN_SPEED EndIf 'If player presses down, move him down If KeyDown(KEY_DOWN) player1.y = player1.y + HUMAN_SPEED End If 'if player presses Pause, pause the game If KeyHit(KEY_P) 'make screen blank Cls DrawText "Press 'P' to Unpause Game",400,300 Flip 'wait for player to unpause While Not KeyHit(KEY_P) Wend EndIf End Function 'TESTAI() 'Updates ball and score and enemy Function TestAI() 'If ball is above computer, move computer up If ball.y > player2.y player2.y = player2.y + COMPUTER_SPEED 'if ball is lower than computer, move computer down ElseIf ball.y < player2.y player2.y = player2.y - COMPUTER_SPEED EndIf 'If ball hits human player, reflect it away from him and vary its velocity and direction If ImagesCollide(ballimage,ball.x,ball.y,0,player1image,60,player1.y,0) ball.xv = -ball.xv + Rand(-X_RANDOM_FACTOR,X_RANDOM_FACTOR) ball.yv = ball.yv + Rand(-Y_RANDOM_FACTOR,Y_RANDOM_FACTOR) 'If ball hits computer, reflect it away from computer and vary its velocity and direction ElseIf ImagesCollide(ballimage,ball.x,ball.y,0,player2image,740,player2.y,0) ball.xv = -ball.xv + Rand(-X_RANDOM_FACTOR,X_RANDOM_FACTOR) ball.yv = ball.yv + Rand(-Y_RANDOM_FACTOR,Y_RANDOM_FACTOR) 'If ball hits top wall, reflect it downward ElseIf ball.y <= 0 ball.xv = ball.xv + Rand (-X_RANDOM_FACTOR,X_RANDOM_FACTOR) ball.yv = -ball.yv + Rand (-Y_RANDOM_FACTOR,Y_RANDOM_FACTOR) 'If ball hits bottom wall, reflect it upward ElseIf ball.y >= 600 ball.xv = ball.xv + Rand (-X_RANDOM_FACTOR,X_RANDOM_FACTOR) ball.yv = -ball.yv + Rand (-Y_RANDOM_FACTOR,Y_RANDOM_FACTOR) 'if ball hits left wall, computer has scored so computer gets one more point ElseIf ball.x <= 0 player2.score = player2.score + 1 'computer scores DrawText "Player 2 Scores!!!",400,300 Flip 'wait two seconds Delay(2000) 'reset level InitializeLevel() 'If ball hits right wall, human scored so give him a point ElseIf ball.x >= 800 player1.score = player1.score + 1 'human scores DrawText "Player 1 Scores!!!", 400, 300 Flip 'wait 2 secs Delay(2000) 'reset level InitializeLevel() EndIf 'update ball's position on screen ball.x = ball.x + ball.xv ball.y = ball.y + ball.yv End Function that my code above. Title of the file is kong.bmx I checked everything but i keep getting this error: Building Kong Compiling:Kong.bmx Linking:Kong.debug clang: warning: no such sysroot directory: '/Developer/SDKs/MacOSX10.6.sdk' ld: library not found for -lcrt1.o clang: error: linker command failed with exit code 1 (use -v to see invocation) Build Error: Failed to link /Users/sanjitsingh/Downloads/BlitzMax/Sources/Chapter1/Kong.debug.app/Contents/MacOS/Kong.debug Process complete Can someone please tell why this going on in my program. |
| ||
Do you have XCode installed? Do you have the XCode command line tools installed? |
| ||
I installed Xcode and Xcode command line tools. did everything for that but its still doing the same error |
| ||
hola: tengo dos laptop una con windows 10 y otra con windows 7 al correr el codigo glblurr de la carpeta Samples en w10 no corre y muestra _ Building glblurr Compiling:glblurr.bmx flat assembler version 1.69.14 (1041399 kilobytes memory) 3 passes, 1.9 seconds, 29628 bytes. Linking:glblurr.debug.exe Executing:glblurr.debug.exe CreateGraphics failed:GLGraphicsDriver failed to set display mode pero en w7 corre ¿ que ocurre,alguien sabe? |
| ||
hola russ90, no habla Espanol! On Windows you need "SetGraphicsDriver GLMax2DDriver()" before "GLGraphics". http://www.blitzbasic.com/Community/posts.php?topic=59414 |