Batch Index du Forum
S’enregistrerRechercherFAQMembresGroupesConnexion
Répondre au sujet Page 1 sur 1
[Part 5] Tutorial Space Invader
Auteur Message
Répondre en citant
Message [Part 5] Tutorial Space Invader 
Now we added movement.

We have a variable called inv_movement with 4 states:
0 do nothing (this is for show the invaders the first time)
1 move to right
2 move to left
3 move to down.

part5a.cmd
Code:

::part5a.cmd
@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"
    )
  )
)

rem to right
rem 0 none
rem 1 right
rem 2 left
rem 3 down
Set "inv_movement=0"
Set "inv_sum_left=0"
Set "inv_sum_right=0"
Set "inv_sum_top=0"
Set "inv_sum_bottom=0"

: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 (
  rem if the invader is live
  If 1 Equ !inv_%%#.live! (

  rem erase the current sprite
  Bg.exe Sprite2 !inv_%%#.top! !inv_%%#.left! !inv_%%#.width! !inv_%%#.eight! 00 mon.!inv_%%#.type!.sfce.!inv_%%#.frame!
 
  rem setup the inv_movement
  Set /A "inv_%%#.left+=inv_sum_left"
  Set /A "inv_%%#.right+=inv_sum_right"
  Set /A "inv_%%#.top+=inv_sum_top"
  Set /A "inv_%%#.bottom+=inv_sum_bottom"
 
  rem show the sprite
  Bg.exe Sprite2 !inv_%%#.top! !inv_%%#.left! !inv_%%#.width! !inv_%%#.eight! !inv_%%#.color! mon.!inv_%%#.type!.sfce.!inv_%%#.frame!
 
  rem change the sprite
  Set /A "inv_%%#.frame=inv_%%#.frame%%2+1"
  )
)

If 1 equ %inv_movement% Set /A "inv_sum_left=1,inv_sum_right=1,inv_sum_top=0,inv_sum_bottom=0"
If 2 equ %inv_movement% Set /A "inv_sum_left=-1,inv_sum_right=-1,inv_sum_top=0,inv_sum_bottom=0"
If 3 equ %inv_movement% Set /A "inv_sum_left=0,inv_sum_right=0,inv_sum_top=1,inv_sum_bottom=1"

Set /A "inv_movement=inv_movement%%3+1"

Goto loop

Pause>Nul


That is slow, and also it flash many times every invader we need optimize it, how?

Because we always move the invader 1 pixel to the left or right, not have sense erase all the sprite. We do as the image 2.


For it we need create a erase sprite with the most long pixels that we erase. In our case we our invaders sizes are: 12x8, 11x8, 8x8, then our max erase will be 12 pixels. And when we use it, we indicate the quantity of pixels that we use.

Then we added this to our sprites:

Code:

:erase
Set "erase=\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF"


For erase a 8 pixel or 11 or 12 pixels. We can use it for erase horizontal or vertical.

and this code:
Code:

rem partial erase of the current sprite
  If %inv_sum_left% Equ 1 Bg.exe Sprite2 !inv_%%#.top! !inv_%%#.left! 1 !inv_%%#.eight! 00 erase
  If %inv_sum_right% Equ -1 Bg.exe Sprite2 !inv_%%#.top! !inv_%%#.right! 1 !inv_%%#.eight! 00 erase
  If %inv_sum_bottom% Equ 1 Bg.exe Sprite2 !inv_%%#.top! !inv_%%#.left! !inv_%%#.width! 1 00 erase


In the first we erase the first vertical.
In the second we erase the last vertical.
Int he third we erase the first horizontal.



Dernière édition par carlos le Lun 2 Sep 2013 - 04:18; édité 1 fois
Message Publicité 
PublicitéSupprimer les publicités ?


Répondre en citant
Message [Part 5] Tutorial Space Invader 
mon8.cmd
Code:

::mon.cmd
::version 8

::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"

:erase
Set "erase=\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF"




