Skip to content

Commit

Permalink
0.18.1 run left
Browse files Browse the repository at this point in the history
running left and animation canceling added
  • Loading branch information
jalowe13 committed Mar 30, 2023
1 parent 34d8313 commit 0abe1d1
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 9 deletions.
2 changes: 1 addition & 1 deletion TheOneSDL/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class Application
//Constants for reference


const char* windowTitle = "C23 Engine: The One SDL v.0.17 FPS:";
const char* windowTitle = "C23 Engine: The One SDL v.0.18.1 FPS:";

int textureWidth = 1920;
int textureHeight = 32;
Expand Down
30 changes: 22 additions & 8 deletions TheOneSDL/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ Player::Player(SDL_Renderer* renderer)
// Test 2
filename = idle_file2.c_str();
texture2 = IMG_LoadTexture(renderer, filename);
SDL_QueryTexture(default_texture, NULL, NULL, &textureWidth, &textureHeight);
SDL_QueryTexture(texture2, NULL, NULL, &textureWidth, &textureHeight);

// Load Run Left
filename = run_left_file.c_str();
run_left = IMG_LoadTexture(renderer, filename);
SDL_QueryTexture(run_left, NULL, NULL, &textureWidth, &textureHeight);

editMS(2);
setTexture(texture);
Expand Down Expand Up @@ -80,7 +85,7 @@ SDL_Texture* Player::getTexture()

void Player::updateTexture(Physics* phys_eng, Terrain* terrain_eng)
{
std::cout << "[Type,F,TEX_X,X,Y]" << idle_file << "," << frame_time << "," << getTexX() << std::endl;
std::cout << "[Frame]" << frame_time << std::endl;
// << "," << getX() << "," << getY() << std::endl;

xTexEdit(getTexX() + frameWidth);
Expand Down Expand Up @@ -134,7 +139,6 @@ void Player::yPathEdit(MovementDirection path)
void Player::xEdit(int x)
{
playerR.x = x;
setTexture(texture2);
}

void Player::yEdit(int y)
Expand Down Expand Up @@ -201,6 +205,12 @@ void Player::handleMovement(Physics* phys_eng, Terrain* terrain_eng, bool animat
{
case Left:
{
std::cout << "Left\n";
if (!inAnimation)
{
setTexture(run_left);
inAnimation = true;
}
xEdit(getX() - getSpeed());
terrain_eng->background_tilemap[tilemap_y][tilemap_x] = '~';
tilemap_x = round(getX()/32);
Expand All @@ -210,30 +220,34 @@ void Player::handleMovement(Physics* phys_eng, Terrain* terrain_eng, bool animat
}
case Right:
{
std::cout << "Right\n";
setTexture(texture);
xEdit(getX() + getSpeed());
terrain_eng->background_tilemap[tilemap_y][tilemap_x] = '~';
tilemap_x = round(getX()/32);
tilemap_y = round(getY()/32);
terrain_eng->background_tilemap[tilemap_y][tilemap_x] = '1';
break;
}
default:
{
setTexture(texture);
inAnimation = false;
}
}
switch (yPath())
{
case Up:
{
setTexture(texture2);
std::cout << "Up\n";
yEdit(getY() - getSpeed());
terrain_eng->background_tilemap[tilemap_y][tilemap_x] = '~';
tilemap_x = round(getX()/32);
tilemap_y = round(getY()/32);
terrain_eng->background_tilemap[tilemap_y][tilemap_x] = '1';
break;
}
case None:
{
setTexture(texture);
}

// Case Down will be needed in future not currently
// If Case down is needed implement collision check
// case Down:
Expand Down
4 changes: 4 additions & 0 deletions TheOneSDL/Player.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,15 @@ class Player
std::string idle_file = "textures\\VGB\\idle\\vgb_idle-Sheet.png";
std::string idle_file2 = "VGB_Idle.png";

std::string run_left_file = "textures\\VGB\\run\\vgb_run_left-Sheet.png";

//Textures stored
SDL_Texture* texture = NULL;
SDL_Texture* texture2 = NULL;
SDL_Texture* run_left = NULL;

int frame_time;
bool inAnimation = false; // toggle to lock animation canceling


};
Expand Down
Binary file modified TheOneSDL/TheOne.exe
Binary file not shown.
Binary file modified TheOneSDL/textures/VGB/run/vgb_run.aseprite
Binary file not shown.
Binary file added TheOneSDL/textures/VGB/run/vgb_run_left-Sheet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0abe1d1

Please sign in to comment.