Posted October 10, 2013 So far all I have in the game is a moving character and it being able to shoot, but the problem is that it doesn't shoot from the actual ship or that it follows where the ship is after it has been shot. Here is the code where it follows the ship : View.Set ("graphics:640;480")var padding : int := 10var x : int := maxx div 2var y : int := 0var speed : int := 1var size : int := 10var fire : boolean := falsevar firey : int := sizevar firespeed : int := 1var firesize : int := 3var control : array char of booleanloop Input.KeyDown (control) if control (KEY_LEFT_ARROW) and x >= padding then x -= speed end if if control (KEY_RIGHT_ARROW) and x <= maxx - size - padding then x += speed end if if control (chr (32)) then fire := true end if if fire = true then firey += firespeed Draw.Box (x, firey, x + firesize, firey + firesize, black) if firey >= maxy then fire := false firey := y end if end if Draw.Box (x, y, x + size, y + size, black) /*put "padding = ", padding put "x = ", x put "y = ", y put "speed = ", speed put "size = ", size put "fire = ", fire put "firex = ", firex put "firey = ", firey put "firespeed = ", firespeed put "firesize = ", firesize */ delay (10) clsend loop Here is the code where it isn't shot from the ship (minor difference is that I changed firex to just use x and vice versa) View.Set ("graphics:640;480")var padding : int := 10var x : int := maxx div 2var y : int := 0var speed : int := 1var size : int := 10var fire : boolean := falsevar firex : int := xvar firey : int := sizevar firespeed : int := 1var firesize : int := 3var control : array char of booleanloop Input.KeyDown (control) if control (KEY_LEFT_ARROW) and x >= padding then x -= speed end if if control (KEY_RIGHT_ARROW) and x <= maxx - size - padding then x += speed end if if control (chr (32)) then fire := true end if if fire = true then firey += firespeed Draw.Box (firex, firey, firex + firesize, firey + firesize, black) if firey >= maxy then fire := false firey := y end if end if Draw.Box (x, y, x + size, y + size, black) /*put "padding = ", padding put "x = ", x put "y = ", y put "speed = ", speed put "size = ", size put "fire = ", fire put "firex = ", firex put "firey = ", firey put "firespeed = ", firespeed put "firesize = ", firesize */ delay (10) clsend loop need help please! turing download if you need it: compsci.ca/holtsoft/Turing%204.1.1.zip Link to comment Share on other sites More sharing options... Link to post Share on other sites More sharing options...
Posted October 10, 2013 Oh god, I remember the days of ICS3U1. I'll help in whatever way I can. I may have forgotten a bit of turing. “The value of a college education is not the learning of many facts but the training of the mind to think” Link to comment Share on other sites More sharing options... Link to post Share on other sites More sharing options...
Posted October 10, 2013 Author Oh god, I remember the days of ICS3U1. I'll help in whatever way I can. I may have forgotten a bit of turing. Thanks, I could help with the syntax. I'm not sure if there's something like getCurrX value of something like that... Link to comment Share on other sites More sharing options... Link to post Share on other sites More sharing options...
Posted October 10, 2013 Thanks, I could help with the syntax When's it due? It might take some time cause I spent like 2 months of a semester learning it with a final project like yours. Our teacher just used it as a bridge to visual basic cause apparently it was taught in gr10 programming but I didn't take that. Nevermind, dumb question lol. It's a long weekend, I forgot. “The value of a college education is not the learning of many facts but the training of the mind to think” Link to comment Share on other sites More sharing options... Link to post Share on other sites More sharing options...
Posted October 10, 2013 K so I just tested the code. I got a quick fix atm. If space fires the missile, then why don't you set 2 variables. When the spacebar is down, the missile uses the position of the ship. That position gets sent to the 2nd variable. Once the spacebar is up, then the missile's gets the position from the 2nd variable. “The value of a college education is not the learning of many facts but the training of the mind to think” Link to comment Share on other sites More sharing options... Link to post Share on other sites More sharing options...
Posted October 10, 2013 View.Set ("graphics:640;480")var padding : int := 10var x : int := maxx div 2var xinitial : int := xvar y : int := 0var speed : int := 1var size : int := 10var fire : boolean := falsevar firey : int := sizevar firespeed : int := 1var firesize : int := 3var control : array char of booleanloop Input.KeyDown (control) if control (KEY_LEFT_ARROW) and x >= padding then x -= speed end if if control (KEY_RIGHT_ARROW) and x <= maxx - size - padding then x += speed end if if control (chr (32)) then fire := true xinitial := x end if if fire = true then firey += firespeed Draw.Box (xinitial, firey, xinitial + firesize, firey + firesize, black) if firey >= maxy then fire := false firey := y end if end if Draw.Box (x, y, x + size, y + size, black) /*put "padding = ", padding put "x = ", x put "y = ", y put "speed = ", speed put "size = ", size put "fire = ", fire put "firex = ", firex put "firey = ", firey put "firespeed = ", firespeed put "firesize = ", firesize */ delay (10) clsend loop if control (chr (32)) thenfire := truexinitial := xend ifif fire = true thenfirey += firespeedDraw.Box (xinitial, firey, xinitial + firesize, firey + firesize, black)if firey >= maxy thenfire := falsefirey := yend ifend if “The value of a college education is not the learning of many facts but the training of the mind to think” Link to comment Share on other sites More sharing options... Link to post Share on other sites More sharing options...
Posted October 10, 2013 Author K so I just tested the code. I got a quick fix atm. If space fires the missile, then why don't you set 2 variables. When the spacebar is down, the missile uses the position of the ship. That position gets sent to the 2nd variable. Once the spacebar is up, then the missile's gets the position from the 2nd variable. sorry, I'm not very good at interpreting these kind of things can you show me? Thanks Link to comment Share on other sites More sharing options... Link to post Share on other sites More sharing options...
Posted October 10, 2013 View.Set ("graphics:640;480")var padding : int := 10var x : int := maxx div 2var xinitial : int := xvar y : int := 0var speed : int := 1var size : int := 10var fire : boolean := falsevar firey : int := sizevar firespeed : int := 1var firesize : int := 3var control : array char of booleanloop Input.KeyDown (control) if control (KEY_LEFT_ARROW) and x >= padding then x -= speed end if if control (KEY_RIGHT_ARROW) and x <= maxx - size - padding then x += speed end if if fire = false then if control (chr (32)) then fire := true xinitial := x end if end if if fire = true then firey += firespeed Draw.Box (xinitial, firey, xinitial + firesize, firey + firesize, black) if firey >= maxy then fire := false firey := y end if end if Draw.Box (x, y, x + size, y + size, black) /*put "padding = ", padding put "x = ", x put "y = ", y put "speed = ", speed put "size = ", size put "fire = ", fire put "firex = ", firex put "firey = ", firey put "firespeed = ", firespeed put "firesize = ", firesize */ delay (10) clsend loop Added a check for if there's still a thing fired so it doesn't just reset it's position if you press space again. if fire = false then if control (chr (32)) then fire := true xinitial := x end if end if “The value of a college education is not the learning of many facts but the training of the mind to think” Link to comment Share on other sites More sharing options... Link to post Share on other sites More sharing options...
Posted October 10, 2013 @T.Vengeance is right....although just thinking his code could have a tweak to it to make it so holding space wont cause the bullet to follow the ship (try holding space ) (I just used your second posted code instead of T.Vengeance, but only because I copied the wrong one initially (I used != don't know if that is the correct syntax, but just one added if statement from Vengeance's version) View.Set ("graphics:640;480")var padding : int := 10var x : int := maxx div 2var y : int := 0var speed : int := 1var size : int := 10var fire : boolean := falsevar firex : int := xvar firey : int := sizevar firespeed : int := 1var firesize : int := 3var control : array char of booleanloop Input.KeyDown (control) if control (KEY_LEFT_ARROW) and x >= padding then x -= speed end if if control (KEY_RIGHT_ARROW) and x <= maxx - size - padding then x += speed end if if control (chr (32)) then if fire != true then firex := x end if fire := true end if if fire = true then firey += firespeed Draw.Box (firex, firey, firex + firesize, firey + firesize, black) if firey >= maxy then fire := false firey := y end if end if Draw.Box (x, y, x + size, y + size, black) /*put "padding = ", padding put "x = ", x put "y = ", y put "speed = ", speed put "size = ", size put "fire = ", fire put "firex = ", firex put "firey = ", firey put "firespeed = ", firespeed put "firesize = ", firesize */ delay (10) clsend loop 0b10111010 10101101 11110000 00001101 Link to comment Share on other sites More sharing options... Link to post Share on other sites More sharing options...
Posted October 10, 2013 @T.Vengeance is right....although just thinking his code could have a tweak to it to make it so holding space wont cause the bullet to follow the ship (try holding space ) (I just used your second posted code instead of T.Vengeance, but only because I copied the wrong one initially (I used != don't know if that is the correct syntax, but just one added if statement from Vengeance's version) Yeah I added a fix after that. I didn't realize that it would reset until after I posted the first code. “The value of a college education is not the learning of many facts but the training of the mind to think” Link to comment Share on other sites More sharing options... Link to post Share on other sites More sharing options...
Posted October 10, 2013 sorry, I'm not very good at interpreting these kind of things can you show me? Thanks No problem “The value of a college education is not the learning of many facts but the training of the mind to think” Link to comment Share on other sites More sharing options... Link to post Share on other sites More sharing options...
Posted October 10, 2013 Author @T.Vengeance is right....although just thinking his code could have a tweak to it to make it so holding space wont cause the bullet to follow the ship (try holding space ) (I just used your second posted code instead of T.Vengeance, but only because I copied the wrong one initially (I used != don't know if that is the correct syntax, but just one added if statement from Vengeance's version)*snip* Added a check for if there's still a thing fired so it doesn't just reset it's position if you press space again. thanks I think it works properly now! I will try to add aliens and their collision detection with the ship and the bullets tonight unless i have hockey Link to comment Share on other sites More sharing options... Link to post Share on other sites More sharing options...
Posted October 11, 2013 Author @T.Vengeance @WanderingFool I just realized that I have no idea how to make an array been avoiding them at all costs I don't want to make eash individual enemy/alien and I'm sure I would want to use an array or something for that... I guess i'll just work on the barriers until i get a response here or find something on the internet about arrays and such... sorry for being so helpless, I'm just a noob Link to comment Share on other sites More sharing options... Link to post Share on other sites More sharing options...
Posted October 11, 2013 @T.Vengeance @WanderingFool I just realized that I have no idea how to make an array been avoiding them at all costs I don't want to make eash individual enemy/alien and I'm sure I would want to use an array or something for that... I guess i'll just work on the barriers until i get a response here or find something on the internet about arrays and such... sorry for being so helpless, I'm just a noob It's alright. I first learnt arrays in VB, trust me, they're so freaking useful. I used it for my summative project to create a destructible ground for a tanks game. To be honest though, I think making one for each alien is less time consuming compared to an array, though I could be wrong. I don't know how arrays work in Turing. (I seemed to have forgot how it looks like . I didn't realize there were so many aliens) http://compsci.ca/v3/viewtopic.php?t=14333 If you haven't seen that, which I'm sure you have, then that's a good place to start. “The value of a college education is not the learning of many facts but the training of the mind to think” Link to comment Share on other sites More sharing options... Link to post Share on other sites More sharing options...
Posted October 11, 2013 @prolemur cause I was bored, I rewrote your firing code using arrays so you can fire more than once . Hope this example of how arrays are used helps with your aliens. View.Set ("graphics:640;480")var padding : int := 10var x : int := maxx div 2var y : int := 0var speed : int := 1var size : int := 10var fire : boolean := falsevar firey : int := sizevar firespeed : int := 1var firesize : int := 3var firerate : real := 1var control : array char of booleanvar pos_array_x : array 0 .. 30 of intvar pos_array_y : array 0 .. 30 of intvar pos_array_size : int := -1var time_after_shot : real := 0for i : 0..30 pos_array_y(i) := 0 pos_array_x(i) := 0end forloop Input.KeyDown (control) if control (KEY_LEFT_ARROW) and x >= padding then x -= speed end if if control (KEY_RIGHT_ARROW) and x <= maxx - size - padding then x += speed end if if control (chr (32)) and fire = false then fire := true pos_array_size += 1 pos_array_x(pos_array_size) := x pos_array_y(pos_array_size) := 1 end if for i : 0..pos_array_size Draw.Box(pos_array_x(i), pos_array_y(i), pos_array_x(i)+firesize, pos_array_y(i)+firesize, black) if pos_array_y(i) >= 1 then pos_array_y(i) += 1 end if end for for i : 0 ..pos_array_size if pos_array_y(i) > maxy then for a : 0 .. pos_array_size - i pos_array_y(i+a) := pos_array_y(i+a+1) pos_array_x(i+a) := pos_array_x(i+a+1) end for pos_array_size -=1 end if end for if fire = true then time_after_shot += 0.01 end if if time_after_shot >= firerate then fire := false time_after_shot := 0 end if Draw.Box (x, y, x + size, y + size, black) /*put "padding = ", padding put "x = ", x put "y = ", y put "speed = ", speed put "size = ", size put "fire = ", fire put "firex = ", firex put "firey = ", firey put "firespeed = ", firespeed put "firesize = ", firesize */ delay (10) clsend loopTell me if you need some explaining and I'll insert some comments in there. “The value of a college education is not the learning of many facts but the training of the mind to think” Link to comment Share on other sites More sharing options... Link to post Share on other sites More sharing options...
Posted October 11, 2013 Author All I added were barriers, I felt pretty lazy today and couldn't take on that massive array tutorial you linked slowly but surely * the variables will be tinkered with such as speeds, sizes, delay and what not btw View.Set ("graphics:640;480")var padding : int := 10var x : int := maxx div 2var y : int := paddingvar speed : int := 1var size : int := 10var fire : boolean := falsevar firex : int := 0var firey : int := padding + sizevar firespeed : int := 1var firesize : int := 3var barrier1 : boolean := truevar barrier2 : boolean := truevar barrier3 : boolean := truevar barrier1x : int := 100var barrier2x : int := 290var barrier3x : int := 480var barriery : int := 60var barrierxsize : int := 60var barrierysize : int := 10var control : array char of booleanloop Input.KeyDown (control) if control (KEY_LEFT_ARROW) and x >= padding then x -= speed end if if control (KEY_RIGHT_ARROW) and x <= maxx - size - padding then x += speed end if if fire = true then firey += firespeed Draw.FillBox (firex, firey, firex + firesize, firey + firesize, white) if firey >= maxy then fire := false firey := y + size end if end if if fire = false then if control (chr (32)) then fire := true firex := x end if end if if firex >= barrier1x and firex < barrier1x + barrierxsize and firey + firesize = barriery and barrier1 = true then barrier1 := false fire := false firey := y + size end if if firex >= barrier2x and firex < barrier2x + barrierxsize and firey + firesize = barriery and barrier2 = true then barrier2 := false fire := false firey := y + size end if if firex >= barrier3x and firex < barrier3x + barrierxsize and firey + firesize = barriery and barrier3 = true then barrier3 := false fire := false firey := y + size end if Draw.Box (x, y, x + size, y + size, white) if barrier1 = true then Draw.Box (barrier1x, barriery, barrier1x + barrierxsize, barriery + barrierysize, white) end if if barrier2 = true then Draw.Box (barrier2x, barriery, barrier2x + barrierxsize, barriery + barrierysize, white) end if if barrier3 = true then Draw.Box (barrier3x, barriery, barrier3x + barrierxsize, barriery + barrierysize, white) end if colorback (black) delay (10) clsend loop Link to comment Share on other sites More sharing options... Link to post Share on other sites More sharing options...
Posted October 11, 2013 All I added were barriers, I felt pretty lazy today and couldn't take on that massive array tutorial you linked slowly but surely * the variables will be tinkered with such as speeds, sizes, delay and what not btw Well here's a quick crash course on arrays. Imagine arrays as like a bookshelf in a library with indexes. Each index represents a spot for books to be in. Those books store information. Since an array is also a variable, you can declare an array and call up the data you want within the array with it's indexes. So if I wanted to get a value stored in the 4th index, I'd say: variable1 := array(4) The same can be said when you want to store information in a certain index, like index 4. array(4) := variable1 So you can expand on this and input all the position of the all the bullets into their respective x and y position arrays, you call them up using a for loop and draw each box. /* If space = true then array size grows by 1, add new x/y value to new/next array index*/if control (chr (32)) and fire = false then fire := true pos_array_size += 1 pos_array_x(pos_array_size) := x pos_array_y(pos_array_size) := 1end if/* Using i for the array index, the box draws based on the x/y-value of each index until the final index (aka array size) */ for i : 0..pos_array_size Draw.Box(pos_array_x(i), pos_array_y(i), pos_array_x(i)+firesize, pos_array_y(i)+firesize, black) if pos_array_y(i) >= 1 then /* I use the value 1 to indicate that there's a bullet in that index. So if there is one, advance the y-position by 1*/ pos_array_y(i) += 1 end ifend for/* There can only be so many bullets on the screen, defined by the array size (0-30, therefore 31 bullets). Therefore, once the y-values reaches y-maxI find which index it's in using the for loop and delete it by shifting each index after it, down by 1. Ex. array(2) = array(3), array(3) = array(4) */ for i : 0 ..pos_array_size if pos_array_y(i) > maxy then for a : 0 .. pos_array_size - i pos_array_y(i+a) := pos_array_y(i+a+1) pos_array_x(i+a) := pos_array_x(i+a+1) end for pos_array_size -=1 /*Since there's now one less bullet, the array size needs to decrease by 1*/ end ifend for “The value of a college education is not the learning of many facts but the training of the mind to think” Link to comment Share on other sites More sharing options... Link to post Share on other sites More sharing options...
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now