|
Post by salamiboy2 on May 14, 2016 14:27:52 GMT -5
Using division, addition and complex math, I was able to make tiles draw based on the co-ordinates of the sprite. As you know, tiles move 8 pixels at a time, and sprites move 1 pixel at a time. This was very difficult to do. Enjoy I guess. Attachments:tiledraw.bin (14.26 KB)
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on May 14, 2016 19:39:15 GMT -5
That's pretty neat!
|
|
|
Post by salamiboy2 on May 15, 2016 3:58:42 GMT -5
Thanks! Here's the code. (sorry if it's buggy)
print " Press Start to begin "
print "------------------------------------"
print "in the game, press start to bring up"
print " the menu. press C to draw tile and "
print " press A to erase tile. "
while joypad().7=0
sleep 1
wend
while joypad().7=1
sleep 1
wend
cls
goto game
game:
dim dxspot as integer
dim dyspot as integer
loadtiles arrow,1,128
loadtiles full,1,129
arrow=addsprite(1,1)
palette &h0A60,0,0
palette &h0EA2,2,1
propsprite arrow,128,0
movesprite arrow,128,128
loop2:
while 1
setgfxplane scroll_b
x=spriteposx(arrow)
y=spriteposy(arrow)
dxspot=x-123/8
dyspot=y-127/8
if joypad().2 then shiftsprite 0,-2,0
if joypad().3 then shiftsprite 0,2,0
if joypad().1 then shiftsprite 0,0,2
if joypad().0 then shiftsprite 0,0,-2
if x<1+128 then shiftsprite 0,2,0
if x>310+128 then shiftsprite 0,-2,0
if y>216+128 then shiftsprite 0,0,-2
if y<1+128 then shiftsprite 0,0,2
if joypad().7 then gosub clear
if joypad().5 then gosub plot
if joypad().6 then gosub erase
sleep 1
wend
' g=(player0y-7)/3
'h=(player0x-10)/4
clear:
ink 1
setgfxplane scroll_a
locate 10,10
print "Press B to clear"
locate 11,10
print "Press A to return"
while 1
if joypad().4 then goto wipe
if joypad().6 then return
wend
wipe:
setgfxplane scroll_b
for y2=0 to 28
for x2=0 to 39
drawtile 0,x2,y2
next x2
next y2
setgfxplane scroll_a
cls
goto loop2
plot:
ink 2
drawtile 129,dxspot,dyspot
return
erase:
ink 2
drawtile 0,dxspot,dyspot
return
arrow:
DATALONG $00011000 ' Tile: 0
DATALONG $00111100
DATALONG $01111110
DATALONG $11111111
DATALONG $00011000
DATALONG $00011000
DATALONG $00011000
DATALONG $00011000
full:
datalong $11111111
datalong $11111111
datalong $11111111
datalong $11111111
datalong $11111111
datalong $11111111
datalong $11111111
datalong $11111111
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on May 15, 2016 8:03:18 GMT -5
Works in SecondBASIC with the modification of 2 lines: The first WHILE...WEND loop was changed to: While j.7 = 0 j = JoyPad() Sleep 1 Wend
SecondBASIC doesn't like returning joypad().7 The second WHILE...WEND loop I just removed and used the WaitPadUp command: WaitPadUp 0
Good job!
|
|
|
Post by sega16 on May 15, 2016 9:23:43 GMT -5
Elusive,
I agree with the second change however for the first change shouldn't you fix SecondBASIC instead of fixing the code?
How does the generated code compare? Does SecondBASIC generate better code?
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on May 15, 2016 10:36:57 GMT -5
Elusive, I agree with the second change however for the first change shouldn't you fix SecondBASIC instead of fixing the code? How does the generated code compare? Does SecondBASIC generate better code? Yes, it should definitely be fixed in SecondBASIC The coding is there to make it work, I just need to check to see what checkup is preventing it from working. Currently, the code generation is nearly identical as BEX except in a few instances where I updated/fixed the routine (the most recent was with the way the FOR...NEXT loops checked the sentinel variable, since doing the following would result in an endless loop in BEX: For i = 1 To 4 Step 2 Locate 1,1: Print i Next
However, if you're going to be using the JoyPad function for state changes in the buttons, it's more efficient to assign it to a variable anyway, as repeatedly calling functions adds overhead. In this instance, it wouldn't matter since it would be adding the same overhead since the only time the JoyPad function is called is to check if the start button was pressed or not. This is going to be the next thing I tackle in SBS, as I've already resolved the other 2 issues for the release (heapstart not being set properly, and runtime libraries not being registered). I'm hoping to have a supplement update early this afternoon, but that's all depending on if I can fix the arguneric/bitwise referencing when using them in loop conditionals.
|
|
|
Post by salamiboy2 on May 15, 2016 13:37:42 GMT -5
elusive, I've looked at your new compiler. It's looking pretty good so far! And yes, I should've used a variable to work with the joypad. It's just that I've been coding since 2013, and I'm used to constantly referring to functions. Hopefully I'll get used to joypad variables.
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on May 15, 2016 17:35:50 GMT -5
elusive, I've looked at your new compiler. It's looking pretty good so far! And yes, I should've used a variable to work with the joypad. It's just that I've been coding since 2013, and I'm used to constantly referring to functions. Hopefully I'll get used to joypad variables. If you only need to look for 1 button press, it's not too bad using it like you did, but if you were going to do something like the following: While 1 If Joypad(0).7 = 1 Then ' Your Code End If If Joypad(0).6 = 1 Then ' Your Code End If Wend
That will add a lot of unnecessary ASM code. I use an integer "j" to help me remember that it's my Joypad variable: While 1 j = Joypad(0) If j.7 = 1 Then ' Your Code End If If j.6 = 1 Then ' Your Code End If Wend
Hope that helps
|
|
|
Post by wraith on May 17, 2016 12:26:32 GMT -5
Cool , check this out... Compiled with SecondBasic tiledraw.bin (22 KB)
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on May 17, 2016 13:02:48 GMT -5
That's awesome!!
|
|
|
Post by salamiboy2 on May 17, 2016 13:11:22 GMT -5
Cool , check this out... Compiled with SecondBasic Woah man. I did not expect that! You got the colours to change and such. And you got the colours and the tiles perfect. Awesome job.
|
|