DIV ARENA FORUMS

Code snippet: Writing letter per letter on screen

Dennis - 20-3-2016 at 08:11 PM

I wrote this thing that makes text appear on the screen letter by letter.

I called it "Flash write" but call it whatever you want :)

include this process in your code:

Code:
/* Parameters: font,x,y,center : the same input parameters as "write()" speed : The amount of frames is between printing a character on screen pointer text id: the id of the text written on screen is passed via this pointer */ process flash_write(font,x,y,center,string text,speed,pointer text_id) private i; len; string new_text; begin len = strlen(text); *text_id=write(font,x,y,center,new_text); for (i=0;i<len;i++) strcat(new_text,*text[i]); frame(speed*100); end end



Example how to call it:

Code:
flash_write(0,160,100,4,"This is text",3,&text_id); // prints the text, a character every 3 frames repeat frame; until(key(_enter)) delete_text(text_id); // removes the text


The code should work, but tell me if you have problems with it.

PS: Maybe we could have a seperate section for code snippets?

MikeDX - 20-3-2016 at 08:14 PM

Very nice, and yes we can. :)

BreadCaster - 20-3-2016 at 08:53 PM

This is a fantastic idea, Dennis - and thanks Mike for making the subforum.

I was actually watching Extra Credits the other day, they did a session on creating your first game - and one of the things they said is how these days a lot of programming languages have resource sharing sections/places where you can pick up code snippets, models, 2D graphics and audio either for free or for a small fixed amount. Often it means that rather than spending weeks stuck on a piece of code or making a model that would take forever, someone else will already have the code and you can pick it up for free or a few bucks - solving the thing which would take forever to do yourself if you're less skilled in the area.

While all languages can draw on the same content - audio, 3d models, artwork, music etc (and I might actually do a post tonight, sharing the ones I know) - I thought to myself, "there isn't a strong enough background of people who know how to code in DIV/DIVDX to have established any 'code snippets' yet..." - and one of the strengths of more popular game creation tools like Unity, for instance, is that if you're really stuck then the code will likely already be floating around somewhere if it's a common task. This helps them become more commonly used and therefore more people write games in them and code snippets in them.

Anyway, what I mean is that having a good bunch of code snippets written for/in DIV (possibly for a small price or for free) could help it become a much more popular language for the hobbyists out there who're just starting out :D


Also, Dennis - I made some code like this for the game I'm currently tweaking/messing around with - it's much less efficient than yours. :lol:

Dennis - 21-3-2016 at 06:34 PM

Why thank you. That'll be 16 dollars.

Just kidding.

This thing popped in my mind because I was trying to make a blinking text (that's why it's called flash_write)

I hope many others will post snippets too!

がんばってください!

BreadCaster - 21-3-2016 at 09:27 PM

Quote: Originally posted by Dennis  
Why thank you. That'll be 16 dollars.

Just kidding.


You joke but, imagine if there were a piece of code to cull polygons from the immediate area where the player wasn't looking. Like if someone wrote that as a function. I'd happily pay for that :p

Personally I'd love it if there were some network play code snippets, as I can't seem to get it working myself!

MikeDX - 21-3-2016 at 09:38 PM

Breadmaster the new network api in div will be dead easy to use.

BreadCaster - 21-3-2016 at 10:46 PM

Quote: Originally posted by MikeDX  
Breadmaster the new network api in div will be dead easy to use.


holy [Censored] I am actually stoked now :D

Dennis - 22-3-2016 at 09:25 PM

Holy censored! That's awesome! I will make a great network game then!

BreadCaster - 22-3-2016 at 09:32 PM

Quote: Originally posted by Dennis  
Holy censored! That's awesome! I will make a great network game then!


I already have a partly made network game at the ready!! ... well, a scrolling starfield and a few menus with text input/strings to enter the IP, but they set the tone for the game very well - just waiting for the network module to be perfected so it can be properly made :D

MikeDX - 23-3-2016 at 10:58 AM

Best get cracking bready, the network works ;)

BreadCaster - 23-3-2016 at 07:09 PM

Quote: Originally posted by MikeDX  
Best get cracking bready, the network works ;)


Finishing the other game I'm working on first :p as it's much further along.

how much information will we need to join a game? Port and IP address to join to another PC?


MikeDX - 23-3-2016 at 07:13 PM

Don't need any port or ip or none of that nonsense

you just give your game a name, setup a struct and call net_join_game() to get your player id

BreadCaster - 23-3-2016 at 07:33 PM

Quote: Originally posted by MikeDX  
Don't need any port or ip or none of that nonsense

you just give your game a name, setup a struct and call net_join_game() to get your player id


hmm alright. I had a very nicely 80s tech retro-themed IP and PORT entry screen with an old fashioned modem sound, looked like something out of Alien, all ready to go, but I guess that's all superfluous to requirements now!

MikeDX - 23-3-2016 at 07:41 PM

Well there will still be the need to join other lobbies I guess since at the moment each game just gets joined on a matchmaking process. It's all still a bit WIP at the moment but the key thing is that it *must* be easy to use.

BreadCaster - 23-3-2016 at 07:47 PM

I could modify it so you can either directly connect to another PC, or go to a lobby? It's already coded with the option for the PC it's being played on to either be client or server side, so I could just recycle that code/option...

MikeDX - 23-3-2016 at 07:51 PM

Well, there are some net.* options that can be tweaked but they are currently configured for old IPX / Modem configuration so anything is possible really. maybe different modes, 1 - matchmaking, 2 - p2p, etc

BreadCaster - 23-3-2016 at 08:09 PM

That would be great - I mean, the game is incredibly simple, it's a 1v1 horror themed space sim. No AI, not much in terms of gameplay, it's all about the atmosphere - which is why I was a little worried about losing the menu so far as it does a great job of helping set the mood haha :smilegrin:

Dennis - 25-3-2016 at 11:50 AM

Broadcaster: Screenshots? :D