Page 1 of 2 12 LastLast
Results 1 to 20 of 26
  1. #1
    Secondary Hivemind Nexus
    Join Date
    Jun 2011
    Posts
    1,830

    Random Programmers Society (game programmers aficionado thread)

    I am eternally writting my first videogame, and I never finish it. Game programming and procrastination don't mix. Then I had this idea. Create a thread in RPS, for people that is writting games as a hobbie. Because, why no?, lets fail togueter! Has a way to quickstart this thread (before we derail it properly) we may use it to share programmer questions, or just share pretty code.

    I will start sharing some DERP code I am starting to write.

    The idea is to write one of these "Create your own virus and wipe humanity" games in html with javascript (...IN SPAACE).

    Function names and stuff is in spanish, but I think they set a obvious enough context is readable anyway.

    Code:
    var Game = Game || [];
    
    Game.mundos = [];
    Game.cuantos = 30;
    
    function repite(num,funcion){
    	for(var t=0;t<num;t++){
    		funcion();
    	}
    }
    
    function paratodos(elementos,funcion){
    	elementos.every(function(e,i,data){
    		funcion(e);
    		return true;
    	});
    }
    
    
    function rand(max){
    	return parseInt(Math.random()*max,10);
    }
    
    function p2px(num){
    	return (num*8)+"px";
    }
    
    
    $(function(){
    
    	Game.crearMundo = function(){
    		
    		var posx = rand(36);
    		var posy = rand(36);
    
    		var mundo = {
    			tipo: "mundo",
    			infectado: false,
    			x: posx,
    			y: posy,
    			$m:false,
    			tipo: "rocas"
    		};
    		
    		Game.mundos.push(mundo);
    	}; 
    
    
    	Game.generarSistemas = function(){
    		console.log("creando sistemas..");
    		repite(Game.cuantos,function(){
    			console.log("creando mundo..");
    			Game.crearMundo();	
    		});
    	};
    
    	Game.mostrarPlanetas = function(){
    		console.log("mostrar planetas..");
    		paratodos(Game.mundos,function(mundo){
    			console.log("mostrando mundo");
    			Game.dibujar(mundo);	
    		});
    	};
    
    	Game.crear = function(mundo){
    		console.log("creando planeta..");
    		console.dir(mundo);
    		var $m = $("<span>m</span>").
    			css({
    			position:"absolute",
    			top:p2px(mundo.y),
    			left:p2px(mundo.x)
    			});
    
    		console.log("info:"+p2px(mundo.x)+",posx:"+mundo.x);
    		//$m.css("left",p2px(mundo.posx));
    		mundo.$me = $m;
    		console.log("agnadiendo...");
    		Game.$map.append($m);	
    	};
    
    	Game.dibujar = function(mundo){
    		if(!mundo.$me){
    			console.log("creando mundo..");
    			Game.crear(mundo);
    		}
    		
    		//console.log("existe -- ");
    		if(mundo.infectado){
    			//console.log("dibujando como infectado..");
    			mundo.$me.html("X");
    		}else{
    			//console.log("dibujando como NO infectado..");
    			mundo.$me.html("M");
    		}
    
    	};
    
    	Game.infectarPlaneta = function(mundo){
    		mundo.infectado = true;
    	};
    	
    	Game.inicia = function(){		
    		console.log("iniciamos el juego");
    
    		Game.generarSistemas();
    
    		Game.infectarPlaneta(Game.mundos[0]);
    		Game.mostrarPlanetas();//dibujamos los planetas en la parrilla
    	};
    
    
    });
    
    
    var times = 0;
    
    function test_loop(){
    	times--;
    	if(times<0) return;
    
    	Game.mostrarPlanetas();
    	setTimeout(function(){
    		test_loop();		
    	},100);
    }
    
    function test(){
    	times = 1;
    	test_loop();
    }

    ...I am just writting this just now, so is just work in progress code, that don't even run yet.
    Last edited by Tei; 20-10-2013 at 02:00 AM.
    I kindly suggest you to donate/subscribe to RPS, to help this type of professional journalism

  2. #2
    Secondary Hivemind Nexus pakoito's Avatar
    Join Date
    Jun 2011
    Location
    Spainishtan
    Posts
    1,850
    Stop coding in spanish, please. Pretty please. Also javascript games.

    So my poisons so far are cocos2d-x (hate) and libgdx (love) but plan to get into Unity and Monogame in the near future.

    This is my latest pet projet, 3 weeks in June: http://forums.tigsource.com/index.php?topic=34202

    Managed to implement a script-based boardgame with full game logic, on top of libgdx, Artemis and beanshell as scripting language.

    Last edited by pakoito; 20-10-2013 at 12:33 AM.

  3. #3
    Secondary Hivemind Nexus
    Join Date
    Jun 2011
    Posts
    1,830
    Ha, I did not know you was also infected by this hobby. Looks good what you are doing. I think the strategy heads would like a game like that :D

    I choosed Javascript+html, because you can create a Thing with very low effort. Also share the result with the same low effort. I am not going to make games in C, because is weeks of work before you can show a sprite on the screen (I am being hiperbolic, but is esentially true). Python or Ruby or other script language would be okay too, but I don't know then very well, and generating something other people may want to try is complicate.
    Last edited by Tei; 20-10-2013 at 02:00 AM.
    I kindly suggest you to donate/subscribe to RPS, to help this type of professional journalism

  4. #4
    Moderator QuantaCat's Avatar
    Join Date
    Jun 2011
    Location
    Vienna, Austria
    Posts
    5,993
    If Y'all know a java programmer for my minecraft cocktailrobot, Id be very happy.
    - Tom De Roeck.

    verse publications

    "Quantacat's name is still recognised even if he watches on with detached eyes like Peter Molyneux over a cube in 3D space, staring at it with tears in his eyes, softly whispering... Someday they'll get it."

    "It's frankly embarrassing. The mods on here are woeful."

    "I wrinkled my nose at QC being a mod."

    "At least he has some personality."

  5. #5
    Secondary Hivemind Nexus
    Join Date
    Jun 2011
    Posts
    1,830
    Some snip I did yesterday for my game. This is a ultrasimple javascript teamplate engine.

    I have tried many Javascript Templating engines, and I don't like any of then. They are too hairy to use.

    Code:
    	UI.template = function(html,param){
    		var $esquema = $(html).clone();
    
    		$.each(param,function(key,$value){
    			$(key,$esquema).append($value);
    		});
    
    		return $esquema;
    	};
    
    //Example of use
    
    	var esquema = "<table border=1 width='100%'><tr><td class='desc'></td><td class='boton' width='50'></td></tr></table>";
    	var $frame = UI.template(esquema,{ ".boton":$boton, ".desc": $("<span>"+gen.description+"</span>") });

    Another snip. In games you often have to procedurally create stuff, like names. This is a function that generate random "chessy-sci-fi-like" names.

    Code:
    	Game.rname = function(){
    		var part = ["","","tor","ix","","","tran",
    			"ra","ga","za","pa","ta","ka","sh","dan","moon","dur","is"];
    		function r(){
    			var num = part.length;
    			var i = parseInt(Math.random()*num);
    			return part[i];
    		}
    
    		return $.trim(r()+r()+r()+r()+r());		
    	};

    This code has nice properties. Like generating names of different lenghs. And using "subwords" to generate words (So you can make 'moon' part of a lot of planets names).
    I kindly suggest you to donate/subscribe to RPS, to help this type of professional journalism

  6. #6
    Lesser Hivemind Node
    Join Date
    Jun 2011
    Location
    Edinburgh
    Posts
    609
    Howdy. I enjoy messing around trying to create overly ambitious strategy games in Unity every now and then. But I find that after a a few months of working on my own, I lose interest. It's a lot easier to keep motivation going when you're part of a team.

  7. #7
    Secondary Hivemind Nexus
    Join Date
    Jun 2011
    Posts
    1,830
    Thats looks good!.

    I tried myself to make a 3D game once, but I lack the skills :(
    Everyone that can make something that look half-way something interesting already impress me. And your thing has style!.

    GO GO! :D
    I kindly suggest you to donate/subscribe to RPS, to help this type of professional journalism

  8. #8
    Unity development is honesty a cake-walk. I've worked on a number of personal projects over the years, none of which I've finished because I'm a lazy lazy programmer. Right now I'm working on a 3d model viewer that utilizes input from a device that is similar to a kinect. It sounds more impressive than it is. My poison of choice is C#.
    Steam: tryqus

  9. #9
    Lesser Hivemind Node
    Join Date
    Jun 2011
    Location
    Edinburgh
    Posts
    609
    Quote Originally Posted by Tei View Post
    Thats looks good!.

    I tried myself to make a 3D game once, but I lack the skills :(
    Everyone that can make something that look half-way something interesting already impress me. And your thing has style!.

    GO GO! :D

    Thanks. The annoying thing is, I've more or less done all the hard work. [Of course, not really, but what I mean is: i've spent hours getting the systems in place for my 3d map and for setting up a simple turn based game in Unity). now all I need to do is the fun game design stuff.

    i might pick the project up again soon if I can find some folk to join in the game dev adventure. it's fun bouncing ideas off other people!

  10. #10
    Secondary Hivemind Nexus
    Join Date
    Jun 2011
    Posts
    1,830
    Sure thing, learning from other people is the best way to learn any software thing, and is the most fun.

    I had a coworker that was making games in unity, It looks like a very complete platform to start very forward in development. He made in front of me a very quick game with a car and a plaform. Cool stuff.
    I kindly suggest you to donate/subscribe to RPS, to help this type of professional journalism

  11. #11
    Lesser Hivemind Node
    Join Date
    Jun 2011
    Location
    Edinburgh
    Posts
    609
    Well, if you have any interest in helping to put together a tbs game, give me a shout. I'm usually on steam

  12. #12
    Secondary Hivemind Nexus
    Join Date
    Jun 2011
    Posts
    1,618
    The nice thing about Unity is it takes care of so much of the basic stuff.
    It already handles collisions, and rendering, and physics and so on.
    All you need to do is create the game logic.

    (The downside is it does sometimes make you awkwardly fit unity systems in to your game, where really you should use your own).

    Here's the class that handled a trigger system in one of my Unity games (language is Boo)

    Code:
    static class TriggerManager (): 
    
        listOfTargets as Hash
        
        public def Initalize():
            listOfTargets = Hash()
        
        public def RegisterTarget(targetName as string ,targetScript as TriggerableTile):
            unless listOfTargets.ContainsKey(targetName):
                listOfTargets[targetName] = List[of TriggerableTile]()
            targets as List of TriggerableTile
            targets = listOfTargets[targetName]
            targets.Add(targetScript)
            
        public def UnRegisterTarget(targetName as string, targetScript as TriggerableTile):
            targets as List of TriggerableTile
            unless listOfTargets[targetName] == null:
                targets = listOfTargets[targetName]
                targets.Remove(targetScript)
            
        public def TriggerTarget(targetName as string):
            for target as TriggerableTile in listOfTargets[targetName]:
                target.Trigger()

  13. #13
    Secondary Hivemind Nexus
    Join Date
    Jun 2011
    Posts
    1,830
    Quote Originally Posted by riadsala View Post
    Well, if you have any interest in helping to put together a tbs game, give me a shout. I'm usually on steam
    Sure thing!.

    And I need help. I am stuck and bored with the current prototype, so I am doomed to abandon it. But maybe I can show it to people and have something to push me continue until completion.


    Quote Originally Posted by CMaster View Post
    The nice thing about Unity is it takes care of so much of the basic stuff.
    It already handles collisions, and rendering, and physics and so on.
    All you need to do is create the game logic.
    I have already worked this way for ages with the quake engine. The result is that I have done some cool shit, but I can't really say I know OpenGL. Is weird.


    (The downside is it does sometimes make you awkwardly fit unity systems in to your game, where really you should use your own).

    Here's the class that handled a trigger system in one of my Unity games (language is Boo)

    Code:
    static class TriggerManager (): 
    
        listOfTargets as Hash
        
        public def Initalize():
            listOfTargets = Hash()
        
        public def RegisterTarget(targetName as string ,targetScript as TriggerableTile):
            unless listOfTargets.ContainsKey(targetName):
                listOfTargets[targetName] = List[of TriggerableTile]()
            targets as List of TriggerableTile
            targets = listOfTargets[targetName]
            targets.Add(targetScript)
            
        public def UnRegisterTarget(targetName as string, targetScript as TriggerableTile):
            targets as List of TriggerableTile
            unless listOfTargets[targetName] == null:
                targets = listOfTargets[targetName]
                targets.Remove(targetScript)
            
        public def TriggerTarget(targetName as string):
            for target as TriggerableTile in listOfTargets[targetName]:
                target.Trigger()
    I have programmed in C for many years, so my eyes automatically scanned the code for string comparison and raised a red flag for each string comparison. I don't know this programming language, but theres a lot of things that look like string comparisons/string lookups, so ouch, ouch, ouch. Other than that looks like some ok code to register and unregister targets. Its very few lines of code so theres very litte area where bugs can hide, and thats a good thing.
    I kindly suggest you to donate/subscribe to RPS, to help this type of professional journalism

  14. #14
    Secondary Hivemind Nexus Zephro's Avatar
    Join Date
    Aug 2011
    Location
    London
    Posts
    1,633
    Quote Originally Posted by QuantaCat View Post
    If Y'all know a java programmer for my minecraft cocktailrobot, Id be very happy.
    What do you need?

    I'd share something in the thread but have only done game code in C/C++ or Java (jMonkey Engine Lightweight Java Game Library).

    To be fair every time I go near this I get bored of doing graphics code and give up on it. Keep making prototypes of a Cyberpunk/procedural generation City game.

    Tried working in Unity C# and Javascript but just ick. I'm not happy unless I can go look at my main thread.

  15. #15
    Secondary Hivemind Nexus
    Join Date
    Jun 2011
    Posts
    1,618
    Quote Originally Posted by Tei View Post
    I have programmed in C for many years, so my eyes automatically scanned the code for string comparison and raised a red flag for each string comparison. I don't know this programming language, but theres a lot of things that look like string comparisons/string lookups, so ouch, ouch, ouch. Other than that looks like some ok code to register and unregister targets. Its very few lines of code so theres very litte area where bugs can hide, and thats a good thing.
    No string comparisons. Some string lookups. Why is that bad?

  16. #16
    Secondary Hivemind Nexus
    Join Date
    Jun 2011
    Posts
    1,830
    Quote Originally Posted by CMaster View Post
    No string comparisons. Some string lookups. Why is that bad?
    But anywhere you can use strings as constants, or index in a table / hash, you can use numerical constants, that in a compiled language will result in a offset. Its also posible that the compiler see a string lookup, and still produce some optimal code, so maybe this is moot point.

    I mean, this is ugly:

    squad.addUnit("TANK").
    squad.strength += strengh["TANK_STR"];

    This is better:

    squad.addUnit( units::TANK ) ;
    squad.strength += TANK_STR;

    the compiler will see:

    squad.addUnit( 22 ) ;
    squad.strength += 110;

    Anyway this is almost not important at all.


    Strings comparisons/lookups, can maybe generate code that made many comparisons. While constants will only need one or zero.
    I kindly suggest you to donate/subscribe to RPS, to help this type of professional journalism

  17. #17
    Network Hub
    Join Date
    Jun 2011
    Posts
    444
    Quote Originally Posted by CMaster View Post
    No string comparisons. Some string lookups. Why is that bad?
    That depends entirely on the internal implementation of string, but even implemented naively a string lookup would just involve hashing the string and then a comparison to check that you've really found the correct item. I know nothing of Boo but I would guess that it's not that simple, and even if it was I wouldn't worry about it unless you're doing it millions of times a second.

  18. #18
    Secondary Hivemind Nexus Zephro's Avatar
    Join Date
    Aug 2011
    Location
    London
    Posts
    1,633
    It's Unity as well and that's just how it works. If you're using an engine or interpreter or anything high level like Javascript then string lookups are part of life and worrying about really low level optimisation is probably fruitless.

  19. #19
    Secondary Hivemind Nexus
    Join Date
    Jun 2011
    Posts
    1,618
    My understanding is that at a low level, indexes in the .NET class ArrayList are indeed hashed, and thats how the comparison is done. It's perhaps worth pointing out that the index can be any object, not just a string. Strings are just what I was using in this case. I'd guessed that the performance was less than staggering, but the lookup will be needed to be performed every few hundred frames on average - it's not going to be a bottleneck.

    Using enumerators like Tei suggests misses what that chunk of code is actually for. The inicies are not generated at compile time - they're made at run time, from map files, which can be created by users. Eg, the use may place a switch and a door. They name the door "Door1" and then tell the switch to activate "Door1" when depressed.

  20. #20
    Secondary Hivemind Nexus
    Join Date
    Jun 2011
    Posts
    1,830
    I have made a thing!.

    Is a page that encrypt text using AES, then serialize it using "terrorism keywords".

    http://zerror.com/zoo/basens.htm

    I did not made the BaseN serializer, or the AES encrypted, so theres not much of my code, other than hunting down the libraries to do it, and having the idea, but the result is great.

    "Wellcometo Rock Paper Shotgun, have fun", encrypted in "BaseNS"

    black computer bomber breach brute el conventional ciudad brown control consular brute enforcement conventional control earthquake bomb collapse earthquake cdc bomber borne brush device colombia domain enriched decapitated border diego colombia disease dirty decapitated consular emergency broadcast enforcement drug denial cikr contamination el enforcement device enriched conficker cikr borne black bomb botnet epidemic dock command colombia decapitated enriched brown crest cikr bomb border dedicated epidemic chemical domestic cops conventional computer conficker colombia command brown cloud enforcement cache cache

    (using password RPS)
    I kindly suggest you to donate/subscribe to RPS, to help this type of professional journalism

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •