Computer Science Canada Help with setting up boundaries |
Author: | windowsall [ Sat Apr 02, 2005 9:34 pm ] | ||
Post subject: | Help with setting up boundaries | ||
Hi, Im new here, and im wondering why my bounderies ar not working? in this prog?
|
Author: | balldragger [ Sat Apr 02, 2005 10:24 pm ] |
Post subject: | this should work now |
setscreen ("graphics:600;400,position:center;center,nobuttonbar") var x, y, a, b, c, d : int var chars : array char of boolean % Randomly Generates Starting points of you and enemy randint (x, 0, 600) randint (y, 0, 400) randint (a, 0, 550) randint (b, 0, 350) c := a + 20 d := b + 20 % Draws the Attacking weapons proc attack for i : 2 .. 50 drawdot (x + i, y, black) delay (10) drawdot (x + i, y, white) end for end attack % Draws The enemy proc enemy drawfillbox (a, b, c, d, blue) end enemy % Declares that you have been hit proc hit if x >= a and y >= b and x <= c and y <= d then put "You Won that Battle" delay (500) end if end hit % Draws You proc you drawoval (x, y, 6, 6, red) delay (10) drawoval (x, y, 6, 6, white) end you % Your Controls proc controls Input.KeyDown (chars) if chars (KEY_UP_ARROW) then y := y + 2 end if if chars (KEY_RIGHT_ARROW) then x := x + 2 end if if chars (KEY_LEFT_ARROW) then x := x - 2 end if if chars (KEY_DOWN_ARROW) then y := y - 2 end if if chars (KEY_ENTER) then attack end if end controls %boundaries proc boundaries if y <= 3 then y := 3 elsif y >= maxy - 3 then y := maxy - 3 elsif x <= 3 then x := 3 elsif x >= maxx - 3 then x := maxx - 3 end if end boundaries loop controls boundaries you enemy hit exit when x >= a and y >= b and x <= c and y <= d end loop % this should work now, circle shouldn't leave screen ![]() |
Author: | windowsall [ Sat Apr 02, 2005 10:43 pm ] | ||
Post subject: | Another Question.. Thanks for the previous Answer | ||
Hey Thanks Man, It boggled me to what i was doing wrong I guess I had to just do different if statements But why is it when i fire upon the 'opponent' which will be one soon I the user right now dissappears is there a way i can easily fix it? heres the updated code!
|
Author: | Cervantes [ Sun Apr 03, 2005 8:04 am ] |
Post subject: | |
You shouldn't be using a for loop to simply draw a dot. A bullet is much more than a dot on the screen. It has a position, velocity, direction, perhaps acceleration... Instead of going through a for loop and drawing a dot on screen, you should try to create a bullet each time the user presses fire. The best way to do this is to use a Flexible Array. However, that might be a little too advanced, so you could perhaps get by with just creating lots of variables (EDIT:for the purposes of simplicity. Though, it won't be as good, as you won't be able to have lots of bullets on the screen at once.) |
Author: | Drakain Zeil [ Sun Apr 03, 2005 8:13 am ] |
Post subject: | |
Turring needs a long addition to the documentation on OOP... Why make an even that can only use finite shots, when you can make all of the shots you want, once. |
Author: | windowsall [ Sun Apr 03, 2005 3:01 pm ] |
Post subject: | What about putting it into a proccess |
I was wondering if i put it into a process would that fix it?? Or is there any other way? |
Author: | illu45 [ Sun Apr 03, 2005 5:31 pm ] |
Post subject: | Re: What about putting it into a proccess |
windowsall wrote: I was wondering if i put it into a process would that fix it??
Or is there any other way? Processes are generally not very well done in Turing, Its easier to use an array, or some variables/ifs if you're not familiar with arrays. |
Author: | Drakain Zeil [ Sun Apr 03, 2005 6:11 pm ] |
Post subject: | |
Before your player moves to a place, have it check for boundrys in that direction, if it's open, move it, if there's a wall = or > that point, keep it where it is. |
Author: | windowsall [ Mon Apr 04, 2005 12:14 pm ] | ||||
Post subject: | Fixed | ||||
AlrightI fixed it I talked to my CompSci teacher and he suggested using a fork so i used a fork and it works YAHOO but as we know when you fix one glitch there comes another. I cant get the bullet to dissappear lol can anyone help? heres the updated code well a bit of it Lines 15- 35 put this there
Lines 82 - 84 add this
and when you press enter to shoot the bullet why wont it dissappear?? |
Author: | jamonathin [ Mon Apr 04, 2005 5:52 pm ] | ||||
Post subject: | |||||
I don't have turing where im at, but im going to take some guesses at it. You're using a process, and when you hit enter, there's no delay or anything, so it's probabily doin that process a couple times before you let go of enter. That and process almost always find a way to mess you up. And you should check if you hit the enemy inside the loop
![]() And, I'm sure most people aren't going to feel like looking up certain lines (even though its easy to match up), just upload the .t file. ![]() One last thing, your white dot probabily isn't showing up, split the delay in half, that way bots dots are being shown.
|
Author: | Cervantes [ Mon Apr 04, 2005 6:20 pm ] |
Post subject: | Re: Fixed |
windowsall wrote: AlrightI fixed it I talked to my CompSci teacher and he suggested using a fork
Would you mind directing your teacher's attention to this thread? http://www.compsci.ca/v2/viewtopic.php?t=7842 If he reads that, either we or he will learn something. ![]() If you insist on using processes, you should at least understand the cons of them. You should read that thread, too. That said, you'll probably want to do something about those cons once you know of them. If so, you should read tony's tutorials on better process usage: Part 1 Part 2 Once you've read all that, you'll probably realize that processes are not the way to go with something like this. The way to go is to use a flexible array (first learn arrays) of a record. If you are interested in learning, follow through those links, spend some time, and you should end up with an excellent game and a knowledge of programming far ahead of that of your class. If not, well, you'll probably end up with a huge amount of variables and if statements: an exceedingly long and confusing program, for certain. The choice is yours. ![]() -Cervantes |