game
.L00 ;  rem Generated 14/03/2016 17:44:53 by Visual bB Version 1.0.0.554

.L01 ;  rem *********************************** 

.L02 ;  rem *<M4K video aula>                              *

.L03 ;  rem *<add som no game>                         *

.L04 ;  rem *<CanalMundo4k>                              *

.L05 ;  rem *<canalmundo4k@gmail.com>        *

.L06 ;  rem *<license free >                                   *

.L07 ;  rem ***********************************

.
 ; 

.L08 ;  rem configuracao geral ( tamanho da rom sistemar de cor  da tv ) 

.
 ; 

.L09 ;  set tv ntsc

.L010 ;  set romsize 4k

.L011 ;  set smartbranching on

.
 ; 

.L012 ;  rem titulo 

.
 ; 

.title
 ; title

.
 ; 

.L013 ;  playfield:

  ifconst pfres
	  ldx #(11>pfres)*(pfres*pfwidth-1)+(11<=pfres)*43
  else
	  ldx #((11*pfwidth-1)*((11*pfwidth-1)<47))+(47*((11*pfwidth-1)>=47))
  endif
	jmp pflabel0
PF_data0
	.byte %00000000, %00000000
	if (pfwidth>2)
	.byte %00000000, %00000000
 endif
	.byte %00000000, %00000000
	if (pfwidth>2)
	.byte %00000000, %00000000
 endif
	.byte %00000000, %00000000
	if (pfwidth>2)
	.byte %00000000, %00000000
 endif
	.byte %00100001, %00000000
	if (pfwidth>2)
	.byte %01100001, %00001000
 endif
	.byte %01110011, %00000001
	if (pfwidth>2)
	.byte %11100001, %00001100
 endif
	.byte %11001100, %10000011
	if (pfwidth>2)
	.byte %10100001, %00000110
 endif
	.byte %11000000, %11000011
	if (pfwidth>2)
	.byte %00100001, %00000011
 endif
	.byte %11000000, %11000011
	if (pfwidth>2)
	.byte %11111001, %00000011
 endif
	.byte %11100001, %00011011
	if (pfwidth>2)
	.byte %01110001, %00000110
 endif
	.byte %01100001, %00011001
	if (pfwidth>2)
	.byte %01100001, %00001100
 endif
	.byte %00100001, %00000000
	if (pfwidth>2)
	.byte %00100001, %00001000
 endif
pflabel0
	lda PF_data0,x
	sta playfield,x
	dex
	bpl pflabel0
.
 ; 

.L014 ;  rem cor do titulo e fundo da tela 

.
 ; 

.L015 ;  COLUBK  =  216

	LDA #216
	STA COLUBK
.L016 ;  COLUPF  =  $90

	LDA #$90
	STA COLUPF
.L017 ;  drawscreen

 jsr drawscreen
.
 ; 

.L018 ;  rem quando finalizar o game esconder os personagens fora da tela 

.
 ; 

.L019 ;  player0x  =  1  :  player0y  =  1

	LDA #1
	STA player0x
	STA player0y
.L020 ;  player1x  =  1  :  player1y  =  1

	LDA #1
	STA player1x
	STA player1y
.
 ; 

.L021 ;  rem se o acionado o botao de tiro pular o titulo 

.
 ; 

.L022 ;  if joy0fire  ||  joy1fire then goto skiptitle

 bit INPT4
	BMI .skipL022
.condpart0
 jmp .condpart1
.skipL022
 bit INPT5
	BMI .skip0OR
.condpart1
 jmp .skiptitle

.skip0OR
.
 ; 

.L023 ;  rem se nao acionado o botao de tiro permanecer no titulo 

.
 ; 

.L024 ;  goto title

 jmp .title

.
 ; 

.L025 ;  rem inicio do loop principal 

.
 ; 

.skiptitle
 ; skiptitle

.
 ; 

.L026 ;  rem tela de jogo inicial (apos o titulo ) 

.
 ; 

.L027 ;  playfield:

  ifconst pfres
	  ldx #(11>pfres)*(pfres*pfwidth-1)+(11<=pfres)*43
  else
	  ldx #((11*pfwidth-1)*((11*pfwidth-1)<47))+(47*((11*pfwidth-1)>=47))
  endif
	jmp pflabel1
