Looping a ForLoop?
Author |
Message |
pers2981
|
Posted: Tue Nov 29, 2011 9:27 am Post subject: Looping a ForLoop? |
|
|
This is my first post, Sorry if I some how mess up the post format or act like a total noob.
What is it you are trying to achieve?
I'm trying to create a wave based "castle defense" game were your job is to survive endless waves of increasing enemies who charge the castle.
What is the problem you are having?
I cant get the bad guys to move on time because they move in a for loop and I think forloops only execute once.
Describe what you have tried to solve this problem
None, I'm really confused on what else I should do / try.
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Field.bmp can be found here.
Uploaded with ImageShack.us
Turing: |
setscreen ("graphics:640;480,nobuttonbar,offscreenonly")
View.Set ("title:Defend Your Castle")
/*
Draw.FillBox (0, 0, 650, 100, grey)
Draw.ThickLine (600, 0, 600, 100, 5, darkgrey)
Draw.Line (100, 350, 550, 350, black)
Draw.FillOval (240, 220, 5, 5, white)
*/
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
var Field := Pic.FileNew ("Field.bmp")
var TotalE : int
var Round : int := 1
var clocks : int := 0
var clockf : int := 0
var i : int := 0
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
proc EnemyCreate
var EnemeyCordsX : array 1 .. TotalE of int
var EnemeyCordsY : array 1 .. TotalE of int
var ESide : array 1 .. TotalE of int
for i : 1 .. TotalE
ESide (i ) := Rand.Int (1, 2)
end for
for i : 1 .. TotalE
if ESide (i ) = 1 then
EnemeyCordsX (i ) := 0
EnemeyCordsY (i ) := 100
end if
if ESide (i ) = 2 then
EnemeyCordsX (i ) := maxx - 25
EnemeyCordsY (i ) := 100
end if
end for
for i : 1 .. TotalE
Draw.FillBox (EnemeyCordsX (i ), EnemeyCordsY (i ), EnemeyCordsX (i ) + 25, EnemeyCordsY (i ) + 50, red)
end for
for i : 1 .. TotalE
if EnemeyCordsX (i ) < 220 then
EnemeyCordsX (i ) := EnemeyCordsX (i ) + 1
end if
if EnemeyCordsX (i ) > 220 then
EnemeyCordsX (i ) := EnemeyCordsX (i ) - 1
end if
end for
end EnemyCreate
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
proc EnemyMove
end EnemyMove
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
proc Update
TotalE := Round * 5
end Update
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
proc DrawField
Pic.Draw (Field, 0, 0, picMerge)
put "Level: ", Round, "" : 50, " Bad guys left : ", TotalE
put clockf
end DrawField
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
proc Count
if clocks = 15 then
clockf := clockf + 1
clocks := 0
end if
clocks := clocks + 1
end Count
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
loop
Update
DrawField
EnemyCreate
EnemyMove
Count
View.Update
delay (100)
cls
end loop
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
Please specify what version of Turing you are using
4.1.1 |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Raknarg
![](http://compsci.ca/v3/uploads/user_avatars/3745510004d8be6689b92f.jpg)
|
Posted: Tue Nov 29, 2011 12:42 pm Post subject: RE:Looping a ForLoop? |
|
|
The obvious solution is then to move them out of a for loop; have all the actions happen at the same time. Instead of moving the enemy across the field then using the other procedures, have them move while everything else is happening as well.
Also, you'll run into another error: You can't set the upper bounds of an array to a variable and change it how you like, it requires different syntax. |
|
|
|
|
![](images/spacer.gif) |
pers2981
|
Posted: Tue Nov 29, 2011 2:53 pm Post subject: RE:Looping a ForLoop? |
|
|
But then how would I move the bad guys? if I got rid of the for loop that is. |
|
|
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
Posted: Tue Nov 29, 2011 2:55 pm Post subject: RE:Looping a ForLoop? |
|
|
same as you would move anything else. Everyone takes a turn to move a step. Repeat. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
![](images/spacer.gif) |
Raknarg
![](http://compsci.ca/v3/uploads/user_avatars/3745510004d8be6689b92f.jpg)
|
Posted: Tue Nov 29, 2011 3:51 pm Post subject: RE:Looping a ForLoop? |
|
|
And whatever you do, do not use processes for it, as some are inclined to do. |
|
|
|
|
![](images/spacer.gif) |
evildaddy911
|
Posted: Wed Nov 30, 2011 9:05 am Post subject: Re: Looping a ForLoop? |
|
|
Quote: Turing: | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
proc EnemyMove
end EnemyMove
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
what does this do? |
|
|
|
|
![](images/spacer.gif) |
|
|