Help with setting up boundaries
Author |
Message |
windowsall
|
Posted: 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?
code: | 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 and sets boundaries
proc controls
Input.KeyDown (chars)
if chars (KEY_UP_ARROW) and y <= maxy - 2 then
y := y + 2
end if
if chars (KEY_RIGHT_ARROW) and x <= maxx - 2 then
x := x + 2
end if
if chars (KEY_LEFT_ARROW) and x <= maxx - 2 then
x := x - 2
end if
if chars (KEY_DOWN_ARROW) and y <= maxy - 2 then
y := y - 2
end if
if chars (KEY_ENTER) then
attack
end if
end controls
loop
controls
you
enemy
hit
exit when x >= a and y >= b and x <= c and y <= d
end loop |
|
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
balldragger
|
Posted: 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 ![Smile Smile](http://compsci.ca/v3/images/smiles/icon_smile.gif) |
|
|
|
|
![](images/spacer.gif) |
windowsall
|
Posted: 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!
code: | setscreen ("graphics:600;400,position:center;center,nobuttonbar")
var x, y, a, b, c, d, e : int
var chars : array char of boolean
drawbox (3, 3, 597, 397, black)
% 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 : 4 .. 100
e := x + i
drawdot (e, y, black)
delay (10)
drawdot (e, y, white)
end for
% Declares that you have hit him
if e >= a and y >= b and e <= c and y <= d then
put "Enemy Target Locked and Fired Upon: Succesfull"
delay (500)
end if
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 "Danger Youve Been Hit, Shields Low"
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
% Runs the Program 10 times
loop
controls
boundaries
you
enemy
hit
exit when x >= a and y >= b and x <= c and y <= d
end loop
|
|
|
|
|
|
![](images/spacer.gif) |
Cervantes
![](http://compsci.ca/v3/uploads/user_avatars/1023105758475ab2e040bde.jpg)
|
Posted: Sun Apr 03, 2005 8:04 am Post subject: (No 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.) |
|
|
|
|
![](images/spacer.gif) |
Drakain Zeil
|
Posted: Sun Apr 03, 2005 8:13 am Post subject: (No 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. |
|
|
|
|
![](images/spacer.gif) |
windowsall
|
Posted: 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? |
|
|
|
|
![](images/spacer.gif) |
illu45
![](http://img9.exs.cx/img9/1348/roadavvy2ht.png)
|
Posted: 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. |
|
|
|
|
![](images/spacer.gif) |
Drakain Zeil
|
Posted: Sun Apr 03, 2005 6:11 pm Post subject: (No 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. |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
windowsall
|
Posted: 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
code: | % Draws the Attacking weapons
process attack
for i : 4 .. 100
e := x + i
drawdot (e, y, black)
delay (10)
drawdot (e, y, white)
end for
% Declares that you have hit him
if e >= a and y >= b and e <= c and y <= d then
put "Enemy Target Locked and Fired Upon: Succesfull"
delay (500)
cls
View.Update
end if
end attack |
Lines 82 - 84 add this
code: | if chars (KEY_ENTER) then
fork attack
end if |
and when you press enter to shoot the bullet why wont it dissappear?? |
|
|
|
|
![](images/spacer.gif) |
jamonathin
![](http://compsci.ca/v3/uploads/user_avatars/57683465145f851a43dd9a.gif)
|
Posted: Mon Apr 04, 2005 5:52 pm Post subject: (No 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
code: |
% Draws the Attacking weapons
process attack
for i : 4 .. 100
e := x + i
drawdot (e, y, black)
delay (10)
drawdot (e, y, white)
if e >= a and y >= b and e <= c and y <= d then
put "Enemy Target Locked and Fired Upon: Succesfull"
delay (500)
cls
View.Update
end if
end for
end attack
|
I'm not sure why you do this (organizing probabily) but its easier to juss put everything you draw into one proc, that way you can put your View.Update in that proc once, so your program is always smooth, and possibly a little easier to take care of.
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.
code: |
for i : 4 .. 100
e := x + i
drawdot (e, y, black)
delay (5)
drawdot (e, y, white)
delay (5)
end for
|
|
|
|
|
|
![](images/spacer.gif) |
Cervantes
![](http://compsci.ca/v3/uploads/user_avatars/1023105758475ab2e040bde.jpg)
|
Posted: 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 |
|
|
|
|
![](images/spacer.gif) |
|
|