|
Title: Becoming a programmer a code at a time. Post by: Strelok on August 12, 2011, 11:13:18 AM So... I opened this topic to help me learn and understand Action Script 3. I'll do it as I program some things. And I hope you guys help me out. What I need is all the info I can get about the lines of the codes that I'll show here. And if there is, easy ways and other ways to do those same lines of code, also explained. Doing it, I'll become better and better, and I'll know the features much more a code at a time.
I'm using FlashDevelop and Flixel to work it out. The first one is this Hello World code: HelloWorld.as Code: package { import org.flixel.*; [SWF(width = "640", height = "480", backgroundColor = "#000000")] public class HelloWorld extends FlxGame { public function HelloWorld() { super(230, 240, PlayState, 2); } } } PlayState.as Code: package { import org.flixel.*; public class PlayState extends FlxState { override public function create():void { add(new FlxText(0, 0, 100, "Olá Mundo")); } } } I made it using a tutorial (http://flashgamedojo.com/wiki/index.php?title=Hello_World_-_FlashDevelop_(Flixel)) on the internet, and it worked just fine. The tutorial explained it a bit, but I couldn't understand at all. Can you guys explain it in a way someone that never coded before understand? Line by line? Title: Re: Becoming a programmer a code at a time. Post by: Evan Balster on August 12, 2011, 03:37:38 PM I'm afraid the individual lines won't quite make sense until you do a few more tutorials. What a "class" is is pretty irrelevant until you've got more than one.
I advise you to do more tutorials; you'll get the hang of things if you take the time to experiment with the code a little after each one. It's pretty normal not to know how in the hell a "hello world" program works; after all, it's a first glimpse into a big and complicated system you must learn one part at a time. Then, you can create new systems of your own and put them to use. Therein lies the beauty of programming. Title: Re: Becoming a programmer a code at a time. Post by: gnat on August 12, 2011, 06:55:14 PM You'll want to pick up a book on a major language: C, C++, Java (make sure it's recent), Javascript or Actionscript 3 if you can find one. And go from there.
Get a good foundation and it will answer a million of your current and future questions at once. Title: Re: Becoming a programmer a code at a time. Post by: Strelok on August 12, 2011, 07:48:53 PM All I know from now about this Hello World program is that I might use it to create an textflow-based-rpg, if I knew how to. But first of all I need to know more about the acronyms and words used in programming.
e.g.: Compiler, Debugger, Profiler, GUI, IDE... For now I think that I'll just do what you guys said, and do more tutorials. Title: Re: Becoming a programmer a code at a time. Post by: Sakar on August 12, 2011, 08:00:18 PM My best advice to you at this stage is to read up on Actionscript 3, maybe even on general programming concepts. Also do some tutorials, but be sure to experiment with what it teaches you. Messing with the program helps a lot in understanding how it works.
Title: Re: Becoming a programmer a code at a time. Post by: ஒழுக்கின்மை on August 12, 2011, 08:18:22 PM if you don't know what a compiler is or what a GUI is, you probably need to read some type of basic article on programming -- i wouldn't go into programming knowing that little about them. even non-programmers usually know what compilers are and what GUIs are
Title: Re: Becoming a programmer a code at a time. Post by: Xardov on August 12, 2011, 09:16:33 PM All I know from now about this Hello World program is that I might use it to create an textflow-based-rpg, if I knew how to. But first of all I need to know more about the acronyms and words used in programming. e.g.: Compiler, Debugger, Profiler, GUI, IDE... For now I think that I'll just do what you guys said, and do more tutorials. A compiler is something that translates the source code into another language to create executables. A debugger is used to locate errors in the code. A profiler is a method of program analysis that measures the usage of memory among other things. A GUI stands for Graphical User Interface. An IDE stands for Integrated Development Environment. Flashdevelop is an example of an IDE. Title: Re: Becoming a programmer a code at a time. Post by: C.D Buckmaster on August 12, 2011, 10:00:57 PM Well, before you even start learning the syntax (basically what each line of code does) of the language, you should learn how object orientated programming works, there's no point learning a language if you don't know the logic. Learn what these words mean and how they work:
Class Initialise Functions (as well as what private, public, static and void mean) Variables For/while loops if then/else/else if statements Data types Title: Re: Becoming a programmer a code at a time. Post by: johanp on August 13, 2011, 03:23:41 AM Skip flixel and any other framework for now. Just learn programing first. :)
Title: Re: Becoming a programmer a code at a time. Post by: Strelok on August 18, 2011, 09:46:18 PM Ok, so... I made a Space Invaders... er... kinda... I was trying to play a trick in a friend of mine with this game. Here is the codes. I used a tutorial for it, and I could learn a couple of things from it. But I would like to understand more about Classes and things like "super();" and "override" and "void".
Code: (MatheusInvaders.as) package { import org.flixel.*; [SWF(width = "640", height = "480", backgroundcolor = "#000000")] [Frame(factoryClass="Precarregar")] public class MatheusInvaders extends FlxGame { public function MatheusInvaders():void { super(320, 240, EstadoDeJogo, 2); forceDebugger = true; FlxG.mouse.show(); } } } As I know until now, this is the core of the game "FlxG.mouse.show" will work so I can see the mouse in the game so I'll click in it, then it'll automaticaly disappear. [Frame(factoryClass="Precarregar")] I don't know what does this line of code does: [SWF(width = "640", height = "480", backgroundcolor = "#000000")] And I know that this line of code will create an window for the game with 640px width and 480px height, and a black background. What I don't know is how do I change that background for something I made myself: Code: (EstadoDeJogo.as (Playstate.as)) package { import org.flixel.*; public class EstadoDeJogo extends FlxState { public var jogador:NaveJogador; public var balasjogador:FlxGroup; public var matheus:FlxGroup; public var matheusbalas:FlxGroup; public var escudos:FlxGroup; public var vsBalasJogador:FlxGroup; public var vsMatheusBalas:FlxGroup; override public function create():void { var i:int if (FlxG.scores.length <= 0) FlxG.scores[0] = "BEM VINDO AO MATHEUS INVADERS, PREPARE O SEU ANUS PARA O ATAQUE FINAL!"; //criar as balas do jogador var numBalasJogador:uint = 8; balasjogador = new FlxGroup(numBalasJogador); var sprite:FlxSprite; for (i = 0; i < numBalasJogador; i++) { sprite = new FlxSprite( -100, -100); sprite.makeGraphic(2, 8); sprite.exists = false; balasjogador.add(sprite) } add(balasjogador); //criar a nave do jogador jogador = new NaveJogador(); add(jogador); //criar as balas do matheus *niggaface* var numMatheusBalas:uint = 32; matheusbalas = new FlxGroup(numMatheusBalas); for (i = 0; i < numMatheusBalas; i++) { sprite = new FlxSprite( -100, -100); sprite.makeGraphic(2, 8); sprite.exists = false; matheusbalas.add(sprite); } add(matheusbalas); var numMatheus:uint = 50; matheus = new FlxGroup(numMatheus); var a:Matheu; var colors:Array = new Array(FlxG.BLUE, (FlxG.BLUE | FlxG.GREEN), FlxG.GREEN, (FlxG.GREEN | FlxG.RED)) for (i = 0; i < numMatheus; i++) { a = new Matheu(8 + (i % 10) * 32, 24 + int(i / 10) * 32, colors[int(i / 10)], matheusbalas); matheus.add(a); } add(matheus); vsBalasJogador = new FlxGroup(); vsBalasJogador.add(escudos); vsBalasJogador.add(matheus); vsMatheusBalas = new FlxGroup(); vsMatheusBalas.add(escudos); vsMatheusBalas.add(jogador); var t:FlxText = new FlxText(4, 4, FlxG.width - 8, FlxG.scores[0]); t.alignment = "center"; add(t); } override public function update():void { if (FlxG.mouse.justPressed()) FlxG.mouse.hide(); FlxG.overlap(balasjogador, vsBalasJogador, coisaAcertaCoisa); FlxG.overlap(matheusbalas, vsMatheusBalas, coisaAcertaCoisa); super.update(); if (!jogador.exists) { FlxG.scores[0] = "VOCÊ FOI RAPADO!"; FlxG.resetState(); } else if (matheus.getFirstExtant() == null) { FlxG.scores[0] = "VOCÊ SE LIVROU DE PERDER SUAS PREGAS ANAIS!"; FlxG.resetState(); } } protected function coisaAcertaCoisa(Object1:FlxObject, Object2:FlxObject):void { Object1.kill() Object2.kill(); } } } This is the main code source I think. It's where most of the variables are created and where all the magic happens I think. I did understand some things of this. Of course, I Code: (Matheu.as (enemies)) package { import org.flixel.*; public class Matheu extends FlxSprite { private var relogiotiro:Number; private var originalX:int; [Embed(source = "matheu.png")] private var ImgMatheu:Class; public function Matheu(X:int, Y:int, Color:uint, Balas:FlxGroup) { super(X, Y); loadGraphic(ImgMatheu, true); color = Color; originalX = X; resetRelogioTiro(); addAnimation("Default", [0, 1, 0, 2], 6 + FlxG.random() * 4); play("Defaul"); velocity.x = 10; } override public function update():void { if (x < originalX - 8) { x = originalX - 8; velocity.x = -velocity.x velocity.y++; } if (x > originalX + 8) { x = originalX + 8; velocity.x = -velocity.x } if (y > FlxG.height * 0.35) relogiotiro -= FlxG.elapsed; if (relogiotiro <= 0) { resetRelogioTiro(); var bala:FlxSprite = (FlxG.state as EstadoDeJogo).matheusbalas.recycle() as FlxSprite; bala.reset(x + width / 2 - bala.width / 2, y); bala.velocity.y = 65; } } private function resetRelogioTiro():void { relogiotiro = 1 + FlxG.random() * 10; } } } Here is where the enemies are created in all their glory. Their side to side movimentation and their up to down movimentation is all created here. It's also here where their image is provided and their animation created. But that's logic I think... Code: (NaveJogador (player)) package { import org.flixel.*; public class NaveJogador extends FlxSprite { [Embed(source = "nave.png")] private var ImgNave:Class; public function NaveJogador() { super(FlxG.width / 2 - 6, FlxG.height - 12, ImgNave); } override public function update():void { velocity.x = 0; if (FlxG.keys.LEFT) velocity.x -= 150; if (FlxG.keys.RIGHT) velocity.x += 150; super.update(); if (x > FlxG.width - width - 4) x = FlxG.width - width - 4; if (x < 4) x = 4; if (FlxG.keys.justPressed("SPACE")) { var bala:FlxSprite = (FlxG.state as EstadoDeJogo).balasjogador.recycle() as FlxSprite; bala.reset(x + width / 2 - bala.width / 2, y); bala.velocity.y = - 420; } } } } Here is the same as the enemies, but for the player, and without animation. Code: (Precarregar.as (Preloader thing)) package { import org.flixel.system.FlxPreloader; public class Precarregar extends FlxPreloader { public function Precarregar():void { className = "MatheusInvaders"; super(); } } } I really don't know what this does... :handthumbsdownR::facepalm: So can you guys help me understand this a bit more, so I can do improviments like sounds, and special effects like particles? I love particles. :brofistR: :durr: Title: Re: Becoming a programmer a code at a time. Post by: Sakar on August 18, 2011, 10:05:08 PM I'd recommend following everyone's advice and learning general programming concepts first. Games are big, complicated projects, and are very difficult to do if you don't know the fundamentals of programming.
Title: Re: Becoming a programmer a code at a time. Post by: C.D Buckmaster on August 18, 2011, 10:53:20 PM Here, I used this tutuorial when starting out with Flash and it answers all of the question you're asking, it's in the Flashpunk forums but you don't need Flashpunk to do this tutorial.
http://flashpunk.net/forums/index.php?topic=1499.0 (http://flashpunk.net/forums/index.php?topic=1499.0) Title: Re: Becoming a programmer a code at a time. Post by: Prinsessa on August 19, 2011, 02:10:44 AM @Strelok:
Totally off-topic, but I have to ask. És de Portugal ou do Brasil? «Olá, mundo!»? Quero saber agora! :gomez: Title: Re: Becoming a programmer a code at a time. Post by: Strelok on August 19, 2011, 05:13:58 AM Yep, I'm from Brazil.
E julgando pelo seu português polido, o que é raro no Brasil, imagino que sejas português. :gentleman: Title: Re: Becoming a programmer a code at a time. Post by: nahkranoth on August 19, 2011, 05:30:55 AM I think it's important to know what you want and slowly work to it.
Just saying i want to learn how to code is allready a good step, but it's also quiet broad. Qhy do you want to learn how to code? If it is only to make games and you havent done that before i would consider to check into Game Maker, Unity, etc. This will learn you what is needed for a game in a user-friendly way. Through this and it's attached communities you can get into and discuss a lot of different aspects of these software packages - and making games. Also coding. If you want to learn how to code Flash, i would recomend reading a lot of tutorials and trieing out (also, but not only copying code from a tutorial). This will however not allways be games, - not that that is a bad thing. But it could become hard to find the right information and motivation. Title: Re: Becoming a programmer a code at a time. Post by: Prinsessa on August 20, 2011, 07:39:38 AM Yep, I'm from Brazil. O meu português é polido, haha, ou estás a dezer o oposto? E julgando pelo seu português polido, o que é raro no Brasil, imagino que sejas português. :gentleman: E eu não sou português! Sou da Suécia! ;D Title: Re: Becoming a programmer a code at a time. Post by: Strelok on August 20, 2011, 07:16:08 PM Yep, I'm from Brazil. O meu português é polido, haha, ou estás a dezer o oposto? E julgando pelo seu português polido, o que é raro no Brasil, imagino que sejas português. :gentleman: E eu não sou português! Sou da Suecia! ;D As pessoas falam português na Suécia? Ou está usando um tradutor? :noir: Title: Re: Becoming a programmer a code at a time. Post by: Prinsessa on September 06, 2011, 02:54:47 AM Yep, I'm from Brazil. O meu português é polido, haha, ou estás a dezer o oposto? E julgando pelo seu português polido, o que é raro no Brasil, imagino que sejas português. :gentleman: E eu não sou português! Sou da Suécia! ;D As pessoas falam português na Suécia? Ou está usando um tradutor? :noir: Ainda não tenho aprendido muito, mas, de vez em quando, aprendo mais. Eu gosto da língua! Title: Re: Becoming a programmer a code at a time. Post by: Mikademus on September 06, 2011, 03:01:32 AM Take it to PM, this is an English-language forum.
Title: Re: Becoming a programmer a code at a time. Post by: Prinsessa on September 06, 2011, 03:24:38 AM Take it to PM, this is an English-language forum. Ah. Sorry. I'm pretty used to visiting some boards where off-topic discussions are allowed, since they really just want to promote any discussions, and since those boards are linguistically related, foreign conversations are usually just encouraged. :-[ |