FlashGrenade
246 posts
|
Topic: Game Programming /
Deeper Topic (part 3): Events to the rescue!
Originally posted by Ace_Blue:
I would separate keeping track of what keys are pressed how often for how long from deciding what to do with key presses. This way the key handler can be the same whatever the project, whereas the decision part can be written with your specific project in mind, taking advantage of having a ready-made keyboard handler.
The keyboard handler can be as simple as a Vector of ints, with length around 250 (can’t recall the exact number of keycodes off the top of my head.) When a key is released, take its keycode and store the frame number at that position in the array. When a key is pressed take its keycode and look up that position in the array. If the value there is >=0 store -1 instead, else ignore it. On enter_frame loop over the array, decrementing by 1 every value that is already <0.
And voila, you are now keeping track of how long each key has been pressed if it’s pressed and when it was last pressed if it’s not, using only a single int for each key. Only caveat: a value of -N indicates the key is in its Nth frame of being pressed, not that it has been pressed for N full frames (difference of 1).
Edit: I just noticed your downKeys() function counts key repeats, which is bad (as your comment indicates you are aware), but not because of Adobe. It’s bad because key repeat delay and frequency are system-dependent, and Flash has no control over them (nor should it have any. Do you want random Flash apps making changes to your keyboard settings? I don’t.) You should be counting frames of continuous pressing, or time difference between the initial press and the ultimate release.
Oh you mean this?
keys[ev.keyCode].count++;
yeah. I took that out in my later draft. That is used elsewhere in my code where i need it to coordinate my punch/kick combos.
As for the rest I wouldn’t know how to do any of that. I’m not at a level where I can read a suggestion and code it myself.
|
|
|
FlashGrenade
246 posts
|
Topic: Game Programming /
Deeper Topic (part 3): Events to the rescue!
I have a suggestion for player controls.
I’m trying to target this script for player controls and menu controls, but I haven’t properly tested it yet.
I would love to use this as a component so i can just attach it willy nilly at the drop of a hat.
var KEY_UP = 38;
var KEY_DOWN = 40;
var KEY_LEFT = 37;
var KEY_RIGHT = 39;
var KEY_ATTACK = 87;
var keys = new Object();
keys[KEY_UP] = {down:false, count:0, held_down:false, timerA:200,timerB:0,timeElapsed:0};
keys[KEY_DOWN] = {down:false, count:0, held_down:false, timerA:200,timerB:0,timeElapsed:0};
keys[KEY_LEFT] = {down:false, count:0, held_down:false, timerA:200,timerB:0,timeElapsed:0};
keys[KEY_RIGHT] = {down:false, count:0, held_down:false, timerA:200,timerB:0,timeElapsed:0};
keys[KEY_ATTACK] = {down:false, count:0, held_down:false, timerA:200,timerB:0,timeElapsed:0};
////////////////KEYBOARD LISTENERS
function downKeys (ev:KeyboardEvent)
{
//ONLY LOOPS IF THIS KEY IS PRESSED
if (keys[ev.keyCode] != undefined)
{
//IS PRESSED? SET .down to TRUE
keys[ev.keyCode].down = true;
//START COUNT WHEN THE KEY IS HELD DOWN
//NOT AS USEFUL AS YOU MIGHT THINK IN AS3 DUE TO ADOBE
//KEY LISTENER BEHAVIOUR
keys[ev.keyCode].count++;
//COUNT TIME BETWEEN KEY PRESSES
keys[ev.keyCode].timerA = getTimer() - keys[ev.keyCode].timerB;
keys[ev.keyCode].timerB = getTimer();
//trace(keys[ev.keyCode].timerA);
}
}
function upKeys (ev:KeyboardEvent) {
if (keys[ev.keyCode] != undefined)
{
keys[ev.keyCode].down = false;
keys[ev.keyCode].count=0;
//USEFUL BUT THE HELD_DOWN TO TRUE VALUE HAS TO BE SET MANUALLY ELSEWHERE
keys[ev.keyCode].held_down=false;
}
}
//PUT LISTENERS ON THE STAGE FOR KEYS
stage.addEventListener (KeyboardEvent.KEY_DOWN, downKeys);
stage.addEventListener (KeyboardEvent.KEY_UP, upKeys);
if(keys[KEY_ATTACK].down)
{
//SO..AS LONG AS THE KEY ISN'T HELD DOWN WE ALLOW ATTACK
//NOTICE THE VALUE OF HELD_DOWN IS AUTOMATICALLY SET TO FALSE
//WHENEVER A KEY IS RELEASED
if(!keys[KEY_ATTACK].held_down)
{
keys[KEY_ATTACK].held_down=true;
}
}
//////////////////////////ELSE MANAGE DIRECTIONAL MOVEMENT ///////////////////////
//LEFT
if (keys[KEY_LEFT].down)
{
} //RIGHT
else if (keys[KEY_RIGHT].down)
{
}
else if (keys[KEY_DOWN].down)
{
}
Oh yes and this is the striped down version.
|
|
|
FlashGrenade
246 posts
|
Topic: Game Programming /
Deeper Topic (part 3): Events to the rescue!
Oh yeah I tell you I would eat this thread up with a spoon if I was able to.
|
|
|
FlashGrenade
246 posts
|
Topic: Game Design /
Legality of tracing pictures
Dont worry about it. Greg Land does it all the time and he still manages to find work. Except from me. I wouldnt hire pornface to trace my actionscript code.
|
|
|
FlashGrenade
246 posts
|
Topic: Game Design /
Flash games with good stories
I liked the demo. Hard as it was to play with the keyboard. The minute i saw the ads for it on ps2 and gamecube, i was like
HOLY FUCK! FLASH GAMES CAN ACTUALLY BE GOOD!!!!1
in essence this game was the catalyst for my decision to program in AS3 and flash
|
|
|
FlashGrenade
246 posts
|
Topic: Game Design /
Copyright infringment
Originally posted by Drakim:
You can’t copyright gameplay ideas. As long as you don’t use any actual Minecraft things, like Minecraft branding or Minecraft assets (image or sound) you are good.
Thats going to be a bit of a stretch seeing as how all the visual assets are 8bit graphics.
|
|
|
FlashGrenade
246 posts
|
Topic: Game Design /
Flash games with good stories
Alien Homonid. The legend itself. Started off as a demo level, on newgrounds. But then got ported to ps2 and gamecube. I do believe though that they worked on the story and THEN started to build the game.
In the end it just comes down to the story, its development and how its told. If you cant write, don’t write.
Get Alan Moore to write your game story if you can. He actually wrote a piece on how to write comics in a book , so you should give it a google, and look it up.
|
|
|
FlashGrenade
246 posts
|
Topic: Game Design /
Reverse Engineering Classic Games
Yes. I do believe its very beneficial to revere engineer the classics. Understanding how a game is built and how its supposed to flow is much easier hands on than it is looking it up.
My first game is going to be a recreation of a Final Fight Beat-Em-Up. Its been done already, as you can see with Dino Strike, which is why ive been reverse engineering it. But the code is very hard to follow and the fla file tells you nothing really. But I DID learn that the game follows the OpenBOR formula, because of this, the engine limits itself to what it can do. Call me cray but i want my engine to do punch-kick combos and some super moves
|
|
|
FlashGrenade
246 posts
|
Topic: Game Programming /
Unity discontinues Flash support
Lesse here:
10: Print(“ActionScript 3.0 will not be lumped in with BASIC, COBOL or FORTAN!”);
20: goto 10;
|
|
|
FlashGrenade
246 posts
|
Topic: Game Programming /
expecting rightbrace
Okay now this just opens up the door as to how big and confusing a function can be even if it is broken down to its possible smallest form.
Everyone goes through brace confusion. I still go through it. Anyone starting out will do it.
placing a comment after } along WITH proper indentation, can help with this problem.
|
|
|
FlashGrenade
246 posts
|
Topic: Game Programming /
how to make heart containers like zelda [SOLVED]
this is easy.
make your watermelon a movieclip, make frame 1 empty, and start putting in your watermelon pieces accordingly.
I did that with my lifebar. Instead of having a bar that changes scaleX, i put in 1 movieclip with at least 100 ticks
and used lifeBar.gotoandstop(1 + player.getlife());
edit: you may need to craft a second lifebar to act as your white hearts, so you can place the first lifebar on top of that.
http://i.imgur.com/GPe2Hdl.png here this should help you practice.
|
|
|
FlashGrenade
246 posts
|
Topic: Game Programming /
Unity discontinues Flash support
This really shouldnt hurt developers that want to code their games in AS3, seeing as it can be converted into haXe, which can then be exported into other languages, so your game can then be sent to multiple platforms.
|
|
|
FlashGrenade
246 posts
|
|
|
|
FlashGrenade
246 posts
|
Topic: Game Programming /
expecting rightbrace
You would be surprised at all the trouble and frustration a novice coder would have trying to find out which } goes with what when problems like this arise. Even with proper indenting which I reccomend, you might have an extra or missing }.
That said you dont have to put comments on ALL of the } but if you have lots of if statements or switch cases or while loops in a function, having }//these comments, can save your sanity
|
|
|
FlashGrenade
246 posts
|
Topic: Game Programming /
expecting rightbrace
This is exactly the reason I comment my right brackets
}//if (this condition is met)
}//end function doThisNOW()!
}//class
}//package
doing this makes debugging your code easier as it can sniff out the odd { or } you put in or forgot to take out.
|
|
|
FlashGrenade
246 posts
|
Topic: Game Programming /
Beginning in game Development
AlexC4 suggesting pirated software is not smart. Its probably fine for practicing but if word got out that you published
a game on cracked software, that’s it. No your better of buying a licence when the time is right, or publishing the game on a trial version. vectorian giotto is a free substitute for flash, but free. It will take time to learn, but if you combine it with flashdevelop which is free, you can publish games for free. Oh yes did i mention that vectorian giotto is free?
|
|
|
FlashGrenade
246 posts
|
Topic: Game Programming /
HOW DO YOU LINK POWERUPREWARDS TO THIS
My dear boy:
I have absolutely no idea in the world what you are talking about.
At no point whatsoever did you present anything at all that could cause any form of thought.
There is nothing other than poweruprewards and link.
I can give you no answer for your question, I can give you no advice. And may god have mercy on your soul.
|
|
|
FlashGrenade
246 posts
|
Topic: Game Programming /
Did Stencyl copy Scratch or Scratch copied stencyl?
OH please.
There’s no such thing as an original idea anymore. Originality went out the window the moment the first caveman invented fire.
Because he was ripping off what Lightning can do.
All you can do these days is take something and make it better. If you can.
|
|
|
FlashGrenade
246 posts
|
Topic: Game Programming /
Refocus the game?
stage.focus = stage;
what exactly does that do?
is there any benefit to it?
|
|
|
FlashGrenade
246 posts
|
Topic: Game Programming /
Struggling with top-down animation
Ive been working on something for a while that involves lots of animations.
I thought about working with nested movieclips but that turned out to have complications. so im working with these functions and a single movieclip
example http://i.imgur.com/ip19Dt3.png
function runFrames(frameStart:Number, frameEnd:Number):void {
//THIS WILL RUN THE FRAMES FROM TO AND LOOP BACK TO THE BEGINNING
this.currentFrame=cFrame;
if(currentFrame < frameStart || currentFrame >= frameEnd)
{this.gotoAndStop(frameStart);}
else {
nextFrame();
trace(this.currentFrame);
}//if (this.currentFrame….
}//function runFrames
function runAttackFrames(frameStart:Number,frameEnd:Number):void {
this.currentFrame=cFrame;
//THIS SHOULD FIRST TRIGGER THE cFrame LABEL AND THEN RUN THE FRAME SEQUENCE
//HITTING THE cFrame FIRST SHOULD GUARANTEE THE FRAME SEQUENCE WILL RUN IMMEDIATELY AFTER.
if(this.currentFrame == frameEnd){
//INSERT THE DESIRED OUTCOME WHEN THE ANIMATION COMPLETES
}//if (this.currentFrame == frameEnd)
if(this.currentFrame < frameStart || this.currentFrame >= frameEnd){
this.gotoAndStop(frameStart);
}else{
this.nextFrame();
}
}//function runAttackFrames
You may want to add another function like attackFrameCheck if you want something to happen on a specific frame.
For your project you might want to take notes from Zelda: a Link to the past, cause i know theres a link spritesheet
that would be perfect or you to practice animation on.
|
|
|
FlashGrenade
246 posts
|
Topic: Game Programming /
how well planed my project must be before I commission a programmer ?
This is a good question for those looking for help. Ovazi, your first task should be creating a Game Design Document.
Its essentially your blueprint for your game. Once you have that, you’ll be able to present your idea to others and depending on how good it the idea is get the help you need. There’s no wrong way to write a GDR, so long as you are able to present your idea with it. Option 2 and 3 in your first post should be crucial to making a GDR. If you need a good example Im sure theres one stickied on the forum somewhere.
your second task should be learning actionscript 3 or another programming language that means being able to read and write code. Read it so you can tell if your progammer is good, or very sloppy. Write it so you will be able to program and understand the project that you are making.
Hope this advice helps
|
|
|
FlashGrenade
246 posts
|
Topic: Game Programming /
Solution: Stop being retarded.
In Mossy’s defense. I myself have difficulties understanding masks, or blitting for that matter. So I can see how challenging it can be to get it right.
|
|
|
FlashGrenade
246 posts
|
Topic: Game Programming /
FlashDevelop and Flash Professional
Just a heads up Koys, you CAN use Vectorian Giotto which is a free version of what flash does and use both of them without the need for flash.
|
|
|
FlashGrenade
246 posts
|
Topic: Game Programming /
Flash animation problem
you’re probably much better off using code to control your animations. I used to do nested movieclips in my animations, but i stumbled upon something better. It was also coded on a timeline so i had to make some mods.
This may help you out with some ideas. But if youre gonna use this make sure your animations of your hero are on one movieclip.
function runFrames(frameStart:Number, frameEnd:Number):void {
//THIS WILL RUN THE FRAMES FROM TO AND LOOP BACK TO THE BEGINNING
this.currentFrame=cFrame;
if(this.currentFrame < frameStart || this.currentFrame >= frameEnd)
{this.gotoAndStop(frameStart);}
else {
this.nextFrame();
trace(this.action);
trace(this.currentFrame);
}//if (this.currentFrame….
}//function runFrames
function runAttackFrames(frameStart:Number,frameEnd:Number):void {
this.currentFrame=cFrame;
//THIS SHOULD FIRST TRIGGER THE cFrame LABEL AND THEN RUN THE FRAME SEQUENCE
//HITTING THE cFrame FIRST SHOULD GUARANTEE THE FRAME SEQUENCE WILL RUN IMMEDIATELY AFTER.
if(this.currentFrame == frameEnd){
this.isAttacking = false;
if(!(this.attackSuccess=true)){
trace(“Attack WHIFFED!!”);
}else{
this.resetAttackSuccess();
}//if(!(this.attackSuccess=true))
}//if (this.currentFrame == frameEnd)
if(this.currentFrame < frameStart || this.currentFrame >= frameEnd){
this.gotoAndStop(frameStart);
}else{
this.isAttacking=true;
this.nextFrame();
}
}//function runAttackFrames
public function attackFrameCheck():void {
/*this function checks the currentframe of the hero movieclip and if it
hits a certain framedo something
switch (this.currentFrame) {
case 116:
break;
}}
|
|
|
FlashGrenade
246 posts
|
Topic: Game Programming /
AS3 HitTestObject Issue w/ Array
You could try putting your powerups in a vector instead of an array.
what does your powerup class look like anyway? can you put it up?
|