Entrance Events! Chat Gallery Search Everyone Wiki Login Register

Welcome, Guest. Please login or register. - Thinking of joining the forum??
March 12, 2025 - @231.27 (what is this?)
Activity rating: Four Stars Posts & Arts: 63/1k.beats Unread Topics | Unread Replies | My Stuff | Random Topic | Recent Posts Start New Topic  Submit Art
News: :4u: Love is not possession  :4u: Super News: Profile Design Contest! ends March 11th!

+  MelonLand Forum
|-+  Making Things
| |-+  ☆ ∙ Projects
| | |-+  ⚛︎ ∙ Melon's Junk
| | | |-+  TamaNOTchi >:3


« previous next »
Pages: 1 ... 3 4 [5] Print
Author Topic: TamaNOTchi >:3  (Read 7658 times)
TheFrugalGamer
Sr. Member ⚓︎
****


⛺︎ My Room
Itch.io: My Games
RSS: RSS

View Profile WWW

First 1000 Members!Pocket Icelogist!Joined 2022!
« Reply #60 on: February 05, 2025 @725.71 »

I believe there are actually only three :omg:

Also to explain why I have not gone nuts and added a bunch of new species and items already; the issue is that they are actually manually hard coded in PHP - which I'm sure was a good way to start the project, but from a maintainability stance... its a nightmare. Every species, and every item has to be individually coded.. for each gender of pet, and each age :drat:

For example ~ this is the core code for one species of tama, out of a document thats 1000 lines long, all mostly the same as this:
Code
if ($thispet["species"] == 1) {
            // CHUNNEKO
            if ($thispet["age"] == 0) {
                // 0
                $pet = [$device[6] + 12 * $multiplier, $device[7] - 26 * $multiplier, 0, 306 * $multiplier, 16 * $multiplier, 26 * $multiplier];
            }
            if ($thispet["age"] == 1) {
                // 1
                $pet = [$device[6] + 10 * $multiplier, $device[7] - 18 * $multiplier, 18 * $multiplier, 314 * $multiplier, 20 * $multiplier, 12 * $multiplier];
            }
            if ($thispet["age"] == 2) {
                // 2
                $pet = [$device[6] + 12 * $multiplier, $device[7] - 20 * $multiplier, 40 * $multiplier, 312 * $multiplier, 16 * $multiplier, 14 * $multiplier];
            }
            if ($thispet["age"] == 3) {
                // 3
                $pet = [$device[6] + 12 * $multiplier, $device[7] - 24 * $multiplier, 58 * $multiplier, 308 * $multiplier, 16 * $multiplier, 18 * $multiplier];
            }
            if ($thispet["age"] == 4) {
                // 4
                $pet = [$device[6] + 12 * $multiplier, $device[7] - 28 * $multiplier, 76 * $multiplier, 304 * $multiplier, 16 * $multiplier, 24 * $multiplier];
            }
            if ($thispet["age"] == 5) {
                // 5
                $pet = [$device[6] + 12 * $multiplier, $device[7] - 32 * $multiplier, 94 * $multiplier, 300 * $multiplier, 16 * $multiplier, 26 * $multiplier];
            }
            if ($thispet["age"] == 6) {
                // 6
                $pet = [$device[6] + 10 * $multiplier, $device[7] - 32 * $multiplier, 112 * $multiplier, 300 * $multiplier, 20 * $multiplier, 26 * $multiplier];
            }
            if ($thispet["age"] == 7) {
                // 7
                if ($thispet["sex"] == 0) {
                    // FEMALE
                    $pet = [$device[6] + 6 * $multiplier, $device[7] - 32 * $multiplier, 162 * $multiplier, 298 * $multiplier, 26 * $multiplier, 28 * $multiplier];
                }
                if ($thispet["sex"] == 1) {
                    // MALE
                    $pet = [$device[6] + 8 * $multiplier, $device[7] - 32 * $multiplier, 134 * $multiplier, 298 * $multiplier, 26 * $multiplier, 28 * $multiplier];
                }
            }
            if ($thispet["age"] == 8) {
                // 8
                if ($thispet["sex"] == 0) {
                    // FEMALE
                    $pet = [$device[6] + 4 * $multiplier, $device[7] - 32 * $multiplier, 222 * $multiplier, 298 * $multiplier, 30 * $multiplier, 28 * $multiplier];
                }
                if ($thispet["sex"] == 1) {
                    // MALE
                    $pet = [$device[6] + 6 * $multiplier, $device[7] - 32 * $multiplier, 190 * $multiplier, 298 * $multiplier, 30 * $multiplier, 28 * $multiplier];
                }
            }
            if ($thispet["age"] == 9) {
                // 9
                if ($thispet["sex"] == 0) {
                    // FEMALE
                    $pet = [$device[6] + 4 * $multiplier, $device[7] - 32 * $multiplier, 286 * $multiplier, 298 * $multiplier, 30 * $multiplier, 28 * $multiplier];
                }
                if ($thispet["sex"] == 1) {
                    // MALE
                    $pet = [$device[6] + 6 * $multiplier, $device[7] - 32 * $multiplier, 254 * $multiplier, 298 * $multiplier, 30 * $multiplier, 28 * $multiplier];
                }
            }
            if ($thispet["age"] == 10) {
                // 10
                if ($thispet["sex"] == 0) {
                    // FEMALE
                    $pet = [$device[6] + 6 * $multiplier, $device[7] + 12 * $multiplier, 356 * $multiplier, 280 * $multiplier, 38 * $multiplier, 46 * $multiplier];
                }
                if ($thispet["sex"] == 1) {
                    // MALE
                    $pet = [$device[6] + 10 * $multiplier, $device[7] + 12 * $multiplier, 318 * $multiplier, 276 * $multiplier, 36 * $multiplier, 50 * $multiplier];
                }
            }
        } // end if species block for Chunneko

