Batch Index du Forum
S’enregistrerRechercherFAQMembresGroupesConnexion
Répondre au sujet Page 1 sur 1
[Part 4] Tutorial Space Invader
Auteur Message
Répondre en citant
Message [Part 4] Tutorial Space Invader 
Well, I will continue this tutorial, but before continue is need use the new version (alpha version) of bg 2.9 that have a new function called sprite2 (it we give us more speedy).
This is the link:
Code:
https://docs.google.com/file/d/0B7ry-e4DtQ5ISUsxUFRqMVRxb2M/edit?usp=sharing


Now, I do many changes to the code that we can comment.
1- Eliminated the monsters of type 4 and 5. Cause? Our future shoot will have a eight of 4 dots, and we calculate the collision using the coordinates of the shot and the monsters. Monsters 4 and 5 can allow a shot without collision:



Also the margin inside the surface of the sprite was eliminated, now is specified in a number variable.

2- Set a nomenclature name: for the objects we use abbreviations:
sfce (surface)
inv (invader) (this is used as prefix for the invaders).
mon (monster) (this is used as sprite).
exp (explode) (this is used as sprite).
sau (saucer) (this is used as sprite).
nav (nave) (this is used as sprite).


3- Added more properties of the sprite:
width, eight, lmargin, rmargin.
lmargin means left margin.
rmargin means right margin.


Our most bigger monster have a width of 12 pixels, then for align the smaller monsters, we use left and right margin. In the example, 12 - 8 are 4 pixels, then we use 2 to the left and 2 to the right.

4- Added coordinates for each invader. top, right, botom, left. We use this for detect the collisions of the shots.
For example our shot will have a width of 1 pixel and a eight of 4 pixels. If it have a x top coordinate of 48 and left coordiante of 15, and one monster have a bottom coordinate of 49 and a right coordinate of 16 it means a collision.




5- Eliminated the link of the sprites. Now it not use letters, it use numbers. How we link it?
Using a arithmetic operation.

we have a frame that is composed of surface 1, surface 2.
this frame have a index of 1 for use the surface 1.
we always add 1 to the index.

1+1=2
2+1=3

we have a max index of 2.

how convert the 3 in 1?
One option can use a if:
if frame equ 3 frame=1

but the arithmetic uses modulo: %% max
2 % 2 = 0
3 % 2 = 1

then we uses modulo and sum 1 for convert the 0 in 1, and the 1 in 2. Then we always have index 1 or 2 and 2 link to 1 and 1 to 2.


6- For reference to near invader we use : invader.near.east (now we not use invader.right because it is a property of the coordinate of the invader), invader.near.west, invader.near.north, invader.near.south.

7- Now we use the sprite2 function of bg. That is your syntax:
Code:

Bg.exe Sprite2 row column width eight color var_surface


The argument number 8 is a variable name that hold the surface. And because we specify the width and eight of the surface, we not use anymore the \n at the end of each surface of the sprite.

For test this new function use:
Code:

bg sprite2 10 10 9 1 c windir



8- Using a original snapshots of the original space invader game I draw more surface of a sprite like the explodes, the nave and the ir saucer.

mon7.cmd
Code:

::mon.cmd
::version 7

::colors of rows
Set "row.5.clr=D"
Set "row.4.clr=A"
Set "row.3.clr=A"
Set "row.2.clr=B"
Set "row.1.clr=E"

:clean sprites
Set "mon.1.sfce.1="
Set "mon.1.sfce.2="
Set "mon.2.sfce.1="
Set "mon.2.sfce.2="
Set "mon.3.sfce.1="
Set "mon.3.sfce.2="
Set "exp.1.sfce.1="
Set "exp.2.sfce.1="
Set "exp.3.sfce.1="
Set "sau.1.sfce.1="
Set "nav.1.sfce.1="