part5b.cmd
Code:

::part5b.cmd
@Echo Off
SetLocal EnableExtensions EnableDelayedExpansion

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

::initialize sprite data
call mon8.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-1"
    Set /A "inv_!id!.top=x"
    Set /A "inv_!id!.bottom=inv_!id!.top+inv_!id!.eight-1"
    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"
    )
  )
)

rem to right
rem 0 none
rem 1 right
rem 2 left
rem 3 down
Set "inv_movement=0"
Set "inv_sum_left=0"
Set "inv_sum_right=0"
Set "inv_sum_top=0"
Set "inv_sum_bottom=0"

: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 (
  rem if the invader is live
  If 1 Equ !inv_%%#.live! (

  rem partial erase of the current sprite
  If %inv_sum_left% Equ 1 Bg.exe Sprite2 !inv_%%#.top! !inv_%%#.left! 1 !inv_%%#.eight! 00 erase
  If %inv_sum_right% Equ -1 Bg.exe Sprite2 !inv_%%#.top! !inv_%%#.right! 1 !inv_%%#.eight! 00 erase
  If %inv_sum_bottom% Equ 1 Bg.exe Sprite2 !inv_%%#.top! !inv_%%#.left! !inv_%%#.width! 1 00 erase
 
  rem setup the inv_movement
  Set /A "inv_%%#.left+=inv_sum_left"
  Set /A "inv_%%#.right+=inv_sum_right"
  Set /A "inv_%%#.top+=inv_sum_top"
  Set /A "inv_%%#.bottom+=inv_sum_bottom"
 
  rem show the sprite
  Bg.exe Sprite2 !inv_%%#.top! !inv_%%#.left! !inv_%%#.width! !inv_%%#.eight! !inv_%%#.color! mon.!inv_%%#.type!.sfce.!inv_%%#.frame!
 
  rem change the sprite
  Set /A "inv_%%#.frame=inv_%%#.frame%%2+1"
  )
)

If 1 equ %inv_movement% Set /A "inv_sum_left=1,inv_sum_right=1,inv_sum_top=0,inv_sum_bottom=0"
If 2 equ %inv_movement% Set /A "inv_sum_left=-1,inv_sum_right=-1,inv_sum_top=0,inv_sum_bottom=0"
If 3 equ %inv_movement% Set /A "inv_sum_left=0,inv_sum_right=0,inv_sum_top=1,inv_sum_bottom=1"

Set /A "inv_movement=inv_movement%%3+1"

Goto loop

Pause>Nul




Dernière édition par carlos le Lun 2 Sep 2013 - 04:20; édité 1 fois
Répondre en citant
Message [Part 5] Tutorial Space Invader 
For understand how it works:

replace this:
Code:

 rem partial erase of the current sprite
  If %inv_sum_left% Equ 1 Bg.exe Sprite2 !inv_%%#.top! !inv_%%#.left! 1 !inv_%%#.eight! 00 erase
  If %inv_sum_right% Equ -1 Bg.exe Sprite2 !inv_%%#.top! !inv_%%#.right! 1 !inv_%%#.eight! 00 erase
  If %inv_sum_bottom% Equ 1 Bg.exe Sprite2 !inv_%%#.top! !inv_%%#.left! !inv_%%#.width! 1 00 erase


for this:

Code:

 rem partial erase of the current sprite
  If %inv_sum_left% Equ 1 Bg.exe Sprite2 !inv_%%#.top! !inv_%%#.left! 1 !inv_%%#.eight! 33 erase &pause>nul
  If %inv_sum_right% Equ -1 Bg.exe Sprite2 !inv_%%#.top! !inv_%%#.right! 1 !inv_%%#.eight! 44 erase &pause>nul
  If %inv_sum_bottom% Equ 1 Bg.exe Sprite2 !inv_%%#.top! !inv_%%#.left! !inv_%%#.width! 1 55 erase &pause>nul


And press a key for look how it erase like this:





Message [Part 5] 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