trouble with moving mutiple "AI"
Author |
Message |
caldrium
|
Posted: Wed Jan 18, 2006 7:10 pm Post subject: trouble with moving mutiple "AI" |
|
|
I have a few problems (and sorry for the messy program ill give it a tweak in a bit):
1. the cls is also deleting the spawned fish (see the proc fishSpawn)
2. i want the fish to move from right to left (they spawn at right[but then disapear due to the cls thing])
3. lastly even with View.Update (maybe its in a bad spot, maybe it doesnt matter) it still flashes a bit, and im assuming it will probably get worse with the new fishes come in
Help would be greatly appreciated. (sorry for all these posts) im terrible at this stuff and i gotta hand in a major project for next week :S
code: | var fish, fishy, level, size : int
var buttons : array char of boolean
var maxX, maxY : int := 200
level := 1
%var fishPic := Pic.FileNew ("fish.jpg") %circles good for now
proc fishSpawn
randint (fish, level, 50)
if (fish = 50) then
randint (fishy, 50, maxy)
randint (size, 10, 30)
Draw.FillOval (maxx, fishy, size, size, 2)
end if
end fishSpawn
fishSpawn
loop
fishSpawn
%fishMove
Draw.FillOval (maxX, maxY, 20, 20, 5)
% Pic.Draw (fishPic, maxX, maxY,picMerge)
View.Update
Input.KeyDown (buttons)
if buttons (KEY_UP_ARROW) then %if the up arrow is pressed
maxY := maxY + 2 %move up
elsif buttons (KEY_DOWN_ARROW) then %if the down arrow is pressed
maxY := maxY - 2 %move down
elsif buttons (KEY_LEFT_ARROW) then %if the left arrow is pressed
maxX := maxX - 2 %move left
elsif buttons (KEY_RIGHT_ARROW) then %if the right arrow is pressed
maxX := maxX + 2 %move right
end if
colorback (100) %backround colour
delay (30)
cls
end loop
|
|
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
zylum
![](http://compsci.ca/v3/uploads/user_avatars/1689129126468091c334ee0.gif)
|
Posted: Wed Jan 18, 2006 8:57 pm Post subject: (No subject) |
|
|
uh huh... looks like you dont have any of the basics down. id recommend reading up on arrays, records and procedures.
as for the flickering, you need to set your screen to offscreenonly at the beginning of the program. the syntax would be:
setscreen("offscreenonly")
or if you prefer
View.Set ("offscreenonly") |
|
|
|
|
![](images/spacer.gif) |
sylvester-27
![](http://www.icejerseys.com/images/vintage_collection/toronto_st_pats/heritage_jersey.jpg)
|
Posted: Thu Jan 19, 2006 1:10 pm Post subject: (No subject) |
|
|
i agree. also your fishy's aren't actually ai's. Or atleast you don't have to go to the trouble of making them ai's. All you have to do is have them move across the screen (-1) +1 if your going the other way. Then just have your "fish" (suggestion: actually draw some fish use a drawoval and a drawpolygon) move across the screen and recognize when they have hit u. |
|
|
|
|
![](images/spacer.gif) |
codemage
![](http://usera.imagecave.com/codemage/codemage-small.gif)
|
Posted: Thu Jan 19, 2006 2:09 pm Post subject: (No subject) |
|
|
You only want to spawn your fish once per round.
Otherwise, you want them to move left once every time in the loop.
Once they get to a certain spot (x < 0 or somesuch), then respawn them again. |
|
|
|
|
![](images/spacer.gif) |
caldrium
|
Posted: Thu Jan 19, 2006 4:08 pm Post subject: (No subject) |
|
|
well..
i just want them to move from right to left then dissapear, but i dun know how to put them into the loop without dissapearing, im thinking its gotta be done with an array, but im not for sure... can someone tell me how to set them up
if you want to get it check my game so far:
i remmed the fish stuff out so you dun have to download the graphics, and sorry for my program being in a complete mess.
code: |
var fish, fishy, level, size, fishdirection, sprint,score : int
var buttons : array char of boolean
var maxX, maxY : int := 200
level :=1
score:=0
fishdirection := 0
sprint := 500
setscreen ("offscreenonly")
%var fishPic := Pic.FileNew ("fish.jpg")
%var fishPic2 := Pic.FileNew ("fish2.jpg")
Pic.Draw (fishPic, maxX, maxY, picMerge)
proc fishSpawn
randint (fish, level, 50)
if (fish = 50) then
randint (fishy, 50, maxy)
randint (size, 10, 30)
Draw.FillOval (maxx, fishy, size, size, 2)
end if
end fishSpawn
proc scoreBoard
score:=score+10
delay (0)
locate (1,1)
if score >=10000 then
score:=0
level:=level+1
end if
put "LEVEL ",level, " ":23, "SWIM POWER: ",sprint," ":13, "NEXT LEVEL(10k): ",score
end scoreBoard
fishSpawn
loop
scoreBoard
Input.KeyDown (buttons)
drawline (550, 0, 550, maxy, 2)
%fishMove
Draw.FillOval (maxX, maxY, 20, 20, 5)
% if fishdirection = 0 then
% Pic.Draw (fishPic, maxX, maxY, picMerge)
% else
% Pic.Draw (fishPic2, maxX, maxY, picMerge)
% end if
View.Update
%FISH MOVEMENT RESTRICTIONS
if (maxX <= -20) then %if you go to far left
maxX := -20 %restrict you from moving further
elsif (maxX >= 440) then %if you try to pass the line
maxX := 440 %restrict you from moving further
end if
if (maxY <= -20) then %if you go to far down
maxY := -20 %restrict you from moving further
elsif (maxY >= 350) then %if you go to far up
maxY := 350 %restrict you from moving further
end if
%FISH MOVEMENT
%NORMAL MOVEMENT
if buttons (KEY_UP_ARROW) then %if the up arrow is pressed
maxY := maxY + 6 %move up
elsif buttons (KEY_DOWN_ARROW) then %if the down arrow is pressed
maxY := maxY - 6 %move down
elsif buttons (KEY_LEFT_ARROW) then %if the left arrow is pressed
maxX := maxX - 6 %move left
fishdirection := 0 %face fish left
elsif buttons (KEY_RIGHT_ARROW) then %if the right arrow is pressed
maxX := maxX + 6 %move right
fishdirection := 1 %face fish right
end if
%SWIM POWER USAGE
if buttons (KEY_SHIFT) and sprint not= 0 then %if they hold shift down
sprint:=sprint-1 %lower their Swim Power
delay (0)
end if
%SWIM POWER MOVEMENT
if buttons (KEY_UP_ARROW) and buttons (KEY_SHIFT) and sprint not= 0 then %if the up arrow +shift key is pressed
maxY := maxY + 9 %move up fast
elsif buttons (KEY_DOWN_ARROW) and buttons (KEY_SHIFT) and sprint not= 0 then %if the down arrow +shift key is pressed
maxY := maxY - 9 %move down fast
elsif buttons (KEY_LEFT_ARROW) and buttons (KEY_SHIFT) and sprint not= 0 then %if the left arrow +shift keyis pressed
maxX := maxX - 9 %move left fast
fishdirection := 0 % face fish left
elsif buttons (KEY_RIGHT_ARROW) and buttons (KEY_SHIFT) and sprint not= 0 then %if the right arrow +shift keyis pressed
maxX := maxX + 9 %move right fast
fishdirection := 1 %face fish right
end if
colorback (11) %backround colour
delay (30)
cls
end loop
|
|
|
|
|
|
![](images/spacer.gif) |
|
|