Batch Index du Forum
S’enregistrerRechercherFAQMembresGroupesConnexion
Répondre au sujet Page 1 sur 1
[Part 6] Tutorial Space Invader
Auteur Message
Répondre en citant
Message [Part 6] Tutorial Space Invader 
Hello. Sorry for the delay.

Now, I continue this tutorial.

A continuation we add the system for destroy a invader and also add the movement of the invaders.

part6.cmd
Code:


::part6.cmd
@Echo Off
SetLocal EnableExtensions EnableDelayedExpansion

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

::initialize sprite data
call mon8.cmd

:margins
Set "INVADER.SEPARATION.X=6"
Set "INVADER.SEPARATION.Y=4"

Set "invaders_count=55"
Set "LIMIT_RIGHT=180"
Set "LIMIT_LEFT=10"

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

::x row
::y column

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 "mov=0"
Set "prev=0"

:loop

Set "lastLeft=0"
Set "lastRight=0"

::show in the screen in the next order
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! (

    If 0 Equ !inv_%%#.near.west! If !inv_%%#.near.south! Equ !lastLeft! Set "lastLeft=%%#"
    If 0 Equ !inv_%%#.near.east! If !inv_%%#.near.south! Equ !lastRight! Set "lastRight=%%#"   

    rem partial erase of the current sprite
    rem and show the sprite

    If %mov% Equ 1 (
      Bg.exe Sprite2 !inv_%%#.top! !inv_%%#.left! 1 !inv_%%#.eight! 00 erase
      Set /A "inv_%%#.left+=1,inv_%%#.right+=1"
      Bg.exe Sprite2 !inv_%%#.top! !inv_%%#.left! !inv_%%#.width! !inv_%%#.eight! !inv_%%#.color! mon.!inv_%%#.type!.sfce.!inv_%%#.frame!
    )

    If %mov% Equ 2 (
      Bg.exe Sprite2 !inv_%%#.top! !inv_%%#.right! 1 !inv_%%#.eight! 00 erase
      Set /A "inv_%%#.left-=1,inv_%%#.right-=1"
      Bg.exe Sprite2 !inv_%%#.top! !inv_%%#.left! !inv_%%#.width! !inv_%%#.eight! !inv_%%#.color! mon.!inv_%%#.type!.sfce.!inv_%%#.frame!
    )

    If %mov% Equ 3 (
      Bg.exe Sprite2 !inv_%%#.top! !inv_%%#.left! !inv_%%#.width! !inv_%%#.eight! 00 mon.!inv_%%#.type!.sfce.!inv_%%#.frame!
      Set /A "inv_%%#.top+=8,inv_%%#.bottom+=8"
      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"

 
  )
)

:kill some invaders
If %mov% neq 0 (
Call :kill_inv 11
Call :kill_inv 53
Call :kill_inv 25
Call :kill_inv 40
Call :kill_inv 23
)

rem Set next movement
If %mov% Equ 0 (
  Set "mov=1"
) Else If %mov% Equ 1 (
    If !inv_%lastRight%.left! Equ %LIMIT_RIGHT% Set /A "mov=3,prev=1"
) Else If %mov% Equ 2 (
    Echo !inv_%lastLeft%.left!>>log.txt
    If !inv_%lastLeft%.left! Equ %LIMIT_LEFT% Set /A "mov=3,prev=2"
) Else (
  If %prev% Equ 1 Set "mov=2"
  If %prev% Equ 2 Set "mov=1"
)


Goto loop

:kill_inv

rem if the invader is dead do nothing
If 0 Equ !inv_%~1.live! Goto :Eof

Set /A "invaders_count-=1"

Set inv_%~1.live=0

rem dereference near invaders
Set "west=!inv_%~1.near.west!"
Set "east=!inv_%~1.near.east!"
Set "north=!inv_%~1.near.north!"
Set "south=!inv_%~1.near.south!"

rem update references
Set "inv_%west%.near.east=%east%"
Set "inv_%east%.near.west=%west%"
Set "inv_%north%.near.south=%south%"
Set "inv_%south%.near.north=%north%"

rem Show explosion
Bg.exe Sprite2 !inv_%~1.top! !inv_%~1.left! !exp.1.width! !exp.1.eight! 0C exp.1.sfce.1
Bg.exe Sleep 100
Bg.exe Sprite2 !inv_%~1.top! !inv_%~1.left! !exp.1.width! !exp.1.eight! 00 exp.1.sfce.1


Goto :Eof





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"






Message Publicité 
PublicitéSupprimer les publicités ?


Répondre en citant
Message [Part 6] Tutorial Space Invader 
I cancel this tutorial.

I write a new version of the game, with the main difference that we will manage a row of monster. Then, for update the graphics I will update only 5 rows, this is call to sprite function only 5 times and not 56 times. Sure this will do that the game fly.

I will write it with the public version 2.9 of bg that I will upload the monday.



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