PF_data1
	.byte %00000000, %00000000
	if (pfwidth>2)
	.byte %00000000, %00000000
 endif
	.byte %00000000, %00000000
	if (pfwidth>2)
	.byte %00000000, %00000000
 endif
	.byte %00000000, %00000000
	if (pfwidth>2)
	.byte %00000000, %00000000
 endif
	.byte %00000000, %00000000
	if (pfwidth>2)
	.byte %00000000, %00000000
 endif
	.byte %00000000, %00000000
	if (pfwidth>2)
	.byte %00000000, %00000000
 endif
	.byte %00000000, %00000000
	if (pfwidth>2)
	.byte %00000000, %00000000
 endif
	.byte %00000000, %00000000
	if (pfwidth>2)
	.byte %00000000, %00000000
 endif
	.byte %00000000, %00000000
	if (pfwidth>2)
	.byte %00000000, %00000000
 endif
	.byte %00000000, %00000000
	if (pfwidth>2)
	.byte %00000000, %00000000
 endif
	.byte %00000000, %00000000
	if (pfwidth>2)
	.byte %00000000, %00000000
 endif
	.byte %11111111, %11111111
	if (pfwidth>2)
	.byte %11111111, %11111111
 endif
pflabel1
	lda PF_data1,x
	sta playfield,x
	dex
	bpl pflabel1
.
 ; 

.startposx
 ; startposx

.L028 ;  player1x  =  rand

 jsr randomize
	STA player1x
.L029 ;  if player1x  >  150 then goto startposx

	LDA #150
	CMP player1x
     BCS .skipL029
.condpart2
 jmp .startposx

.skipL029
.startposy
 ; startposy

.L030 ;  player1y  =  rand

 jsr randomize
	STA player1y
.L031 ;  if player1y  >  100 then goto startposy

	LDA #100
	CMP player1y
     BCS .skipL031
.condpart3
 jmp .startposy

.skipL031
.
 ; 

.L032 ;  rem posicao dos personagens na tela 

.
 ; 

.L033 ;  player0x  =  75  :  player0y  =  80

	LDA #75
	STA player0x
	LDA #80
	STA player0y
.L034 ;  player1x  =  80  :  player1y  =  1

	LDA #80
	STA player1x
	LDA #1
	STA player1y
.
 ; 

.L035 ;  rem configura?o do missil saindo do heroi 

.
 ; 

.L036 ;  missile0height  =  4  :  missile0y  =  255

	LDA #4
	STA missile0height
	LDA #255
	STA missile0y
.
 ; 

.L037 ;  rem cor do fundo da tela 

.
 ; 

.L038 ;  COLUBK  =  216

	LDA #216
	STA COLUBK
.
 ; 

.L039 ;  rem configuracao das contagens de pontos e cor do score 

.
 ; 

.L040 ;  score  =  00000  :  scorecolor  =  $0E

	LDA #$00
	STA score+2
	LDA #$00
	STA score+1
	LDA #$00
	STA score
	LDA #$0E
	STA scorecolor
.L041 ;  m  =  0

	LDA #0
	STA m
.
 ; 

.L042 ;  rem loop principal 

.
 ; 

.main
 ; main

.
 ; 

.L043 ;  rem cor dos personagens e da base do canhao (heroi)

.
 ; 

.L044 ;  COLUP1  =  $00

	LDA #$00
	STA COLUP1
.L045 ;  COLUP0  =  $0E

	LDA #$0E
	STA COLUP0
.L046 ;  COLUPF  =  $90

	LDA #$90
	STA COLUPF
.L047 ;  f = f + 1

	INC f
.L048 ;  g = g + 1

	INC g
.
 ; 

.L049 ;  rem heroi 

.
 ; 

.
 ; 

.L050 ;  if f = 10 then player0:

	LDA f
	CMP #10
     BNE .skipL050
.condpart4
	LDX #<player4then_0
	STX player0pointerlo
	LDA #>player4then_0
	STA player0pointerhi
	LDA #7
	STA player0height
.skipL050
.
 ; 

.L051 ;  if f = 20 then player0:

	LDA f
	CMP #20
     BNE .skipL051
.condpart5
	LDX #<player5then_0
	STX player0pointerlo
	LDA #>player5then_0
	STA player0pointerhi
	LDA #7
	STA player0height
.skipL051
.
 ; 

.L052 ;  if f = 30 then player0:

	LDA f
	CMP #30
     BNE .skipL052
.condpart6
	LDX #<player6then_0
	STX player0pointerlo
	LDA #>player6then_0
	STA player0pointerhi
	LDA #7
	STA player0height
.skipL052
.
 ; 

.L053 ;  if f = 40 then player0:

	LDA f
	CMP #40
     BNE .skipL053
.condpart7
	LDX #<player7then_0
	STX player0pointerlo
	LDA #>player7then_0
	STA player0pointerhi
	LDA #7
	STA player0height
.skipL053
.
 ; 

.
 ; 

.
 ; 

.L054 ;  rem vilao 

.
 ; 

.
 ; 

.L055 ;  if f = 10 then player1:

	LDA f
	CMP #10
     BNE .skipL055
.condpart8
	LDX #<player8then_1
	STX player1pointerlo
	LDA #>player8then_1
	STA player1pointerhi
	LDA #7
	STA player1height
.skipL055
.
 ; 

.L056 ;  if f = 20 then player1:

	LDA f
	CMP #20
     BNE .skipL056
.condpart9
	LDX #<player9then_1
	STX player1pointerlo
	LDA #>player9then_1
	STA player1pointerhi
	LDA #7
	STA player1height
.skipL056
.
 ; 

.L057 ;  if f = 30 then player1:

	LDA f
	CMP #30
     BNE .skipL057
.condpart10
	LDX #<player10then_1
	STX player1pointerlo
	LDA #>player10then_1
	STA player1pointerhi
	LDA #7
	STA player1height
.skipL057
.
 ; 

.L058 ;  if f = 40 then player1:

	LDA f
	CMP #40
     BNE .skipL058
.condpart11
	LDX #<player11then_1
	STX player1pointerlo
	LDA #>player11then_1
	STA player1pointerhi
	LDA #7
	STA player1height
.skipL058
.
 ; 

.L059 ;  if f = 40 then f = 0

	LDA f
	CMP #40
     BNE .skipL059
.condpart12
	LDA #0
	STA f
.skipL059
.L060 ;  if g = 40 then g = 0

	LDA g
	CMP #40
     BNE .skipL060
.condpart13
	LDA #0
	STA g
.skipL060
.
 ; 

.L061 ;  rem velocidade que o vilao ataca o heroi 

.
 ; 

.L062 ;  a  =  a  +  1  :  if a  <  1 then goto checkfire

	INC a
	LDA a
	CMP #1
     BCS .skipL062
.condpart14
 jmp .checkfire

.skipL062
.L063 ;  a  =  0

	LDA #0
	STA a
.
 ; 

.L064 ;  rem forma que o vilao persegue o heroi 

.
 ; 

.L065 ;  if player1y  <  player0y then player1y  =  player1y  +  1

	LDA player1y
	CMP player0y
     BCS .skipL065
.condpart15
	INC player1y
.skipL065
.L066 ;  if player1y  >  player0y then player1y  =  player1y  -  1

	LDA player0y
	CMP player1y
     BCS .skipL066
.condpart16
	DEC player1y
.skipL066
.L067 ;  if player1x  <  player0x then player1x  =  player1x  +  1

	LDA player1x
	CMP player0x
     BCS .skipL067
.condpart17
	INC player1x
.skipL067
.L068 ;  if player1x  >  player0x then player1x  =  player1x  -  1

	LDA player0x
	CMP player1x
     BCS .skipL068
.condpart18
	DEC player1x
.skipL068
.L069 ;  player1x  =  player1x  :  player1y  =  player1y

	LDA player1x
	STA player1x
	LDA player1y
	STA player1y
.
 ; 

.L070 ;  rem verificando se o tiro saiu do heroi 

.
 ; 

.checkfire
 ; checkfire

.L071 ;  if missile0y > 240 then goto skip

	LDA #240
	CMP missile0y
     BCS .skipL071
.condpart19
 jmp .skip

.skipL071
.L072 ;  missile0y  =  missile0y  -  2  :  goto draw

	LDA missile0y
	SEC
	SBC #2
	STA missile0y
 jmp .draw

.
 ; 

.skip
 ; skip

.L073 ;  rem tiro emitido inicia o jogo e sons de fundo e disparo  

.L074 ;  if joy0fire then missile0y = player0y - 2 : missile0x = player0x + 4 :  goto firesound

 bit INPT4
	BMI .skipL074
.condpart20
	LDA player0y
	SEC
	SBC #2
	STA missile0y
	LDA player0x
	CLC
	ADC #4
	STA missile0x
 jmp .firesound

.skipL074
.
 ; 

.draw
 ; draw

.L075 ;  drawscreen

 jsr drawscreen
.
 ; 

.L076 ;  rem se o tiro acertar o vilao somar pontos ordem crescente surgir outro vilao na tela e som de vilao abatido 

.
 ; 

.L077 ;  if collision(missile0,player1) then score = score + 1 : player1x = rand / 2 : player1y = 0 : missile0y = 255  :  goto pointsound

	bit 	CXM0P
	BPL .skipL077
.condpart21
	SED
	CLC
	LDA score+2
	ADC #$01
	STA score+2
	LDA score+1
	ADC #$00
	STA score+1
	LDA score
	ADC #$00
	STA score
	CLD
 jsr randomize
	lsr
	STA player1x
	LDA #0
	STA player1y
	LDA #255
	STA missile0y
 jmp .pointsound

.skipL077
.
 ; 

.L078 ;  rem se o vilao encostar no heroi som de explosao retorna para o titulo 

.
 ; 

.L079 ;  if collision(player0,player1) goto deadsound  :  then title

	bit 	CXPPMM
 if ((* - .deadsound) < 127) && ((* - .deadsound) > -128)
	bmi .deadsound
 else
	bpl .0skipdeadsound
	jmp .deadsound
.0skipdeadsound
 endif
.
 ; 

.
 ; 

.L080 ;  rem configuracao de limite de tela 

.
 ; 

.L081 ;  if m  =  1  &&  collision(player0,playfield) then player0y  =  player0y  +  1  :  goto skipmove

	LDA m
	CMP #1
     BNE .skipL081
.condpart22
	bit 	CXP0FB
	BPL .skip22then
.condpart23
	INC player0y
 jmp .skipmove

.skip22then
.skipL081
.L082 ;  if m  =  2  &&  collision(player0,playfield) then player0x  =  player0x  +  1  :  goto skipmove

	LDA m
	CMP #2
     BNE .skipL082
.condpart24
	bit 	CXP0FB
	BPL .skip24then
.condpart25
	INC player0x
 jmp .skipmove

.skip24then
.skipL082
.L083 ;  if m  =  3  &&  collision(player0,playfield) then player0y  =  player0y  -  1  :  goto skipmove

	LDA m
	CMP #3
     BNE .skipL083
.condpart26
	bit 	CXP0FB
	BPL .skip26then
.condpart27
	DEC player0y
 jmp .skipmove

.skip26then
.skipL083
.L084 ;  if m  =  4  &&  collision(player0,playfield) then player0x  =  player0x  -  1 :  goto skipmove

	LDA m
	CMP #4
     BNE .skipL084
.condpart28
	bit 	CXP0FB
	BPL .skip28then
.condpart29
	DEC player0x
 jmp .skipmove

.skip28then
.skipL084
.
 ; 

.L085 ;  rem configuracao de movimentos do heroi 

.
 ; 

.L086 ;  rem if joy0up && !collision(player0,playfield) then player0y = player0y - 1 : m = 1 : goto skipmove

.L087 ;  if joy0left  &&  !collision(player0,playfield) then player0x  =  player0x  -  1  :  REFP0  =  8  :  m  =  2  :  goto skipmove

 bit SWCHA
	BVS .skipL087
.condpart30
	bit 	CXP0FB
	BMI .skip30then
.condpart31
	DEC player0x
	LDA #8
	STA REFP0
	LDA #2
	STA m
 jmp .skipmove

.skip30then
.skipL087
.L088 ;  rem if joy0down  && !collision(player0,playfield) then player0y = player0y + 1  : m = 3 : goto skipmove

.L089 ;  if joy0right  &&  !collision(player0,playfield) then player0x  =  player0x  +  1  :  m  =  4  :  REFP0  =  0  :  goto skipmove

 bit SWCHA
	BMI .skipL089
.condpart32
	bit 	CXP0FB
	BMI .skip32then
.condpart33
	INC player0x
	LDA #4
	STA m
	LDA #0
	STA REFP0
 jmp .skipmove

.skip32then
.skipL089
.
 ; 

.skipmove
 ; skipmove

.L090 ;  if player0x  <  player1x then REFP1  =  8

	LDA player0x
	CMP player1x
     BCS .skipL090
.condpart34
	LDA #8
	STA REFP1
.skipL090
.L091 ;  if player0x  >  player1x then REFP1  =  0

	LDA player1x
	CMP player0x
     BCS .skipL091
.condpart35
	LDA #0
	STA REFP1
.skipL091
.L092 ;  goto main

 jmp .main

.
 ; 

.
 ; 

.L093 ;  rem fim do loop principal 

.
 ; 

.
 ; 

.L094 ;  rem configuracao de sons do jogo 

.
 ; 

.L095 ;  rem som dos pontos ( quando o vilao morre)

.
 ; 

.pointsound
 ; pointsound

.L096 ;  AUDV0  =  15

	LDA #15
	STA AUDV0
.L097 ;  AUDC0  = 8

	LDA #8
	STA AUDC0
.L098 ;  AUDF0  =  3

	LDA #3
	STA AUDF0
.
 ; 

.L099 ;  p  =  p  +  1

	INC p
.L0100 ;  drawscreen

 jsr drawscreen
.L0101 ;  rem tempo que o som toca 

.L0102 ;  if p  <  8 then pointsound

	LDA p
	CMP #8
 if ((* - .pointsound) < 127) && ((* - .pointsound) > -128)
	bcc .pointsound
 else
	bcs .1skippointsound
	jmp .pointsound
.1skippointsound
 endif
.L0103 ;  p  =  0

	LDA #0
	STA p
.L0104 ;  AUDV0  =  0 :  AUDC0  =  0 :  AUDF0  =  0

	LDA #0
	STA AUDV0
	STA AUDC0
	STA AUDF0
.L0105 ;  goto main

 jmp .main

.
 ; 

.L0106 ;  rem som do tiro 

.
 ; 

.firesound
 ; firesound

.L0107 ;  AUDV0  =  15

	LDA #15
	STA AUDV0
.L0108 ;  AUDC0  = 8

	LDA #8
	STA AUDC0
.L0109 ;  AUDF0  =  18

	LDA #18
	STA AUDF0
.
 ; 

.L0110 ;  rem som de fundo (fica mis facil configurar aqui no tiro) 

.
 ; 

.L0111 ;  AUDV1  =  10

	LDA #10
	STA AUDV1
.L0112 ;  AUDC1  =  2

	LDA #2
	STA AUDC1
.L0113 ;  AUDF1  =  31

	LDA #31
	STA AUDF1
.
 ; 

.L0114 ;  p  =  p  +  1

	INC p
.L0115 ;  drawscreen

 jsr drawscreen
.L0116 ;  rem tempo que o som toca

.L0117 ;  if p  <  5 then firesound

	LDA p
	CMP #5
 if ((* - .firesound) < 127) && ((* - .firesound) > -128)
	bcc .firesound
 else
	bcs .2skipfiresound
	jmp .firesound
.2skipfiresound
 endif
.L0118 ;  p  =  0

	LDA #0
	STA p
.L0119 ;  AUDV0  =  0 :  AUDC0  =  0 :  AUDF0  =  0

	LDA #0
	STA AUDV0
	STA AUDC0
	STA AUDF0
.L0120 ;  goto main

 jmp .main

.
 ; 

.L0121 ;  rem Som do heroi morredo 

.deadsound
 ; deadsound

.L0122 ;  AUDV1  =  15

	LDA #15
	STA AUDV1
.L0123 ;  AUDC1  =  8

	LDA #8
	STA AUDC1
.L0124 ;  AUDF1  =  31

	LDA #31
	STA AUDF1
.L0125 ;  p  =  p  +  1

	INC p
.L0126 ;  drawscreen

 jsr drawscreen
.L0127 ;  rem tempo que o som toca 

.L0128 ;  if p  <  30 then deadsound

	LDA p
	CMP #30
 if ((* - .deadsound) < 127) && ((* - .deadsound) > -128)
	bcc .deadsound
 else
	bcs .3skipdeadsound
	jmp .deadsound
.3skipdeadsound
 endif
.L0129 ;  p  =  0

	LDA #0
	STA p
.L0130 ;  AUDV1  =  0 :  AUDC1  =  0 :  AUDF1  =  0

	LDA #0
	STA AUDV1
	STA AUDC1
	STA AUDF1
.L0131 ;  if a  =  0 then goto title

	LDA a
	CMP #0
     BNE .skipL0131
.condpart36
 jmp .title

.skipL0131
.
 ; 

.L0132 ;  goto main

 jmp .main

.
 ; 

.L0133 ;  rem fim do programa
 if (<*) > (<(*+7))
	repeat ($100-<*)
	.byte 0
	repend
	endif
player4then_0
	.byte  %01111100
	.byte  %00111000
	.byte  %00010000
	.byte  %00010000
	.byte  %00000000
	.byte  %00000000
	.byte  %00000000
	.byte  %00000000
 if (<*) > (<(*+7))
	repeat ($100-<*)
	.byte 0
	repend
	endif
player5then_0
	.byte  %01011100
	.byte  %00111000
	.byte  %00010000
	.byte  %00010000
	.byte  %00000000
	.byte  %00000000
	.byte  %00000000
	.byte  %00000000
 if (<*) > (<(*+7))
	repeat ($100-<*)
	.byte 0
	repend
	endif
player6then_0
	.byte  %01101100
	.byte  %00111000
	.byte  %00010000
	.byte  %00010000
	.byte  %00000000
	.byte  %00000000
	.byte  %00000000
	.byte  %00000000
 if (<*) > (<(*+7))
	repeat ($100-<*)
	.byte 0
	repend
	endif
player7then_0
	.byte  %01110100
	.byte  %00111000
	.byte  %00010000
	.byte  %00010000
	.byte  %00000000
	.byte  %00000000
	.byte  %00000000
	.byte  %00000000
 if (<*) > (<(*+7))
	repeat ($100-<*)
	.byte 0
	repend
	endif
player8then_1
	.byte  %10000001
	.byte  %10011001
	.byte  %10111101
	.byte  %11100111
	.byte  %10111101
	.byte  %10011001
	.byte  %10000001
	.byte  %00000000
 if (<*) > (<(*+7))
	repeat ($100-<*)
	.byte 0
	repend
	endif
player9then_1
	.byte  %10000001
	.byte  %10011001
	.byte  %10100101
	.byte  %11111111
	.byte  %10111101
	.byte  %10011001
	.byte  %10000001
	.byte  %00000000
 if (<*) > (<(*+7))
	repeat ($100-<*)
	.byte 0
	repend
	endif
player10then_1
	.byte  %10000001
	.byte  %10011001
	.byte  %10111101
	.byte  %11111111
	.byte  %10100101
	.byte  %10011001
	.byte  %10000001
	.byte  %00000000
 if (<*) > (<(*+7))
	repeat ($100-<*)
	.byte 0
	repend
	endif
player11then_1
	.byte  %10000001
	.byte  %10011001
	.byte  %10111101
	.byte  %11111111
	.byte  %10111101
	.byte  %10011001
	.byte  %10000001
	.byte  %00000000
 if ECHOFIRST
       echo "    ",[(scoretable - *)]d , "bytes of ROM space left")
 endif 
ECHOFIRST = 1
 
 
 
