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

Username:   Password: 
 RegisterRegister   
 My very first game !! XD
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
slender0123




PostPosted: Sat Sep 14, 2013 7:04 pm   Post subject: My very first game !! XD

Hello there everyone! This is my very very first game that I finished for turing! Its difficult at first, but once you get the drift of it, it gets reletivly easy..

Goal.
Keep the ball in the air!!

Use the left and right arrows to move the line to make the ball bounce! (I will change the line to a rectangle once i get familier with the collision of a rectangle!)

the ball will surprise you sometimes where it spawns.
here it is

If its too fast (it probibly will be, my com lags a little (I found out when i ran another jump based program i made from my com at my school, i could hardly make it it was waay to fast lol)) so if its too fast, nerf the delay by 6 or 7, it should make it go the needed speed.

Turing:

var keys : array char of boolean %my variables and constants
var x, y, y2 := 25
var x2 := 125
var X, Y := 100
var y_velocity := 0
const gravity := 2
var bounce := 0
var try : string
var ch : char
setscreen ("graphics:500;400, offscreenonly")

proc intro
put skip
 put "The Bouncing Game!"
put skip
 put "How many times can you make the ball bounce?"
  put "I managed to get 67 bounces!"
 put "Good luck!"
put "Press any key to start!"
drawline (x,y,x2,y2, black) %Objects and end loop
Draw.FillOval(X, Y, 15,15, blue )
View.Update
Input.Pause

end intro

procedure game
loop
Input.KeyDown (keys) %Line movements
  if keys (KEY_RIGHT_ARROW)  and x2 < maxx then
    x2 += 20
    x += 20
  end if
  if keys (KEY_LEFT_ARROW) and x > 0 then
    x2 -= 20
    x -= 20
  end if

y_velocity -= gravity  %Ball gravity effect
Y += y_velocity 

if Y <= 0 then
  x := 25
  x2 := 125
  y := 25
  y2 := 25
  X := 100
  y_velocity := 0
  Y := 100

 
 put "You bounced ",bounce," times!"
    put "Press any key to retry!"
    drawline (x,y,x2,y2, black) %Objects and end loop
    Draw.FillOval(X, Y, 15,15, blue )
     bounce := 0
     
    View.Update
    Input.Pause
    game
end if
   
if Math.DistancePointLine (X,Y,x,y,x2,y2) < 30 then %Ball bounce
 y_velocity := 35
  X := Rand.Int(1, 500)
  bounce := bounce + 1
end if
 
drawline (x,y,x2,y2, black) %Objects and end loop
Draw.FillOval(X, Y, 15,15, blue )

delay (1)
View.Update
cls
end loop
end game
intro
game
Sponsor
Sponsor
Sponsor
sponsor
Raknarg




PostPosted: Sat Sep 14, 2013 8:53 pm   Post subject: RE:My very first game !! XD

Cool little tool: Time.DelaySinceLast.

It's similar to delay; delay indefinitely pauses the program for the given amount of time. Time.DelaySinceLast is a little different. It takes into account how long your program takes to run things. It compares time put into the parameter to the time it took since the function was last called.

Lets say you wanted to have a frame about every 10 milliseconds. Your program takes 5 seconds on your computer to run per frame. Therefore, it will only pause the program for 5 milliseconds. If you give it to someone else who can run it in 2 milliseconds, it pauses for 8 seconds. If it takes someone 12 milliseconds, it disregards the delay. This makes it so it optimizes framerate even between different computers as much as possible just through delaying.
slender0123




PostPosted: Sat Sep 14, 2013 9:27 pm   Post subject: RE:My very first game !! XD

I will try to mess around with that new statement, I personally never heard of it before. so it will be completely new to me to figure out, much like arrays and such (which I still need to work on) Right now it's getting late, so I think I will try to figure it out tommorow.
Nathan4102




PostPosted: Sat Sep 14, 2013 9:39 pm   Post subject: RE:My very first game !! XD

Besides being impossible on my computer, it's pretty good for a first game, especially considering the best my classmates could do after 4 months of classes was a 2 player Rock paper scissors game! Keep up the good work
slender0123




PostPosted: Sun Sep 15, 2013 5:11 pm   Post subject: RE:My very first game !! XD

