Posted: Tue Dec 13, 2011 6:42 pm Post subject: Remove Flickering (it came back) and program simple AI
What is it you are trying to achieve?
Remove the god damn flickering! once and for all... before i got rid of it but now i came back and its not gonig away.
I also want to program the AI where i indicated it... i want to know how to go about doing that.
What is the problem you are having?
The flickering is really pissing me off. And the A.I is confusing :O
I want the A.I to follow the direction of the ball once i make it move ( which i can do ) but i want to know how to make the paddle follow the ball and make it miss sometimes but not alot
Describe what you have tried to solve this problem
Read all the documentations for flickering ... got nada from it.
A.I - I have not really looked that much into it, im just looking for someone to share some words of wisdom or a tutorial on it.
Turing:
import GUI
View.Set("graphics:638;690") %_______The "Bank"_______% type DataOfBlock : record
x, y, width, height, center :int
defeated :boolean endrecord type DataOfShell : record
right, top, left, bottom, c :int endrecord type BallData : record
x, y, r, xv, yv, speed, c :int endrecord %_______Global Variables_______% var PicID :int var x :int:=700 var y :int:=500 var replay :string var fontS :int
fontS :=Font.New("Verdana:20")
PicID :=Pic.FileNew("ball02.jpg") Pic.Draw(PicID, maxxdiv2 - (638div2),maxydiv2 - (690div2),picCopy) %_______Procedures_______% procedure TheGame
setscreen("graphics:1400;700,title:The AI BrickBreaker Game") View.Set("offscreen") %------------------------------ %Block variables % var xSpacing, ySpacing :int% var blockH, blockW :int% var shell : DataOfShell % var ball : BallData %%% var blockXDimension :int:=20% var blockYDimension :int:=10%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% var block :array1.. blockXDimension, 1.. blockYDimension of DataOfBlock %
shell.right :=710%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
shell.top :=680%
shell.left :=60%
shell.bottom :=50%
shell.c :=35% %------------------------------ %--------------------------- %Player Co-ords % var x1, y1, x2, y2 :int%
x1 :=250%
y1 :=25%
x2 :=350%
y2 :=50% %--------------------------- %------------------------------------------------ %Ball Co-ords % var ball_x1, ball_x2, ball_y1, ball_y2 :int% var ball_directionx :int:=1% var ball_directiony :int:=1% var ball_speed :int%
ball_speed :=10%
ball_x1 :=512%
ball_y1 :=200%
ball_x2 :=1024%
ball_y2 :=200% % %------------------------------------------------ %---------------------------------------- %Game Basics % var continueGame :string% var lives :int:=2% var score :int:=0% var timeElapsed :int:=Time.Elapsed% %---------------------------------------- %---------------------------------------------------- %Boundaries (paddle + ball) % var boundary_x1 :int:=((maxxdivmaxx) - 1) + 20% var boundary_x2 :int:=maxx - 20% var boundary_y1 :int:=maxy - 20% var boundary_y2 :int:=((maxydivmaxy) - 1) + 20% %---------------------------------------------------- var arrowKeys :arraycharofboolean
lives +=1 loop locate(1, 10) put"Lives: ", lives
locate(1, 30) put"Score: ", score
locate(1, 50) put"Game Time: ",Time.Elapsed / 1000 var block_x1, block_y1, block_x2, block_y2 :int
block_x1 :=50
block_y1 :=300
block_x2 :=100
block_y2 :=350
%% Player Screen %%________________________________________________
%%_________________________________________________%% if ball_y1 < 25then
lives -=1 if lives <= 0then cls Font.Draw("You Have Lost :(",50, 50, fontS, green) put"You have acquired a total score of: ", score
loop put"Would you like to play again?" get replay
if replay ="Yes"or replay ="yes"or replay ="y"then put"Your game will replay shortly..." put"Get READY!" Time.Delay(3000)
timeElapsed :=0
TheGame
elsif replay ="No"or replay ="no"or replay ="n"then put"Good bye, and thanks for playing!" Time.Delay(2500) cls break else put"Invalid answer" cls endif endloop endif endif loop if ball_y1 <= 20then cls put"Would you like to continue? y/n: "..
get continueGame
else exit endif if continueGame ="y"or continueGame ="yes"then cls
ball_x1 :=512
ball_y1 :=200
ball_directionx :=1
ball_directiony :=1 exit elsif continueGame ="n"or continueGame ="No"then put"Have A Nice Day!" delay(2500) break else put"Invalid answer." delay(2500) cls endif endloop delay(10) endloop end TheGame
procedure Instructions
colorback(16) color(48) cls locate(4, 1) put"The objective of the game is..." locate(7, 1) color(58) put"to destroy all of the blocks on your side of the screen (bottom)" locate(10, 1) color(73) put"Before the computer destroys all of his blocks on his side of the screen (top)" locate(13, 1) color(81) put"You will use the 'Left' and 'Right' Arrow keys to move left and right" locate(16, 1) color(67) put"If you press the 'ESC' key on your keyboard the game will exit." locate(19, 1) color(96) put"Good Luck and go smash some blocks. HINT : You only have 3 Lives!"
end Instructions
procedure TheTitleScreen
var font1 :int
font1 :=Font.New("Arial:13") assert font1 > 0 Pic.Draw(PicID, maxxdiv2 - (638div2),maxydiv2 - (690div2),picCopy) var game_Button :int:=GUI.CreateButton(265, 275, 0, "Click To Play!", TheGame) var instruction :string locate(37, 4) Font.Draw("Please hold 'Click to Play' while you type your answer below!",50, 150, font1, yellow) locate(38, 4) Font.Draw("You will be redirected to the instructions so keep holding your mouse.",50, 125, font1, green) locate(39, 4) Font.Draw("Or drag away from 'Click to Play' then read and Click it afterwards.",50, 75, font1, yellow) locate(40, 4) Font.Draw("Do you want to see the game Instructions? ",50, 40, font1, green) locate(50, 47) get instruction
if instruction ="yes"then
Instructions
else
Instructions
endif end TheTitleScreen
procedure returnBack
var go_back :char:="n" loop get go_back
if go_back ="y"then
TheTitleScreen
endif endloop end returnBack
TheTitleScreen
loop exitwhenGUI.ProcessEvent endloop
Please specify what version of Turing you are using
4.1.1a
Gladly giving karma for help
Sponsor Sponsor
Insectoid
Posted: Tue Dec 13, 2011 6:51 pm Post subject: RE:Remove Flickering (it came back) and program simple AI
code:
View.UpdateArea (0, 0, maxx, maxy)
How many times does this line occur in your code?
Dreadnought
Posted: Tue Dec 13, 2011 7:08 pm Post subject: Re: Remove Flickering (it came back) and program simple AI
Velocity wrote:
Read all the documentations for flickering ... got nada from it.
Did the documentation actually tell you that this line (the exact way it is written here and in your code) was valid?
and for the AI, a possible way you can have it move is that if the paddle is not even with the ball's location, you can have it follow by a random integer such as
or whatever you wan the upper range to be. You can adjust these bounds through testing to find an optimal way of having it work. If it has a constant movement then you can give it a certain chance that the paddle will move or not. I have implemented basic AI such as this in a few places and it works quite well. Since it should read through the code many times a second, it will appear to move slowly as opposed to stop/start type of motion that would come with a boolean move or don't statement. Thee are a few ideas to get you started, but there are countless ways of designing an AI and it all depends on how strong you want it and what you want it to do.
Velocity
Posted: Tue Dec 13, 2011 10:00 pm Post subject: RE:Remove Flickering (it came back) and program simple AI
crossley thanks, i know alot about A.I in C++ as i do quite alot of work in C++, i also tutor it. Turing is like a whole new story for me. Thanks alot for the advice and @ insectoid and dreadnought i have already tried all the possible things that are inside the documentation and none of them work? can you guys please run my program and implement something that could possibly run it smoothly? i was thinking of how it take a picture of every single line or procedure that way it has a saved knowledge of how it may run.
P.S To all i will gladly give you all karma and bits once i get the commands implemented, and since you tried thanks.
Tony
Posted: Tue Dec 13, 2011 10:17 pm Post subject: Re: RE:Remove Flickering (it came back) and program simple AI
Velocity @ Tue Dec 13, 2011 10:00 pm wrote:
i do quite alot of work in C++, i also tutor it.
I highly doubt that you are able to write anything meaningful in something as complex as C++, and then have trouble figuring out Turing's documentation while people are telling you exactly what you are doing wrong.
With a bit of paraphrasing:
Dreadnought @ Tue Dec 13, 2011 7:08 pm wrote:
[hey Velocity, you made up an invalid mode instead of using one from documentation; your error is at:]
Posted: Wed Dec 14, 2011 12:10 am Post subject: Re: Remove Flickering (it came back) and program simple AI
I agree. I'm sorry to flame, but 90% of your posts fail to show that you actually try anything. You usually fail to do anything on your own, or use tools provided to you. You seem to waver from question to question, never figuring out how to think for your self.
velocity wrote:
i have already tried all the possible things that are inside the documentation and none of them work?
... Further more ...
velocity wrote:
can you guys please run my program and implement something
134 posts and you still fail to think for your self. You deem the tools everybody else uses as useless, and look to everybody else to solve your problems. Here's some people to look to;
Posted: Wed Dec 14, 2011 7:14 am Post subject: RE:Remove Flickering (it came back) and program simple AI
okay i tried to use this as a help forums, never mind.
Sponsor Sponsor
Aange10
Posted: Wed Dec 14, 2011 8:34 am Post subject: Re: RE:Remove Flickering (it came back) and program simple AI
Velocity @ 14/12/2011, 6:14 am wrote:
okay i tried to use this as a help forums, never mind.
into
Quote:
can you guys please run my program and implement something
If you read the rules
Welcome to Turing Help; Important Info & Tutorial Links wrote:
... Also plz don't post asking people to do your schoolwork for you, we will help but we will not do your projects for you. ...
... Please use these sources, as well as the Search, before posting your question. ...
You must try so hard.
mirhagk
Posted: Wed Dec 14, 2011 8:45 am Post subject: RE:Remove Flickering (it came back) and program simple AI
Velocity, I ran your code, and fixed it (along with other various mistakes you had which prevented it from even running). Here is your game logic:
As everyone has said, you need to draw everything all at once and do any of the following:
draw everything
View.Update
delay
cls
or
cls
draw everything
VIew.Update
delay
Do one of those. Also in this particular instance I fixed it by first of all using offscreenonly not offscreen, and then removing every View.Update or View.UpdateArea and only having 1 in your code. You should only ever have 1 per loop.
Insectoid
Posted: Wed Dec 14, 2011 9:06 am Post subject: RE:Remove Flickering (it came back) and program simple AI
Velocity, do you know what causes flickering? It happens because Turing draws things to the video buffer at a different speed than the video card draws to the screen. When you tell Turing to draw lots of things, it only manages to draw a few of them before the video card draws to the screen. So the video card draws half an image, then Turing draws a little more, the video card draws a little more, Turing draws a little more, the video card draws a little more, etc. This causes flickering.
View.Set ("offscreenonly") tells turing to double-buffer graphics. This means when you tell it to draw things, it will draw them to its own internal 'screen' (you can't see it). The video card never gets to see this. Then, when you call View.Update, Turing shows the whole picture to the video card and says "Draw all of these things".
If you call View.Update more than once per loop, it's just like drawing things individually. You'll draw half an image, show it to the video card, then draw a bit more, show it to the video card, and then draw some more, and show it to the video card.
Hopefully this illustrates why you should be using View.Update, how you are using it wrong, and how to fix it.
crossley7
Posted: Wed Dec 14, 2011 12:07 pm Post subject: RE:Remove Flickering (it came back) and program simple AI
Also, if you say you have made AI in C++ then you should be fine in turing. Changing language doesn't change the logic, just the words that are used to implement it. I use C++ mostly now and I find it tends to be a step up from Turing rather than a step down. It is faster and has more functionality and the only thing turing has on it is if you need really basic graphics for a simple program.
I somehow doubt that you struggle with Turing if you have any understanding of any language, nevermind C++.
Velocity
Posted: Wed Dec 14, 2011 6:37 pm Post subject: RE:Remove Flickering (it came back) and program simple AI
Thank you very much for mirhagk for that help, since now i have completely removed my flickering.
Also thank you very much to Insectoid for clearly explaining in detail the purpose of those commands (that cleared up alot of thing, thanks alot) !
mirhagk
Posted: Wed Dec 14, 2011 8:23 pm Post subject: RE:Remove Flickering (it came back) and program simple AI
For future reference don't post and say "My program flickers and I can't fix it, I've read everything, you guys fix it". Try and understand and fix it on your own, and failing that, ask us to explain it. We will gladly explain things in detail if you ask, it's just a matter of asking for help in understanding.
Velocity
Posted: Wed Dec 14, 2011 8:36 pm Post subject: RE:Remove Flickering (it came back) and program simple AI
That being said, may you please explain to me my next post that i made about clearing the brick after it is hit.