Computer Science Canada

My first game; Paddleball!

Author:  Aange10 [ Sat Sep 03, 2011 10:07 pm ]
Post subject:  My first game; Paddleball!

This is my first game! I hope you guys enjoy! I started programming yesterday, so I think it's in order i give a big THANKS to the players at compsci.ca! Wouldn't have been possible without you!

Turing:

View.Set("Offscreen, graphics:maxx;maxxy")
var mainmenu : boolean % Using this varriable to tell wether or not to pull up the main menu.
var fontTNR : int % A to allow me to make a font style into a variable
var mainmenuexit : string % The varriable i am using to exit the main meny/ skip past it
var oval_x1,oval_y1,oval_xr1,oval_yr1 : int % I made the drawoval syntax as variables
var oval_speed : int %This is to set my oval's speed
var oval_directionx, oval_directiony : int % To set my ovals trajectory direction
var box1_x1, box1_x2, box1_y1, box1_y2 : int
var chars : array char of boolean % Not sure what this is, just know you have to have it to use keys
var continue : string % Get the y/n asking if the player would like to continue
var score : int % Keeps track of the score
oval_x1 := 70      % the x cord for the ball
oval_y1 := 70      % the y cord for the ball
oval_xr1 := 10     % the radius x for the ball
oval_yr1 := 10     % the radius y for the ball
oval_speed := 2    % the speed of the ball pfp (Pixles per frame ;) )
oval_directionx := 1 % Direction of the x cord of the oval (1 = right, -1 = left)
oval_directiony := 1  % direction of the y cord of the oval ( 1 = up, -1 = down)
box1_x1 := 85 % Box x1 cord
box1_x2 := 200 % box x2 cord
box1_y1 := 20 % box y1 cord
box1_y2 := 40 % box y2 cord
mainmenu := true %a varriable to control the main menu
continue := "y" %a varriable to tell wether or not to continue
score := 0
loop % Main loop
    cls
        loop % main menu debugging loop
            if mainmenu = true then
                fontTNR := Font.New ("TimeNewRoman:14")
                Font.Draw ("Game O' Paddle Ball!", maxx div 2, maxy div 2, fontTNR, green)
                delay (1000)
                fontTNR := Font.New ("Courier:8")
                Font.Draw ("Use AD or Arrow Keys to move! Press b to begin!", maxx div 2 - 100, maxy div 2 - 20, fontTNR, red)
                score := 0 % Just to prevent people from spamming the debug system to gain points
                get mainmenuexit % It asks the user for input
            else
                exit
            end if
            if mainmenuexit = "b" then %When user inputs b, it changes mainmenu to false so that the loop will skip the main menu if statement
                mainmenu := false
            else
                cls
                put "Invalid key."
                delay (2000)
                exit
            end if
        end loop % Ends the main menu de bugging loop
    cls
    var timestart := Time.Elapsed % So I can measure the time elapsed from this point
    put "Time elapsed:", timestart / 1000 % How much time has elapsed since exiting the menu
    if oval_y1 >= 400 then %if y cord of oval goes >=400 then it inverses the direction of the y
        oval_directiony := oval_directiony * -1
    end if
    if oval_x1 >= 630 then %if the x cord of the oval goes >= 630 then it inverses the direction of the x
        oval_directionx := oval_directionx * -1
    end if
    if oval_x1 <= 0 then %  x cord direction inverse
        oval_directionx := oval_directionx * -1
    end if
        loop % Loop to de bug the continue system
            if oval_y1 <= 20 then %  if y cord hits <= 20 it asks if you'd like to continue (reseting score)
                cls
                put "Would you like to continue? y/n: " ..
                get continue   % if you'd like to continue..
            else
                exit
            end if
            if continue = "y" or continue = "n" then
                cls % Clears the screen after you type in a valid answer
                oval_x1 := 328
                oval_y1 := 228
                oval_directionx := 1
                oval_directiony := 1 % Reset the direction & placement of the ball
                score := 0 % Resets the score
                exit
            else
                put "Invalid answer."
                delay (2000)
                cls
            end if
        end loop % End the debugging loop
    if continue = "n" then
        put "Good Bye!" %Says goodbye and closes if you chose not to keep going
        delay (2000)
        break
    end if
    oval_x1 += (oval_directionx * oval_speed) % adds the direction *speed to the x cord of the ball
    oval_y1 += (oval_directiony * oval_speed) % " but with the y cord
    drawfilloval (oval_x1,oval_y1,oval_xr1,oval_yr1,yellow) %draw the ball
        Input.KeyDown (chars)
            if chars (KEY_RIGHT_ARROW) then %Right key move the paddle to the right
                box1_x1 := box1_x1 + 5
                box1_x2 := box1_x2 + 5
            end if
            if chars ('d') then % " but d
                box1_x1 := box1_x1 + 5
                box1_x2 := box1_x2 + 5
            end if
            if chars (KEY_LEFT_ARROW) then % left key move paddle to the left
                box1_x2 := box1_x2 - 5
                box1_x1 := box1_x1 - 5
            end if
            if chars ('a') then % " but a
                box1_x2 := box1_x2 - 5
                box1_x1 := box1_x1 - 5
            end if
        if box1_x1 >= 630 - 115 or box1_x2 >= 630 then %Sets the far x bounds for the paddle
            box1_x1 := box1_x1 - 5
            box1_x2 := box1_x2 - 5
        end if
        if box1_x1 <= 0 or box1_x2 <= 15 + 115 then %Sets the near x bounds for the paddle
            box1_x1 := box1_x1 + 5
            box1_x2 := box1_x2 + 5
        end if
    drawfillbox (box1_x1, box1_y1, box1_x2, box1_y2, red) %Draw the changes to the box
        if oval_x1 <= box1_x2 & oval_y1 <= box1_y2 & oval_x1 >= box1_x1 & oval_y1 >= box1_y1 then %If collision occurs, the ball moves in the oposite direction
            oval_directiony := oval_directiony * -1
            score := score + 1
        end if
    put "Score:", score
    View.Update % Supposed to fix screen flickering
    delay (10)
