liblashgame

Pathfinder and path decision making library for 2D tile game
git clone git://holbrook.no/liblashgame.git
Log | Files | Refs

sprite.cpp (2377B)


      1 // test sprite functions
      2 
      3 #include <stdio.h>
      4 #include <stdlib.h>
      5 #include <string.h>
      6 #include <time.h>
      7 #include <stdint.h>
      8 
      9 #include "../lash_game_sprite.h"
     10 
     11 void dumpsprite(Lash_Sprite_2D_Simple *sprite, char *description) {
     12 	
     13 	printf("%s:\nx %.2f, y %.2f, w %d, h %d, ax %.2f, ay %.2f, vx %.2f, vy %.2f\n", description, sprite->getX(), sprite->getY(), sprite->getW(), sprite->getH(), sprite->getAccelerationX(0), sprite->getAccelerationY(0), sprite->getVelX(), sprite->getVelY());
     14 	//printf("%s:\nx %.2f, y %.2f, w %d, h %d, a %.2f, ra %.2f, v %.2f, rv %.2f\n", description, sprite->getX(), sprite->getY(), sprite->getW(), sprite->getH(), sprite->getAccelerationX(0), sprite->getAccelerationY(0), sprite->getVelX(), sprite->getVelY());
     15 	static char statestring[33];
     16 	sprite->dumpState(statestring);
     17 	printf("state is now 0x%s\n\n", statestring);	
     18 }
     19 
     20 int main() {
     21 	srand(clock());
     22 	float x = rand() % 127;
     23 	float y = rand() % 127;
     24 	uint32_t w = rand() % 127;
     25 	uint32_t h = rand() % 127;
     26 	float inita = 0.3;
     27 	float inca = 0.4;
     28 	char *description = (char*)malloc(sizeof(char)*255);
     29 	Lash_Sprite_2D_Simple *sprite = new Lash_Sprite_2D_Simple(w, h, inita, inca);
     30 	
     31 	sprintf(description, "Sprite init %p w %d h %d", sprite, w, h);
     32 	dumpsprite(sprite, description);
     33 	
     34 	sprite->setX(x);
     35 	sprintf(description, "Set X %.2f", x);
     36 	dumpsprite(sprite, description);
     37 	
     38 	sprite->setY(y);
     39 	sprintf(description, "Set Y %.2f", y);
     40 	dumpsprite(sprite, description);
     41 	
     42 	sprite->walkLeft();
     43 	strcpy(description, "Walkleft\0");
     44 	dumpsprite(sprite, description);
     45 	
     46 	sprite->move();
     47 	strcpy(description, "Move\0");
     48 	dumpsprite(sprite, description);
     49 	
     50 	sprite->accelerate();
     51 	strcpy(description, "Accelerate\0");
     52 	dumpsprite(sprite, description);
     53 
     54 	sprite->move();
     55 	strcpy(description, "Move\0");
     56 	dumpsprite(sprite, description);
     57 		
     58 	sprite->addAccelerationX(0.6);
     59 	sprintf(description, "Add acceleration %f", 0.6);
     60 	dumpsprite(sprite, description);
     61 	
     62 	sprite->accelerate();
     63 	strcpy(description, "Accelerate\0");
     64 	dumpsprite(sprite, description);
     65 	
     66 	sprite->move();
     67 	strcpy(description, "Move\0");
     68 	dumpsprite(sprite, description);
     69 
     70 	sprite->jump();
     71 	strcpy(description, "Jump\0");
     72 	dumpsprite(sprite, description);
     73 
     74 	sprite->land();
     75 	strcpy(description, "Land\0");
     76 	dumpsprite(sprite, description);
     77 
     78 	sprite->stop();
     79 	strcpy(description, "Stop\0");
     80 	dumpsprite(sprite, description);
     81 	
     82 	return 0;
     83 }