|
YOU CAN PLAY IT RIGHT HERE Controls are WASD (jump, stop, slide, run right). You might have to click the game window with your mouse once if you can't control anything. I don't wanna poo poo up the Game Development thread any further, so here it is: My own little thread for my own little game that nobody will reply to ever, but hey. Keep in mind that I'm terribly new to coding and probably have borderline retarded code. Feel free to point out anything that bothers you, or just help me with my problems, or call me a terrible coder, whatever you feel like. I'm trying to comment my code as much as I can, so it's easier to understand what I was thinking writing that paradox or this division by zero. My current problem: If you jump over or slide under a bullet, the game traces "points!" and makes a little sound. After 5 bullets or so, it stops doing that. No sound, no trace. If you keep jumping and sliding, it occasionally does it one more time after failing to do so like 3 times, and sometimes it also did it again if you jumped a bullet once the last one spawned and the game traces "An Exit Appears". I have no idea why. Here's the Code for that section: code:
If the counter is above 4, it gets locked at 4, cause that's when the first bullet has appeared, and I'm assuming it wastes memory if you have a counter ticking up for nothing. Then the counter makes a variable click on, so the if function doesn't have to reference the counter. Again, which I assume saves memory or data or whatever you'd call it. That's all I can think of for now, thank you for reading. Pizzatime fucked around with this message at 17:00 on May 6, 2014 |
# ? May 6, 2014 16:56 |
|
|
# ? May 5, 2024 01:34 |
|
I'm one step closer to the solution. I found out that it stops working whenever there's another bullet to the right of the one you're jumping over/sliding under. So the faster the timer gets, the more likely it is that there has already another bullet spawned on the right of the screen, and the one you're jumping over won't count anymore. The closer you move to the right edge of the screen, the longer it still works. And if I keep the spawninterval at a static 2.5, it never stops working because there's only another bullet spawning when the first one is already gone. At first I thought it's simply that two or more bullets will cause this, but it really seems to be that the function only checks the rightmost bullet. I don't know how to fix it yet, but the problem has at least become more apparent. Also I've tidied up the function. code:
Pizzatime fucked around with this message at 11:20 on May 7, 2014 |
# ? May 6, 2014 22:54 |
|
Good on you for learning a new skill. You're doing it the best possible way, too: MAKE poo poo. BREAK poo poo. That being said - I have some general tips to offer you and some other possible approaches to try. First, try to avoid comments like this: code:
Comments like THIS on the other hand: code:
And then there's this: code:
code:
Spend time to make sure your code is readable. if the code itself isn't obvious, then add a comment to clarify. I have been coding for 20 years, and I can't count the number of times I have been looking at some routine going "wtf is this guy doing here?" only to find out that "this guy" was ME, years earlier - before I had the value of writing readable well documented code drilled into my head. So I don't know Flash or Flixel or whatever language you are working in, but here's one possible approach to your bullet problem: Assuming your bullets basically have 3 properties: X position (Left/Right), Y position (Up/Down) and Velocity (how fast they are moving). If you know in advance the greatest number of bullets that can EVER be on screen at one time - you can go ahead and create them in advance. Give them X and Y coords which make them off the screen, and give them a velocity of 0. You have a list for them already. Add one more property to the bullets: an isActive flag, true/false, indicating if it's currently on screen, in play, etc. Then, break up your createbullet function into two: createbullets and spawnbullet. Something like this (again I don't know Flash. Pretend this is pseudo code): code:
This a long post with a lot to absorb, so I will stop here. Good luck, tho!
|
# ? May 7, 2014 01:43 |
|
Oh man thanks a lot, there's a lot of stuff there that really helps me get better at this. Also thank you for the kind opening, words of encouragement are more important than I thought at first when delving into something you know nothing about. On the "counter": I've managed to forego it completely. I switched it out with a simple if (bullet != null) on top of the whole bullet function. So it's starting exactly when I need it to, not sometime about when it has to, and I can get rid of that silly timer. On the "spawntimer": I've copied that bit from some other tutorial, and yesterday evening, when I had learned enough that I thought maybe I could try and understand it, I went through everything related to it in the code. It seemed like a really shoddy thing that actually appeared to not make sense at times, even though it does work. The spawninterval is declared as 2.5, then the spawntimer is declared as -= FlxG.elapsed, or itself - FlxG.elapsed. But then this: code:
I will try and implement your suggestion on the whole bullets things and report back with what comes of it. Again, thank you very very much! Another thing that came up: I've made a little intro state that basically looks like the playstate, but doesn't have any bullets, scrolling or controls. Just the player falling from the top of the screen on the play area and looping his stand animation until you press a key, then it loads the playstate. My problem here, no matter what I input as the y spawn position of the player in the playstate, he doesn't spawn standing on the ground. He always spawns being in the air, and does his jumping animation for a frame or two along with his landing sound. I'd like him to appear standing on the ground though, because that'd be a seamless transition from the little intro state, but I can't figure out how. And one more thing: I tried making a reset button for when you die and wanna start over, but no matter if I reset the state, or switch the state to itself, the game crashes. I read somewhere that states are not meant to be loaded more than once, but that shouldn't go for a reset of the state, right? Switching from the intro state to the playstate works fine though. Just a reset of the playstate results in a crash, which I find odd. Pizzatime fucked around with this message at 11:34 on May 7, 2014 |
# ? May 7, 2014 11:11 |
|
- Don't waste your time, I've already figured it out. More at the bottom of this post. - Here's another super simple thing I just can't get to work. code:
I did it with that variable for now to make sure the problem isn't that I hosed up the if function. I figure a better way to write it would be: code:
e: A minute later I've figure it out. I guess I'll explain the mistake anyway, just in case any code newbies are reading this and wonder. I had to set it to if (player.justTouched(FlxObject.FLOOR)). Otherwise it kept checked for the floor to be touched, and as long as it did, it played the "crystal" animation. With justTouched, it only checks for the initial touch, and that's what you want here. Pizzatime fucked around with this message at 13:46 on May 7, 2014 |
# ? May 7, 2014 13:39 |
|
Okay so I'll be writing this out just so I maybe figure this out just by writing it out. So I have two similar functions that both use a counter in two different states. One works, and one doesn't. In the one that does, I set the counter in the beginning, like so: code:
code:
code:
code:
code:
code:
code:
code:
Note: If I set the bullet function to code:
I havn't tested it yet, but I'm pretty sure I've figured it out. The spawnInterval == 0.7, right? So it keeps setting the publictimer to 2, and it never hits 0. There we go, there we go. Man, coding is awesome. Pizzatime fucked around with this message at 18:29 on May 7, 2014 |
# ? May 7, 2014 18:17 |
|
Just a quick driveby comment:Pizzatime posted:
You forgot an extra =, so you're assigning the number 2 to the variable publictimer instead of checking if its the same as 2.
|
# ? May 7, 2014 18:40 |
|
Whoops, thanks Karma. I've cleaned up my code. Look at what Playstate has turned into: code:
|
# ? May 8, 2014 15:34 |
|
It's got a name now
|
# ? May 9, 2014 13:40 |
What IDE are you using? That accidental assignment within a conditional should have been caught by any halfway-decent IDE...
|
|
# ? May 9, 2014 14:04 |
|
|
# ? May 5, 2024 01:34 |
|
That looks like FlashDevelop to me.
|
# ? May 9, 2014 14:54 |