Computer Science Canada Control Problems via Input.KeyDown () |
Author: | Flashkicks [ Fri May 13, 2005 12:00 pm ] | ||
Post subject: | Control Problems via Input.KeyDown () | ||
Hay hay ppl'z! This is Flashkicks here! I am just trying to make simple asteroids game and its been awhile. I was just seeing if anyone can remember or tell me how to have two things going at one withOUT using a process. Example, have my spaceship move, while shooting lasers at the same time. Here's the code.
So run it and you will see once you shoot- you can not move. And I've made a game like this before so i KNOW its possible. Good Luck-and have fun! ~Flashkicks |
Author: | Dylan-182 [ Fri May 13, 2005 12:07 pm ] |
Post subject: | |
i tried it and its coolness i have no idea how 2 help u with it but so far its cool i think im guna look at the code n figure out how 2 do this for myself then maybe go on 2 make a cool game of my own... lol ne ways sry i culdnt help but at least i got 2 see that this sorta thing is possible with turing, gives me sumthin 2 aim for |
Author: | Delos [ Fri May 13, 2005 12:12 pm ] |
Post subject: | |
My general comment on this (after having looked through your code), is to set up your 'main' loop to be the one that controls all movement/firing etc. Break down these actions into procedures, somewhat like the way you have it. This way, if one of the arrow keys are pressed, the corresponding movement is called via a procedure/function. When the key to fire is pressed, the object be be fired is created, and then in subsequent checks by the main loop, its status is checked and changed (i.e., its x-/y- pos'ns are altered, etc etc). Of course, these changes are done in a seperate procedure altogether. Compartmentalization is good! Don't put additional loops within your main loop... This is the general idea that I used when making ~Star Catcher~ [/shameless plug]. |
Author: | jamonathin [ Fri May 13, 2005 12:23 pm ] | ||
Post subject: | |||
Now some of the variables can be changed to boolean, and I heard it a million tiem to do so, but it's my personal preference not to, say what you will, but anyways here's a code for what you need. I didn't edit your program, beacause you'll remember more you edit your program yourself.
Have fun. Edit: Once again, I should type faster |
Author: | Flashkicks [ Fri May 13, 2005 12:47 pm ] |
Post subject: | |
Hay- thanks very much for that demo. I will try to incorporate it into mine.. I will let you now how it goes! ~Flashkicks Hold on- I have ONE question that I have been seeing a lot lately. Well, not the question, but .. yeah.Okay----what is this; += ??.. Anyways.. :: EDIT :: (About 15 minutes later) Okay, that demo proggy you left me is wonderful, however, I can NOT interpret it into my program :'( .. Im not sure what to do now. I tried the whole upper with hold and everything and it just wont shoot any lasers at all... I dont want to just copy all your code so do you think you can get me started as of what to do next to interpret it into my coding??.. I will keep trying but Im really just getting frustrated. Anyway, thanks, and hopefully you can help me out.. BTY-My teacher liked the sample you left lol.. Kay, c ya! ~Flashkicks :: EDIT :: Okay- I got it to shoot now, but once 10 lasers are shot-its DONE! You cant shoot no more .. achoo Help!!..... |
Author: | jamonathin [ Fri May 13, 2005 1:49 pm ] | ||||
Post subject: | |||||
Ok, this is what += means.
And for your shooting problem. . . when do you reset the shots? Do you ever make it so when the laser gets past the top of the screen that you reset it, making it available to shoot again? Take a look at this again
Once the lasery is > maxy, I reset that laser, making it available to shoot again, and I use a for loop to check through all 10 lasers to save up room. |
Author: | Flashkicks [ Mon May 16, 2005 7:57 am ] | ||
Post subject: | |||
haha-sorry.. I had a silly mistake and everything werks fine.. My Baad.. Anyways.. I thank you very much.. Now comes the asteroids ~Flashkicks :UPDATE: OKAY-wtfrick... My asteroids arent werking either.. I feel like I cant do anything.. Anyways.. Heres what I have for it- they draw but they never move..
I call asteroids in my main Controls loop... Maybe I shouldnt be going through this using a record But I thought it would be a good idea cuz then I could eventually keep track of different sizes of asteroids.. |
Author: | jamonathin [ Tue May 17, 2005 8:17 am ] | ||||||||
Post subject: | |||||||||
Ok, there's nothing wrong with using a record, it just how you're using it. Declare everything outside of the procedure. This is what your record should look like:
Now here's why your asteroids wont move. You "Declare initial values", and then you decide to "Make move". The when we run through the procedure again, you declare, then move. We run through the procedure again, you declare, them move. You only need to "declare" them once, not everytime in the procedure, because then they wont go anywhere. So add that to the bottom of your array.
Now, all thats left is to move, and that's what should be in your "asteroids" procedure. I noticed that you're using the "draw over top of the old ball to get rid of it" technique, don't. There's no need to. Clear the last screen, and then Update. Now, we need to change our setscreen/View.Set options to offscreenonly to use View.Update. But we only do this once, and not inside any loop or procedure. Just at the top of your program.
Now your loop and procedure is small, and this is what your entire program should look like.
|
Author: | Flashkicks [ Tue May 17, 2005 9:26 am ] | ||
Post subject: | |||
Okay.. I tried all your stuff (which by the way was WOW, wut a cool program you made.. I love the "effect ..lol.. Anyway") and it like.. Okay, the program RUNS- but not anything like yours.. First, the asteroids dont move quickly and swiftly. Also, my ship is lagging like a mad mother monkey Im not sure what to do.. I will put my code in here so you can see how I have it ALL set up. If you comment out the "asteroids" in the 'DrawShipAndShoot' procedure, youll notice how nice and smooth it runs.. But oce I throw the 'asteroids' in there, it goes BOOM...lol
I think im missing something major(but is probably very small ) .. If you can catch it than I must say, your Good...lol.. You've helped a lot alreay and Im still sitting here every stinkin day werking on it.. But once again-Im stuck:(.. |
Author: | jamonathin [ Tue May 17, 2005 1:04 pm ] | ||
Post subject: | |||
Here's your code, I added a cool background for yas. The reason it went incredibly slow was because you were delaying(5) and updating the screen (View.Update) 100 times in that for loop. You only need View.Update once, and thats before your delay. I changed things so that only one asteroid comes at a time, and as you shoot more, you can change the new variable i made (rocks) to a higher value, so more asteroids come. I cleaned up a couple of little things that I forget, but I left the collision for you . If you need help with it just ask, but your programs lookin good so far, keep goin.
|
Author: | Flashkicks [ Wed May 18, 2005 7:55 am ] | ||
Post subject: | |||
Hay man!!.. I got the whole asteroids thing werking and I guess I shoudla told you that yesterday already bcuz I had it werking near the end of class- not sure if its as efficient as yours though..lol.. but anyways, I really like the background idea so I will throw that in mine.. Im werking on the collision detection right now and its going good, Im just making a life gauge and its giving me hassles..lol.. I'll let you know how it turns out.. TTY soon.. ~Flashkicks :: UPDATE :: Okay.. The life gauge is all set and its kinda nifty.. It disappears when its not being used..lol.. But anyways.. Okay, not the asteroids. I made a lil procedure to check for collision with a laser and the rock. This is what I've got;
It works maybe 40% of the time.. Any ideas Why it only werks so seldom??.. NOTE: the red oval in the middle is not part of the game, its just my way of checking if a rock is hit.. you know.. |
Author: | jamonathin [ Wed May 18, 2005 11:23 am ] | ||
Post subject: | |||
This is the method that I use for collision with lasers. - I Start off with a for loop running every rock - Then I run a for loop inside that running for every laser shot - Then I run a for loop inside That, checking the length of the laser And what the third for loop does is it checks every pixel on that laser, and as a result, if any point on it touches anything you dont want it to, it'll know. This method's very efficient. Actually last night I was playing some Intellevision games on my PS2 and I got addicted to Astrosmash! and decided to make it. I dont know when I'll be submitting it, I'm gonnan be busy in the next few weeks, but I'm actually almost done, I only need all of those special features that the actual game has . . . But I'm trying to make it exactly like the real game. Anyways, here's your code that you should use.
|
Author: | Flashkicks [ Thu May 19, 2005 7:57 am ] | ||
Post subject: | |||
Hmmm.. The procedure yopu gave is kinda confusing me.. I dont get how the "checking every point in laser" would werk.. Well- I guess I understand but I dont know if I ever woudla thought of that..lol.. Anyways- You said to use my lasers variable for
~Flashkicks ::UPDATE:: Okay nevermind, .. I got it to werk now..lol.. Its pretty sweet man.. Now I get to design a nifty lil proc for them blowing up Thats always fun.. KAY- Ill tty soon, and let you know how things are going.. ~Flashkicks |
Author: | jamonathin [ Thu May 19, 2005 8:18 am ] |
Post subject: | |
Send your code over, I wanna see how its goin |
Author: | Flashkicks [ Thu May 19, 2005 9:05 am ] | ||||
Post subject: | |||||
Okay, so I this right here is what i want it to look like.
So run that and you will see what I mean.. Now when I transfered it into my actual program, it lagged like you wouldnt believe, yet didnt even do the explosion(effect). ::UPDATE:: hahahaha.. Okay.. Sorry. This was really dumb of me.. In my actual program that I sent you I forgot to tell the computer WHERE to draw all the explosions.. This is what it SHOULD look like..
There we go.. But either way, it still lags like a biznitch.. And I dont know how to make it run swiftly and smooth like an Iced Cuppicinno... |
Author: | jamonathin [ Sun May 22, 2005 10:04 am ] |
Post subject: | |
Flashkicks wrote: Hay- in the new stuff you added, is there anywhere I can add something so that the laser will be depleted imiediately after it hits an asteroid?.. You know, so it doesnt keep shooting through killing all the asteroids behind it?.. I tried throwing some code in a few procedures and its just.. Okay, if it hits a rock, then another laser will immediatly shoot out even if Im NoT pressing/holding "Tab" .. Any ideas why that might be happeneding?? Ill keep playing around with it........
~Flashkicks Yup, really simple. Look at his proc: proc shoots, and this line: proc shoots wrote: if hold (i) = 0 and done = 0 then
Now for a recap, 'hold (i)' tells the program that the current laser is free and can be reshot, and 'done' is just the delay inbetween the two lasers. Now take a look at proc Shoot, and these lines: proc Shoot wrote: if hold (i) = 1 then laserX (i) += dif * 3 The X-Value on the laser only moves when 'hold (i) = 1'. So if we look back at the other procedure (which is acutally after this procedure in the coding) It will reset any laser whos 'hold (i)' is equal to one. Now, I'm not at home or school so I done have your current code, but where ever you check collision with the lasers, just make the 'hold (i)' equal to 0, and the program will/should take care of the rest. Try it out and tell me how it goes. |
Author: | Flashkicks [ Fri May 27, 2005 7:56 am ] |
Post subject: | |
Okay, in mycollision procedure where it checks if a rock has been hit, I added the one simple line of hold (i) := 0 And as soon as the first asteroid is shot it gives the error "Array subscript outta range" .. And so I've tried SO many things and can not figure out what Im missing.. I've tried seperate for statements and changing hold(i) to different variables.. And still, nothing happens.. Any ideas??.. ~Flashkicks |
Author: | jamonathin [ Fri May 27, 2005 8:12 am ] |
Post subject: | |
Here's what you have to look at (since i dont know where your updated code is): what the array number on hold (var hold : array 1 .. ? of ***), then you need to check your for loop. Does the max number exceed the '?' in your hold variable? Does the for loop start at 0? Check those things out first, because that's the only reason you're getting that message. |
Author: | Flashkicks [ Mon May 30, 2005 7:42 am ] | ||
Post subject: | |||
woops, sorry-Here, Ill add the code in. Just comment out the lil intro part that requires the pic ..
Also, you will notice my "Levels" isnt very good either.. It only shows on screen for like a split second. I cant get that to werk nicely either.. Anyways.. Im sure you know where to look and you understand what does what.. Im gonna keep trying to get my levels to look a lil better here lol... TTYL ~Flashkicks |
Author: | jamonathin [ Mon May 30, 2005 8:17 am ] | ||||
Post subject: | |||||
Your View.Update was in the wrong spot. View.Update must go before an delay.
Also, use >= rather than =, it's more accurate, because you could be on 9 and hit 2 at the same time (juss happened to me)
Other than that I dont see any other errors, just make your levels better, and reset the asteroids to maxx. There should be more asteroids per level. All you ahve to do is add 1 to a variable every time you use the nextlevel proc. Then change how many asteroids move accordingly. You sould also have to shoot down more than 10 asteroids. |
Author: | Flashkicks [ Mon May 30, 2005 8:55 am ] |
Post subject: | |
Haha... Silly little errors.. I hate those.. Maybe Im too unfocused and Im not conentrating enough.. Im trying to make my final project at the same time and not just that- but the 'boss' for my Asteroids game as well..lol.. *phew*.. But thanks for that.. But now Im still stuck on the stupid non-depleting missiles...lol... *gRRRRrrr* ~Flashkicks |
Author: | jamonathin [ Mon May 30, 2005 1:40 pm ] | ||
Post subject: | |||
Your "hold" variable tells the program if that laser can be shot, so just add a "hold (x) := 0" into your proc, like this:
|
Author: | Flashkicks [ Tue May 31, 2005 9:46 am ] |
Post subject: | |
Why is it that you make things seem so simple??..lol.. It werks great.. I think its bcuz I kept trying to change that variable in a different procedure.. Unless I tried it but used the wrong array Either way- the game is 99.9% DONE!! I made this really cool 'boss' thingy and it werks already. But the Asteroids game is supposed to be run with a joystick (which I got werking already as well ) But incorporating the joystick into my 'boss' program is giving me huge difficulties. I KNOW its possible but its just a matter of figuring out how it will werk... Ill figure it out.. Anyways-enuff rambling.. Thanks a bunch. Ill give you my whole proggy in a PM once I am COMPLETELY 100% done with it. (dont werry, you will be able to use the keyboard and not the joystick...) ~Flashkicks |