Hi, i was bored so decided to make a pong variation game. Figured it would be fun.
I ran into a problem though. I made an input screen in the beginning of the game. Where it asks you how many players, 2 or 1. When you input 1, i tried to make it use the previosly created initializelevel() function i created. For some reason i cannot see, it doesnt work. It starts the game as normal, but with everything at the top of the screen on the y axis, and the ball behind player 1. Obiously this does not work.
If someone could please point out my mistake, or offer some help of any kind, that would really help me. Im just using an input for now, i may go to something bigger and better later, but for now just input help please.
Here is the code if anyone needs it.
I ran into a problem though. I made an input screen in the beginning of the game. Where it asks you how many players, 2 or 1. When you input 1, i tried to make it use the previosly created initializelevel() function i created. For some reason i cannot see, it doesnt work. It starts the game as normal, but with everything at the top of the screen on the y axis, and the ball behind player 1. Obiously this does not work.
If someone could please point out my mistake, or offer some help of any kind, that would really help me. Im just using an input for now, i may go to something bigger and better later, but for now just input help please.
Here is the code if anyone needs it.
Graphics3D 800,600 ;seed the random generator SeedRnd(MilliSecs()) SetBuffer BackBuffer() AutoMidHandle True ;welcome options two$=("2") one$=("1") Function welcome() player$=Input$("How many players? 1 or 2? ") If player$=two$ Then initializelevel() ElseIf player$=one$ Then initializelevel() Else EndIf End Function welcome() AppTitle "Boredbb Pong V 1.0" ;consts ;the following are key constants Const upkey = 200 ;up Const downkey = 208 ;down Const pausekey = 25 ; P button Const humanspeed = 7 ;the humans maximum speed Const computerspeed = 6 ;the computers maximum speed ;types ;the player type ;Human/Opponent Type player Field y,score ;y position the score End Type ;the ball type ;for the ball Type ball Field x,y,xv,yv ;x/y cordinate and velocity End Type ;images ;human player image Global player1image = LoadImage("Red team.jpg") ;computer player image Global player2image = LoadImage("Blue team.jpg") ;the picture of the ball Global ballimage = LoadImage("ball.jpg") ;loads the ball image ;Type initialization 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(2,6) ball\yv = Rand(-8,8) ;place the players in thier correct positions player2\y = 300 player1\y = 300 End Function ;drawscore() Function drawscore() ;write the human score Text 700,0,"Player 1: "+player1\score ;write the computers score Text 700,30,"Player 2: "+player2\score End Function ;testkeyboard() ;moves the player up and down based on the keyboard inputs Function testkeyboard() ;if player hits up, move up If KeyDown(upkey) player1\y = player1\y - humanspeed EndIf ;If player presses down, move him down If KeyDown(downkey) player1\y = player1\y+ humanspeed EndIf ;if player presses pause, then pause the game If KeyHit(pausekey) ;make screen blank Cls Text 400,300,"Press the P button to unpause the game." Flip ;wait for player unpause While Not KeyDown(pausekey) Wend EndIf End Function ;testAI() ;update ball and score and enemy Function TestAI() ;if ball is above the computer. move computer up If ball\y>player2\y player2\y = player2\y + computerspeed ;if ball is lower than computer, move computer down ElseIf ball\y<player2\y player2\y = player2\y - computerspeed EndIf ;if ball hits human player, reflect it away. If ImagesOverlap(ballimage,ball\x,ball\y,player1image,60,player1\y) ball\xv = -ball\xv + Rand(-4,4) ball\xv = ball\xv + Rand(-4,4) ;if ball hits computer , reflect it away ElseIf ImagesOverlap(ballimage,ball\x,ball\y,player2image,740,player2\y) ball\xv = -ball\xv + Rand(-4,4) ball\yv = ball\yv + Rand(-4,4) ;if ball hits top wall, reflect ElseIf ball\y <= 0 ball\yv = -ball\yv + Rand(-1,1) ball\xv = ball\xv + Rand(-1,1) ;if ball hits the bottom wall, reflect it upward ElseIf ball\y >= 600 ball\yv = -ball\yv + Rand(-1,1) ball\xv = ball\xv + Rand(-1,1) ;if ball hits the left wall, player 2 point ElseIf ball\x <= 0 player2\score = player2\score + 1 ;computer scores! Text 400,300,"Player 2 Scores!!!!" Flip ;wait 2 seconds Delay(2000) ;reset the level initializelevel() ;if ball hits right wall, human scored so he gets a point ElseIf ball\x >= 800 player1\score = player1\score + 1 ;human scores Text 400,300,"Player 1 Scores!!!!" Flip ;wait 2 seconds Delay(2000) ;reset level initializelevel() EndIf ;if player hits the top, he stops If player1\y <= 0 player1\y=player1\y + humanspeed EndIf If player1\y >=600 player1\y=player1\y - humanspeed EndIf If player2\y <= 0 player2\y=player2\y + humanspeed EndIf If player2\y >= 600 player2\y=player2\y - humanspeed EndIf ;update ball's postition on screen ball\x = ball\x + ball\xv ball\y = ball\y + ball\yv End Function ;create the ball Global ball.ball = New ball ;create the human Global player1.player = New player ;create the computer Global player2.player = New player ;set initial scores player1\score = 0 player2\score = 0 ;___________________________________________ ;_______________Main Loop___________________ ;___________________________________________ While Not KeyDown(1) ;clears 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) ;masking the green MaskImage ballimage,11,255,20 ;test what user has pressed testkeyboard() ;what should AI do? testAI() ;draw the hud drawscore() Flip Delay 20 Wend End