Sure enough, it was putAndSprite...I changed it to XOR the images to the screen, and that works fine. Plus, I dont know what I was doing with offsetting by 9...I instead changed it to offset by 8, like you suggested. And the one last item regarding why I put the explosion 5 times: I made the list as follows:
Code:
.nolist
#include "ion.inc"
#include "keys.inc"
.list
x = saferam1+0
y = saferam1+2
xbul = saferam1+4
exbul = saferam1+6
bulpress = saferam1+8
return = saferam1+10
timer = saferam1+12
temp1 = saferam1+14
enemydirection = saferam1+16
loadflag = saferam1+18
saveflag = saferam2+150
savepcoord = saferam2+152
savepbullets = saferam2+155
#ifdef TI83P
.org progstart-2
.db $BB,$6D
#else
.org progstart
#endif
ret
jr nc,start
.db "~By Justin Niles",0
start:
DI
bcall(_clrlcdfull)
bcall(_cleargbuf)
ld a,40
ld (x),a
ld a,30
ld (y),a
call loadgmecode
call movebullets
ld a,0
ld (return),a
ld a,0
ld (bulpress),a
ld a,0
ld (timer),a
[color=red]
ld a,1
ld (enemydirection),a ;set the ships to start moving right (1=moving right; -1=moving left)
ld hl,level_enemy_data
ld de,level1_enemies ;"level1_enemies" is similar to the explosions list: it contains 54 elements broken into sections of 3. 54/3=18 enemies
;First element in a list of 3 holds the enemy type
;Second element holds the x-coord of the enemy
;Third element hold the y-coord of the enemy
ld b,54
loop4: ;load "level1_enemies" into "level_enemy_data"
ld a,(de)
ld (hl),a
inc de
inc hl
djnz loop4
call dispenemy1 ;display the enemies onto the screen (this code is found towards the bottom)
[/color]
ld hl,explosiondata
ld b,5
loop3:
ld (hl),0
inc hl
djnz loop3
ld a,(y)
ld l,a
ld a,(x)
ld b,7
ld ix,ship
call ionPutSprite
call ionFastCopy
mainloop:
ld a,group1
out (1),a
in a,(1)
bit 6,a
jp z,gameexit
[color=red]
call handleenemies
[/color]
call move
call firebullets
call movebullets
call enemybullets
call moveebullets
call handleexplosions
call ionFastCopy
ld hl,timer
inc (hl)
jr mainloop
[color=red]
;-----------------------
;>>>>Enemy Ship Code<<<<
;-----------------------
handleenemies:
ld a,(timer) ;
sub 4 ;only move enemies every 4 cycles
ret nz ;
ld hl,level_enemy_data
ld b,18 ;set to loop through all 18 enemies
enemyloop:
ld a,(hl)
or a
push bc
push hl
call nz,putenemy ;if (hl)/=0, goto putenemy
pop hl
pop bc
inc hl ;
inc hl ;Increment "level_enemy_data" to the next set of 3 elements
inc hl ;
djnz enemyloop
ret
putenemy:
push hl
rla ;
rla ;Find the enemy image offset by multiplying a by 8.
rla ;
sub 8 ;then subtracting 8
push af ;preserve a
ld d,0
ld e,a
ld ix,enemyimages
add ix,de ;essientially adding a to ix
inc hl
ld d,(hl) ;load enemy x-coord into d
inc hl
ld a,(hl)
ld l,a ;load enemy y-coord into l
ld a,d ;ld a,d
ld b,8
call ionPutSprite ;copy Sprite using XOR logic
pop af ;restore a
pop hl ;restore hl
ld d,0
ld e,a
ld ix,enemyimages
add ix,de ;get image offset again
inc hl
ld d,(hl) ;load x-coord into d
;
push hl ;preserve hl
ld hl,enemydirection
ld a,d ;ld a,(x-coord of enemy)
sub 2
jr nz,leftok
ld (hl),1 ;basically, if (x-coord of enemy)=2, then set the enemies to move right
leftok: ld a,d ;reload a,(x-coord of enemy)
sub 85
jr nz,rightok
ld (hl),-1 ;if (x-coord of enemy)=85, then set the enemies to move left
rightok:
ld a,d ;reload a,(x-coord of enemy)
add a,(hl) ;add either 1 or -1 to the x-coord, causing the enemy to move either left or right
ld d,a ;ld d,(new x-coord)
pop hl ;restore hl
;
ld (hl),a ;ld (x-coord of enemy),a
inc hl
ld a,(hl)
ld l,a ;ld l,(y-coord of enemy)
ld a,d ;ld a,d (which contains the new x-coord)
ld b,8
call ionPutSprite ;copy the sprite to the screen using XOR logic
ret
[/color]
;----------------------
;>>>>Explosion Code<<<<
;----------------------
handleexplosions:
ld a,(timer)
sub 4
ret nz
ld hl,timer
ld (hl),0
ld hl,explosiondata
ld b,5
exfloop:
ld a,(hl)
or a
push hl
push bc
call nz,doexplosion
pop bc
pop hl
inc hl
inc hl
inc hl
djnz exfloop
ret
doexplosion:
push af
push hl
rla
rla
rla
sub 8
ld d,0
ld e,a
ld ix,explosionimage
add ix,de
inc hl
ld d,(hl)
inc hl
ld a,(hl)
ld l,a
ld a,d
ld b,8
call ionPutSprite
pop hl
pop af
inc (hl)
sub 9
jr nz,skipover1
ld (hl),0
skipover1:
ld a,(hl)
or a
ret z
rla
rla
rla
sub 8
ld d,0
ld e,a
ld ix,explosionimage
add ix,de
inc hl
ld d,(hl)
inc hl
ld a,(hl)
ld l,a
ld a,d
ld b,8
call ionPutSprite
ret
;-----------------------------
;>>Player Ship Movement Code<<
;-----------------------------
move:
ld a,group0 ;
out (1),a ;
in a,(1) ;determine if arrow
ld b,4 ;keys were pressed
movl: rra ;
jr c,aropres ;
djnz movl ;
ret ;else: return
aropres:
ld a,(y)
ld l,a
ld a,(x)
ld b,7
ld ix,ship
call ionPutSprite
in a,(1)
ld b,a
bit 0,b
jr nz,nodown
ld a,(y)
cp 60
jr z,nodown
inc a
ld (y),a
nodown: bit 3,b
jr nz,noup
ld a,(y)
cp 10
jr z,noup
dec a
ld (y),a
noup: bit 1,b
jr nz,noleft
ld a,(x)
cp 0
jr z,noleft
dec a
ld (x),a
noleft: bit 2,b
jr nz,norght
ld a,(x)
cp 88
jr z,norght
inc a
ld (x),a
norght: ld a,(y)
ld l,a
ld a,(x)
ld b,7
ld ix,ship
call ionPutSprite
ret
;-------------------------
;>>>>Enemy Bullet Code<<<<
;-------------------------
enemybullets:
ld b,11
call ionRandom
sub 10
ret m
ld hl,ebuls
ld b,10
feloop:
ld a,(hl)
or a
jr z,ebulletfound
inc hl
inc hl
inc hl
djnz feloop
ret
ebulletfound:
ld (hl),1
inc hl
push hl
ld b,96
call ionRandom
pop hl
ld (hl),a
ld (exbul),a
inc hl
ld (hl),0
call drawebullet
ret
moveebullets:
ld a,(timer)
sub 2
ret z
sub 2
ret z
ld hl,ebuls
ld b,10
emloop:
ld a,(hl)
or a
push hl
push bc
call nz,ebulletmove
pop bc
pop hl
inc hl
inc hl
inc hl
djnz emloop
ret
ebulletmove:
inc hl
ld a,(hl)
ld (exbul),a
inc hl
push hl
call drawebullet
pop hl
ld a,(return)
or a
ret nz
push hl
jr checkecollision
return2:
pop hl
ld a,(hl)
inc a
cp 64
jr nz,eok
dec hl
dec hl
ld (hl),0
ret
eok:
ld (hl),a
call drawebullet
ret
checkecollision:
ld b,(hl)
ld a,(y)
sub b
jp p,return2
ld a,(y)
add a,3
sub b
jp m,return2
ld a,(exbul)
add a,1
ld b,a
ld a,(x)
sub 2
sub b
jp p,return2
ld a,(x)
add a,9
sub b
jp m,return2
dec hl
dec hl
ld (hl),0
ld de,explosiondata
ld b,5
ploop:
ld a,(de)
or a
jr z,found1
inc de
inc de
inc de
djnz ploop
ret
found1:
ld a,1
ld (de),a
inc hl
inc de
ld a,(hl)
ld (de),a
inc hl
inc de
ld a,(hl)
ld (de),a
ld a,(de)
ld l,a
dec de
ld a,(de)
ld b,8
ld ix,explosionimage
call ionPutSprite
pop hl
ret
;----------------------
;>>Player Bullet Code<<
;----------------------
firebullets:
ld a,group6
out (1),a
in a,(1)
bit 5,a
jr z,firebul
ld a,0
ld (bulpress),a
ret
firebul:
ld a,(bulpress)
or a
ret nz
ld a,1
ld (bulpress),a
ld hl,bulletarray
ld b,10
floop:
ld a,(hl)
or a
jr z,bulletfound
inc hl
inc hl
inc hl
djnz floop
ret
bulletfound:
ld a,1
ld (hl),a
inc hl
ld a,(x)
add a,3
ld (hl),a
ld (xbul),a
inc hl
ld a,(y)
sub 6
ld (hl),a
push hl
call drawbullet
pop hl
ret
movebullets:
ld hl,bulletarray
ld b,10
mloop:
ld a,(hl)
or a
push hl
push bc
call nz,bulletmove
pop bc
pop hl
inc hl
inc hl
inc hl
djnz mloop
ret
bulletmove:
inc hl
ld a,(hl)
ld (xbul),a
inc hl
push hl
call drawbullet
pop hl
ld a,(return)
or a
ret nz
ld a,(hl)
dec a
or a
jp p,ok
dec hl
dec hl
ld (hl),0
ret
ok:
ld (hl),a
call drawbullet
ret
erasebul:
ld a,(hl)
ld l,a
ld a,(xbul)
ld b,5
ld ix,bullet
call ionPutSprite
ret
drawbullet:
ld a,(hl)
ld l,a
ld a,(xbul)
ld b,5
ld ix,bullet
call ionPutSprite
ret
drawebullet:
ld a,(hl)
ld l,a
ld a,(exbul)
ld b,3
ld ix,ebullet
call ionPutSprite
ret
nosave: ;~
ld a,0 ;
ld (saveflag),a ;No
ld b,30 ;Save
ld hl,bulletarray ;Game
nosveloop: ;exit
ld a,0 ;code
ld (hl),a ;
inc hl ;
djnz nosveloop ;
EI ;
ret ;~
gameexit: ;~
ld b,30 ;
ld hl,ebuls ;
l2loop: ;
ld (hl),0 ;
inc hl ;
djnz l2loop ;
ld a,group6 ;
out (1),a ;
in a,(1) ;
bit 7,a ;
jr z,nosave ;
ld a,1 ;
ld (saveflag),a ;
ld hl,savepcoord ;
ld a,(x) ;Game
ld (hl),a ;Exit
inc hl ;code
ld a,(y) ;
ld (hl),a ;
ld hl,savepbullets ;
ld de,bulletarray ;
ld b,30 ;
svloop: ;
ld a,(de) ;
ld (hl),a ;
inc hl ;
inc de ;
djnz svloop ;
EI ;
ret ;~
;----------------------
;>>>>Load Game Code<<<<
;----------------------
loadgmecode:
ld a,(saveflag)
ld (return),a
or a
ret z
ld hl,savepcoord
ld a,(hl)
ld (x),a
inc hl
ld a,(hl)
ld (y),a
ld hl,savepbullets
ld de,bulletarray
ld b,30
ldloop:
ld a,(hl)
ld (de),a
inc de
inc hl
djnz ldloop
ret
[color=red]
dispenemy1:
ld hl,level_enemy_data
ld b,18
enemyloop1:
ld a,(hl)
or a
push bc
push hl
call nz,putenemy
pop hl
pop bc
inc hl
inc hl
inc hl
djnz enemyloop1
ret
putenemy1:
rla
rla
rla
sub 8
ld d,0
ld e,a
ld ix,enemyimages
add ix,de
inc hl
ld d,(hl)
inc hl
ld a,(hl)
ld l,a
ld a,d
ld b,8
call ionPutSprite
ret
[/color]
ship:
.db %00011000
.db %00111100
.db %00111100
.db %10111101
.db %10111101
.db %11111111
.db %01111110
bullet:
.db %11000000
.db %11000000
.db %11000000
.db %11000000
.db %11000000
ebullet:
.db %01000000
.db %11100000
.db %01000000
explosionimage:
.db %00000000
.db %00000000
.db %00010000
.db %00111000
.db %00011100
.db %00111000
.db %00000000
.db %00000000
;explosionimage2:
.db %00000000
.db %00001000
.db %00101100
.db %00011110
.db %01100100
.db %00010110
.db %00011000
.db %00000000
;explosionimage3:
.db %00000010
.db %00101100
.db %01100101
.db %01011111
.db %00110000
.db %00010110
.db %01100010
.db %00010000
;explosionimage4:
.db %00001100
.db %01010010
.db %00100101
.db %00010010
.db %11101101
.db %00010110
.db %01010010
.db %00110001
;explosionimage5:
.db %01010001
.db %11001101
.db %01111010
.db %00111111
.db %01001010
.db %10111100
.db %00101010
.db %01010101
;explosionimage6:
.db %11100101
.db %00010000
.db %01011010
.db %10000010
.db %00000000
.db %11010001
.db %00101010
.db %10101001
;explosionimage7:
.db %10001001
.db %00100010
.db %00000000
.db %01000010
.db %00000000
.db %10000001
.db %00100010
.db %10001001
;explosionimage8:
.db %01000011
.db %00000001
.db %10000000
.db %00000000
.db %00000000
.db %00000000
.db %00000001
.db %11000101
;explosionimage9:
.db %00000100
.db %10000000
.db %00000000
.db %00000000
.db %00000000
.db %00000000
.db %00000001
.db %01000000
[color=red]
enemyimages:
;enemy image 1
.db %10000001
.db %10000001
.db %10000001
.db %01111110
.db %00111100
.db %00011000
.db %00000000
.db %00000000
[/color]
bulletarray:
.db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
ebuls:
.db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
explosiondata:
.db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
[color=red]
level_enemy_data:
.db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
.db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
.db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
level1_enemies:
.db 1,3,5,1,16,5,1,29,5,1,42,5,1,55,5,1,68,5
.db 1,3,15,1,16,15,1,29,15,1,42,15,1,55,15,1,68,15
.db 1,3,25,1,16,25,1,29,25,1,42,25,1,55,25,1,68,25
[/color]
.end
END
|