Set "mon.1.width=12"
Set "mon.1.eight=8"
Set "mon.1.lmargin=0"
Set "mon.1.rmargin=0"
:mon.1.sfce.1
Set "mon.1.sfce.1=%mon.1.sfce.1%\FF\FF\FF\FF\DB\DB\DB\DB\FF\FF\FF\FF"
Set "mon.1.sfce.1=%mon.1.sfce.1%\FF\DB\DB\DB\DB\DB\DB\DB\DB\DB\DB\FF"
Set "mon.1.sfce.1=%mon.1.sfce.1%\DB\DB\DB\DB\DB\DB\DB\DB\DB\DB\DB\DB"
Set "mon.1.sfce.1=%mon.1.sfce.1%\DB\DB\DB\FF\FF\DB\DB\FF\FF\DB\DB\DB"
Set "mon.1.sfce.1=%mon.1.sfce.1%\DB\DB\DB\DB\DB\DB\DB\DB\DB\DB\DB\DB"
Set "mon.1.sfce.1=%mon.1.sfce.1%\FF\FF\FF\DB\DB\FF\FF\DB\DB\FF\FF\FF"
Set "mon.1.sfce.1=%mon.1.sfce.1%\FF\FF\DB\DB\FF\DB\DB\FF\DB\DB\FF\FF"
Set "mon.1.sfce.1=%mon.1.sfce.1%\DB\DB\FF\FF\FF\FF\FF\FF\FF\FF\DB\DB"
:mon.1.sfce.2
Set "mon.1.sfce.2=%mon.1.sfce.2%\FF\FF\FF\FF\DB\DB\DB\DB\FF\FF\FF\FF"
Set "mon.1.sfce.2=%mon.1.sfce.2%\FF\DB\DB\DB\DB\DB\DB\DB\DB\DB\DB\FF"
Set "mon.1.sfce.2=%mon.1.sfce.2%\DB\DB\DB\DB\DB\DB\DB\DB\DB\DB\DB\DB"
Set "mon.1.sfce.2=%mon.1.sfce.2%\DB\DB\DB\FF\FF\DB\DB\FF\FF\DB\DB\DB"
Set "mon.1.sfce.2=%mon.1.sfce.2%\DB\DB\DB\DB\DB\DB\DB\DB\DB\DB\DB\DB"
Set "mon.1.sfce.2=%mon.1.sfce.2%\FF\FF\DB\DB\DB\FF\FF\DB\DB\DB\FF\FF"
Set "mon.1.sfce.2=%mon.1.sfce.2%\FF\DB\DB\FF\FF\DB\DB\FF\FF\DB\DB\FF"
Set "mon.1.sfce.2=%mon.1.sfce.2%\FF\FF\DB\DB\FF\FF\FF\FF\DB\DB\FF\FF"

Set "mon.2.width=11"
Set "mon.2.eight=8"
Set "mon.2.lmargin=1"
Set "mon.2.rmargin=0"
:mon.2.sfce.1
Set "mon.2.sfce.1=%mon.2.sfce.1%\FF\FF\DB\FF\FF\FF\FF\FF\DB\FF\FF"
Set "mon.2.sfce.1=%mon.2.sfce.1%\FF\FF\FF\DB\FF\FF\FF\DB\FF\FF\FF"
Set "mon.2.sfce.1=%mon.2.sfce.1%\FF\FF\DB\DB\DB\DB\DB\DB\DB\FF\FF"
Set "mon.2.sfce.1=%mon.2.sfce.1%\FF\DB\DB\FF\DB\DB\DB\FF\DB\DB\FF"
Set "mon.2.sfce.1=%mon.2.sfce.1%\DB\DB\DB\DB\DB\DB\DB\DB\DB\DB\DB"
Set "mon.2.sfce.1=%mon.2.sfce.1%\DB\FF\DB\DB\DB\DB\DB\DB\DB\FF\DB"
Set "mon.2.sfce.1=%mon.2.sfce.1%\DB\FF\DB\FF\FF\FF\FF\FF\DB\FF\DB"
Set "mon.2.sfce.1=%mon.2.sfce.1%\FF\FF\FF\DB\DB\FF\DB\DB\FF\FF\FF"
:mon.2.sfce.2
Set "mon.2.sfce.2=%mon.2.sfce.2%\FF\FF\DB\FF\FF\FF\FF\FF\DB\FF\FF"
Set "mon.2.sfce.2=%mon.2.sfce.2%\DB\FF\FF\DB\FF\FF\FF\DB\FF\FF\DB"
Set "mon.2.sfce.2=%mon.2.sfce.2%\DB\FF\DB\DB\DB\DB\DB\DB\DB\FF\DB"
Set "mon.2.sfce.2=%mon.2.sfce.2%\DB\DB\DB\FF\DB\DB\DB\FF\DB\DB\DB"
Set "mon.2.sfce.2=%mon.2.sfce.2%\DB\DB\DB\DB\DB\DB\DB\DB\DB\DB\DB"
Set "mon.2.sfce.2=%mon.2.sfce.2%\FF\DB\DB\DB\DB\DB\DB\DB\DB\DB\FF"
Set "mon.2.sfce.2=%mon.2.sfce.2%\FF\FF\DB\FF\FF\FF\FF\FF\DB\FF\FF"
Set "mon.2.sfce.2=%mon.2.sfce.2%\FF\DB\FF\FF\FF\FF\FF\FF\FF\DB\FF"

