Omnimaga

Calculator Community => TI Calculators => Axe => Topic started by: JWinslow23 on November 29, 2013, 02:01:21 pm

Title: Lights Out help?
Post by: JWinslow23 on November 29, 2013, 02:01:21 pm
I need help with adding a selection box to this code (basically, I want a white box around the square selected). I know what I want, but try as I might, I can't do it! And the fact that the keys are so sensitive (and repeat) don't help, either.

The tries I did for adding it in either have it not move, have it be black and not moving right, or having it (apparently) go out of bounds. I thought I did it right, but it just doesn't work! What can I add to this code to make that? I can probably figure out the ENTER pressing light change afterwards.

Code: [Select]
.LIGHTOUT
ClrDraw rr
DrawInv
DrawInv r
[00C0F0FCFEFEFFFF]→Pic1
[FFFFFFFFFFFFFFFF]→Pic2
[0000000000000000]→Pic3
0→C
Repeat C
For(X,0,5
For(Y,0,5
Pt-Off(9*X+1,9*Y+1,Pic3
Pt-Off(9*X+1,9*Y+1,Pic1)r
If rand^2
Pt-On(9*X+1,9*Y+1,Pic2
C+1→C
End
End
End
End
Repeat getKey(15)
DispGraph rr
End
Title: Re: Lights Out help?
Post by: Streetwalrus on November 30, 2013, 08:56:16 am
And the fact that the keys are so sensitive (and repeat) don't help, either.
About that, you can add a delay or even some simple debouncing code such as :
Code: [Select]
While 1            .More optimised than While getKey(0)
Pause 5            .Necessary for it to work, else it would loop so fast that it wouldn't detect any key presses and thus be useless
End!If getKey(0)   .See first line
It should do the trick. ;)
Title: Re: Lights Out help?
Post by: JWinslow23 on November 30, 2013, 11:45:19 am
Where exactly would I put that in the code?
Title: Re: Lights Out help?
Post by: Streetwalrus on November 30, 2013, 11:45:58 am
Right after your input code.
Title: Re: Lights Out help?
Post by: JWinslow23 on November 30, 2013, 11:57:45 am
I'll tweak the code accordingly. Thanks!

I'll get back to you when it's done.

EDIT: The motion code works well, but apparently the debounce code given made the grayscale look weird when I was pressing buttons at all. I'll try to tweak THAT.

EDIT 2: I can't figure out another debounce code! Can anyone give me a debounce routine for use with 4 level grayscale?

EDIT 3: Never mind, Xeda Elnara made one for me. Here it is:
Code: [Select]
getKey -> A
If A=B
0 -> A
Else
A -> B
End

And you use B=code instead of getKey(code).

I'll be sure to credit her. Also, I'm working on the light toggling and wincheck. Soon, I'll post the code!

EDIT 4: The source is attached. I will add a win message, a title screen, and everything else to make this "presentable" later, but I at least want optimization for this part. Can someone optimize this code? I'm using the latest version of Axe Parser.
Title: Re: Lights Out help?
Post by: Streetwalrus on November 30, 2013, 04:27:48 pm
Not him, her. Xeda is a girl. Other than that, yes it works but it is much slower. The reason why my debounce code messes up greyscale is that it stops the program until you release every key. Hence greyscale is not shown anymore. An option would be to move the DispGraph^^rr in the loop I gave you and remove the Pause 5 because it's not needed anymore. ;)
Title: Re: Lights Out help?
Post by: JWinslow23 on November 30, 2013, 04:49:17 pm
Sorry, HER. I keep forgetting she is a girl. :-\

Anyways, that's actually EXACTLY what I want. I just want it so that if a button is pressed, it doesn't repeat the action (and if it does, as for the arrow keys with this method, not very fast. :D)

EDIT: Also, does the Text command HAVE to be inside the loop for it to display text in the current situation? Because I just added it outside of the loop in the version still on my calc, and the text keeps getting erased.
Title: Re: Lights Out help?
Post by: Streetwalrus on November 30, 2013, 04:56:30 pm
Yes you need it in the loop because you erase the whole thing every time. And text draws directly to the screen, not the buffer so you have to look at the fix command.
Title: Re: Lights Out help?
Post by: JWinslow23 on November 30, 2013, 05:01:58 pm
Fix 5, you are my hero! :D

Well, now to add the fancy stuff.

Also, Can somebody optimize my code?
Title: Re: Lights Out help?
Post by: Streetwalrus on November 30, 2013, 05:03:26 pm
Please be specific about what you want us to optimize and for size or speed ? Also do a bit of research about it in the Axe forum. It's good to know how to do it yourself. ;)
Title: Re: Lights Out help?
Post by: JWinslow23 on November 30, 2013, 05:09:53 pm
Size. The speed is adequate. And sorry, this is my first ACTUAL endeavour in Axe.

EDIT: Never mind, the Rect and RectI commands are providing many chances for optimizations. I'll get back to you.

EDIT 2: Now the size of the compiled result is 1,767 bytes. Code tomorrow, along with some other stuff for an in-game sidebar.
Title: Re: Lights Out help?
Post by: ClrDraw on November 30, 2013, 07:54:34 pm
(http://img.ourl.ca//lightsOutDemo.gif)

This is pretty cool! +1

Here's one thing you can optimize: instead of A+1->A use A++
Title: Re: Lights Out help?
Post by: JWinslow23 on November 30, 2013, 08:16:19 pm
I did in the source already, just figured out that trick. Also, I made an optimized version, so change the screenie. (Looks cool, though!)

The source is attached.

Oh, and the black squares are lights "on", and the white squares are lights "off". Just looked like you thought the opposite.

EDIT: Uhhhh...SHOULD it be the opposite?
Title: Re: Lights Out help?
Post by: ClrDraw on November 30, 2013, 09:01:23 pm
Haha yeah I think it should probably be the opposite  ;) Also they eye is attracted to lighter colors so people will naturally try removing the white squares.
Title: Re: Lights Out help?
Post by: JWinslow23 on November 30, 2013, 09:15:22 pm
OK, an update is coming tomorrow. Xeda Elnara is now working on whatever optimizations I missed, and in the meantime, I'll give you this (http://www.mediafire.com/download/zww3khli0316mii/ALIGHTS.8xp) to mess around with if you want. It's the Axe source.
If you want, I can make gameplay modes to select, like Lit Only, Toggle, or even choosing the x move instead of the + move! But should I include the puzzles from the original? I don't know if I should, there are literally 900.
Title: Re: Lights Out help?
Post by: Streetwalrus on December 01, 2013, 01:57:13 am
You have some pretty nice graphics here. :) I'm waiting for the final release though. I guess instead of packing levels with it you should just randomize the board.
Title: Re: Lights Out help?
Post by: Hayleia on December 01, 2013, 03:19:33 am
The graphics look a lot like the ones used by leafy in LightsOff (http://ourl.ca/13794/258606). If you used those sprites, be sure to add him in the credits ;)

(http://img.removedfromgame.com/imgs/110211.gif)
LightsOff by leafy
Title: Re: Lights Out help?
Post by: Sorunome on December 01, 2013, 04:13:53 am
(http://img.ourl.ca//lightsOutDemo.gif)

This is pretty cool! +1

Here's one thing you can optimize: instead of A+1->A use A++
wha, i love those graphics, great job JWinslow!
Title: Re: Lights Out help?
Post by: ClrDraw on December 01, 2013, 10:56:16 am
Wow that is  :o
Title: Re: Lights Out help?
Post by: JWinslow23 on December 01, 2013, 12:21:34 pm
Sorunome and Streetwalker, thanks for the compliments! Final version in a few days, hopefully.

Hayleia, I actually DID base my graphics off of his, and I will be sure to credit him for the graphics.

Xeda has also optimized it to 1,400 bytes compiled. Now to add a win message...and code coming sooner today!

EDIT: The source is attached, and I have a screenie. (Sorry the graphics look weird in the win message, I used Wabbitemu. They look fine on a TI-83+, so I don't know what was wrong there.)
(http://i.imgur.com/2RrPhyl.gif)
If you don't have Axe Parser, I'm releasing the no-shell compiled result too! The Axe source is ASHUTDN.8xp, and the compiled result is SHUTDOWN.8xp.
Title: Re: Lights Out help?
Post by: ClrDraw on December 01, 2013, 03:47:44 pm
Sounds fun I'm downloading now  :)
Title: Re: Lights Out help?
Post by: JWinslow23 on December 01, 2013, 04:26:40 pm
Is there an equivalent of sub( in BASIC for use in Axe? And can you store a string to a Pic (sprite)?
Title: Re: Lights Out help?
Post by: Hayleia on December 01, 2013, 04:47:02 pm
Is there an equivalent of sub( in BASIC for use in Axe?
Try this code.

"Imma Absol"[00]->°String
Text(0,0,°String)
Text(0,6,°String+1)
Text(0126,°String+2)

This will be the output (if I didn't make a typo):

Imma Absol
mma Absol
ma Absol

Why ? Because pointers.
So if you want to display part of a string, just copy the part of the string you like somewhere, add a zero behind and you're ok. Try this code for example,

"Imma Absol"[00]->°String
Copy(°String+2,L1,4)
0->{L1+5}
Text(0,,L1)

And can you store a string to a Pic (sprite)?
"Pic" is a pointer, not an object, you can't store anything inside ;)
But what do you mean with "store a string to a Pic" ? Like doing "Imma Absol"[00]->Pic1 ? Well, that would work since Pic1 is a pointer like any other one.
Title: Re: Lights Out help?
Post by: ClrDraw on December 01, 2013, 05:06:15 pm
I have not tested this, but it should work.

Code: [Select]
:.TEST
:"TEST STRING"->String1
:Fill(L1,20,0)
:Copy(String1+4,L1,5)
:ClrHome
:Output(0,0,L1)

This should take "TEST STRING" and output "STRING".
Title: Re: Lights Out help?
Post by: JWinslow23 on December 01, 2013, 05:14:14 pm
The following code displayed "SLHLULTLDLOLWLNL", but there seems to be no mention of an L. Help?

Code: [Select]
.EXAMPLE
"SHUTDOWN"->Str1
For(X,0,7
Copy(Str1+X,L1,1
0->{L1+2}
Disp L1
End

EDIT: Never mind, ClrDraw fixed it.

I'll incorporate it into a title screen. I'll post code in 1 - 2 days.
Title: Re: Lights Out help?
Post by: Hayleia on December 02, 2013, 12:48:22 am
The problem with your code (and I guess with my code) is that the 0->{L1+2} puts the 0 a bit too far, so you have a random byte (that correspond to the L) between the character you are trying to display and the end of the string. Try the same with a L1+1, it should work.
The reason why ClrDraw's code works is because he doesn't place a zero, he places a whole bunch of them :P
But his code only works for strings shorter than 20 characters while mine (once fixed) would work for any.

Also, I thought about another code that doesn't waste RAM.

"Imma Absol again"->°String
Text(0,6)
°String+2-1->r1
For(4)
 Text {r1+1->r1}>Char
End
Title: Re: Lights Out help?
Post by: JWinslow23 on December 02, 2013, 01:39:02 am
But...L1, according to the documentation, is "free RAM", which doesn't take up any RAM. The earlier method is fine.

EDIT: Also, I decided I won't need it for this project. Maybe Cookie Clicker.

BTW, can someone make some code to draw a 3 level grayscale cookie?
Title: Re: Lights Out help?
Post by: XiiDraco on December 02, 2013, 02:14:23 am
Weird I thought I saw someone mention a cookie clicker before on the forum, but when I searched this page was the ONLY result. Huh.

Also. I love floating point math.   >:D
Title: Re: Lights Out help?
Post by: Eiyeron on December 02, 2013, 07:21:44 am
(http://osl.cemetech.net/images/upload/9.png)
Code :
Code: [Select]
[0007C000003FFC0000F81F0001F70F8007CF8BC00FCF89C01E6709E03C2000707810183070003C3860003C38E0001818E03C0018E07E001CF07E001CD83C039CCC00079CC200031C6000081870000338708001B839C000F039E000F01CC801E00E0803C00738078001F00E0000E01800003FF00000078000]->Pic1
[0007C000003FFC0000FFFF0001FF1F8007FF9FC00FEF8FC01FE79FE03FF319F07C783C70781C7E7870027E38E0383C18E07C0018F07E001CFC7E031CFC7E079CFC1C07BCE300433C7080193870208FF879D083F839E903F03DEB03F01ECE03E00FF807C007FC1F8001FEFE0000FFF800003FF00000078000]->Pic2
But I don't remember how to use sprites from cemetech. This cokkie is 30*30 sized, and uses 4*4sprites. I think theyr are aligned like this
Code: [Select]
0|1|2|3
--------
4|5|6|7
--------
8|9|A|B
--------
C|D|E|F
Code: [Select]
For(F,0,3
For(E,0,3
Pt-On(E*8,F*8,F*4+E*8+Pic1)
Pt-On(E*8,F*8,F*4+E*8+Pic2)^^r
End:End
Title: Re: Lights Out help?
Post by: JWinslow23 on December 02, 2013, 11:32:38 am
The cookie looks good! But the image on the calculator...not so much.  :-\

Sorry, but the code doesn't work. And not just because you didn't add a ClrDraw at the beginning and Repeat getKey(15):DispGraph r:End at the end, but because it doesn't display a cookie. It looks like MissingNo.

The cookie is an image I will consider, though!  ;D(http://www.omnimaga.org/Themes/default/images/gpbp_arrow_up.gif)

EDIT:
Weird I thought I saw someone mention a cookie clicker before on the forum, but when I searched this page was the ONLY result. Huh.

That was me. Seriously, it would look GREAT in Assembly!

Also. I love floating point math.   >:D

How to do that, how to do that...

I don't know, this Cookie Clicker talk should be a bigger project for us. Maybe I can partner with some of the Coders of Tomorrow for the floating point math, as well as formatting.  :D
Title: Re: Lights Out help?
Post by: Eiyeron on December 02, 2013, 11:41:07 am
(MissingNo has 3 correct sprites: the two fossils and the specter, it's only the other glitches that looks, and are, garbage),

Does the top-left corner looks right?
Title: Re: Lights Out help?
Post by: Hayleia on December 02, 2013, 12:13:46 pm
But...L1, according to the documentation, is "free RAM", which doesn't take up any RAM. The earlier method is fine.
It is only free RAM as long as you don't use it ;)
Yes it is free RAM and you can use it whenever you want, but my point is that you might need it somewhere else so if you can save it, save it but if you don't need to, don't save it.

For the cookie image, are you sure it is divided in sprites like that and not just divided in plain bytes ?
If it's plain bytes, something like this should work (if I made no errors this time :P):

.unoptimized
For(X,0,3)
 For(Y,0,29)
  {Y*4+X->r1+Pic1}->{r1+L6}
  {r1+Pic2}->{r1+L3}
 End
End

(Sorry, can't test right now)
Title: Re: Lights Out help?
Post by: JWinslow23 on December 02, 2013, 07:04:32 pm
But...L1, according to the documentation, is "free RAM", which doesn't take up any RAM. The earlier method is fine.
It is only free RAM as long as you don't use it ;)
Yes it is free RAM and you can use it whenever you want, but my point is that you might need it somewhere else so if you can save it, save it but if you don't need to, don't save it.

For the cookie image, are you sure it is divided in sprites like that and not just divided in plain bytes ?
If it's plain bytes, something like this should work (if I made no errors this time :P):

.unoptimized
For(X,0,3)
 For(Y,0,29)
  {Y*4+X->r1+Pic1}->{r1+L6}
  {r1+Pic2}->{r1+L3}
 End
End

(Sorry, can't test right now)

Testing soon.
Title: Re: Lights Out help?
Post by: Hayleia on December 03, 2013, 01:49:59 am
See why I said "if I made no errors this time" ? :P
Just tested my code, and there are some things to change, but you get the idea.
Here's the full working (unoptimized) code to display that cookie:
Code: [Select]
[0007C000003FFC0000F81F0001F70F8007CF8BC00FCF89C01E6709E03C2000707810183070003C3860003C38E0001818E03C0018E07E001CF07E001CD83C039CCC00079CC200031C6000081870000338708001B839C000F039E000F01CC801E00E0803C00738078001F00E0000E01800003FF00000078000]->Pic1
[0007C000003FFC0000FFFF0001FF1F8007FF9FC00FEF8FC01FE79FE03FF319F07C783C70781C7E7870027E38E0383C18E07C0018F07E001CFC7E031CFC7E079CFC1C07BCE300433C7080193870208FF879D083F839E903F03DEB03F01ECE03E00FF807C007FC1F8001FEFE0000FFF800003FF00000078000]->Pic2
ClrDraw(L6)
ClrDraw(L3)
For(X,0,3)
 For(Y,0,29)
  {Y*4+X->r1+Pic1}->{Y*12+X->r2+L6}
  {r1+Pic2}->{r2+L3}
 End
End
While 1
DispGraph^^r
EndIf getKey(15)

edit just thought of an easier way to put it lol (but I like playing with bytes, I made my own sprite routine in Omniblade so that the player sprite loops :P)
Code: [Select]
[201D]->Pic1
[0007C000003FFC0000F81F0001F70F8007CF8BC00FCF89C01E6709E03C2000707810183070003C3860003C38E0001818E03C0018E07E001CF07E001CD83C039CCC00079CC200031C6000081870000338708001B839C000F039E000F01CC801E00E0803C00738078001F00E0000E01800003FF00000078000]
[201D]->Pic2
[0007C000003FFC0000FFFF0001FF1F8007FF9FC00FEF8FC01FE79FE03FF319F07C783C70781C7E7870027E38E0383C18E07C0018F07E001CFC7E031CFC7E079CFC1C07BCE300433C7080193870208FF879D083F839E903F03DEB03F01ECE03E00FF807C007FC1F8001FEFE0000FFF800003FF00000078000]
ClrDraw(L6)
ClrDraw(L3)
Bitmap(0,0,Pic1,L6)
Bitmap(0,0,Pic2,L3)
While 1
DispGraph^^r
EndIf getKey(15)
Title: Re: Lights Out help?
Post by: JWinslow23 on December 03, 2013, 12:35:44 pm
I wonder if you could optimize it, the cookie looks GREAT!

Now for a cursor (without DCS, mind you!), and floating point math.
Title: Re: Lights Out help?
Post by: Streetwalrus on December 03, 2013, 12:51:03 pm
A mouse cursor is the easiest thing to make. ;)
Title: Re: Lights Out help?
Post by: Hayleia on December 03, 2013, 02:16:42 pm
I wonder if you could optimize it
Just ask and you shall get.
The version I gave you is 496 bytes.

Optimizing the two For loops, we can get down to 477 bytes
Code: [Select]
[0007C000003FFC0000F81F0001F70F8007CF8BC00FCF89C01E6709E03C2000707810183070003C3860003C38E0001818E03C0018E07E001CF07E001CD83C039CCC00079CC200031C6000081870000338708001B839C000F039E000F01CC801E00E0803C00738078001F00E0000E01800003FF00000078000]->Pic1
[0007C000003FFC0000FFFF0001FF1F8007FF9FC00FEF8FC01FE79FE03FF319F07C783C70781C7E7870027E38E0383C18E07C0018F07E001CFC7E031CFC7E079CFC1C07BCE300433C7080193870208FF879D083F839E903F03DEB03F01ECE03E00FF807C007FC1F8001FEFE0000FFF800003FF00000078000]->Pic2
ClrDraw^^r^^r
0
For(4)
 ->X
 ~1->Y
 For(30)
  {Y+1->Y*4+X->r1+Pic1}->{Y*12+X->r2+L6}
  {r1+Pic2}->{r2+L3}
 End
 X+1
End
While 1
DispGraph^^r
EndIf getKey(15)

Then, changing the algorithm a bit, we can get down to  467 bytes
Code: [Select]
[0007C000003FFC0000F81F0001F70F8007CF8BC00FCF89C01E6709E03C2000707810183070003C3860003C38E0001818E03C0018E07E001CF07E001CD83C039CCC00079CC200031C6000081870000338708001B839C000F039E000F01CC801E00E0803C00738078001F00E0000E01800003FF00000078000]->Pic1
[0007C000003FFC0000FFFF0001FF1F8007FF9FC00FEF8FC01FE79FE03FF319F07C783C70781C7E7870027E38E0383C18E07C0018F07E001CFC7E031CFC7E079CFC1C07BCE300433C7080193870208FF879D083F839E903F03DEB03F01ECE03E00FF807C007FC1F8001FEFE0000FFF800003FF00000078000]->Pic2
ClrDraw^^r^^r
~1->r1
~9->r2
For(120)
 {Select(r1+1,->r1 and 3??r2+8->r2)+Pic1}->{r2+1->r2+L6}
 {r1+Pic2}->{r2+L3}
End
While 1
DispGraph^^r
EndIf getKey(15)

Now ask Runer112 and you'll get down to 5 bytes.

edit
I am so stupid, this can be done in 457 bytes
Code: [Select]
[0007C000003FFC0000F81F0001F70F8007CF8BC00FCF89C01E6709E03C2000707810183070003C3860003C38E0001818E03C0018E07E001CF07E001CD83C039CCC00079CC200031C6000081870000338708001B839C000F039E000F01CC801E00E0803C00738078001F00E0000E01800003FF00000078000]->Pic1
[0007C000003FFC0000FFFF0001FF1F8007FF9FC00FEF8FC01FE79FE03FF319F07C783C70781C7E7870027E38E0383C18E07C0018F07E001CFC7E031CFC7E079CFC1C07BCE300433C7080193870208FF879D083F839E903F03DEB03F01ECE03E00FF807C007FC1F8001FEFE0000FFF800003FF00000078000]->Pic2
ClrDraw^^r^^r
~4->r1
~12->r2
For(30)
 Copy(r1+4->r1+Pic1,r2+12->r2+L6,4)
 Copy(r1+Pic2,r2+L3,4)
End
While 1
DispGraph^^r
EndIf getKey(15)



For the code with Bitmaps commands, I don't see a lot to optimize except the two Clrdraws to put in a ClrDraw^^r^^r and the "0,0," to transorm into "0,,".
Title: Re: Lights Out help?
Post by: JWinslow23 on December 03, 2013, 02:19:20 pm
A mouse cursor is the easiest thing to make. ;)
Well, yes, but how to do it with 3-level grayscale without erasing anything behind it? I just think that anything on the main buffer will be erased by the cursor. I know, I tried.
Title: Re: Lights Out help?
Post by: Hayleia on December 03, 2013, 02:26:41 pm
Easy, just save what's behind the sprite before drawing it, then draw it then erase it. Beware though to put your operations in a smart order so you don't have the DispGraph^^r between the erasing and the drawing part :P

Would look like this (check the Commands for proper syntax, I may mess up with the order of the arguments)

Pt-Get(X,Y,L6,L1)
Pt-Get(X,Y,L3,L1+8)
Pt-On(X,Y,°SpriteBlack,L6)
Pt-On(X,Y,°SpriteGrey,L3)
DispGraph^^r
Pt-Off(X,Y,L1,L6)
Pt-Off(X,Y,L1+8,L3)
Title: Re: Lights Out help?
Post by: Streetwalrus on December 03, 2013, 03:11:09 pm
Also look at Pt-Mask if you want a partly transparent cursor. ;)
Title: Re: Lights Out help?
Post by: aeTIos on December 03, 2013, 07:18:25 pm
offtopic: oh my streetwalker, dat profile pic o.o
Title: Re: Lights Out help?
Post by: Streetwalrus on December 04, 2013, 11:34:33 am
offtopic: oh my streetwalker, dat profile pic o.o
Yes I wanted to look like a total nut. I'm a noob at taking better selfies. :P
Title: Re: Lights Out help?
Post by: aeTIos on December 04, 2013, 11:35:34 am
(http://t0.gstatic.com/images?q=tbn:ANd9GcR58clsN4i5hazeW7KTeYIT7k0PkASVKv_b7f42vp26Og1nGwIEdQ)
You failed.
And I'm derailing the thread.
Title: Re: Lights Out help?
Post by: JWinslow23 on December 04, 2013, 09:26:01 pm
Sorry for the bump, but I want to tell you three things:

1. I quit the Cookie Clicker project. The numbers thing was too hard, bordering on impossible. :/
2. I just made a tiny optimization, and I'm attaching the game (SHUTDOWN) and the source (ASHUTDN) here.
3. I'm working on getting this on ticalc.org. I'll post back when I have the link.

EDIT: It's on ticalc.org!

http://www.ticalc.org/archives/files/fileinfo/457/45769.html

EDIT 2: I made a menu!