Computer Science Canada why is program working weird after a while? |
Author: | tianxiao [ Wed Dec 24, 2008 12:10 am ] |
Post subject: | why is program working weird after a while? |
my game is only starting to take shape. But when my 2 clouds shoot lightning, they were fine at the beginning (they shoot at where they stops) but then after about 2 minutes the lightning sprites begin to appear everywhere. What's happening? how can this be improved? Sample of program: %FINAL PROJECT var gCloudY : int var gCloudX : int var groundh : int %Main Menu var win : int win := Window.Open ("title:DISASTER;position:center;middle;nocursor;noecho;graphics:716,700") %FONTS var font1 : int font1 := Font.New ("Comic Sans MS:18x12: bold") %Sprites: Sand var sand1, sand2, sand3, sand4 : int sand1 := Sprite.New (Pic.FileNew ("sand1.bmp")) sand2 := Sprite.New (Pic.FileNew ("sand2.bmp")) sand3 := Sprite.New (Pic.FileNew ("sand3.bmp")) sand4 := Sprite.New (Pic.FileNew ("sand4.bmp")) %Sprites: Fire var fire1, fire2, fire3, fire4 : int fire1 := Sprite.New (Pic.FileNew ("fire1.bmp")) fire2 := Sprite.New (Pic.FileNew ("fire2.bmp")) fire3 := Sprite.New (Pic.FileNew ("fire3.bmp")) fire4 := Sprite.New (Pic.FileNew ("fire4.bmp")) %Sprites: Block %Sprite: Meteor var meteor : int meteor := Sprite.New (Pic.FileNew ("meteor11.bmp")) %Sprite: Cloud var cloud : int cloud := Sprite.New (Pic.FileNew ("cloud.bmp")) %Sprite: Lightning var lightning1, lightning2, lightning3, lightning4, lightning5 : int var lightning6, lightning7, lightning8 : int lightning1 := Sprite.New (Pic.FileNew ("lightning1.bmp")) lightning2 := Sprite.New (Pic.FileNew ("lightning2.bmp")) lightning3 := Sprite.New (Pic.FileNew ("lightning3.bmp")) lightning4 := Sprite.New (Pic.FileNew ("lightning4.bmp")) lightning5 := Sprite.New (Pic.FileNew ("lightning5.bmp")) lightning6 := Sprite.New (Pic.FileNew ("lightning6.bmp")) lightning7 := Sprite.New (Pic.FileNew ("lightning7.bmp")) lightning8 := Sprite.New (Pic.FileNew ("lightning8.bmp")) process sand var sand1, sand2, sand3, sand4 : int sand1 := Sprite.New (Pic.FileNew ("sand1.bmp")) sand2 := Sprite.New (Pic.FileNew ("sand2.bmp")) sand3 := Sprite.New (Pic.FileNew ("sand3.bmp")) sand4 := Sprite.New (Pic.FileNew ("sand4.bmp")) var sandx, sandy : int var num, maxnum : int sandy := 100 maxnum := 100 randomize loop num := Rand.Int (1, maxnum) sandx := Rand.Int (0, 680) if (num = 8) then Sprite.SetPosition (sand1, sandx, sandy, false) Sprite.Show (sand1) delay (100) Sprite.Hide (sand1) Sprite.SetPosition (sand2, sandx, sandy, false) Sprite.Show (sand2) delay (100) Sprite.Hide (sand2) Sprite.SetPosition (sand3, sandx, sandy, false) Sprite.Show (sand3) delay (100) Sprite.Hide (sand3) Sprite.SetPosition (sand4, sandx, sandy, false) Sprite.Show (sand4) delay (2000) Sprite.Hide (sand4) end if end loop end sand randomize process cloudright var cloud : int cloud := Sprite.New (Pic.FileNew ("cloud.bmp")) var CloudY : int loop CloudY := groundh + 282 for CloudX : -170 .. 1240 by 1 Sprite.SetPosition (cloud, CloudX, CloudY, false) Sprite.Show (cloud) delay (8) Sprite.Hide (cloud) end for end loop end cloudright process lightning var lightning1, lightning2, lightning3, lightning4, lightning5 : int var lightning6, lightning7, lightning8 : int lightning1 := Sprite.New (Pic.FileNew ("lightning1.bmp")) lightning2 := Sprite.New (Pic.FileNew ("lightning2.bmp")) lightning3 := Sprite.New (Pic.FileNew ("lightning3.bmp")) lightning4 := Sprite.New (Pic.FileNew ("lightning4.bmp")) lightning5 := Sprite.New (Pic.FileNew ("lightning5.bmp")) lightning6 := Sprite.New (Pic.FileNew ("lightning6.bmp")) lightning7 := Sprite.New (Pic.FileNew ("lightning7.bmp")) lightning8 := Sprite.New (Pic.FileNew ("lightning8.bmp")) Sprite.SetPosition (lightning1, gCloudX, gCloudY - 10, false) Sprite.Show (lightning1) delay (20) Sprite.Hide (lightning1) Sprite.SetPosition (lightning2, gCloudX, gCloudY - 78, false) Sprite.Show (lightning2) delay (20) Sprite.Hide (lightning2) Sprite.SetPosition (lightning3, gCloudX, gCloudY - 92, false) Sprite.Show (lightning3) delay (20) Sprite.Hide (lightning3) Sprite.SetPosition (lightning4, gCloudX, gCloudY - 132, false) Sprite.Show (lightning4) delay (20) Sprite.Hide (lightning4) Sprite.SetPosition (lightning5, gCloudX, gCloudY - 162, false) Sprite.Show (lightning5) delay (20) Sprite.Hide (lightning5) Sprite.SetPosition (lightning6, gCloudX, gCloudY - 186, false) Sprite.Show (lightning6) delay (20) Sprite.Hide (lightning6) Sprite.SetPosition (lightning7, gCloudX, gCloudY - 218, false) Sprite.Show (lightning7) delay (40) Sprite.Hide (lightning7) Sprite.SetPosition (lightning8, gCloudX, gCloudY - 214, false) Sprite.Show (lightning8) delay (40) Sprite.Hide (lightning8) end lightning process CLOUDLEFT var cloud : int cloud := Sprite.New (Pic.FileNew ("cloud.bmp")) var CloudY : int var num1 : int var guess : int loop CloudY := groundh + 242 gCloudY := CloudY guess := Rand.Int (1, 2) num1 := Rand.Int (1, 1000) if (guess = 1) then for decreasing CloudX : 1240 .. num1 by 1 gCloudX := num1 Sprite.SetPosition (cloud, CloudX, CloudY, false) Sprite.Show (cloud) delay (8) Sprite.Hide (cloud) end for Sprite.SetPosition (cloud, num1, CloudY, false) Sprite.Show (cloud) delay (1000) Sprite.Hide (cloud) fork lightning Sprite.SetPosition (cloud, num1, CloudY, false) Sprite.Show (cloud) delay (1000) Sprite.Hide (cloud) else for decreasing CloudX : 1240 .. -300 by 1 Sprite.SetPosition (cloud, CloudX, CloudY, false) Sprite.Show (cloud) delay (8) Sprite.Hide (cloud) end for end if end loop end CLOUDLEFT process CLOUDRIGHT var cloud : int cloud := Sprite.New (Pic.FileNew ("cloud.bmp")) var CloudY : int var num : int var guess : int loop CloudY := groundh + 242 gCloudY := CloudY guess := Rand.Int (1, 2) num := Rand.Int (1, 1000) if (guess = 1) then for CloudX : -300 .. num by 1 gCloudX := num Sprite.SetPosition (cloud, CloudX, CloudY, false) Sprite.Show (cloud) delay (8) Sprite.Hide (cloud) end for Sprite.SetPosition (cloud, num, CloudY, false) Sprite.Show (cloud) delay (1000) Sprite.Hide (cloud) fork lightning Sprite.SetPosition (cloud, num, CloudY, false) Sprite.Show (cloud) delay (1000) Sprite.Hide (cloud) else for CloudX : -300 .. 1240 by 1 Sprite.SetPosition (cloud, CloudX, CloudY, false) Sprite.Show (cloud) delay (8) Sprite.Hide (cloud) end for end if end loop end CLOUDRIGHT %77 %161 procedure moon var groundheight : int groundheight := 77 groundh := groundheight var moonmx, moonmy, moonmb : int win := Window.Open ("title:Moon;position:center;middle;nocursor;noecho;graphics:1238,660") Pic.ScreenLoad ("moon.jpg", 0, 0, picMerge) fork sand fork CLOUDRIGHT fork CLOUDLEFT delay (1000000) Window.Close (win) end moon var ngamex, ngamey : int ngamex := 100 ngamey := 500 var insx, insy : int insx := 100 insy := 430 var optx, opty : int optx := 100 opty := 360 Font.Draw ("New Game", ngamex, ngamey, font1, red) Font.Draw ("Instructions", insx, insy, font1, red) Font.Draw ("Options", optx, opty, font1, red) var mousex, mousey, mouseb : int loop Mouse.Where (mousex, mousey, mouseb) %if mouse is over New Game if (mousex >= ngamex - 4 and mousex <= ngamex + 170) and (mousey >= ngamey - 5 and mousey <= ngamey + 22) then Font.Draw ("New Game", ngamex, ngamey, font1, blue) if (mouseb = 1) then moon end if %if mouse is over Instructions elsif (mousex >= insx - 5 and mousex <= insx + 192) and (mousey >= insy - 6 and mousey <= insy + 23) then Font.Draw ("Instructions", insx, insy, font1, blue) if (mouseb = 1) then end if %if mouse is over Options elsif (mousex >= optx - 4 and mousex <= optx + 120) and (mousey >= opty - 10 and mousey <= opty + 20) then Font.Draw ("Options", optx, opty, font1, blue) if (mouseb = 1) then moon end if else Font.Draw ("New Game", ngamex, ngamey, font1, red) Font.Draw ("Instructions", insx, insy, font1, red) Font.Draw ("Options", optx, opty, font1, red) end if end loop |
Author: | revangrey [ Wed Dec 24, 2008 12:22 am ] |
Post subject: | Re: why is program working weird after a while? |
just before someone else mentions it... I don't think anyone can check your program if they don't have those pictures downloaded. and someone will probably tell you to use code tags/syntax tags [syntax="programming language"] insert code here [/syntax] or code tags |
Author: | tianxiao [ Wed Dec 24, 2008 12:40 am ] |
Post subject: | Re: why is program working weird after a while? |
Here are the attachments. i used bmps because i didn't wanna ruin the picture quality. Everything's in there. I fixed it a bit so only the parts i need help with ares uncommented. And please explain to me what you're saying. I just started this year with programming in grade 10 so i don't know much about it. |
Author: | DemonWasp [ Wed Dec 24, 2008 1:39 am ] |
Post subject: | RE:why is program working weird after a while? |
Not that it's a particular issue with your 250KB fileset, but you can safely encode pictures as PNG without losing image quality. I'm not sure whether Turing loads them offhand. |
Author: | sliverofshadows475 [ Wed Dec 24, 2008 9:33 am ] |
Post subject: | Re: why is program working weird after a while? |
Oh, and just a reminder, please read the: "Announcement: Please do NOT post "I need help" titles" post. It just explains that its much easier to help you if you tell what you need help with in the title. It also helps for people searching up the certain problems. so they don't have to look through every search item to find what they need. |
Author: | Insectoid [ Wed Dec 24, 2008 10:36 am ] |
Post subject: | RE:why is program working weird after a while? |
First of all, you're using processes. They are only good for music and situations where you are simulating things happening at the same time with no control over each other that the 'main' program must handle, the latter never being used in Turing. My guess is that the processes are falling out of sync and then it screws up. Look up procedures and how to use them in a main loop. It is far more reliable and efficient. |
Author: | tianxiao [ Wed Dec 24, 2008 10:37 am ] |
Post subject: | Re: why is program working weird after a while? |
well i need to have 2 animations running at the same time. How can i use procedure? |
Author: | Insectoid [ Wed Dec 24, 2008 10:44 am ] | ||
Post subject: | RE:why is program working weird after a while? | ||
You have them both in the same loop. One delay. The first one moves, the second one moves, View.Update, end loop. Do NOT have both animations in individual loops. For example, to move a ball right and a box up,
|
Author: | tianxiao [ Wed Dec 24, 2008 10:52 am ] |
Post subject: | Re: why is program working weird after a while? |
sorry i'm new to this... i kinda get that, what's the += and how exactly can i put the two processes in one loop?! and i have one more process (lightning shooting) that gets called on in each of the process..... |
Author: | Insectoid [ Wed Dec 24, 2008 11:02 am ] | ||
Post subject: | RE:why is program working weird after a while? | ||
ovalX += 1 is the same as ovalX := ovalX+1. Just easier to write. So make lightning its own procedure and call it from the other 2.
|
Author: | tianxiao [ Wed Dec 24, 2008 11:27 am ] |
Post subject: | Re: why is program working weird after a while? |
i did what you told me to but it's not working. clouds aren't appearing. i sent an attachment. Can you try to correct in there? i can't get it to work for some reason. |
Author: | Insectoid [ Wed Dec 24, 2008 11:30 am ] |
Post subject: | RE:why is program working weird after a while? |
I have given you a template; it's up to you to figure out the rest. That is what programming is about. Solving problems. The only other thing I can do is point you to the Turing Walkthrough. |