This is only my second week into programming with turing! I'm wayy ahead of my classmates lol, im pretty sure there still working on loops, im trying out arrays at this moment, because once you said 2 player rock paper scissors game, i wanted to make a rock papper scissors game with an option for 1 player or 2 player!
I will probibly need to know how to open up other turing windows though.. if 1 of you guys could help a bit with that via pm or something, that would be of gr8 help Very Happy

And about the time delay since last thing..
would this be the code for it?
Turing:

Time.DelaySinceLast (1)
View.Update
cls
end loop
end game
intro
game
evildaddy911




PostPosted: Sun Sep 15, 2013 5:52 pm   Post subject: RE:My very first game !! XD

pretty much. However, the parameter is "time in MILLISECONDS". that means that you will be getting up to 1000 frames per second. with that delay, all you will see is a white flash before the game over screen. Most games' delays will be about 10-30ms, so keep changing that parameter until you feel the game moves fast enough to be hard, but slow enough to be possible
Nathan4102




PostPosted: Sun Sep 15, 2013 5:59 pm   Post subject: RE:My very first game !! XD

I would wait a bit before attempting a 1 player Rock Paper Scissors. Only one player means the other player is computer controlled, which means getting into AI. Fun stuff, but not really 2 weeks experience stuff :p You could look into it though if you really want to do it.
slender0123




PostPosted: Sun Sep 15, 2013 6:16 pm   Post subject: RE:My very first game !! XD

I will fix my bounce game at school tommorow, i will make it possible on faster computers XD

This is my rock paper scissors game so far XD

Turing:

import GUI
var rock : boolean := false
var paper : boolean := false
var scissors : boolean := false
var computer1 : int
var correct : int
correct := 0

computer1 := Rand.Int(1,3)

proc ROCK
 rock := true
  computer1 := Rand.Int(1,3)
   if computer1 = 1 then
    put "Its a tie!"
   elsif computer1 = 2 then
    put "You lose! Paper covers rock!"
   elsif computer1 = 3 then
    put "You win! Rock beats Scissors!"
     correct += 1
   end if
  end ROCK

proc PAPER
 paper := true
  computer1 := Rand.Int(1,3)
   if computer1 = 1 then
    put "You win!! Paper covers rock!"
     correct += 1
   elsif computer1 = 2 then
    put "It's a tie!"
   elsif computer1 = 3 then
    put "You lose! Scissor cuts paper!"
   end if
 end PAPER

proc SCISSOR
 scissors := true
  computer1 := Rand.Int(1,3)
   if computer1 = 1 then
    put "You lose! Rock beats Scissors!"
   elsif computer1 = 2 then
    put "You win! scissors cuts paper!"
     correct += 1
   elsif computer1 = 3 then
    put "Its a tie!"
  end if
 end SCISSOR

View.Set ("graphics:365;200,nobuttonbar")
var Rock : int := GUI.CreateButtonFull (50, 50, 0, "Rock",
    ROCK, 0, '^D', true)
   
var Paper : int := GUI.CreateButtonFull (150, 50, 0, "Paper",
    PAPER, 0, '^D', true)
   
var Scissor : int := GUI.CreateButtonFull (250, 50, 0, "Scissors",
    SCISSOR, 0, '^D', true)
   
var quitBtn : int := GUI.CreateButton (152, 10, 0, "Quit", GUI.Quit)

loop
exit when GUI.ProcessEvent
end loop


Theres one problem i want to ask for help though. I want it so that once the text hits a certain column, it will just delete the top row of words and push the rest up.. If you could post some pseudo code or something for it, that would be great! Thanks!
Sponsor
Sponsor
Sponsor
sponsor
tiedye1




PostPosted: Sun Sep 15, 2013 7:32 pm   Post subject: Re: My very first game !! XD

To keep the text from overlapping the buttons in your rock paper scissors game, you can use the GUI.Refresh procedure to redraw the buttons and cls to clear the screen.
evildaddy911




PostPosted: Sun Sep 15, 2013 7:57 pm   Post subject: RE:My very first game !! XD

How I would do it is using an array.

code:

Str: string array 1-15
% initialize each element as ""

Procedure output ( text: string)
1<= i <= 15
    If Str (I) = "" then % if there's an empty element, fill it!
        Str (I) = text
        Return % exits procedure
    End if

1 <= I <= 14 % shift each element up 1 line
    Str (I) = Str (I+1)
End for
Str (15) = text

End output

Use the output procedure instead of put statements, then use cls, GUI.Refresh and a for loop to put each element to the screen
Raknarg




PostPosted: Sun Sep 15, 2013 9:21 pm   Post subject: RE:My very first game !! XD

@Nathan unless you want to build a database which records an opponent's past moves and takes them into account, the AI is basically random.
slender0123




PostPosted: Mon Sep 16, 2013 6:02 am   Post subject: RE:My very first game !! XD

I think I will just post all my little games on this topic... Speaking of little games.. heres number 2! A finished 1 player rock paper scissors game!

Turing:

import GUI
var rock : boolean := false
var paper : boolean := false
var scissors : boolean := false
var computer1 : int 

proc ROCK
 rock := true
  cls
  GUI.Refresh
  computer1 := Rand.Int(1,3)
   if computer1 = 1 then
    put "Its a tie!"
   elsif computer1 = 2 then
    put "You lose! Paper covers rock!"
   elsif computer1 = 3 then
    put "You win! Rock beats Scissors!"
   end if
  end ROCK

proc PAPER
 paper := true
  cls
  GUI.Refresh
  computer1 := Rand.Int(1,3)
   if computer1 = 1 then
    put "You win!! Paper covers rock!" 
   elsif computer1 = 2 then
    put "It's a tie!"
   elsif computer1 = 3 then
    put "You lose! Scissor cuts paper!"
   end if
 end PAPER

proc SCISSOR
 scissors := true
  cls
  GUI.Refresh
  computer1 := Rand.Int(1,3)
   if computer1 = 1 then
    put "You lose! Rock beats Scissors!"
   elsif computer1 = 2 then
    put "You win! scissors cuts paper!" 
   elsif computer1 = 3 then
    put "Its a tie!"
  end if
 end SCISSOR

View.Set ("graphics:365;200,nobuttonbar")
var Rock : int := GUI.CreateButtonFull (50, 50, 0, "Rock",
    ROCK, 0, '^D', true)
   
var Paper : int := GUI.CreateButtonFull (150, 50, 0, "Paper",
    PAPER, 0, '^D', true)
   
var Scissor : int := GUI.CreateButtonFull (250, 50, 0, "Scissors",
    SCISSOR, 0, '^D', true)
   
var quitBtn : int := GUI.CreateButton (152, 10, 0, "Quit", GUI.Quit)

loop
exit when GUI.ProcessEvent
end loop
slender0123




PostPosted: Mon Sep 16, 2013 8:45 am   Post subject: RE:My very first game !! XD

This is the bouncing game, it should be fixed now for faster computers.

Turing:

var keys : array char of boolean %my variables and constants
var x, y, y2 := 25
var x2 := 125
var X, Y := 100
var y_velocity := 0
const gravity := 2
var bounce := 0
var try : string
var ch : char
setscreen ("graphics:500;400, offscreenonly")

proc intro
put skip
 put "The Bouncing Game!"
put skip
 put "How many times can you make the ball bounce?"
  put "I managed to get 67 bounces!"
 put "Good luck!"
put "Press any key to start!"
drawline (x,y,x2,y2, black) %Objects and end loop
Draw.FillOval(X, Y, 15,15, blue )
View.Update
Input.Pause

end intro

procedure game
loop
Input.KeyDown (keys) %Line movements
  if keys (KEY_RIGHT_ARROW)  and x2 < maxx then
    x2 += 20
    x += 20
  end if
  if keys (KEY_LEFT_ARROW) and x > 0 then
    x2 -= 20
    x -= 20
  end if

y_velocity -= gravity  %Ball gravity effect
Y += y_velocity 

if Y <= 0 then
  x := 25
  x2 := 125
  y := 25
  y2 := 25
  X := 100
  y_velocity := 0
  Y := 100

 
 put "You bounced ",bounce," times!"
    put "Press any key to retry!"
    drawline (x,y,x2,y2, black) %Objects and end loop
    Draw.FillOval(X, Y, 15,15, blue )
     bounce := 0
     
    View.Update
    Input.Pause
    game
end if
   
if Math.DistancePointLine (X,Y,x,y,x2,y2) < 20 then %Ball bounce
 y_velocity := 35
  X := Rand.Int(1, 500)
  bounce := bounce + 1
end if
 
drawline (x,y,x2,y2, black) %Objects and end loop
Draw.FillOval(X, Y, 15,15, blue )

Time.DelaySinceLast (20)
View.Update
cls
end loop
end game
intro
game
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 13 Posts ]
Jump to:   


Style:  
Search: