Skip to content

Commit

Permalink
- useSDL_gfx rotate in target_exact missiles
Browse files Browse the repository at this point in the history
- fixes #76, #71 and #55
  • Loading branch information
protoman committed Dec 9, 2017
1 parent c373500 commit 5d9ae1f
Show file tree
Hide file tree
Showing 12 changed files with 105 additions and 21 deletions.
4 changes: 2 additions & 2 deletions Rockbot.pro
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ QT -= gui



#CONFIG += linux
CONFIG += android
CONFIG += linux
#CONFIG += android
#CONFIG += win32
#CONFIG += playstation2
#CONFIG += dingux
Expand Down
Binary file modified build/games/Rockbot1/data/game_projectile_list_v3.dat
Binary file not shown.
Binary file modified build/games/Rockbot1/game_ai_list.dat
Binary file not shown.
Binary file modified build/games/Rockbot1/game_enemy_list_3_1_1.dat
Binary file not shown.
Binary file modified build/games/Rockbot1/map_npc_data.dat
Binary file not shown.
2 changes: 1 addition & 1 deletion character/artificial_inteligence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1129,7 +1129,7 @@ bool artificial_inteligence::throw_projectile(int projectile_type, bool invert_d
}
if (projectile_list.size() >= max_shots) {
_ai_state.sub_status = IA_ACTION_STATE_FINISHED;
std::cout << "AI::SHOT::LEAVE #2, shots[" << projectile_list.size() << "], max_shots[" << max_shots << "]" << std::endl;
//std::cout << "AI::SHOT::LEAVE #2, shots[" << projectile_list.size() << "], max_shots[" << max_shots << "]" << std::endl;
return false;
}

Expand Down
2 changes: 2 additions & 0 deletions file/format/st_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,8 @@ struct graphicsLib_gSurface {
}
if (surface != NULL) {
gSurface = surface;
width = gSurface->w;
height = gSurface->h;
} else {
gSurface = NULL;
}
Expand Down
67 changes: 54 additions & 13 deletions graphicslib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2123,12 +2123,10 @@ void graphicsLib::place_water_tile(st_position dest)
}
}

void graphicsLib::zoom_image(graphicsLib_gSurface picture, int smooth)
// zoom from a small size to the picture size
void graphicsLib::zoom_image(st_position dest, graphicsLib_gSurface picture, int smooth)
{
SDL_Surface *rotozoom_picture;
SDL_Rect dest;
int framecount, framemax, frameinc;
float zoomxf,zoomyf;

/*
// Zoom and display the picture
Expand Down Expand Up @@ -2164,21 +2162,64 @@ void graphicsLib::zoom_image(graphicsLib_gSurface picture, int smooth)
updateScreen();
}
*/
for (float i=0.1; i<1.0; i+=0.1) {
if ((rotozoom_picture = zoomSurface(picture.get_surface(), i, i, smooth))!=NULL) {
if (SDL_BlitSurface(rotozoom_picture, NULL, gameScreen.get_surface(), &dest) < 0 ) {
fprintf(stderr, "Blit failed: %s\n", SDL_GetError());
break;
}
timer.delay(100);
st_position center(dest.x+picture.width/2, dest.y+picture.height/2);
std::cout << ">>>>>>>>>>> dest[" << dest.x << "][" << dest.y << "]" << std::endl;
std::cout << "center[" << center.x << "][" << center.y << "]" << std::endl;

for (float i=0.1; i<1.0; i+=0.03) {
if ((rotozoom_picture = zoomSurface(picture.get_surface(), i, i, smooth)) != NULL) {
//double angle = 360*i;
//if ((rotozoom_picture = rotozoomSurface(picture.get_surface(), angle, 1.0, smooth)) != NULL) {
std::cout << "GRAPHLIB::ZOOM #1 [" << i << "]" << std::endl;
struct st_rectangle origin_rectangle(0, 0, rotozoom_picture->w, rotozoom_picture->h);

st_position dest_zoom(center.x-rotozoom_picture->w/2, center.y-rotozoom_picture->h/2);
std::cout << "rotozoom_picture[" << rotozoom_picture->w << "][" << rotozoom_picture->h << "]" << std::endl;
std::cout << "dest_zoom[" << dest_zoom.x << "][" << dest_zoom.y << "]" << std::endl;

// clear area
clear_area(dest_zoom.x, dest_zoom.y, rotozoom_picture->w, rotozoom_picture->h, CONFIG_BGCOLOR_R, CONFIG_BGCOLOR_G, CONFIG_BGCOLOR_B);


copySDLArea(origin_rectangle, dest_zoom, rotozoom_picture, game_screen, false);
updateScreen();
clear_area(dest.x, dest.y, rotozoom_picture->w, rotozoom_picture->h, CONFIG_BGCOLOR_R, CONFIG_BGCOLOR_G, CONFIG_BGCOLOR_B);
timer.delay(20);
SDL_FreeSurface(rotozoom_picture);
} else {
std::cout << "Error creating zoomed surface" << std::endl;
}
}

/* Pause for a sec */
SDL_Delay(1000);
SDL_Delay(100);
}

void graphicsLib::rotate_image(graphicsLib_gSurface &picture, double angle)
{
SDL_Surface *rotozoom_picture;

SDL_Surface *alpha_surface = SDL_DisplayFormatAlpha(picture.get_surface());

if ((rotozoom_picture = rotozoomSurface(alpha_surface, angle, 1.0, true)) != NULL) {
SDL_Surface *res_surface = SDL_DisplayFormatAlpha(rotozoom_picture);
SDL_FreeSurface(rotozoom_picture);
SDL_SetColorKey(res_surface, SDL_SRCCOLORKEY, SDL_MapRGB(game_screen->format, COLORKEY_R, COLORKEY_G, COLORKEY_B));
picture.set_surface(res_surface);
//std::cout << "GRAPHLIB::rotate_image - #3: rotozoom_picture w[" << picture.width << "], h[" << picture.height << "]" << std::endl;
} else {
std::cout << "GRAPHLIB::rotate_image - Error generating rotated image" << std::endl;
}
SDL_FreeSurface(alpha_surface);
}

void graphicsLib::rotated_from_image(graphicsLib_gSurface *picture, graphicsLib_gSurface &dest, double angle)
{
SDL_Surface *rotozoom_picture;
if ((rotozoom_picture = rotozoomSurface(picture->get_surface(), angle, 1.0, true)) != NULL) {
dest.set_surface(rotozoom_picture);
} else {
std::cout << "GRAPHLIB::rotate_image - Error generating rotated image" << std::endl;
}
}

#ifdef PSP
Expand Down
4 changes: 3 additions & 1 deletion graphicslib.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,9 @@ class graphicsLib
void psp_show_available_ram(int n);
#endif

void zoom_image(graphicsLib_gSurface picture, int smooth);
void zoom_image(st_position dest, graphicsLib_gSurface picture, int smooth);
void rotate_image(graphicsLib_gSurface& picture, double angle);
void rotated_from_image(graphicsLib_gSurface *picture, graphicsLib_gSurface& dest, double angle);

private:
void copySDLArea(struct st_rectangle, struct st_position, SDL_Surface*, SDL_Surface*, bool fix_colors);
Expand Down
36 changes: 36 additions & 0 deletions projectilelib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,39 @@ void projectile::set_target_position(st_float_position *pos)
set_direction_from_targetpos(TILESIZE/2);


graphLib.initSurface(st_size(_size.width, _size.height), &rotated_surface);
int temp_direction = direction;
direction = ANIM_DIRECTION_LEFT;
graphLib.copyArea(st_rectangle(0, 0, _size.width, _size.height), st_position(0, 0), get_surface(), &rotated_surface);
direction = temp_direction;


// calculate angle and set image
angle = atan2(abs(dist_y), abs(dist_x));
angle = (360*angle)/6.28;
std::cout << ">>>>>>>>>>>>> ANGLE[" << angle << "], w[" << get_surface()->width << "]" << std::endl;
//angle = 55;
// TODO: generate an image from the region, not the whole picture
// TARGET to the LEFT
if (dist_x < 0) {
if (dist_y < 0) {
angle *= -1;
}
// if target is to the left, we need to "flip" image
// TARGET to the RIGHT
} else {
angle += 180;
if (dist_y > 0) {
angle *= -1;
}
}

std::cout << "### AJUDSTED-ANGLE[" << angle << "],dist_y[" << dist_y << "]" << std::endl;
if (angle != 0.0) {
graphLib.rotate_image(rotated_surface, angle);
}


} else if (_target_position != NULL && _move_type == TRAJECTORY_ARC_TO_TARGET) {
_trajectory_parabola = trajectory_parabola(_target_position->x - position.x);
position0.y = position.y;
Expand Down Expand Up @@ -907,6 +940,9 @@ void projectile::draw() {
// point
graphLib.showSurfaceRegionAt(get_surface(), st_rectangle(anim_pos+frame_w*2, 0, frame_w, _size.height), st_position(realPosition.x + (frame_w + frame_w*status), realPosition.y));

} else if (_move_type == TRAJECTORY_TARGET_EXACT) {
//std::cout << "TRAJECTORY_TARGET_EXACT - w[" << rotated_surface.width << "], h[" << rotated_surface.height << "]" << std::endl;
graphLib.showSurfaceAt(&rotated_surface, realPosition, false);
} else {
//printf(">> PROJECTILE::DRAW[%d] - direction[%d], show_width[%d], _size.height[%d], anim_pos[%d], img.w[%d], img.h[%d] <<\n", _id, direction, show_width, _size.height, anim_pos, get_surface()->width, get_surface()->height);
if (direction == ANIM_DIRECTION_UP && get_surface()->height >= _size.height*2) {
Expand Down
5 changes: 4 additions & 1 deletion projectilelib.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class projectile

bool diagonal_flag; // used to control diagonal shot angle
Uint8 _max_frames; // number of frames for the projectile
float angle;
double angle;
short int radius;

// used for quake effect
Expand Down Expand Up @@ -151,5 +151,8 @@ class projectile
character* owner;
short frame_w;

// used for rotated images
graphicsLib_gSurface rotated_surface;

};
#endif // PROJECTILELIB_H
6 changes: 3 additions & 3 deletions sceneslib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ void scenesLib::draw_main()
std::string intro_path = FILEPATH + "/images/logo.png";
graphLib.surfaceFromFile(intro_path, &intro_screen);
//graphLib.copyArea(st_position(-graphLib.RES_DIFF_W, -graphLib.RES_DIFF_H+20), &intro_screen, &graphLib.gameScreen);
//graphLib.zoom_image(intro_screen, false);
gfx_sin_wave gfx_wave_obj(&intro_screen);
gfx_wave_obj.show(-graphLib.RES_DIFF_W, -graphLib.RES_DIFF_H+20);
graphLib.zoom_image(st_position(-graphLib.RES_DIFF_W, -graphLib.RES_DIFF_H+20), intro_screen, false);
//gfx_sin_wave gfx_wave_obj(&intro_screen);
//gfx_wave_obj.show(-graphLib.RES_DIFF_W, -graphLib.RES_DIFF_H+20);


graphLib.draw_text(8, 8, VERSION_NUMBER);
Expand Down

0 comments on commit 5d9ae1f

Please sign in to comment.