CodeWalrus

Development => Calculators => Calc Projects, Programming & Tutorials => Topic started by: Strontium on May 05, 2015, 02:22:15 AM

Title: Greed [ti-nspire cx] [UPDATED!]
Post by: Strontium on May 05, 2015, 02:22:15 AM
Hello! I have ported greed (a CLI game for Linux created by Matthew Day) to the TI-Nspire CX. And it supports OS 3.1 and 3.6 this time :P

(https://i.imgur.com/46EDybH.jpg)

Instructions (slightly modified from the original):
The object of Greed is to erase as much of the screen as possible by moving around in a grid of numbers. Your location is signified by the 'P' symbol. When you move in a direction, you erase N number of grid squares in that direction, N being the first number in that direction. Your score reflects total number of squares eaten. Greed will not let you make a move that would have placed you off the grid of over a previously eaten square.

It *almost* perfectly mimics the original. It is missing three features:
-scoreboards (who cares!)
-loss detection (just press 5 to reset instead :P)
-possible move highlighting

There are always going to be a few bugs, of course

TODO:
only redraw the bits that need to be redrawn, in order to speed things up

Old post for posterity:
[spoiler]
Hello! I have ported greed (a CLI game for Linux created by Matthew Day) to the TI-Nspire CX. Currently, it only supports OS 3.9 & OS 4.0, but if someone wants to backport it for me, go ahead.

(https://i.imgur.com/6QR0AfD.jpg)

Directions (slightly modified from the original greed directions):
The object of Greed is to erase as much of the screen as possible by moving around in a grid of numbers. Your location is signified by the 'P' symbol. When you move in a direction, you erase N number of grid squares in that direction, N being the first number in that direction. Your score reflects total number of squares eaten. Greed will not let you make a move that would have placed you off the grid of over a previously eaten square.

Controls and your current score are on page 1.2, the directions are also written on page 1.3.

It's extremely close to the original. Its only missing the following three features:
- Automatic loss detection ('twas too lazy to implement it, just press 5 to reset instead)
- Possible move highlighting
- Scoreboard

Download attached.

EDIT: There is a bug where if you are right next to the left or right wall and try to move towards it, you will crash. I am trying to fix this, but have been unable to thus far.

EDIT2: Someone made an online version of Greed if you want to try it out before downloading my version: http://www.greedjs.com

EDIT3: I am going to rewrite this entire thing, since it is riddled with bugs and is spaghetti code.[/spoiler]
Title: Re: Greed
Post by: Dream of Omnimaga on May 06, 2015, 03:58:39 PM
Ooh I like the idea. Too bad it's not 3.6 compatible, as it's the most popular Ndlessable OS. But hopefully someone ne can port it back.
Title: Re: Greed [ti-nspire cx]
Post by: Strontium on May 07, 2015, 12:18:20 AM
Once I rewrite it, it will support OS 3.1 and 3.6. I didn't try to support them at first because I was lazy.

This is why I didn't want to try to support older versions:
(https://i.imgur.com/JPOF2oZ.jpg)

I have no clue why the last row doesn't get drawn.
Title: Re: Greed
Post by: Dream of Omnimaga on May 07, 2015, 12:44:58 AM
Oh that's weird. I wonder why that could happen? Maybe you could ask in the other subforum? Does that version use the same commands by the way?
Title: Re: Greed
Post by: Strontium on May 07, 2015, 12:48:29 AM
Quote from: DJ Omnimaga on May 07, 2015, 12:44:58 AM
Oh that's weird. I wonder why that could happen? Maybe you could ask in the other subforum? Does that version use the same commands by the way?

The rendering works the exact same as before, the only change I needed to do was get rid of window.platform:setBackgroundColor() and replace it with a gc:fillRect().

I'm going to test if its a bug on the emulator, first. The emulator sure does have a lot of bugs.
Edit: Not the emulator ):

Edit 2: Its exactly the last two rows of numbers that don't get drawn.
Title: Re: Greed
Post by: Dream of Omnimaga on May 07, 2015, 01:59:15 AM
Have you managed to fix it yet? Also will it require multiple versions for each OS? Also which emulator do you use?
Title: Re: Greed [ti-nspire cx]
Post by: Strontium on May 07, 2015, 02:00:14 AM
1. I managed to fix it. Some rounding functions in Luas math module thing worked differently between API versions for some reason.
2. Nope!
3. The one in the TI Student Software.
Title: Re: Greed
Post by: Dream of Omnimaga on May 07, 2015, 02:01:49 AM
Awesome to hear. :D Also how is the speed?

As for TI Student software it's not an emulator but a simulator. It emulates the OS rather than the calc. As a result, like with the HP Prime simulator, some stuff will be different in it. (although it shouldn't happen)
Title: Re: Greed [ti-nspire cx]
Post by: Strontium on May 07, 2015, 02:04:46 AM
Ah. I always thought it was an emulator :P

And I havent tested it on calc yet, soo...

Let me finish the thing and then I'll test it.

-- some time later --

There is a bug I am completely lost on for the cause :P
There is a bug that allows you to escape the grid on the Y axis. I have no clue why it happens, but I've noticed its usually when a move will land you directly outside the grid. I assume this also applies to the X axis.

-- longer time later --

Haha! The grid was just getting rendered to high, and thus causing the top row to be hidden. Its fixed now :P

@DJ Omnimaga There was no problem with math.floor() :P
Title: Re: Greed
Post by: Dream of Omnimaga on May 07, 2015, 03:54:42 AM
Awesome to hear. I'll definitively give it a try when I have a chance. :)
Title: Re: Greed [ti-nspire cx] [UPDATED!]
Post by: Jonius7 on May 07, 2015, 11:47:39 PM
Good to see you are making nice progress on a Lua project :)
Title: Re: Greed
Post by: Dream of Omnimaga on May 18, 2015, 08:30:06 PM
So any estimate about when an OS 3.1 compatible version will come out? I tried the latest version on it and it tells me I need to upgrade. :(
Title: Re: Greed [ti-nspire cx] [UPDATED!]
Post by: Strontium on May 18, 2015, 08:36:46 PM
Really? Thats strange. It uses apiLevel 1.0
Title: Re: Greed
Post by: Dream of Omnimaga on May 18, 2015, 10:37:49 PM
Yeah I launched your program and I got told to upgrade. Unless you absolutely have to save the program using OS 3.1 or set its version to 3.1?You might need to ask how in a separate topic.
Title: Re: Greed
Post by: Strontium on May 18, 2015, 11:00:46 PM
Quote from: DJ Omnimaga on May 18, 2015, 10:37:49 PM
Yeah I launched your program and I got told to upgrade. Unless you absolutely have to save the program using OS 3.1 or set its version to 3.1?You might need to ask how in a separate topic.

Perhaps if I compile it into a .tns with Luna it may work, but I do not have the resources needed atm.
Title: Re: Greed [ti-nspire cx] [UPDATED!]
Post by: LD Studios on May 19, 2015, 10:39:01 AM
It works fine for me, it told me to update software, I hit cancel, and it opened the document.
Title: Re: Greed
Post by: Dream of Omnimaga on May 19, 2015, 05:20:31 PM
There's no cancel option for me O.O (OS 3.1)