Computer Science Canada More than just 1 appear, and not all dispear after maxy |
Author: | amz_best [ Fri Sep 05, 2014 10:58 am ] | ||
Post subject: | More than just 1 appear, and not all dispear after maxy | ||
What is it you are trying to achieve? im trying to shoot bullets (more than 1 on screen), and i want each seperate bullet to disapear when they reach maxy What is the problem you are having? a) only one bullet will show up b) if i do figure out how to add moar bullets, i expect they will all dispear when only 1 reaches maxy, any way to prevent? Describe what you have tried to solve this problem boolean and int values to see if anything would change Post any relevant code (You may choose to attach the file instead of posting the code if it is too long) unfortunately, i cant attach files so here is my code...
Please specify what version of Turing you are using http://tristan.hume.ca/openturing/ |
Author: | Zren [ Fri Sep 05, 2014 3:58 pm ] | ||||
Post subject: | RE:More than just 1 appear, and not all dispear after maxy | ||||
Quote: const NoOfFlakes := 400
Ha. Someone found the compsci snowflake particle engine "contest" thread. Since Turing has doesn't have any simple tools to add/remove items from an array, use a fixed sized array, along with another variable to represent the current index. The mod operator is used to wrap around to 0.. Eg:
Also, records are awesome. They allow you to bundle variables together as a new data type, which allows you to create an array of "a thing with lots of variables" much easier. Incomplete Example
|
Author: | amz_best [ Fri Sep 05, 2014 4:57 pm ] |
Post subject: | Re: More than just 1 appear, and not all dispear after maxy |
Wow, that seems really cool only, i dont undetstand it xD ik wat an array is, but i dont understand any of the code u wrote xD. im still new to turing and i hope u could explain dis 2 me more thourouly |
Author: | Zren [ Fri Sep 05, 2014 5:18 pm ] | ||
Post subject: | RE:More than just 1 appear, and not all dispear after maxy | ||
Thought as much. Here's a simplier example. Press space to "Fire Bullets"
Note how we cycle a limited number of "bullets". The key is to make the array larger than the maximum number of bullets you'd ever need on the screen. 1. Make the bulletY(i) value increment every frame. 2. Make the bulletY(i) value increment every frame only if bulletVisible(i) is true. 3. Set bulletVisible(currentBulletIndex) to true when pressing the shoot key. 4. Set bulletVisible(i) to false when bulletY(i) is "off the screen". |
Author: | amz_best [ Fri Sep 05, 2014 6:09 pm ] |
Post subject: | RE:More than just 1 appear, and not all dispear after maxy |
wow that is amazing. i can see wat u did and it makes so much moar sense! i got how it works and i typed it out already! except now i dunno how to add the photos when you press space or how 2 make them go up in their sepetrately xD |
Author: | Zren [ Fri Sep 05, 2014 6:16 pm ] |
Post subject: | RE:More than just 1 appear, and not all dispear after maxy |
Quote: them go up in their sepetrately
What's your code? More steps: 5. Load Bullet Picture. Only use one picture for all bullets, as we can redraw it multiple times. 6. Add a bulletX array. 7. For each bullet the arrays, draw the bullet picture at ( bulletX(i), bulletY(i) ). 8. Only draw a bullet if bulletVisible(i) is true. |
Author: | amz_best [ Fri Sep 05, 2014 6:27 pm ] | ||
Post subject: | Re: More than just 1 appear, and not all dispear after maxy | ||
Everytime i run it, it says argument is wrong type, is it becuz im using real numbers?
|
Author: | Zren [ Fri Sep 05, 2014 6:34 pm ] | ||||||||||
Post subject: | RE:More than just 1 appear, and not all dispear after maxy | ||||||||||
It's because of this code from my first example.
Because you're calling
When the function is define as
Don't use any of the code from my first example as it's incompatible with the code from the second one, as I removed a number of techniques to simplify it. Since I don't think you understand procedures/functions very well, don't use them. Instead of:
Just do
|
Author: | Zren [ Fri Sep 05, 2014 6:37 pm ] |
Post subject: | RE:More than just 1 appear, and not all dispear after maxy |
By the way. Press the indent button (often) in Turings menu bar. |
Author: | amz_best [ Fri Sep 05, 2014 7:01 pm ] |
Post subject: | RE:More than just 1 appear, and not all dispear after maxy |
alrite, on the line u gave me, "if bulletVisible(i) then" it says variable has no value. im sorry if u r fustrated in me... |
Author: | Zren [ Fri Sep 05, 2014 7:06 pm ] | ||||||||
Post subject: | RE:More than just 1 appear, and not all dispear after maxy | ||||||||
Yeeeeeep. You really don' understand functions/procedures. xD You'll probably learn about them in the next few weeks. Basically the code wasn't being run.
As you never called the procedure like so:
Just move the code out of the procedure. Eg:
to
Sorry for teasing you with so many advanced concepts when your still on your first week. |
Author: | amz_best [ Fri Sep 05, 2014 7:12 pm ] |
Post subject: | RE:More than just 1 appear, and not all dispear after maxy |
As soon as i saw initialize(), i went back into my code and saw that its not initialized before the loop, so i simply added initialize() and now its working fine, but bullets dont appear when i press space. |
Author: | Zren [ Fri Sep 05, 2014 7:20 pm ] | ||
Post subject: | RE:More than just 1 appear, and not all dispear after maxy | ||
Where exactly are you drawing the bullets? I wrote
Might as well post your code again, this time make sure to click this button first. |
Author: | amz_best [ Fri Sep 05, 2014 7:22 pm ] | ||
Post subject: | Re: More than just 1 appear, and not all dispear after maxy | ||
|
Author: | Zren [ Fri Sep 05, 2014 7:34 pm ] | ||
Post subject: | RE:More than just 1 appear, and not all dispear after maxy | ||
Why are you using the x, and y variable in
? As far as I can guess, x and y refer to the shipX, and shipY? Write variable names that are more descriptive. What was the point of the bulletX and bulletY arrays? They are used to represent where all your bullets are. |
Author: | amz_best [ Fri Sep 05, 2014 7:37 pm ] |
Post subject: | RE:More than just 1 appear, and not all dispear after maxy |
Pic.Draw (bullet, bulletX (i), bulletY (i), picCopy) It loads game but... still no bullet appear, it always did apear before when only 1 bullet shot xD |
Author: | Zren [ Fri Sep 05, 2014 7:56 pm ] | ||||||||||||
Post subject: | RE:More than just 1 appear, and not all dispear after maxy | ||||||||||||
You've got a lot of other code in there (that you copy pasted) so I don't think you fully understand what they do. So let's start from scratch, and only get the bullets working. Game Loop
1 Bullet
10 Bullets (overlaping)
Ship
Basic Input. Move the ship
Homework: 1) Have bullets move upward every frame. 2) Move 1 bullet back to (shipX, shipY) when space is pressed. DO NOT try to copy paste this into your own code until you fully understand it.
|
Author: | amz_best [ Fri Sep 05, 2014 8:32 pm ] |
Post subject: | Re: More than just 1 appear, and not all dispear after maxy |
ok, i will be back in like 2 days with my homework complete xD |
Author: | amz_best [ Sun Sep 07, 2014 12:18 pm ] | ||
Post subject: | Re: More than just 1 appear, and not all dispear after maxy | ||
HOMEWORK COMPLETE! but now, we have a glitch :s everytime a shoot from what looks like y=0..50 the bullet just stays there, on the bottom of the screen... and not move.... wat do i do?
oh, and i also did a bit organizing |
Author: | amz_best [ Sun Sep 07, 2014 12:28 pm ] |
Post subject: | RE:More than just 1 appear, and not all dispear after maxy |
for a temp fix, i simply added %SHOOT BULLET %-------------------------------------------------- if controls (chr (32)) and fire = false then fire := true pos_array_size += 1 bulletX(pos_array_size) := shipX + 30 bulletY(pos_array_size) := shipY end if %-------------------------------------------------- tooo: %SHOOT BULLET %-------------------------------------------------- if controls (chr (32)) and fire = false then fire := true pos_array_size += 1 bulletX(pos_array_size) := shipX + 30 bulletY(pos_array_size) := shipY + 50 end if %-------------------------------------------------- |