Set "mon.3.width=8"
Set "mon.3.eight=8"
Set "mon.3.lmargin=2"
Set "mon.3.rmargin=2"
:mon.3.sfce.1
Set "mon.3.sfce.1=%mon.3.sfce.1%\FF\FF\FF\DB\DB\FF\FF\FF"
Set "mon.3.sfce.1=%mon.3.sfce.1%\FF\FF\DB\DB\DB\DB\FF\FF"
Set "mon.3.sfce.1=%mon.3.sfce.1%\FF\DB\DB\DB\DB\DB\DB\FF"
Set "mon.3.sfce.1=%mon.3.sfce.1%\DB\DB\FF\DB\DB\FF\DB\DB"
Set "mon.3.sfce.1=%mon.3.sfce.1%\DB\DB\DB\DB\DB\DB\DB\DB"
Set "mon.3.sfce.1=%mon.3.sfce.1%\FF\DB\FF\DB\DB\FF\DB\FF"
Set "mon.3.sfce.1=%mon.3.sfce.1%\DB\FF\FF\FF\FF\FF\FF\DB"
Set "mon.3.sfce.1=%mon.3.sfce.1%\FF\DB\FF\FF\FF\FF\DB\FF"
:mon.3.sfce.2
Set "mon.3.sfce.2=%mon.3.sfce.2%\FF\FF\FF\DB\DB\FF\FF\FF"
Set "mon.3.sfce.2=%mon.3.sfce.2%\FF\FF\DB\DB\DB\DB\FF\FF"
Set "mon.3.sfce.2=%mon.3.sfce.2%\FF\DB\DB\DB\DB\DB\DB\FF"
Set "mon.3.sfce.2=%mon.3.sfce.2%\DB\DB\FF\DB\DB\FF\DB\DB"
Set "mon.3.sfce.2=%mon.3.sfce.2%\DB\DB\DB\DB\DB\DB\DB\DB"
Set "mon.3.sfce.2=%mon.3.sfce.2%\FF\FF\DB\FF\FF\DB\FF\FF"
Set "mon.3.sfce.2=%mon.3.sfce.2%\FF\DB\FF\DB\DB\FF\DB\FF"
Set "mon.3.sfce.2=%mon.3.sfce.2%\DB\FF\DB\FF\FF\DB\FF\DB"

Set "exp.1.width=13"
Set "exp.1.eight=8"
Set "exp.1.lmargin=0"
Set "exp.1.rmargin=0"
:exp.l.sfce.1
Set "exp.1.sfce.1=%exp.1.sfce.1%\FF\FF\FF\FF\DB\FF\FF\FF\DB\FF\FF\FF\FF"
Set "exp.1.sfce.1=%exp.1.sfce.1%\FF\DB\FF\FF\FF\DB\FF\DB\FF\FF\FF\DB\FF"
Set "exp.1.sfce.1=%exp.1.sfce.1%\FF\FF\DB\FF\FF\FF\FF\FF\FF\FF\DB\FF\FF"
Set "exp.1.sfce.1=%exp.1.sfce.1%\FF\FF\FF\DB\FF\FF\FF\FF\FF\DB\FF\FF\FF"
Set "exp.1.sfce.1=%exp.1.sfce.1%\DB\DB\FF\FF\FF\FF\FF\FF\FF\FF\FF\DB\DB"
Set "exp.1.sfce.1=%exp.1.sfce.1%\FF\FF\FF\DB\FF\FF\FF\FF\FF\DB\FF\FF\FF"
Set "exp.1.sfce.1=%exp.1.sfce.1%\FF\FF\DB\FF\FF\DB\FF\DB\FF\FF\DB\FF\FF"
Set "exp.1.sfce.1=%exp.1.sfce.1%\FF\DB\FF\FF\DB\FF\FF\FF\DB\FF\FF\DB\FF"

