728x90
여태 까지 Prinny 라는 클래스로 화면을 띄웟다면 이제는 상속 받아서 추가 기능들을 연습 해볼 예정으로
전 게시글에 올렸던 Keyboard 연장선 으로 생각 하면 된다.
Move.cpp
더보기
#include "stdafx.h"
#include "Move.h"
Move::Move(Vector2 position, Vector2 scale)
:Prinny(position, scale)
{
}
Move::~Move()
{
}
void Move::Update(Matrix& V, Matrix& P)
{
Vector2 position = animation->Position();
if (Key->Press('D'))
{
moveSpeed += 300.0f * Time::Delta();
animation->RotationDegree(0, 0, 0);
}
else if (Key->Press('A'))
{
moveSpeed -= 300.0f * Time::Delta() ;
animation->RotationDegree(0, 180, 0);
}
if (moveSpeed >= 300.0f)
moveSpeed = 300.0f;
//속도 초기화 (수정 필요)
if (Key->Up('D') || Key->Up('A'))
moveSpeed = 0.0f;
//x축 이동
position.x += moveSpeed * Time::Delta();
animation->Play((UINT)state);
animation->Position(position);
animation->Update(V, P);
}
Move. h
더보기
#pragma once
#include "Prinny.h"
class Move : public Prinny
{
public:
Move(Vector2 position, Vector2 scale);
~Move();
void Update(Matrix& V, Matrix& P) override;
private:
};
수정
Prinny.h
더보기
#pragma once
#include "Viewer/IFollowing.h"
enum class PState
{
Idle = 0, Walk
};
class Prinny : public IFollowing
{
public:
Prinny(Vector2 position, Vector2 scale);
~Prinny();
virtual void Update(Matrix& V, Matrix& P);
void Render();
//크기
void Position(float x, float y){Position(Vector2(x, y));}
void Position(Vector2 & position){animation->Position(position);}
Vector2 Position(){ return animation->Position();}
//위치
void Scale(float x, float y) { Scale(Vector2(x, y)); }
void Scale(Vector2 & vec) { animation->Scale(vec); }
Vector2 Scale() { return animation->Scale(); }
//실제 크기값
Vector2 ScaledSize();
//World 값 가져오기
Sprite* GetSprite();
private:
// IFollwing을(를) 통해 상속됨 카메라 값
void Focus(Vector2 * position, Vector2 * size) override;
private:
Vector2 position;
Vector2 scale;
Vector3 rotation;
protected:
Animation* animation;
PState state;
float moveSpeed;
//Vector2 focusOffset = Vector2(0.0f, 200.0f); //카메라 시야값
};
그림으로 약간 쉽게 생각하면
Prinny class는 이미지 모션 추가, Rander 기본 변수값 이외 공통으로 쓰는 변수들만 선언 하는곳으로
이제 상속받은 class 들은 Update 관련만 새로 작성해서 사용 하기만 하면 된다
'DirectX > DirectX 2D_(구)' 카테고리의 다른 글
DX_Collider [1 / 3] (0) | 2021.01.18 |
---|---|
DX_카메라 시점변환 (0) | 2021.01.05 |
DX_Keyboard (0) | 2020.12.21 |
DX_DirectWrite (0) | 2020.11.24 |
DX_카메라 (고정, 자유) (0) | 2020.11.18 |