Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 [Game] [Blitz] Pong
Index -> Programming, Visual Basic and Other Basics -> Other Basics
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
shorthair




PostPosted: Mon Feb 16, 2004 10:00 pm   Post subject: [Game] [Blitz] Pong

Okay here is an entire tutorial about making Pong in Blitz , this is a good sarting point on how to make game in blitz , you will notice the code will be very much like that of Turing .



code:
;controls are 8 on num pad for up
;2 on num pad for down

; sets the graphics mode
Graphics 640,480

; lets windows know the name of the program
AppTitle "Pong"


;does everything in the background ready to show when "flip" is used
SetBuffer BackBuffer()


;loads the pictures we'll need to use
Ball = LoadImage("ball.bmp")
Player=LoadImage ("bat.bmp")
Opp=LoadImage("bat.bmp")

;sets up the settings for the start:

;player location
Player_x=20
Player_y=420

;opponant location
Opp_x=600
Opp_y=420

;starting speed
SpeedX = 5
SpeedY = 5

;ball location
Ball_x = 5
Ball_y = 5

;players score
p_score=0

;opponants score
o_score=0

;while esc. key isn't pressed
While Not KeyHit(1)

;if the 8(up) key on num. pad is pressed
If  KeyDown (12)

     ;Moves 4 up the y axis
     Player_y=Player_y-4

      ;If y axis is less than zero then change to zero (stops it going
      ;off screen)
      If Player_y<0 Then Player_y=0

  ;closes the if command
  EndIf

;if the 2(down) key on num. pad is pressed
If  KeyDown (13)

    ;Moves 4 Down the y axis
    Player_y=Player_y+4
     
     ;If y axis is more than 400 then change to 400 (stops it going
     ;off screen)
     If Player_y>400 Then Player_y=400
 
 ;closes the if command
 EndIf

; If the player's bat hits the ball then make the ball go a little faster
If ImagesCollide(Player,Player_x,Player_y,0,Ball,Ball_x,Ball_y,0) Then SpeedX= SpeedX-(2*SpeedX)
; If the opponent's bat hits the ball then make the ball go a little faster
If ImagesCollide(Ball,Ball_x,Ball_y,0,Opp,Opp_x,Opp_y,0) Then SpeedX= SpeedX-(2*SpeedX)

; If the ball goes behind the opponent's bat then add 10 to player's
; score
If Ball_x<1 Then p_score=p_score+10

; If the ball goes behind the player's bat then add 10 to player's
; score

If Ball_x>600 Then o_score=o_score+10


; Clear The Screen
Cls

; Stops the bat going off the screen
If Opp_y>400 Then Opp_y=400

; Stops the bat going off the screen
If Opp_y<0 Then Opp_y=0

;sets a random command to generate a number between 1 and 3
random = Rand(1,3)

;if the ball touches the opponant
If Ball_y>Opp_y Then 

;is the random number one if so make the bat stay where it is
If random = 1 Then Opp_y=Opp_y 

;otherwise the bat is moved down by five
Else Opp_y=Opp_y-5

;Closes the if command
End If

;if the ball touches the opponant
If Ball_y>Opp_y Then 

;is the random number one if so make the bat stay where it is
;otherwise the bat is moved down by five
If random = 1 Then Opp_y = Opp_y Else Opp_y=Opp_y+5   
;Closes the if command
End If

;Draw the ball 
DrawImage Ball,Ball_x,Ball_y

;If the ball goes off the screen either side move it back to starting
;speed and position
If Ball_x<1  Or Ball_x>GraphicsWidth()-40 Then Ball_x=5 Ball_y=5 SpeedX=5  SpeedY=5   
If Ball_y<1 Or Ball_y>GraphicsHeight()-40 Then SpeedY =- SpeedY


;Ball location is current location plus the speed it is travelling at
Ball_x = Ball_x + SpeedX
Ball_y = Ball_y + SpeedY

;draws the bat of the Player
DrawImage Player,Player_x,Player_y

;draws the bat of the Opponent
DrawImage Opp,Opp_x,Opp_y


;prints the opponents's score
Text 300,0,o_score,1

;prints the players score
Text 340,0,p_score,1

;displays the BackBuffer
Flip

;closes the while command
Wend

;end of code
End


ask all of your questions in here , also to make this work you will need the to pictures andblitz , if anyone wants them so they can run it , feel free to ask



pong pics.zip
 Description:

Download
 Filename:  pong pics.zip
 Filesize:  288 Bytes
 Downloaded:  412 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Tue Feb 17, 2004 4:01 pm   Post subject: (No subject)

yeah please post those pics Smile This program seems to be really wierd on my computer... anyways post the pics and then we'll see Confused

also is there a auto-indent like F2 in Turing?
Display posts from previous:   
   Index -> Programming, Visual Basic and Other Basics -> Other Basics
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 2 Posts ]
Jump to:   


Style:  
Search: