Code:

.BULLET
ClrDraw
DispGraph
DiagnosticOff
[000C021D020C0000]->Str1
0->A->C->X->Y->T
1->E
Fill(L1,100,0)
Pt-Change(X,Y,Str1
Repeat getKey(15)
For(A,0,11
A*4+L1->B
If B
If {B+3}<95
Pt-Change({B+3},{B+2},Str1
{B+3}+1->{B+3}
Pt-Change({B+3},{B+2},Str1
Else
0->B
End
End
End
If getKey(54)
If T>20
If C>11
0->C
End
1+C->C
(C*4)+L1->B
X+8->{B+3}
Y->{B+2}
1->B
0->T
Pt-Change({B+3},{B+2},Str1
End
End
If getKey(4)
Pt-Change(X,Y,Str1
Y-1->Y
Pt-Change(X,Y,Str1
End
If getKey(1)
Pt-Change(X,Y,Str1
Y+1->Y
Pt-Change(X,Y,Str1
End
If T<21
T+1->T
End
DispGraph
End



As you can see in the screenshot it's not behaving like i think it should :/

(I want to be able to shoot image [000C021D020C0000] and leave nothing but the cursor behind.)

Any help or optimizations are appreciated.

Credit to the SHMUP tutorial here for starting me out
http://www.cemetech.net/forum/viewtopic.php?t=9695
I have looked over your code and applied some bugfixes and some basic code form improvements. The bugfixes mainly had to do with bullet handling, as would probably be expected from your screenshot. The main non-bugfix change I made was to change the renderer to render each frame from scratch instead of undrawing and redrawing things that moved. I believe you'll find this change will make your life a fair amount easier. Other changes included removing unnecessary code (at least, it looked unnecessary), initializing the data in L₁ to 255 instead of 0, (in turn allowing simplified bullet processing to only process bullets with X coordinates less than 96,) and making bullets spawn exactly at the ship's position rather than in front of it (more of a personal preference).

The 8xp of my changed code can be found here, and you can see the SourceCoder-ized code below:


Code:
.BULLET
ClrDraw
DiagnosticOff
[000C021D020C0000]->Str1
0->C->X->Y->T
Fill(L1,100,255)
Repeat getKey(15)
For(A,0,11)
A*4+L1->B
If {B+3}<96
{B+3}+1->{B+3}
Pt-On({B+3},{B+2},Str1)
End
End
If getKey(54)
If T>=20
C+1->C
If C>11
0->C
End
C*4+L1->B
X->{B+3}
Y->{B+2}
0->T
End
End
If getKey(4)
Y-1->Y
End
If getKey(1)
Y+1->Y
End
T+1->T
Pt-On(X,Y,Str1)
DispGraphClrDraw
End



And in case you want to give yourself a headache, I went a bit further and you can find a heavily optimized version here, or below:


Code:
.BULLET
ClrDraw
DiagnosticOff
[000C021D020C0000]->Str1
0->C->X->Y->T
Fill(L1,100,)
While 1
L1+3
For(12)
If {->B} xor 100
{B}++
Pt-On({B-1}^^r^^r,/256,Str1)
End
B+4
End
!If T
If getKey(54)
(C??12)-1->C
X->{C*4+L1+3->B}
Y->{B-1}
20->T
End
End
T?T^^r--
Pt-On(X,getKey(1)-getKey(4)+Y->Y,Str1)
DispGraphClrDraw
EndIf getKey(15)
Runer112 wrote:
I have looked over your code and applied some bugfixes and some basic code form improvements. The bugfixes mainly had to do with bullet handling, as would probably be expected from your screenshot. The main non-bugfix change I made was to change the renderer to render each frame from scratch instead of undrawing and redrawing things that moved. I believe you'll find this change will make your life a fair amount easier. Other changes included removing unnecessary code (at least, it looked unnecessary), initializing the data in L₁ to 255 instead of 0, (in turn allowing simplified bullet processing to only process bullets with X coordinates less than 96,) and making bullets spawn exactly at the ship's position rather than in front of it (more of a personal preference).

The 8xp of my changed code can be found here, and you can see the SourceCoder-ized code below:


This is very nice code and it would be no problem to use if i were making something like a space shooter Smile. The problem is i was going to make a sidescroller with physics and a map and i don't know if there is a way to not have to redraw the map every frame as this would slow down the game quite a bit.
You can still make a sidescroller without having to redraw the whole map every frame. This is commonly done by keeping the map (and the map only) in a separate drawing buffer, shifting it around and redrawing data shifted in as necessary, and simply copying this buffer to the main drawing buffer at the start of rendering every frame. To put into perspective how much time this takes, copying one buffer to another in memory is about four times faster than copying a buffer to the screen (DispGraph). So this method adds a small constant time to each frame rendered, but subtracts a linear amount of time from sprite rendering and generally makes it easier because you don't have to keep track of every sprite that was drawn and erase ones that have moved. This sprite erasing process becomes even more complicated/slow if you draw sprites with logic other than XOR via Pt-Change(), which I believe you may soon find you'll want to do anyways because XOR'ing sprites onto a background image that is not just plain white or black can look weird.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement