Jump to content

Oroton

Members
  • Posts

    6
  • Joined

  • Last visited

Everything posted by Oroton

  1. This is a code i have to get data from the database and turn it into javascript basically.. what it does is it gets a field from the database. relating to columns. It creates an array to get all the column data for that map. Then for each column, it does another query to get all the info for each row in that column. Some row's have particular functions or multiple functions so it also queries whether that particular one has one or not. Now this code works and produces the desired effect. but is there a better way to do it? I feel doing one query first then doing a while loop and then a for loop inside might be better than doing a query then query the same table again. (i also know that SELECT * is slower but i'll optimise that later.) Anyway here is the code $_chip = chippy; //db unique modifyer for table //End Global Variables //Begin Table Names define('SCENEDATA', $_chip."_scenedata"); //Begin Table Names define('SCENEFUNCTION', $_chip."_scenefunction"); //scenedata table name //End Table Name $sceneid = '1'; $sceneinfo="SELECT * FROM " . SCENEDATA . " WHERE scene_value ='$sceneid' GROUP BY scene_column ORDER BY scene_column ASC "; $sceneinfo2=mysql_query($sceneinfo) or die("could not get map data!"); //could you get data? $sceneNumCols = mysql_num_rows($sceneinfo2); $scenecol_list = ""; $colcount = 1; $colcount_num = 0; while ($sceneinfo3=mysql_fetch_array($sceneinfo2)) { $scenecol_num = $sceneinfo3['scene_column']; if ($colcount_num == $scenecol_num) { if ($colcount == $sceneNumCols) { $colcomma = "<br>"; // last row } else { $colcount++; $colcomma = ",<br>"; // not last row } $scenedatainfo="SELECT d.*, f.* FROM " . SCENEDATA . " d LEFT JOIN " . SCENEFUNCTION . " f ON (d.scene_id = f.scenedata_id) WHERE d.scene_value ='$sceneid' AND d.scene_column = '$scenecol_num' ORDER BY d.scene_column ASC, d.scene_row ASC"; $scenedatainfo2=mysql_query($scenedatainfo) or die(mysql_error()); //could you get data? $sceneNumRows = mysql_num_rows($scenedatainfo2); //scene_value The Scene that it is $scenerow_list = ""; $rowcount = 1; $rowcount_num = 0; $scene_function = ""; //Begining of the Row lists. while ($scenedatainfo3=mysql_fetch_array($scenedatainfo2)) {//1 $scene_idv = $scenedatainfo3['scene_id']; $scene_row = $scenedatainfo3['scene_row']; $scene_name = $scenedatainfo3['scene_name']; $scene_fid = $scenedatainfo3['scene_function']; $sceneunique_id = $scenedatainfo3['scene_id']; $scenedatafunction_id = $scenedatainfo3['scenedata_id']; if ($scenedatafunction_id == $sceneunique_id) { $scene_function = ",<br>". $scene_fid; } elseif ($scenedatafunction_id != $sceneunique_id) { $scene_function = ""; } if ($rowcount == $sceneNumRows) { $rowcomma = "<br>"; // last row } else { $rowcomma = ","; // not last row $rowcount++; } if (empty($scene_name)) { $scenemap_name = "' ' "; $scene_new_map = ""; $scene_end_map = ""; } else {//2 $scenemap_name = $scene_name; $scene_new_map = " <b>new map</b> ("; $scene_end_map = "<br>)"; }//2 //else scene name $scenerow_list.= $scene_new_map . $scenemap_name.$scene_function .$scene_end_map. $rowcomma ."<br>"; }//end while row // This is the return of the each Column. $scenecol_list.= " [<i>//column " . $scenecol_num. "</i> <BR>" .$scenerow_list. " ]". $colcomma; $colcount_num++; }//end if first col else { } } //end colum WHILE print "<html><br><b> var maps</b> = [<br>" . $scenecol_list. "<br>];<br><br>".$sceneNumCols ."/" .$colcount."</html>"; This is the result. var maps = [ [//column 0 new map (map0x0, function() { if (game.plotSequence == 0) { eng.setMessage('Arrow keys to move, Spacebar to interact and close messages.'); game.plotSequence ++; } this.precip('rain', 35); } ), new map (map0x1, function() { this.precip('rain', 35); } ), new map (map0x2, function() { if (game.plotSequence == 1) { eng.setMessage('AHHHHH!!! What is that thing!? Help me!!!'); game.plotSequence ++; } this.precip('rain', 35); } ), ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , new map (map0x12 ) ], [//column 1 ' ' , new map (map1x1 ), new map (map1x2 ), new map (map1x3 ) ] ]; 2/2
  2. Oroton

    How to animate sprite

    I actually figured it out, i wasn't adding code to the correct variables. On to the next prolem
  3. So I have a sprite variable, and when I draw it i use, Sprite.prototype.draw = function() { if (!this.flashOn) { ctx.drawImage( this.tileset.image, this.states[this.currentState].frames[this.states[this.currentState].currentFrame].split(',')[0] * this.tileset.tileWidth, this.states[this.currentState].frames[this.states[this.currentState].currentFrame].split(',')[1] * this.tileset.tileHeight, this.tileset.tileWidth, this.tileset.tileHeight, Math.round(this.x), Math.round(this.y), this.width, this.height ); } } If I create a sprite, like this var spriteLeftAnim = new Animation(['1,1', '1,0'], 200); var spriteRightAnim = new Animation(['0,1', '0,0'], 200); var spriteUpAnim = new Animation(['2,1', '2,0'], 200); var spriteDownAnim = new Animation(['3,1', '3,0'], 200); var spriteDefinitions = { turtle: new SpriteDefinition( tilesets.turtle, { 'left': spriteLeftAnim, 'right': spriteRightAnim, 'down': spriteDownAnim, 'up': spriteUpAnim }, //Added by Oroton, 300, //200? 5, true, true ) It runs perfectly, I have to create another function for to run solid objects and i use this var chestAnim = new staticObj(['3,0']); chest: new SpriteDefinition( tilesets.maptiles, { down: chestAnim } these are the functions.. function Animation(frames, frameDuration) { this.frames = frames; this.currentFrame = 0; this.frameTimer = Date.now(); this.frameDuration = frameDuration; } function staticObj(frames) { this.frames = frames; this.currentFrame = 0; } What I want to do is instead of writing [code]var chestAnim = new staticObj(['3,0']); chest: new SpriteDefinition( tilesets.maptiles, { down: chestAnim //change this here } Write for the solid objects, but what happens is when i draw the item, it under currentState.frames.. [code]var chestAnim = new staticObj(['3,0']); chest: new SpriteDefinition( tilesets.maptiles, { down: '3,0' //to this here }
  4. Oroton

    downloaded spritesheet

    Need to know how you are writing your game? Library or from scratch?
  5. Oroton

    How to animate sprite

    So, you can see where all the added Animation code is.. with //Added by Oroton. Any help here would be good. I just can't figure out why it isn't animating I think it's a syntax error. Found around Here.. Sprite.prototype.draw = function() { if (!this.flashOn) { ctx.drawImage( this.tileset.image, /* Obscure everthing below this */ //Added by Oroton this.states[this.currentState].frames[this.states[this.currentState].currentFrame].split(',')[0] * this.tileset.tileWidth, this.states[this.currentState].frames[this.states[this.currentState].currentFrame].split(',')[1] * this.tileset.tileHeight, this.tileset.tileWidth, /* Obscure everthing above this */ //Added by Oroton this.tileset.tileHeight, Math.round(this.x), Math.round(this.y), this.width, this.height ); } } wizAnim.zip
  6. and play here.. www.brissyriders.com/turtlewiz/index.htm What i am wanting is to know how do I animate the character. and how can i animate the enemies. I have extended the character (turtle.png) sprite sheet, but I don't know how to animate it when he walks. Or how to Animate the enimies, can anyone help me? Thanks. Turtlewiz_files.zip
×
×
  • Create New...