ohstereo Posted August 13, 2007 Share Posted August 13, 2007 Alright, all day I've been looking at this tutorial: http://kofk.de/?p=howto But this guy doesn't give me any help at all on what I should be doing.. I know he's telling me to read those articles, but that won't help. =/ So far, I have my image: http://prettyknives.net/pf/bg.jpg My script: http://prettyknives.net/pf/sample.php CODE: <?php // Begin Constant definitions define('BACKGROUND', 'bg.jpg'); // End definitions $image = imagecreatefromjpeg(BACKGROUND); $hp = calculateHitpoints(); drawHitpointBar($image, $hp); writeName($image, "Pet Name"); // Output header("Content-Type: image/jpeg"); imagejpeg($image, "", 95); ?> <?php function calculateHitpoints(){ $feed = isset($_GET['feed']); } $hp = loadFromDatafile(DATAFILE); $hp -= (int)((time() - filemtime(DATAFILE)) / DRAIN); // Insert these somewhere in the constants definition block define('DATAFILE', "petdata.dat"); define('DRAIN', 300); define('FOODVALUE', 10); define('MAXHP', 300); function calculateHitpoints(){ $feed = isset($_GET['feed']); $hp = loadFromDatafile(DATAFILE); $hp -= (int)((time() - filemtime(DATAFILE)) / DRAIN); if ($feed) $hp += FOODVALUE; if ($hp > MAXHP) $hp = MAXHP; if ($hp < 1) $hp = 1; if ($feed) saveToDatafile($hp, DATAFILE); return $hp; } // Insert these somewhere in the constants definition block define('BAR_X', 10); define('BAR_Y', 200); define('BAR_MAXWIDTH', 400); define('BAR_HEIGHT', 6); define('BAR_R', 0xdd); define('BAR_G', 0x5a); define('BAR_B', 0x7c); function paintHPBar($image, $hp) { $width = ceil(BAR_MAXWIDTH * $hp / MAXHP); $bar_color = imagecolorallocate($image, BAR_R, BAR_G, BAR_B); imagefilledrectangle($image, BAR_X, BAR_Y, BAR_X + $width, BAR_Y + BAR_HEIGHT, $bar_color); } // Insert these somewhere in the constants definition block define('NAME_X', 20); define('NAME_Y', 160); define('NAME_R', 0x4f); define('NAME_G', 0x66); define('NAME_B', 0x81); // GD has 5 built-in fonts, called 1, 2, 3, 4, and 5 define('FONT', 5); //If you want to use TTF, you need these define('ANGLE', 0); define('FONTSIZE', 14); define('FONTFILE', 'arial.ttf'); function writeName($image, $name) { $text_color = imagecolorallocate($image, NAME_R, NAME_G, NAME_B); // If you want to use a font file imagettftext($image, FONTSIZE, ANGLE, NAME_X, NAME_Y, $text_color, FONTFILE, $name); // Else, use one of the built-in fonts imagestring($image, FONT, NAME_X, NAME_Y, $name, $text_color); } ?> I just need someone to guide me through this. Thank you! <3 Quote Link to comment https://forums.phpfreaks.com/topic/64762-coding-feedable-pets/ Share on other sites More sharing options...
uwannadonkey Posted August 13, 2007 Share Posted August 13, 2007 well 1) that image is WAY small, think about resizing it! and 2, post your code in a [ code ] [/ code] format, without spaces please Quote Link to comment https://forums.phpfreaks.com/topic/64762-coding-feedable-pets/#findComment-323034 Share on other sites More sharing options...
ohstereo Posted August 14, 2007 Author Share Posted August 14, 2007 That's the image size I want to use, they're pixel pets. =P But I have to change the filetype, JPG is utter crap. And I posted the code. =] Quote Link to comment https://forums.phpfreaks.com/topic/64762-coding-feedable-pets/#findComment-323043 Share on other sites More sharing options...
uwannadonkey Posted August 14, 2007 Share Posted August 14, 2007 im not a pro like some people, but i can see some errors, mainly the error u see on the sample page: drawHitpointBar($image, $hp); its not set, you need to set it something like function drawHitpointbar($image,$hp) { what happens, blah blah } Quote Link to comment https://forums.phpfreaks.com/topic/64762-coding-feedable-pets/#findComment-323044 Share on other sites More sharing options...
uwannadonkey Posted August 14, 2007 Share Posted August 14, 2007 Fatal error: Call to undefined function: drawhitpointbar() in /home/prettykn/public_html/pf/sample.php on line 10 so i think its what i said, i MAY be wrong.. Quote Link to comment https://forums.phpfreaks.com/topic/64762-coding-feedable-pets/#findComment-323046 Share on other sites More sharing options...
uwannadonkey Posted August 14, 2007 Share Posted August 14, 2007 misclicked*delete post! Quote Link to comment https://forums.phpfreaks.com/topic/64762-coding-feedable-pets/#findComment-323047 Share on other sites More sharing options...
ohstereo Posted August 14, 2007 Author Share Posted August 14, 2007 Yeah, but I don't understand what happens there. See this? // Insert these somewhere in the constants definition block define('BAR_X', 10); define('BAR_Y', 200); define('BAR_MAXWIDTH', 400); define('BAR_HEIGHT', 6); define('BAR_R', 0xdd); define('BAR_G', 0x5a); define('BAR_B', 0x7c); function paintHPBar($image, $hp) { $width = ceil(BAR_MAXWIDTH * $hp / MAXHP); $bar_color = imagecolorallocate($image, BAR_R, BAR_G, BAR_B); imagefilledrectangle($image, BAR_X, BAR_Y, BAR_X + $width, BAR_Y + BAR_HEIGHT, $bar_color); } The guy didn't explain what each define means. =P Quote Link to comment https://forums.phpfreaks.com/topic/64762-coding-feedable-pets/#findComment-323049 Share on other sites More sharing options...
uwannadonkey Posted August 14, 2007 Share Posted August 14, 2007 that code, defines the size of the image. presumably the bar. but thats not your problem your problem is function drawHitpointbar its not a function, but you wrote it like it is. what is the purpose of that function? or is it not ur code? Quote Link to comment https://forums.phpfreaks.com/topic/64762-coding-feedable-pets/#findComment-323054 Share on other sites More sharing options...
ohstereo Posted August 14, 2007 Author Share Posted August 14, 2007 It's not my code, I'm trying to customize this guy's code: http://kofk.de/?p=howto But he doesn't explain it very well. What would happen if I just got rid of it? Quote Link to comment https://forums.phpfreaks.com/topic/64762-coding-feedable-pets/#findComment-323056 Share on other sites More sharing options...
lifutushi Posted August 14, 2007 Share Posted August 14, 2007 Fatal error: Call to undefined function: drawhitpointbar() in /home/prettykn/public_html/pf/sample.php on line 10 so i think its what i said, i MAY be wrong.. i'm a newbie so i might be wrong, but shouldn't you check the case first> Quote Link to comment https://forums.phpfreaks.com/topic/64762-coding-feedable-pets/#findComment-323060 Share on other sites More sharing options...
dbillings Posted August 14, 2007 Share Posted August 14, 2007 His tutorial is kind of crap, the drawHitpointBar($image, $hp) function magically transforms into paintHPBar($image, $hp), but the way you have your script posted it calls the function drawHitpointBar($image, $hp) before you define it. Even though the function changes to paintHPBar(). If PHP is what your interested in learning his tutorial is a little advanced and poorly written. Try w3schools.com Quote Link to comment https://forums.phpfreaks.com/topic/64762-coding-feedable-pets/#findComment-323071 Share on other sites More sharing options...
keeB Posted August 14, 2007 Share Posted August 14, 2007 sample.php is broken Quote Link to comment https://forums.phpfreaks.com/topic/64762-coding-feedable-pets/#findComment-323126 Share on other sites More sharing options...
ohstereo Posted August 14, 2007 Author Share Posted August 14, 2007 It's not broken anymore. But the error is still there. I don't have a clue what it is. =[ Quote Link to comment https://forums.phpfreaks.com/topic/64762-coding-feedable-pets/#findComment-323161 Share on other sites More sharing options...
keeB Posted August 14, 2007 Share Posted August 14, 2007 drawHitpointBar($image, $hp); You need to code this function Quote Link to comment https://forums.phpfreaks.com/topic/64762-coding-feedable-pets/#findComment-323174 Share on other sites More sharing options...
uwannadonkey Posted August 14, 2007 Share Posted August 14, 2007 I ONLY SAID THAT 6 HOURS AGO lol sorry Quote Link to comment https://forums.phpfreaks.com/topic/64762-coding-feedable-pets/#findComment-323184 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.