Set "exp.2.width=8"
Set "exp.2.eight=8"
Set "exp.2.lmargin=0"
Set "exp.2.rmargin=0"
:exp.2.sfce.1
Set "exp.2.sfce.1=%exp.2.sfce.1%\DB\FF\FF\FF\DB\FF\FF\DB"
Set "exp.2.sfce.1=%exp.2.sfce.1%\FF\FF\DB\FF\FF\FF\DB\FF"
Set "exp.2.sfce.1=%exp.2.sfce.1%\FF\DB\DB\DB\DB\DB\DB\FF"
Set "exp.2.sfce.1=%exp.2.sfce.1%\DB\DB\DB\DB\DB\DB\DB\DB"
Set "exp.2.sfce.1=%exp.2.sfce.1%\DB\DB\DB\DB\DB\DB\DB\DB"
Set "exp.2.sfce.1=%exp.2.sfce.1%\FF\DB\DB\DB\DB\DB\DB\FF"
Set "exp.2.sfce.1=%exp.2.sfce.1%\FF\FF\DB\FF\FF\DB\FF\FF"
Set "exp.2.sfce.1=%exp.2.sfce.1%\DB\FF\FF\DB\FF\FF\FF\DB"

Set "exp.3.width=21"
Set "exp.3.eight=8"
Set "exp.3.lmargin=0"
Set "exp.3.rmargin=0"
:exp.3.sfce.1
Set "exp.3.sfce.1=%exp.3.sfce.1%\FF\FF\DB\FF\FF\DB\FF\DB\FF\FF\FF\FF\FF\FF\DB\FF\DB\FF\FF\DB\FF"
Set "exp.3.sfce.1=%exp.3.sfce.1%\FF\FF\FF\DB\FF\FF\FF\FF\FF\FF\FF\FF\DB\DB\FF\FF\FF\FF\DB\FF\FF"
Set "exp.3.sfce.1=%exp.3.sfce.1%\DB\FF\DB\FF\FF\FF\DB\DB\DB\DB\FF\FF\FF\DB\DB\FF\FF\FF\FF\FF\FF"
Set "exp.3.sfce.1=%exp.3.sfce.1%\FF\FF\FF\FF\FF\DB\DB\DB\DB\DB\DB\DB\FF\FF\DB\DB\DB\FF\FF\DB\FF"
Set "exp.3.sfce.1=%exp.3.sfce.1%\FF\FF\FF\FF\DB\DB\DB\FF\DB\FF\DB\FF\DB\FF\FF\DB\DB\DB\FF\FF\DB"
Set "exp.3.sfce.1=%exp.3.sfce.1%\FF\FF\DB\FF\FF\FF\DB\DB\DB\DB\DB\FF\FF\FF\DB\DB\FF\FF\FF\FF\FF"
Set "exp.3.sfce.1=%exp.3.sfce.1%\DB\FF\FF\FF\FF\FF\FF\DB\FF\DB\FF\FF\FF\DB\DB\FF\FF\FF\DB\FF\FF"
Set "exp.3.sfce.1=%exp.3.sfce.1%\FF\FF\DB\FF\FF\FF\DB\FF\FF\FF\DB\FF\FF\FF\FF\DB\FF\FF\FF\FF\FF"


