Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- setscreen ("graphics:1024;768")
- View.Set ("title: Pong by Vince Lai")
- var chars : array char of boolean %delcaring player input variable
- var xBall := 509 %delcaring all varibles for the ball
- var yBall := 384
- var xInc := 1
- var yInc := 1
- var font1 : int %declaring all font variables
- var font2 : int
- var font3 : int
- font1 := Font.New ("sans serif:28") %declaring all fonts
- font2 := Font.New ("sans serif:12")
- font3 := Font.New ("verdana bold:30")
- var choice : string
- var lpady1 := 340 %declaring all the variables for the paddles
- var lpady2 := 430
- var lpadx1 := 10
- var lpadx2 := 20
- var rpady1 := 340
- var rpady2 := 430
- var rpadx1 := 1009
- var rpadx2 := 1021
- var paddleInc := 1
- var paddleInc2 := 1
- var player1score : int := 0 %declaring playerscore variables
- var player2score : int :=0
- var player1 : string
- var player2 : string
- View.Set ("offscreenonly")
- var scoretable : array 0 .. 0 of string
- % var score : int
- % var topscore : string
- % open : stream, "topscore.txt", read
- % read : stream, score
- % write : stream, score
- procedure Pong
- loop % a loop so the program does not end unless user closes it
- cls %clear screen to draw new animation
- drawfillbox (508, 0, 512, maxy, 3) % middle line
- drawfilloval (xBall, yBall, 8, 8, black) %drawing ball, paddles, mid line etc
- drawfillbox (lpadx1, lpady1, lpadx2, lpady2, blue)
- drawfillbox (rpadx1, rpady1, rpadx2, rpady2, red)
- drawfillbox (0, 700, maxx, maxy, 3) %top bar
- drawoval (0, 384, 60, 80, blue) %ice rink graphics left and right circle
- drawoval (maxx, 384, 60, 80, red)
- drawoval (250, 576, 60, 60, blue) %ice rink circles
- drawfilloval (250, 576, 5, 5, blue)
- drawoval (768, 576, 60, 60, red)
- drawfilloval (768, 576, 5, 5, red)
- drawoval (250, 192, 60, 60, blue)
- drawfilloval (250, 192, 5, 5, blue)
- drawoval (250, 192, 60, 60, blue)
- drawfilloval (250, 192, 5, 5, blue)
- drawoval (768, 192, 60, 60, red)
- drawfilloval (768, 192, 5, 5, red)
- drawoval (511, 382, 60, 60, 3)
- drawfilloval (511, 382, 5, 5, 3)
- Draw.Text (player1 + " Score: " + intstr (player1score), 25, 720, font1, white)
- Draw.Text (player2 + " Score: " + intstr (player2score), 525, 720, font1, white)
- xBall += xInc
- yBall += yInc
- if xBall <= 0 and yBall <= 462 and yBall >= 302 then %playerscore system
- player2score := player2score + 1 %if the xvalue of the xBall is smaller or equal to 0 then add a point to player 2
- xBall := 509
- yBall := 384
- xInc *= -1
- lpady1 := 340 %declaring all the variables for the paddles
- lpady2 := 430
- lpadx1 := 10
- lpadx2 := 20
- rpady1 := 340
- rpady2 := 430
- rpadx1 := 1009
- rpadx2 := 1021
- Time.Delay (1000)
- View.Update
- end if
- if xBall >= maxx and yBall <= 462 and yBall >= 302 then
- xBall := 509
- yBall := 384
- xInc *= -1
- player1score := player1score + 1 %if the xvalue of the xBall is bigger or equal to max x value then add a point to player 1
- lpady1 := 340 %declaring all the variables for the paddles
- lpady2 := 430
- lpadx1 := 10
- lpadx2 := 20
- rpady1 := 340
- rpady2 := 430
- rpadx1 := 1009
- rpadx2 := 1021
- Time.Delay (1000)
- View.Update
- end if
- if xBall >= maxx or xBall <= 0 then %ball mechanics so ball does not bounce outside of the given parameters
- xInc *= -1
- end if
- if yBall >= 700 or yBall <= 0 then
- yInc *= -1
- end if
- if yBall <= lpady2 and yBall >= lpady1 and xBall >= lpadx1 and xBall <= lpadx2 + 10 and xInc = -1 then
- %if the ball bounces on the paddle then it will reflect at an opposite direction isntead towards the same direction as previous
- yInc *= 1
- xInc *= -1
- end if
- if yBall <= lpady2 and yBall >= lpady1 and xBall >= lpadx1 - 10 and xBall <= lpadx2 and xInc = 1 then
- %if the ball bounces on the paddle then it will reflect at an opposite direction isntead towards the same direction as previous
- yInc *= 1
- xInc *= -1
- end if
- if yBall <= rpady2 and yBall >= rpady1 and xBall >= rpadx1 - 10 and xBall <= rpadx2 and xInc = 1 then
- yInc *= 1
- xInc *= -1
- end if
- if yBall <= rpady2 and yBall >= rpady1 and xBall >= rpadx1 and xBall <= rpadx2 + 10 and xInc = -1 then
- yInc *= 1
- xInc *= -1
- end if
- Input.KeyDown (chars) %all player input
- if chars (KEY_UP_ARROW) and rpady2 < 690 then %setting parameters so the paddles do not go outside of the parameters
- rpady1 := rpady1 + paddleInc
- rpady2 := rpady2 + paddleInc
- end if
- if chars (KEY_LEFT_ARROW) and rpadx1 > 516 then
- rpadx1 := rpadx1 - paddleInc2
- rpadx2 := rpadx2 - paddleInc2
- end if
- if chars (KEY_RIGHT_ARROW) and rpadx2 < maxx then
- rpadx1 := rpadx1 + paddleInc2
- rpadx2 := rpadx2 + paddleInc2
- end if
- if chars (KEY_DOWN_ARROW) and rpady1 > 0 then
- rpady1 := rpady1 - paddleInc
- rpady2 := rpady2 - paddleInc
- end if
- if chars ('w') and lpady2 < 690 then
- lpady1 := lpady1 + paddleInc
- lpady2 := lpady2 + paddleInc
- end if
- if chars ('a') and lpadx1 > 0 then
- lpadx1 := lpadx1 - paddleInc2
- lpadx2 := lpadx2 - paddleInc2
- end if
- if chars ('d') and lpadx2 < 505 then
- lpadx1 := lpadx1 + paddleInc
- lpadx2 := lpadx2 + paddleInc
- end if
- if chars ('s') and lpady1 > 0 then
- lpady1 := lpady1 - paddleInc2
- lpady2 := lpady2 - paddleInc2
- end if
- if player1score = 10 then %win conditions
- Music.PlayFile ("Super Mario Bros. Music - Level Complete.mp3")
- Draw.Text ("Player 1 has won!", 25, 650, font1, red)
- View.Update
- Time.Delay (3000)
- exit
- end if
- if player2score = 10 then %win conditions
- Music.PlayFile("Super Mario Bros. Music - Level Complete.mp3")
- Draw.Text ("Player 2 has won!", 525, 650, font1, red)
- View.Update
- Time.Delay (3000)
- exit
- end if
- Time.Delay (1)
- View.Update
- end loop
- end Pong
- procedure loading
- loop
- drawfillbox (0, 0, maxx, maxy, green)
- Draw.Text ("Welcome to Pong by Vince Lai", 180, 600, font3, blue) %intro screen text
- Draw.Text ("Get 10 points to win!", 290, 300, font3, blue)
- Time.Delay (300)
- cls
- drawfillbox (0, 0, maxx, maxy, yellow)
- Draw.Text ("Welcome to Pong by Vince Lai", 180, 600, font3, red) %intro screen text
- Draw.Text ("Get 10 points to win!", 290, 300, font3, red)
- View.Update
- Time.Delay (300)
- cls
- drawfillbox (0, 0, maxx, maxy, red)
- Draw.Text ("Welcome to Pong by Vince Lai", 180, 600, font3, yellow) %intro screen text
- Draw.Text ("Get 10 points to win!", 290, 300, font3, yellow)
- View.Update
- Time.Delay (300)
- cls
- drawfillbox (0, 0, maxx, maxy, blue)
- Draw.Text ("Welcome to Pong by Vince Lai", 180, 600, font3, green) %intro screen text
- Draw.Text ("Get 10 points to win!", 290, 300, font3, green)
- View.Update
- Time.Delay (300)
- cls
- View.Update
- Draw.Text ("What is player 1 name?", 250, 600, font3, blue) %intro screen text
- View.Update
- get player1
- Draw.Text ("Welcome! " + player1, 320, 500, font3, blue) %intro screen text
- View.Update
- Time.Delay (1000)
- cls
- Draw.Text ("What is player 2 name?", 250, 600, font3, blue) %intro screen text
- View.Update
- get player2
- Draw.Text ("Welcome! " + player2, 320, 500, font3, blue) %intro screen text
- View.Update
- Time.Delay (1000)
- exit
- end loop
- end loading
- loop
- Music.PlayFileLoop ("MACINTOSH420.mp3")
- loop
- player1score := 9
- player2score := 9
- loading
- Pong
- cls
- drawfillbox (0, 0, maxx, maxy, blue)
- Draw.Text ("Do you want to restart? Y/N", 200, 600, font3, white)
- View.Update
- get choice
- if choice = ('y') then
- player1score := 9
- player2score := 9
- loading
- Pong
- elsif choice = ('n') then
- Window.Close (defWinID)
- end if
- end loop
- Music.PlayFileStop
- end loop
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement