Posted: Mon Dec 19, 2011 4:53 pm Post subject: Need Help with Collision and Screen Flickering
What is it you are trying to achieve?
<Replace all the <> with your answers/code and remove the <>>
What is the problem you are having?
Screen Flickers too much due to the nature of the way I generated the bullets.
Collision with edge of screen not working. Boot collision with the black part of the portal doesnt work
Describe what you have tried to solve this problem
Tried using various types of arrays and configurations with arrays to help with the bullet problem. Tried moving the View.Update to various sensible places in the program. Tried using only one view.update (which didnt work).
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
My game
Turing:
% Declare Variables
var CXBLSSBbody, CYBLSSBbody, CXTRSSBbody, CYTRSSBbody, CXSBarm, CYSBarm, CXRSBarm, CYRSBarm, CXSBfan, CYSBfan, CXRSBfan :int var CYRSBfan, CXBLSSBhead, CYBLSSBhead, CXTRSSBhead, CYTRSSBhead, CXBLSSBleftleg, CYBLSSBleftleg, CXTRSSBleftleg :int var CYTRSSBleftleg, CXBLSSBrightleg, CYBLSSBrightleg, CXTRSSrightleg, CYTRSSBrightleg, CXBLSSBleftshoe, CYBLSSBleftshoe :int var CXTRSSBleftshoe, CYTRSSBleftshoe, CXBLSSBrightshoe, CYBLSSBrightshoe, CXTRSSrightshoe, CYTRSSBrightshoe :int var CXSBlefteye, CYSBlefteye, CXRSBlefteye, CYRSBlefteye, CXSBrighteye, CYSBrighteye, CXRSBrighteye, CYRSBrighteye :int var CXBLP, CYBLP, CXRSBbiglandingpad, CYRBLP, CXSLP, CYSLP, CXRSLP, CYRSLP, CXESbody, CYESbody, CXRESbody, CYRESbody :int var CX1ESspiketopleft, CX2ESspiketopleft, XY1ESspiketopleft, CY2spiketopleft, CX1ESspiketopright, CX2ESspiketopright :int var XY1ESspiketopright, CY2spiketopright, CX1ESspikebottomleft, CX2ESspikebottomleft, XY1ESspikebottomleft :int var CY2spikebottomleft, CX1ESspikebottomright, CX2ESspikebottomright, XY1ESspikebottomright, CY2spikebottomright :int var CX1ESspikeleftleft, CX2ESspikeleftleft, XY1ESspikeleftleft, CY2spikeleftleft, CX1ESspikeleftright :int var CX2ESspikeleftright, XY1ESspikeleftright, CY2spikeleftright, CX1ESspikerightleft, CX2ESspikerightleft :int var XY1ESspikerightleft, CY2spikerightleft, CX1ESspikerightright, CX2ESspikerightright, XY1ESspikerightright :int var CY2spikerightright, CXBLSP, CYBLSP, CXTRSP, CYTRSP, CXB, CYB, CXRB, CYRB, CXBLSBH, CYBLSBH, CXTRSBH, CYTRSBH :int var life, speed :int var ch :string(1)
loop var x, y, button :int mousewhere(x, y, button)
Font.Draw("Play",50, maxy - 150, arialb, c) if button =0and x > 50and x < 130and y > 320and y < 356then
c :=94 elsif
button =1and x > 50and x < 130and y > 320and y < 356then
if CXRSBarm >= maxxand CXSBarm <= 0and CYRSBarm >= maxyand CYSBarm <= 0then
life := life - 1
elsif CXTRSSBbody >= maxxand CXBLSSBbody <= 0and CYBLSSBbody >= maxyand CYTRSSBbody <= 0then
life := life - 1
elsif CXTRSSBhead >= maxxand CXBLSSBhead <= 0and CYBLSSBhead >= maxyand CYTRSSBhead <= 0then
life := life - 1
elsif CXTRSSBleftleg >= maxxand CXBLSSBleftleg <= 0and CYBLSSBleftleg >= maxyand CYTRSSBleftleg <= 0then
life := life - 1
elsif CXTRSSrightleg >= maxxand CXBLSSBrightleg <= 0and CYBLSSBrightleg >= maxyand CYTRSSBrightleg <= 0then
life := life - 1
elsif CXTRSSBleftshoe >= maxxand CXBLSSBleftshoe <= 0and CYBLSSBleftshoe >= maxyand CYTRSSBleftshoe <= 0then
life := life - 1
elsif CXTRSSrightshoe >= maxxand CXBLSSBrightshoe <= 0and CYBLSSBrightshoe >= maxyand CYTRSSBrightshoe <= 0then
life := life - 1
endif
% Colission with Portal
if CXRSBarm >= CXBLSBH and CXSBarm <= CXTRSBH and CYRSBarm >= CYBLSBH and CYSBarm <= CYTRSBH then
life := life - 1
elsif CXTRSSBbody >= CXBLSBH and CXBLSSBbody <= CXTRSBH and CYBLSSBbody >= CYBLSBH and CYTRSSBbody <= CYTRSBH then
life := life - 1
elsif CXTRSSBhead >= CXBLSBH and CXBLSSBhead <= CXTRSBH and CYBLSSBhead >= CYBLSBH and CYTRSSBhead <= CYTRSBH then
life := life - 1
elsif CXTRSSBleftleg >= CXBLSBH and CXBLSSBleftleg <= CXTRSBH and CYBLSSBleftleg >= CYBLSBH and CYTRSSBleftleg <= CYTRSBH then
life := life - 1
elsif CXTRSSrightleg >= CXBLSBH and CXBLSSBrightleg <= CXTRSBH and CYBLSSBrightleg >= CYBLSBH and CYTRSSBrightleg <= CYTRSBH then
life := life - 1
elsif CXTRSSBleftshoe >= CXBLSBH and CXBLSSBleftshoe <= CXTRSBH and CYBLSSBleftshoe >= CYBLSBH and CYTRSSBleftshoe <= CYTRSBH then
life := life - 1
elsif CXTRSSrightshoe >= CXBLSBH and CXBLSSBrightshoe <= CXTRSBH and CYBLSSBrightshoe >= CYBLSBH and CYTRSSBrightshoe <= CYTRSBH then
life := life - 1
/*elsif x2 >= CXBLSBH and x1 <= CXTRSBH and y2 >= CYBLSBH and y1 <= CYTRSBH then
life := life - 1
elsif x2 >= CXBLSBH and x1 <= CXTRSBH and y2 >= CYBLSBH and y1 <= CYTRSBH then
life := life - 1
elsif x2 >= CXBLSBH and x1 <= CXTRSBH and y2 >= CYBLSBH and y1 <= CYTRSBH then
life := life - 1*/ endif
endloop
var r, axle :int var h, k, x1 :real var xchange :int:=20 const pi :=22 / 7
r :=640
k :=18
x1 := r
axle :=300 loop
x1 := x1 + xchange
if x =200then
xchange := xchange * -1 endif
if x =0then
xchange := xchange * -1 endif
h := r *cos(k * x1) + axle
drawfilloval(round(x1),round(h),25, 25, black) put h
%View.Update delay(100) cls endloop
else
c :=66 endif endloop
Please specify what version of Turing you are using
Turing 4.1
Sponsor Sponsor
Tony
Posted: Mon Dec 19, 2011 5:09 pm Post subject: RE:Need Help with Collision and Screen Flickering
Quote:
fork ParticleGenerationBlaster
Well there's your problem. You can't have a forked loop that draws things to screen _and_ View.Update. Think a bit about what View.Update does and what fork does to figure out why those two are mutually exclusive.
Posted: Tue Dec 20, 2011 8:11 am Post subject: Re: Need Help with Collision and Screen Flickering
Sorry, I was a little bit ill when I posted the last post. I meant to say how would I only execute the fork once when I press the spacebar and all other spacebar presses will effect the proccess itself and not start another fork.
EDIT: Actually, I think the better question to ask would be how to get all the View.Update's to synchronize with each other.
Insectoid
Posted: Tue Dec 20, 2011 9:17 am Post subject: RE:Need Help with Collision and Screen Flickering
You don't. You don't use processes at all. You don't (and can't) synchronize View.Updates. You only need one. There are many, many threads explaining how to make things move at the same time. I suggest you search for them. There's probably even a few on the front page of Turing Help.
Sponsor Sponsor
Nablo
Posted: Tue Dec 20, 2011 1:23 pm Post subject: Re: Need Help with Collision and Screen Flickering
I tried eliminating the processes and making one big program but that didnt work because of the nature of my bullet generation.
Aange10
Posted: Tue Dec 20, 2011 1:43 pm Post subject: RE:Need Help with Collision and Screen Flickering
There are many ways to do the same thing. With that aside, if you understand now that you don't need proccesses, then good. You're done with the first step.
I bet you next question is 'But Aange! How do I make bullets?", to which my response is: 'Search for it in the tutorial section and the help section. If anything, as a last resort, look in the submissions and see how they did it!'
Raknarg
Posted: Tue Dec 20, 2011 1:50 pm Post subject: RE:Need Help with Collision and Screen Flickering
Well put. You see, the basic logic of animation in Turing is:
1. Set all the points of everything (bullets, characters, etc.)
You check the environment for certain conditions, such as a button being pressed or if a bullet hits an enemy, or an enemy hits you, if a bullet is live, etc. You calculate the next step for everything on screen
2. Draw everything in the same loop
After all the positions have been calculated, you can then draw them to the screen at it's new position. Processes are unessesary.
You're logic was probably "I need them all to move at the same time; I must use processes." However, that's not true. You need them to seem like they're moving at the same time. Therefore, if you calculate all the points and then draw them in a sequence, you'll get the same effect without the annoyance and unpredictability of processes.
Aange10
Posted: Tue Dec 20, 2011 2:16 pm Post subject: RE:Need Help with Collision and Screen Flickering
And also, to add, proccess (unless ran on multiple cores) do not run at the same time, rather, they run EXTEREMLY fast between each process.
Nablo
Posted: Tue Dec 20, 2011 2:22 pm Post subject: Re: Need Help with Collision and Screen Flickering
@Raknarg, how can I can everything in the same loop if my bullet generation is triggered by the pressing of a button. Now I know you might suggest "Well, then put an if statement to run the bullet generation if you press the button" but then the getch would prevent the next sequence of animation from taking place due to the getch. So I'm rather confused onto what to do. Btw, I saw how other people did their bullet generation and their variable system is much different from mine and because of that I cant understand some of their systems.
DemonWasp
Posted: Tue Dec 20, 2011 2:23 pm Post subject: RE:Need Help with Collision and Screen Flickering
Actually, Turing's process implementation is entirely single-threaded at the OS level: Turing does all the task switching itself (and clumsily at that). That means that although those processes are running asynchronously from your "main" thread, they aren't running in parallel.
Tony
Posted: Tue Dec 20, 2011 2:57 pm Post subject: Re: Need Help with Collision and Screen Flickering
Nablo @ Tue Dec 20, 2011 2:22 pm wrote:
the getch would prevent the next sequence of animation from taking place due to the getch.
Good point; so then you need to use non-blocking IO. Examples include Input.KeyDown or using hasch.