What exactly do these numbers mean? How are they calculated? I only vaguely know! If any really smart PHP wizards want to figure out how to replace this with an automatic system ~ I would be eternally grateful  :omg:


Ok wow, yeah that looks a mess! I wonder what the $device array holds? It's pulling something out of there to get to stats, and it's also not using the first 6 objects in it (at least not here). It also looks like each of the species have different stats?

I'd have to see all of the code to know for sure, but it seems like the pets would best be handled by objects (because it looks like they're currently stored as variables?). Then you could collapse all of that repetition into an object call for each of them instead of copy/pasting a bunch of variables over and over again. But I dunno, that could be totally wrong based on what else is going on with the site. Also changing the basic pet code would probably entail a lot more work than just this portion you've posted here.
Logged

Melooon
Hero Member ⚓︎
*****


So many stars!

⛺︎ My Room
SpaceHey: Friend Me!
StatusCafe: melon
iMood: Melonking
Itch.io: My Games
RSS: RSS

View Profile WWWArt

Thanks for being rad!a puppy for your travelsAlways My PalFirst 1000 Members!spring 2023!
« Reply #61 on: February 05, 2025 @738.02 »

I wonder what the $device array holds?
Ok so I can decode it a little; what your looking at is called the img2.php file; and its the final render of all TamaNotchis, when you see a tama, it was created by this file.

The $device contains the parameters for the tama's device (the console thingy they are in before adulthood); Im unsure why that pet does not used the first 6 values though.
EDIT: I found a key in the comments!
Code
//********** set device shape coords (x/y start, width/height, x/y start for the buttons, x/y to place buttons)
        // of course only do this if the pet isn't fully-grown!

The $multiplier is only ever 1 or 0.5, and it's what lets you select between a big tama or a small one in your embeds. I believe all the actual numbers are relative positioning coordinates to pull the pets template out of a single sprite sheet.

Once it has all the parts of the pet from the spritesheet, it layers them, tints them based on your colour choices from the database and renders them as a single png.

I think your suggestion of converting it into a class is actually a really good one; this is an end-result file, meaning no other scripts depend on it; it just returns images; so it can be changed pretty freely, the key thing is that this file gets called prob 100k+ times a day, so it needs to be reaallly fast :omg:

Maybe there is a hope :grin:
Logged


everything lost will be recovered, when you drift into the arms of the undiscovered
TheFrugalGamer
Sr. Member ⚓︎
****


⛺︎ My Room
Itch.io: My Games
RSS: RSS

View Profile WWW

First 1000 Members!Pocket Icelogist!Joined 2022!
« Reply #62 on: February 05, 2025 @746.25 »

I think your suggestion of converting it into a class is actually a really good one; this is an end-result file, meaning no other scripts depend on it; it just returns images; so it can be changed pretty freely, the key thing is that this file gets called prob 100k+ times a day, so it needs to be reaallly fast :omg:

Maybe there is a hope :grin:

Yeah, I would've also suggested switch statements for the age, but I think in most languages those are actually slightly slower than the if statements, though they are easier to read.

I'm not sure how you'd streamline the sprite sheet--working with images for me has always lead to ugly code. I am a bit confused by the multiplier bit, though. Since the sprites themselves are so small, I would've served up the same image for both and used CSS to make one smaller, which would clean up the code a lot and be faster, since CSS always renders pretty quick. Come to think of it, the tints could also be done via CSS probably, but it wouldn't work for folks who wanted to right-click save their sprites for whatever reason.
Logged

Pages: 1 ... 3 4 [5] Print 
« previous next »
 

Vaguely similar topics! (3)

Tamanotchi Discord Server

Started by 6andBoard ⚛︎ ∙ Melon's Junk

Replies: 5
Views: 454
Last post November 13, 2024 @669.32
by Seryndelle
do you use tamanotchi?

Started by MemoryBoard ⚛︎ ∙ Melon's Junk

Replies: 10
Views: 1346
Last post October 22, 2024 @868.18
by KatiePla.net
Link your TamaNOTchis!

Started by plasticseaslugBoard ☁︎ ∙ Hyperlinks

Replies: 6
Views: 490
Last post January 31, 2025 @737.05
by armxnd.io

Melonking.Net © Always and ever was! SMF 2.0.19 | SMF © 2021 | Privacy Notice | ~ Send Feedback ~ Forum Guide | Rules | RSS | WAP | Mobile


MelonLand Badges and Other Melon Sites!

MelonLand Project! Visit the MelonLand Forum! Support the Forum
Visit Melonking.Net! Visit the Gif Gallery! Pixel Sea TamaNOTchi