end loop


Enjoy!

~Also I'm not worried about giving out the source code for this, haha. But if in the future I'd like to show you the game while keeping my source code safe.. How would I go about doing that?

Author:  Insectoid [ Sat Sep 03, 2011 10:43 pm ]
Post subject:  RE:My first game; Paddleball!

If you want to keep your source hidden, you can compile your code into an executable program that does not require Turing to run. Note that you cannot do this with Turing 4.1.1. Download 4.1 (your code will still work fine) explore the drop-down menues until you find "Generate Standalone Program" or something. Click that. DO NOT DO THIS with 4.1.1. It is broken. I suggest you completely delete 4.1.1 and use 4.1 exclusively.

I don't even know why compsci still hosts 4.1.1...

Author:  Aange10 [ Sat Sep 03, 2011 11:21 pm ]
Post subject:  RE:My first game; Paddleball!

Done and done! Thankyou!

Author:  Zren [ Sun Sep 04, 2011 5:13 pm ]
Post subject:  RE:My first game; Paddleball!

View.Set("Offscreen, graphics:maxx;maxxy")

It's: View.Set("offscreenonly")

get statements don't work when double buffering (offscreenonly drawing). So use "noffscreenonly" beforehand, then change back afterwards.
Turing:

var blah : string

View.Set ("offscreenonly")
get blah
View.Set ("nooffscreenonly")
get blah


I suggest turning it on when you start the game, and turning it off afterwards.

From your other thread about getting a rounded number of seconds passed.

put "Time elapsed:", timestart / 1000 % How much time has elapsed since exiting the menu

timestart / 1000 is real division.
timestart div 1000 is integer division (always rounded down).
Eg: 10 / 3 is 3 and a remainder of 1. Using div would return 3, while using mod (modulus) returns the remainder (1).

From other thread. The reason why you get the white bar is due to the put statments.
put will draw the background color over the entire line even if it's whitespace. I suggest using Font.Draw for any in-game text.

Author:  Rakusan2 [ Sat Dec 10, 2011 9:47 pm ]
Post subject:  Re: My first game; Paddleball!

use Draw.Text instead of put

Author:  Aange10 [ Sun Dec 11, 2011 2:05 pm ]
Post subject:  RE:My first game; Paddleball!

Check the time stamp


: