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

Username:   Password: 
 RegisterRegister   
 New to turing requesting assistance
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
TuringScrubLord




PostPosted: Thu Oct 30, 2014 12:50 pm   Post subject: New to turing requesting assistance

So I am new to turing and I'm challenging myself to make a tron lightcycle styled game. Here's what I have so far...

%Variables

var x, y : int := 10
var x2, y2 : int := 490
var char1 : array char of boolean

%Sets window size

View.Set ("graphics: 500;500")

%Starts the game
loop

%move with arrow keys
Input.KeyDown (char1)
if char1 (KEY_UP_ARROW) then
y := y + 10
elsif char1 (KEY_RIGHT_ARROW) then
x := x + 10
elsif char1 (KEY_LEFT_ARROW) then
x := x - 10
elsif char1 (KEY_DOWN_ARROW) then
y := y - 10
end if
%move with "w" "a" "s" "d"
if char1 ('w') then
y2 := y2 + 10
elsif char1 ('d') then
x2 := x2 + 10
elsif char1 ('a') then
x2 := x2 - 10
elsif char1 ('s') then
y2 := y2 - 10
end if

%set boundaries
if x < 0 then
x := 0
elsif x > 500 then
x := 500
elsif y < 0 then
y := 0
elsif y > 500 then
y := 500
end if

if x2 < 0 then
x2 := 0
elsif x2 > 500 then
x2 := 500
elsif y2 < 0 then
y2 := 0
elsif y2 > 500 then
y2 := 500
end if

%the thing you move
Draw.FillOval (x, y, 5, 5, red)
Draw.FillOval (x2, y2, 5, 5, blue)
delay (50)

%Collision Detection

if x = x2 and y = y2 then
exit
elsif x = 0 or x = 500 then
exit
elsif y = 0 or y = 500 then
exit
elsif x2 = 0 or x2 = 500 then
exit
elsif y2 = 0 or y2 = 500 then
exit
end if

end loop

If you play it, it does run. There are two things I would like to do:
1) Make it so the characters move on their own in a direction by themselves until direction is changed by user input
2) Make it so if the characters hit any dot/wall created by either character, the game ends

I would love for this game to work. Making something like this would boost my programming confidence.

So, how can I make those two things possible?
Sponsor
Sponsor
Sponsor
sponsor
Insectoid




PostPosted: Thu Oct 30, 2014 4:30 pm   Post subject: RE:New to turing requesting assistance

Can you make your characters move in one direction, and one direction only, no matter what (don't worry about key presses or changing direction yet). This should be trivial. Just write some code that makes something move infinitely to the right and off the screen.

That was easy, you were just adding 1 or 5 or 10 to the X value (depending on how fast you want to move). Wanna make it go to the right? Just subtract from the X value.

That 1 or 5 or 10 that you were adding to X is an integer. You know what's nice about integers? You can make a variable out of them! Make an int named 'direction' or something and set it to 1 or 5 or 10 or whatever, and add that variable to X instead of a straight number. Now you can write some code that uses your arrow keys to change the direction variable, and we're done! Remember, if x is positive, your character moves right. If it's negative, your character moves left. Easy!

Doing it for the Y axis is just as easy, but you can figure that out yourself.
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  [ 2 Posts ]
Jump to:   


Style:  
Search: