Batch Index du Forum
S’enregistrerRechercherFAQMembresGroupesConnexion
Répondre au sujet Page 1 sur 1
[Part 1] Tutorial Space Invader
Auteur Message
Répondre en citant
Message [Part 1] Tutorial Space Invader 
Hello. I begin this tutorial of write a space invader in batch using the bg tool.

The first step is download bg tool 2.8 at:
Code:
http://code.google.com/p/bg-tool/


Now I will work in C:\batchgame\
the i left here the bg.exe

Now, this is the plan of the work, is a very incremental plan.

1- Define the objects: monsters, nave, etc.
2- Define the size of the
3- Write the sprites of it, and show in the screen.

Then, will begin.
1- Define the objects: monsters, nave, etc.

I found this image in google:


Then I will use the six characters, except the nave (will add it at end part.)



Dernière édition par carlos le Sam 24 Aoû 2013 - 06:30; édité 2 fois
Message Publicité 
PublicitéSupprimer les publicités ?


Répondre en citant
Message [Part 1] Tutorial Space Invader 


the monster 1 have a size of 11x8 dots
the monster 2 have a size of 12x8 dots
the monster 3 have a size of 8x8 dots.

Using a resolution screen of 1024x768 and:
in cmd.exe using the default font size of 8x12: the max sixe of windows is 100x55

but using a font size of 4x6 the max windows allowed for fit in the screen is 250x110.



then if we need put 11 monsters, and i added 2 dots for each for border, the max monster dot size is 16*12, this is 16*11 = 176, then it size is very large and allow 11 monsters. If we put 3 lines of monsters this is 12*3 = 36, then, for only use the monsters in the screen we need 176x35 dots, then i will use this: 3 lines of monsters and 11 monsters by line.



Répondre en citant
Message [Part 1] Tutorial Space Invader 
In the documentation of bg I found a sprite of the first monster, but only 1 of two images (without movement).

Then adapting it for show a advance I can test the speed of cmd.exe for show 11 monsters and repat it 3 times. If is slow. I will adapt it.

For avoid calculations I will added inside the sprite a transparent margin border.




example1.cmd
Code:

@Echo Off
SetLocal EnableExtensions EnableDelayedExpansion

Color 07
Mode Con Cols=200 Lines=110
Bg.exe Font 0

:monster1
Set "monster1.width=15"
Set "monster1.eight=12"
Set "monster1.color=3F"
Set "monster1="
Set "monster1=%monster1%\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\n"
Set "monster1=%monster1%\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\n"
Set "monster1=%monster1%\00\00\00\00\DB\00\00\00\00\00\DB\00\00\00\00\n"
Set "monster1=%monster1%\00\00\00\00\00\DB\00\00\00\DB\00\00\00\00\00\n"
Set "monster1=%monster1%\00\00\00\00\DB\DB\DB\DB\DB\DB\DB\00\00\00\00\n"
Set "monster1=%monster1%\00\00\00\DB\DB\20\DB\DB\DB\20\DB\DB\00\00\00\n"
Set "monster1=%monster1%\00\00\DB\DB\DB\DB\DB\DB\DB\DB\DB\DB\DB\00\00\n"
Set "monster1=%monster1%\00\00\DB\00\DB\DB\DB\DB\DB\DB\DB\00\DB\00\00\n"
Set "monster1=%monster1%\00\00\DB\00\DB\00\00\00\00\00\DB\00\DB\00\00\n"
Set "monster1=%monster1%\00\00\00\00\00\DB\DB\00\DB\DB\00\00\00\00\00\n"
Set "monster1=%monster1%\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\n"
Set "monster1=%monster1%\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\n"

Set "con.X=1"
For /L %%R in (1,1,3) Do (
  Set "con.Y=1"
  For /L %%C in (1,1,11) Do (
    Bg.exe Sprite !con.X! !con.Y! %monster1.color% %monster1%
    Set /A "con.Y+=%monster1.width%"
  )
  Set /A "con.X+=%monster1.eight%"
)

Pause




Répondre en citant
Message [Part 1] Tutorial Space Invader 
I can comment a good practique.
In the constant values we use normal expansion: %var% and in values that change we use delayed expansion: !var! this is for avoid re expand constant values many times, that is unnecesary. Also in variables that hold numbers we only specify /A parameter to SET command, when I will do some calculation.



Dernière édition par carlos le Sam 24 Aoû 2013 - 06:31; édité 1 fois
Répondre en citant
Message [Part 1] Tutorial Space Invader 
Now i will do some modification for show movement to the monsters:

test2.cmd
Code:

@Echo Off
SetLocal EnableExtensions EnableDelayedExpansion

Color 07
Mode Con Cols=200 Lines=110
Bg.exe Font 0
Bg.exe Maximize


:monster1a
Set "monster1a.width=16"
Set "monster1a.eight=12"
Set "monster1a.color=F"
Set "monster1a="
Set "monster1a=%monster1a%\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\n"
Set "monster1a=%monster1a%\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\n"
Set "monster1a=%monster1a%\FF\FF\FF\FF\DB\FF\FF\FF\FF\FF\DB\FF\FF\FF\FF\FF\n"
Set "monster1a=%monster1a%\FF\FF\FF\FF\FF\DB\FF\FF\FF\DB\FF\FF\FF\FF\FF\FF\n"
Set "monster1a=%monster1a%\FF\FF\FF\FF\DB\DB\DB\DB\DB\DB\DB\FF\FF\FF\FF\FF\n"
Set "monster1a=%monster1a%\FF\FF\FF\DB\DB\FF\DB\DB\DB\FF\DB\DB\FF\FF\FF\FF\n"
Set "monster1a=%monster1a%\FF\FF\DB\DB\DB\DB\DB\DB\DB\DB\DB\DB\DB\FF\FF\FF\n"
Set "monster1a=%monster1a%\FF\FF\DB\FF\DB\DB\DB\DB\DB\DB\DB\FF\DB\FF\FF\FF\n"
Set "monster1a=%monster1a%\FF\FF\DB\FF\DB\FF\FF\FF\FF\FF\DB\FF\DB\FF\FF\FF\n"
Set "monster1a=%monster1a%\FF\FF\FF\FF\FF\DB\DB\FF\DB\DB\FF\FF\FF\FF\FF\FF\n"
Set "monster1a=%monster1a%\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\n"
Set "monster1a=%monster1a%\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\n"

:monster1b
Set "monster1b.width=16"
Set "monster1b.eight=12"
Set "monster1b.color=F"
Set "monster1b="
Set "monster1b=%monster1b%\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\n"
Set "monster1b=%monster1b%\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\n"
Set "monster1b=%monster1b%\FF\FF\FF\FF\DB\FF\FF\FF\FF\FF\DB\FF\FF\FF\FF\FF\n"
Set "monster1b=%monster1b%\FF\FF\DB\FF\FF\DB\FF\FF\FF\DB\FF\FF\DB\FF\FF\FF\n"
Set "monster1b=%monster1b%\FF\FF\DB\FF\DB\DB\DB\DB\DB\DB\DB\FF\DB\FF\FF\FF\n"
Set "monster1b=%monster1b%\FF\FF\DB\DB\DB\FF\DB\DB\DB\FF\DB\DB\DB\FF\FF\FF\n"
Set "monster1b=%monster1b%\FF\FF\DB\DB\DB\DB\DB\DB\DB\DB\DB\DB\DB\FF\FF\FF\n"
Set "monster1b=%monster1b%\FF\FF\FF\DB\DB\DB\DB\DB\DB\DB\DB\DB\FF\FF\FF\FF\n"
Set "monster1b=%monster1b%\FF\FF\FF\FF\DB\FF\FF\FF\FF\FF\DB\FF\FF\FF\FF\FF\n"
Set "monster1b=%monster1b%\FF\FF\FF\DB\FF\FF\FF\FF\FF\FF\FF\DB\FF\FF\FF\FF\n"
Set "monster1b=%monster1b%\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\n"
Set "monster1b=%monster1b%\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\n"

:ani
Bg.exe Sleep 200

Set "con.X=1"
For /L %%R in (1,1,3) Do (
  Set "con.Y=1"
  For /L %%C in (1,1,11) Do (
    Bg.exe Sprite !con.X! !con.Y! %monster1a.color% %monster1a%
    Set /A "con.Y+=%monster1a.width%"
  )
  Set /A "con.X+=%monster1a.eight%"
)


Set "con.X=1"
For /L %%R in (1,1,3) Do (
  Set "con.Y=1"
  For /L %%C in (1,1,11) Do (
    Bg.exe Sprite !con.X! !con.Y! %monster1b.color% %monster1b%
    Set /A "con.Y+=%monster1a.width%"
  )
  Set /A "con.X+=%monster1a.eight%"
)

goto ani

Pause>Nul



We changed in the sprite info the \00 (transparent) for \FF (background color), this is because if we print the sprite 1 with transparent color if we not erase it before print sprite 2, we show some like this:


because, reprint the old sprite with background and foreground color black (for erase it) add cycles to the batch, I prefer use a invisible character that show the background color, it can be the space (0x20) or 255 ascii (0xff) I choose this last for a readibility reason in the code.

Note: if you comment the line that says:
Code:
Bg.exe Sleep 200
you can see the animation in your max speed.

Here is showed more clear the sprites:



Now I will add horizontal movements to the monsters.



Dernière édition par carlos le Sam 24 Aoû 2013 - 06:33; édité 1 fois
Répondre en citant
Message [Part 1] Tutorial Space Invader 
Carlos, Very good stuff, and nice job !

We are waiting for part two...

Thanks






______________________________________________________
AffPng.exe , StringBetween.exe , Hex2Png.exe
Répondre en citant
Message [Part 1] Tutorial Space Invader 
Thanks.
Please, who begin the tutorial using the bg 2.7 please remove it and download bg 2.8, I will continue the tutorial using this version that is the best.



Message [Part 1] Tutorial Space Invader 


Montrer les messages depuis:
Répondre au sujet Page 1 sur 1
  



Index | créer un forum | Forum gratuit d’entraide | Annuaire des forums gratuits | Signaler une violation | Conditions générales d'utilisation
Copyright 2008 - 2016 // Batch