Set "sau.1.width=16"
Set "sau.1.eight=7"
Set "sau.1.lmargin=0"
Set "sau.1.rmargin=0"
:sau.1.sfce.1
Set "sau.1.sfce.1=%sau.1.sfce.1%\FF\FF\FF\FF\FF\DB\DB\DB\DB\DB\DB\FF\FF\FF\FF\FF"
Set "sau.1.sfce.1=%sau.1.sfce.1%\FF\FF\FF\DB\DB\DB\DB\DB\DB\DB\DB\DB\DB\FF\FF\FF"
Set "sau.1.sfce.1=%sau.1.sfce.1%\FF\FF\DB\DB\DB\DB\DB\DB\DB\DB\DB\DB\DB\DB\FF\FF"
Set "sau.1.sfce.1=%sau.1.sfce.1%\FF\DB\DB\FF\DB\DB\FF\DB\DB\FF\DB\DB\FF\DB\DB\FF"
Set "sau.1.sfce.1=%sau.1.sfce.1%\DB\DB\DB\DB\DB\DB\DB\DB\DB\DB\DB\DB\DB\DB\DB\DB"
Set "sau.1.sfce.1=%sau.1.sfce.1%\FF\FF\DB\DB\DB\FF\FF\DB\DB\FF\FF\DB\DB\DB\FF\FF"
Set "sau.1.sfce.1=%sau.1.sfce.1%\FF\FF\FF\DB\FF\FF\FF\FF\FF\FF\FF\FF\DB\FF\FF\FF"

Set "nav.1.width=13"
Set "nav.1.eight=8"
Set "nav.1.lmargin=0"
Set "nav.1.rmargin=0"
:nav.1.sfce.1
Set "nav.1.sfce.1="
Set "nav.1.sfce.1=%nav.1.sfce.1%\FF\FF\FF\FF\FF\FF\DB\FF\FF\FF\FF\FF\FF"
Set "nav.1.sfce.1=%nav.1.sfce.1%\FF\FF\FF\FF\FF\DB\DB\DB\FF\FF\FF\FF\FF"
Set "nav.1.sfce.1=%nav.1.sfce.1%\FF\FF\FF\FF\FF\DB\DB\DB\FF\FF\FF\FF\FF"
Set "nav.1.sfce.1=%nav.1.sfce.1%\FF\DB\DB\DB\DB\DB\DB\DB\DB\DB\DB\DB\FF"
Set "nav.1.sfce.1=%nav.1.sfce.1%\DB\DB\DB\DB\DB\DB\DB\DB\DB\DB\DB\DB\DB"
Set "nav.1.sfce.1=%nav.1.sfce.1%\DB\DB\DB\DB\DB\DB\DB\DB\DB\DB\DB\DB\DB"
Set "nav.1.sfce.1=%nav.1.sfce.1%\DB\DB\DB\DB\DB\DB\DB\DB\DB\DB\DB\DB\DB"
Set "nav.1.sfce.1=%nav.1.sfce.1%\DB\DB\DB\DB\DB\DB\DB\DB\DB\DB\DB\DB\DB"




part4.cmd
Code:

@Echo Off
SetLocal EnableExtensions EnableDelayedExpansion

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

::initialize sprite data
call mon7.cmd

:margins
Set "INVADER.SEPARATION.X=3"
Set "INVADER.SEPARATION.Y=2"

::create 55 monsters
::every 11 monsters we change the type of monster
::each monster is separated of the next by INVADER.SEPARATION.
::we create the monsters in this order and id:
::
:: 01,02,03,04,05,06,07,08,09,10,11
:: 12,13,14,15,16,17,18,19,20,21,22
:: 23,24,25,26,27,28,29,30,31,32,33
:: 34,35,36,37,38,39,40,41,42,43,44
:: 45,46,47,48,49,50,51,52,53,54,55
::

