I've just started studying game design and programming at the university and I'm gonna go through ActionScript, JavaScript and C# on the first year. Have you got any tips for a programming noob (besides from practising, of course)? public var tips:int; public var help:String = "HELP! Gimme more tips"; if (tips <= 0) { trace(help); } LOLZ Thanks !
Download the free version of Unity and some free stuff that you like from the marketplace and see how it's done! Read Unity tutorials and try to write your own scripts that you attach to your game objects! Learn by doing that's how you learn to program. btw, in your code I guess the intended meaning was trace(help), without the quotes In Unity you would write Debug.log(help) and probably put it in the Update function, haha.
Indeed, I have downloaded Unity, which we will be using in class, but after we've ended with programming logic, if i'm not mistaken. On the code, yeah, it was meant without the "" to call on the variable, thanks for the correction. Silly noob mistake.
Code: public var alltips:int; public var curtips:int; public var help:String = "HELP! Gimme more tips"; public var tips:String[]; do { tips = get_tips_from_gurus(); curtips = count_tips(tips); if (curtips <= 0) { trace(help); } else { save_tips_to_brain(tips); } alltips += curtips; } while (alltips <= 1000)
Inside program called GetTips. No, I just followed the syntax of your post. Edit: Btw, after you learn C# try PowerShell. It has its own scripting capabilities, it permits direct usage of .Net types framework and all objects at your hands are real .Net objects with properties and methods.
The part after the variable declarations should at least be in a function. (and of course all the other functions you use should be defined elsewhere) Now it's starting to look like Javascript Code: public var alltips:int; public var curtips:int; public var help:String = "HELP! Gimme more tips"; public var tips:String[]; function getTips() { do { tips = get_tips_from_gurus(); curtips = count_tips(tips); if (curtips <= 0) { trace(help); } else { save_tips_to_brain(tips); } alltips += curtips; } while (alltips <= 1000); } Also mind the previously missing semicolon ; after the while statement. You could start here learning about scripting in Unity: http://unity3d.com/learn/tutorials/modules/beginner/scripting
I'm doing a frogger right now, as an exercise for programming logic... Here's the unfinished code (made in flash builder 4.6) Mind that it has got some words in spanish! Spoiler package { import flash.display.Sprite; import flash.events.Event; import flash.events.KeyboardEvent; import flash.ui.Keyboard; [SWF(width="800" , height="600")] public class Main extends Sprite { public var escenario:Sprite; public var enemigo:Sprite; public var personaje:Sprite; public var enemigo2:Sprite; public var enemigo3:Sprite; public var velocidad:int = 8; public var velocidad2:int = 15; public var velocidad3:int = 20; public var velocidad4:int = 12; public var velocidad5:int = 10; public var direccion:int = 1; public var der:Boolean = false; public var izq:Boolean = false; public var arr:Boolean = false; public var abj:Boolean = false; public function Main() { escenario = dibujarRectangulo(0x004bc8,800,100,400,50) // estanque dibujarRectangulo(0x007f21,800,60,400,100) // pasto superior dibujarRectangulo(0xc3c3c3,800,12,400,130) //cordon superior dibujarRectangulo(0x007f21,800,60,400,570) //pasto inferior dibujarRectangulo(0xc3c3c3,800,12,400,540) //cordon inferior dibujarRectangulo(0x202020,800,399,400,335) //AVENIDA dibujarRectangulo(0xe8e500,50,10,100,335)//franjas amarillas dibujarRectangulo(0xe8e500,50,10,0,335) dibujarRectangulo(0xe8e500,50,10,200,335) dibujarRectangulo(0xe8e500,50,10,300,335) dibujarRectangulo(0xe8e500,50,10,400,335) dibujarRectangulo(0xe8e500,50,10,500,335) dibujarRectangulo(0xe8e500,50,10,600,335) dibujarRectangulo(0xe8e500,50,10,700,335) dibujarRectangulo(0xe8e500,50,10,800,335) ; enemigo = dibujarRectangulo(0xff0000,45,20,300,500); //primer auto inferior enemigo2 = dibujarRectangulo(0xff0000,70,28,135,450); // segundo auto inferior enemigo3 = dibujarRectangulo(0xff0000,50,22,600,395); personaje = dibujarCirculo(0x79bd46,12,400,565); //ranita stage.addEventListener(Event.ENTER_FRAME , update); // cuando se presiona una tecla stage.addEventListener(KeyboardEvent.KEY_DOWN , apretoTecla); // cuando se suelta una tecla stage.addEventListener(KeyboardEvent.KEY_UP , sueltoTecla); } public function update(e:Event):void { moverEnemigo(); moverPersonaje(); comprobarColisiones(); } public function comprobarColisiones():void { if (personaje.hitTestObject(enemigo) == true) { personaje.x = 400; personaje.y = 565; } if (personaje.hitTestObject(enemigo2) == true) { personaje.x = 400; personaje.y = 565; } } public function moverPersonaje():void { if (der == true) { personaje.x += velocidad; } if (izq == true) { personaje.x -= velocidad; } if (arr == true) { personaje.y -= velocidad; } if (abj == true) { personaje.y += velocidad; } } public function moverEnemigo():void { enemigo.x = enemigo.x + velocidad2 * direccion; if (enemigo.x > stage.stageWidth - enemigo.width / 2) { enemigo.x = 0 } if (enemigo.x < 0 + enemigo.width / 2 ) { direccion = 1; } enemigo2.x = enemigo2.x + velocidad5 * direccion; if (enemigo2.x > stage.stageWidth - enemigo2.width / 2) { enemigo2.x = 0 } if (enemigo2.x < 0 + enemigo2.width / 2 ) { direccion = 1; } enemigo3.x = enemigo3.x + velocidad4 * direccion; if (enemigo3.x > stage.stageWidth - enemigo3.width / 2) { enemigo3.x = 0 } if (enemigo3.x < 0 + enemigo3.width / 2 ) { direccion = 1; } } public function sueltoTecla(e:KeyboardEvent):void { switch(e.keyCode) { case Keyboard.RIGHT: der = false; break; case Keyboard.LEFT: izq = false; break; case Keyboard.DOWN: abj = false; break; case Keyboard.UP: arr = false; break; } } public function apretoTecla(e:KeyboardEvent):void { switch(e.keyCode) { case Keyboard.RIGHT: der = true; break; case Keyboard.LEFT: izq = true; break; case Keyboard.DOWN: abj = true break; case Keyboard.UP: arr = true; break; } } public function dibujarCirculo(color:int,radio:int, posX:int,posY:int):Sprite { var dj:Sprite = new Sprite(); dj.graphics.beginFill(color,1); dj.graphics.drawCircle(0,0,radio); dj.graphics.endFill(); stage.addChild(dj); dj.x = posX; dj.y = posY; return dj; } public function dibujarRectangulo(color:int,ancho:int,alto:int, posX:int,posY:int):Sprite { var dj:Sprite = new Sprite(); dj.graphics.beginFill(color,1); dj.graphics.drawRect(-ancho/2 , -alto/2 , ancho , alto); dj.graphics.endFill(); stage.addChild(dj); dj.x = posX; dj.y = posY; return dj; } } } Dunno if any of you got the soft to debug and try it I'm still missing the cars that go the other way and the 3 lifes for the frog. No real sprites yet, just drawn with pure code.
This is the finished "idea" Spoiler package { import flash.display.Sprite; import flash.events.Event; import flash.events.KeyboardEvent; import flash.ui.Keyboard; [SWF(width="800" , height="600")] public class Main extends Sprite { public var escenario:Sprite; public var enemigo:Sprite; public var personaje:Sprite; public var enemigo2:Sprite; public var enemigo3:Sprite; public var enemigo4:Sprite; //enemigos de parte superior public var enemigo5:Sprite; public var enemigo6:Sprite; public var velocidad:int = 8; public var velocidad2:int = 15; public var velocidad3:int = 20; public var velocidad4:int = 12; public var velocidad5:int = 10; public var direccion:int = 1; public var direccion2:int = -1; public var vida:int = 3; //las vidas de la ranita public var der:Boolean = false; public var izq:Boolean = false; public var arr:Boolean = false; public var abj:Boolean = false; public function Main() { escenario = dibujarRectangulo(0x004bc8,800,100,400,50) // estanque dibujarRectangulo(0x007f21,800,60,400,100) // pasto superior dibujarRectangulo(0xc3c3c3,800,12,400,130) //cordon superior dibujarRectangulo(0x007f21,800,60,400,570) //pasto inferior dibujarRectangulo(0xc3c3c3,800,12,400,540) //cordon inferior dibujarRectangulo(0x202020,800,399,400,335) //AVENIDA dibujarRectangulo(0xe8e500,50,10,100,335)//franjas amarillas dibujarRectangulo(0xe8e500,50,10,0,335) dibujarRectangulo(0xe8e500,50,10,200,335) dibujarRectangulo(0xe8e500,50,10,300,335) dibujarRectangulo(0xe8e500,50,10,400,335) dibujarRectangulo(0xe8e500,50,10,500,335) dibujarRectangulo(0xe8e500,50,10,600,335) dibujarRectangulo(0xe8e500,50,10,700,335) dibujarRectangulo(0xe8e500,50,10,800,335) ; enemigo = dibujarRectangulo(0xff0000,45,20,300,500); //primer auto inferior enemigo2 = dibujarRectangulo(0xff0000,70,28,135,450); // segundo auto inferior enemigo3 = dibujarRectangulo(0xff0000,50,22,600,395); // tercer auto inferior enemigo4 = dibujarRectangulo(0xff0000,75,30,690,170); // primer auto superior enemigo5 = dibujarRectangulo(0xff0000,45,25,540,225); // segundo auto superior enemigo6 = dibujarRectangulo(0xff0000,55,22,310,280);// tercer auto superior personaje = dibujarCirculo(0x79bd46,12,400,565); //ranita stage.addEventListener(Event.ENTER_FRAME , update); // cuando se presiona una tecla stage.addEventListener(KeyboardEvent.KEY_DOWN , apretoTecla); // cuando se suelta una tecla stage.addEventListener(KeyboardEvent.KEY_UP , sueltoTecla); } public function update(e:Event):void { moverEnemigo(); moverPersonaje(); comprobarColisiones(); comprobarVida(); comprobarSiGano(); } public function comprobarSiGano():void { if(personaje.y <= 0) { trace("GANASTE"); personaje.x = 400; personaje.y = 565; vida = 3; } } public function comprobarVida():void { if(vida == 0) { trace("GAME OVER"); vida = 3; } } public function comprobarColisiones():void { if (personaje.hitTestObject(enemigo) == true) { personaje.x = 400; personaje.y = 565; vida -- } if (personaje.hitTestObject(enemigo2) == true) { personaje.x = 400; personaje.y = 565; vida -- } if (personaje.hitTestObject(enemigo3) == true) { personaje.x = 400; personaje.y = 565; vida -- } if (personaje.hitTestObject(enemigo4) == true) { personaje.x = 400; personaje.y = 565; vida -- } if (personaje.hitTestObject(enemigo5) == true) { personaje.x = 400; personaje.y = 565; vida -- } if (personaje.hitTestObject(enemigo6) == true) { personaje.x = 400; personaje.y = 565; vida -- } } public function moverPersonaje():void { if (der == true) { personaje.x += velocidad; } if (izq == true) { personaje.x -= velocidad; } if (arr == true) { personaje.y -= velocidad; } if (abj == true) { personaje.y += velocidad; } } public function moverEnemigo():void { enemigo.x = enemigo.x + velocidad2 * direccion; if (enemigo.x > stage.stageWidth - enemigo.width / 2) { enemigo.x = 0 } enemigo2.x = enemigo2.x + velocidad5 * direccion; if (enemigo2.x > stage.stageWidth - enemigo2.width / 2) { enemigo2.x = 0 } enemigo3.x = enemigo3.x + velocidad4 * direccion; if (enemigo3.x > stage.stageWidth - enemigo3.width / 2) { enemigo3.x = 0 } enemigo4.x = enemigo4.x + velocidad3 * direccion2; if (enemigo4.x < 0 + enemigo4.width / 2) { enemigo4.x = 800 } enemigo5.x = enemigo5.x + velocidad5 * direccion2; if (enemigo5.x < 0 + enemigo5.width / 2) { enemigo5.x = 800 } enemigo6.x = enemigo6.x + velocidad3 * direccion2; if (enemigo6.x < 0 + enemigo6.width / 2) { enemigo6.x = 800 } } public function sueltoTecla(e:KeyboardEvent):void { switch(e.keyCode) { case Keyboard.RIGHT: der = false; break; case Keyboard.LEFT: izq = false; break; case Keyboard.DOWN: abj = false; break; case Keyboard.UP: arr = false; break; } } public function apretoTecla(e:KeyboardEvent):void { switch(e.keyCode) { case Keyboard.RIGHT: der = true; break; case Keyboard.LEFT: izq = true; break; case Keyboard.DOWN: abj = true break; case Keyboard.UP: arr = true; break; } } public function dibujarCirculo(color:int,radio:int, posX:int,posY:int):Sprite { var dj:Sprite = new Sprite(); dj.graphics.beginFill(color,1); dj.graphics.drawCircle(0,0,radio); dj.graphics.endFill(); stage.addChild(dj); dj.x = posX; dj.y = posY; return dj; } public function dibujarRectangulo(color:int,ancho:int,alto:int, posX:int,posY:int):Sprite { var dj:Sprite = new Sprite(); dj.graphics.beginFill(color,1); dj.graphics.drawRect(-ancho/2 , -alto/2 , ancho , alto); dj.graphics.endFill(); stage.addChild(dj); dj.x = posX; dj.y = posY; return dj; } } }
Hey, cool ^^ I haven't got the software to test it right now, but here are some general tips for your code! It is a good idea to never include 'magic numbers' inside your code, but use constants instead! A constant variable can be reused and easily altered in all the places by just changing one number. Moreover if you declare all your constants at the top of the file it's easy to find their value back. For example: Code: static var RESET_PLAYER_X = 400; static var RESET_PLAYER_Y = 565; (Maybe you can declare it a static const or something, not sure about the syntax, I rarely use Javascript-like syntax ^^. Furthermore, you've got quite some code repetition in some parts! For example in collision testing for enemies. If you had all the enemies in an 'enemies' array then you could iterate over the list and would only have to reposition your personaje once Code: for(var enemy : Sprite in enemies) { if (personaje.hitTestObject(enemy)) { personaje.x = RESET_PLAYER_X; personaje.y = RESET_PLAYER_Y; vida --; break; } }
Thank you very much, I really appreciate your tips. I will try and optimize my code further. The array was something I was considering as there are and could be more moving enemies later on, well, they are actually vehicles, but... whatever. I found that I was proclive to hardcoding and I had to slap my hand a couple of times, so yeah, hope I can get enough practice time to improve further, as I have 6 different courses in this semester... and I also work EDIT: oh, and I forgot, this is ActionScript 3.0 and it was done in Flash Builder 4.6
Np, I hope you can keep enough spare time to do your own projects Those are the best, right When I was still studying I made my own version of Snake in Java. I've still got it online here: http://vulturexmakinggames.webklik.nl/page/downloads It's a piece of ****, but it was fun to do and a good learning experience
Haha nice game man! I tested it out and it was like my childhood again but then with different Mods! :wanker: Me messing with the Editor-mode: LOL xD - - Anyways, I really like this and I wish that there were more games like this made by new pupils, but yeah you don't see this kinda stuff often. Thanks for making my day, haha. PS: I liked the Hayate Tsukiko Mod the best!
Thanks! That's nice to hear, I think you're the first one telling me this xD I posted this in the gaming section as well a few years ago, but I had 0 replies or likes xD I tried a lot of different things while making this, but there are some weird bugs regarding start-up or loading (which will hang some times on some systems) and fullscreen, which has bad performance, but I'm glad at least someone had fun with it
Don't friggin put Debug.Log in update! What i'm gonna say about game design, is that you'll have to have a careful design document of your games and don't deviate much from it if game play is fun. Adding new features that weren't in your design from the get go, might take your more time to implement later on than making a whole new world . Sometimes it may brake up things that you forgot you made that were dependent on something you changed.
This is coming from a fellow game design student, the programming stuff has to do a bit with the professor and you. On our very first basic programming class, the professor mostly just scribbled code on the projector and explained them rarely. Mostly it was up to us to figure out what code did what, which wasn't really helping the lazy dudes like myself. Hell even the top student at our block was complaining about incompetent teaching, and it was on programming which was a core part of game development. Next is where it has to do with you, and is the reason why only a small portion of our course has decent or better programmers. If the professor messes up, then it's up to YOU to keep up. And at first you might feel great to pass your programming class without learning much or even anything(cheatz) by your later years itll come back to haunt you as theres no way to get back to your beginner programming class. I'm friends with like the top 3 programmers in our batch and all of them learned on their own, ****ty prof or not it was all their hard work(could say professors just guided and introduced them a bit). If you feel your programming is lagging behind ask anyone for help or clarifications before the ditch gets too deep trust me. Sorry for the long message and the preaching, just dont want you to end up in the ****hole Im in
Awesome, nice for your first poject. I'm downloading it right now to test out. I just did the skeleton of the program. no fancy sprites or whatever as it wasn't even intiduced at that time in class. Handed it in, it was OK. That is entirely true. I will end this semester soon and when I have time with summer vacations (here it's from december to february) and I will skecth new game ideas and try to make my own games. I get what you say and I really do understand it. I will not hesitate in asking and I just realized this myself. Anyone can itroduce you to programming, give you the basics, the main logic procedures... but after that it's up to you. I will try hard to keep up as I felt this last week I lagged a bit behind other teammates, as I was finishing some game desing projects for other classes (texturizing and a simple side-scroller game design). On a side note, I have found a site which I found VERY helpful to understand how and what to do with some stuff I had doubts about and the teacher had no time to answer. Here it is: asgamer.com I was doing a simple asteroid type of game and had trouble with the 360 degree turning of the sprite, that's when I asked the teacher and he told me I had to use radians. But that was it. no further explanation... so then i found this: http://asgamer.com/2009/asteroids-style-movement-firing-lasers Awesome indeed. It's helping me a lot to understand what is happening behind the game. I'm gonna try and implement this in my own way, but it has been very helpful indeed.
http://goo.gl/s3h3ag Have a look at this site. It shows the insides of Mario64. While it is an old game, the way it was assembled and how stuff works, it's actually really really similar to how a game would be assembled today in Unity. (Infact it made me feel less smart on a couple of things i've done there because they did it better )