Set "id=0"
::coords for the first monster
Set "x=10"
::Set "y=10"
::r variable is for reference to a imaginary row and allow select the color.
Set "r=5"
For %%T In (3,2,2,1,1) Do (
  Set "y=10"
  For /L %%# In (1,1,11) Do (
    Set /A "id+=1"
    Set /A "inv_!id!.near.north=id-11"
    Set /A "inv_!id!.near.east=id+1"
    Set /A "inv_!id!.near.south=id+11"
    Set /A "inv_!id!.near.west=id-1"
    Set "inv_!id!.live=1"
    Set "inv_!id!.type=%%T"
    Set "inv_!id!.frame=1"
    For %%C In (row.!r!.clr) Do Set "inv_!id!.color=!%%C!"
    Set /A "inv_!id!.width=mon.%%T.width"
    Set /A "inv_!id!.eight=mon.%%T.eight"
    Set /A "inv_!id!.left=y+mon.%%T.lmargin"
    Set /A "inv_!id!.right=inv_!id!.left+inv_!id!.width"
    Set /A "inv_!id!.top=x"
    Set /A "inv_!id!.bottom=inv_!id!.top+inv_!id!.eight"
    Set /A "y=inv_!id!.right+mon.%%T.rmargin+%INVADER.SEPARATION.Y%"
  )
  Set /A "x=inv_!id!.bottom+%INVADER.SEPARATION.X%"
  Set /a "r-=1"
)

::set the references to 0
For /L %%# In (1,1,11) Do Set "inv_%%#.near.north=0"
For /L %%# In (11,11,55) Do Set inv_%%#.near.east=0"
For /L %%# In (45,1,55) Do Set "inv_%%#.near.south=0"
For /L %%# In (1,11,45) Do Set "inv_%%#.near.west=0"

::set list of mons that can shoot.
Set "can_shoot.size=0"
For /L %%# in (1,1,55) Do (
  If 0 equ !inv_%%#.near.down! (
    If 1 equ !inv_%%#.live! (
      Set "can_shoot[!can_shoot.size!]=%%#"
      Set /A "can_shoot.size+=1"
    )
  )
)


:loop

::show in the screen
For %%# In (
45,46,47,48,49,50,51,52,53,54,55
34,35,36,37,38,39,40,41,42,43,44
23,24,25,26,27,28,29,30,31,32,33
12,13,14,15,16,17,18,19,20,21,22
1,2,3,4,5,6,7,8,9,10,11
) Do (
  Bg.exe Sprite2 !inv_%%#.top! !inv_%%#.left! !inv_%%#.width! !inv_%%#.eight! !inv_%%#.color! mon.!inv_%%#.type!.sfce.!inv_%%#.frame!
  Set /A "inv_%%#.frame=inv_%%#.frame%%2+1"
)
goto loop


Pause>Nul




and currently it looks like this:


This is more of the same? In the next part we added movement to the monsters to left, right and down.



Message Publicité 
PublicitéSupprimer les publicités ?


Répondre en citant
Message [Part 4] Tutorial Space Invader 
hello!
I do not understand (but this) tutorial!
But I feel that bg improves the display speed!
I think you could integrate my bg-Sprite DangerouSpace to a concrete example!
Furthermore, the main problem of my game iis its slowness, adding BG could be remedied
(Source: Google: Translation)

hello !
je ne comprend pas le (but de ce) tuto !
Mais j'ai l'impression que bg ameliore la rapidité d'affichage !
Je pense que tu pourrait intégrer bg-Sprite à mon DangerousSapaces pour faire un exemple concret !
De plus, le principale probléme de mon jeu est sa lenteur, l'ajout de BG pourrait y remédier
( source: Google: Traduction )




______________________________________________________
Clickez sur Saturne pour voir mes tutoriels et sur la Terre pour voir mon Forum:


Skype
Répondre en citant
Message [Part 4] Tutorial Space Invader 
What of the code you don't understand?



Répondre en citant
Message [Part 4] Tutorial Space Invader 
I do not understand the purpose of the tutorial!
Explain a game that you did not create ? ...

Je ne comprend pas le but du tuto !
Expliquer un jeu que tu n'a pas encore créer ? ...




______________________________________________________
Clickez sur Saturne pour voir mes tutoriels et sur la Terre pour voir mon Forum:


Skype
Répondre en citant
Message [Part 4] Tutorial Space Invader 
But d'un tutoriel :

http://fr.wikipedia.org/wiki/Tutoriel

Okay




______________________________________________________
AffPng.exe , StringBetween.exe , Hex2Png.exe
Message [Part 4] 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