Add in Transformed View.
This commit is contained in:
parent
2a538d0aee
commit
2ec0daf59e
olcCodeJam2023Entry
@ -11,3 +11,6 @@ vf2d CONSTANT::UNSELECTED={-99,-99};
|
||||
|
||||
Renderable CONSTANT::VIRUS_IMG1;
|
||||
Renderable CONSTANT::SELECTION_CIRCLE;
|
||||
|
||||
vi2d CONSTANT::TILE_SIZE={24,24};
|
||||
vi2d CONSTANT::WORLD_SIZE={64,64};
|
@ -13,4 +13,7 @@ public:
|
||||
static vf2d UNSELECTED;
|
||||
|
||||
static Renderable VIRUS_IMG1,SELECTION_CIRCLE;
|
||||
|
||||
static vi2d TILE_SIZE;
|
||||
static vi2d WORLD_SIZE;
|
||||
};
|
@ -66,7 +66,14 @@ Unit::Unit(std::vector<Memory>memory,vf2d pos,Renderable&img,bool friendly)
|
||||
|
||||
|
||||
|
||||
void Unit::Draw(PixelGameEngine*pge){
|
||||
void Unit::Draw(TileTransformedView&game){
|
||||
game.DrawRotatedDecal(pos,img.Decal(),0,img.Sprite()->Size()/2,{1,1},friendly?Pixel{192,192,255}:Pixel{255,192,192});
|
||||
if(IsSelected()){
|
||||
game.DrawRotatedDecal(pos,CONSTANT::SELECTION_CIRCLE.Decal(),0,CONSTANT::SELECTION_CIRCLE.Sprite()->Size()/2,vf2d(img.Sprite()->Size())/CONSTANT::SELECTION_CIRCLE.Sprite()->Size(),WHITE);
|
||||
}
|
||||
}
|
||||
|
||||
void Unit::DrawHud(TileTransformedView&game){
|
||||
int initialBarX=pos.x-GetMemorySize()/2*CONSTANT::BAR_SQUARE_SIZE.x;
|
||||
int initialBarY=pos.y-CONSTANT::BAR_SQUARE_SIZE.y-img.Sprite()->height/2-2;
|
||||
Pixel col=0;
|
||||
@ -93,15 +100,11 @@ void Unit::Draw(PixelGameEngine*pge){
|
||||
for(int i=0;i<GetMemorySize();i++){
|
||||
CheckColor(i,col);
|
||||
|
||||
pge->FillRectDecal({float(initialBarX)+i*CONSTANT::BAR_SQUARE_SIZE.x,
|
||||
game.FillRectDecal({float(initialBarX)+i*CONSTANT::BAR_SQUARE_SIZE.x,
|
||||
float(initialBarY)},CONSTANT::BAR_SQUARE_SIZE,memory[i]?col:col/4);
|
||||
pge->DrawRectDecal({float(initialBarX)+i*CONSTANT::BAR_SQUARE_SIZE.x,
|
||||
game.DrawRectDecal({float(initialBarX)+i*CONSTANT::BAR_SQUARE_SIZE.x,
|
||||
float(initialBarY)},CONSTANT::BAR_SQUARE_SIZE,BLACK);
|
||||
}
|
||||
pge->DrawRotatedDecal(pos,img.Decal(),0,img.Sprite()->Size()/2,{1,1},friendly?Pixel{192,192,255}:Pixel{255,192,192});
|
||||
if(IsSelected()){
|
||||
pge->DrawRotatedDecal(pos,CONSTANT::SELECTION_CIRCLE.Decal(),0,CONSTANT::SELECTION_CIRCLE.Sprite()->Size()/2,vf2d(img.Sprite()->Size())/CONSTANT::SELECTION_CIRCLE.Sprite()->Size(),WHITE);
|
||||
}
|
||||
}
|
||||
|
||||
int Unit::GetBits(Marker&m){
|
||||
|
@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "olcPixelGameEngine.h"
|
||||
#include "olcPGEX_TransformedView.h"
|
||||
#include "Constant.h"
|
||||
|
||||
struct Marker{
|
||||
@ -33,7 +34,8 @@ public:
|
||||
std::vector<bool>memory;
|
||||
void Update(float fElapsedTime);
|
||||
virtual void Attack(Unit&victim)=0;
|
||||
virtual void Draw(PixelGameEngine*pge);
|
||||
virtual void Draw(TileTransformedView&game);
|
||||
virtual void DrawHud(TileTransformedView&game);
|
||||
bool IsFriendly();
|
||||
bool IsSelected();
|
||||
void Select();
|
||||
|
@ -2,8 +2,12 @@
|
||||
#include "olcPixelGameEngine.h"
|
||||
#define OLC_SOUNDWAVE
|
||||
#include "olcSoundWaveEngine.h"
|
||||
#include "VirusAttack.h"
|
||||
#define OLC_PGEX_TRANSFORMEDVIEW
|
||||
#include "olcPGEX_TransformedView.h"
|
||||
#include "olcUTIL_Geometry2D.h"
|
||||
#include "olcUTIL_Camera2D.h"
|
||||
|
||||
#include "VirusAttack.h"
|
||||
|
||||
VirusAttack::VirusAttack()
|
||||
{
|
||||
@ -12,10 +16,13 @@ VirusAttack::VirusAttack()
|
||||
}
|
||||
|
||||
bool VirusAttack::OnUserCreate(){
|
||||
game.Initialise(GetScreenSize());
|
||||
|
||||
CONSTANT::VIRUS_IMG1.Load("assets/unit.png");
|
||||
CONSTANT::SELECTION_CIRCLE.Load("assets/selection_circle.png");
|
||||
|
||||
TILE.Load("assets/tile.png",nullptr,false,false);
|
||||
|
||||
units.push_back(std::make_unique<BasicUnit>(vf2d{32,32},CONSTANT::VIRUS_IMG1,true));
|
||||
for(int i=0;i<10;i++){
|
||||
if(rand()%2==0){
|
||||
@ -33,11 +40,11 @@ void VirusAttack::HandleDraggingSelection(){
|
||||
u->Deselect();
|
||||
}
|
||||
if(startingDragPos==CONSTANT::UNSELECTED){
|
||||
startingDragPos=GetMousePos();
|
||||
startingDragPos=GetWorldMousePos();
|
||||
}
|
||||
}
|
||||
if(GetMouse(0).bReleased){
|
||||
vf2d endDragPos=GetMousePos();
|
||||
vf2d endDragPos=GetWorldMousePos();
|
||||
if(endDragPos.x<startingDragPos.x){std::swap(startingDragPos.x,endDragPos.x);}
|
||||
if(endDragPos.y<startingDragPos.y){std::swap(startingDragPos.y,endDragPos.y);}
|
||||
geom2d::rect<float> selectionRegion(startingDragPos,endDragPos-startingDragPos);
|
||||
@ -52,9 +59,13 @@ void VirusAttack::HandleDraggingSelection(){
|
||||
}
|
||||
}
|
||||
|
||||
vf2d VirusAttack::GetWorldMousePos(){
|
||||
return game.ScreenToWorld(GetMousePos());
|
||||
}
|
||||
|
||||
void VirusAttack::DrawSelectionRectangle(){
|
||||
if(startingDragPos!=CONSTANT::UNSELECTED){
|
||||
FillRectDecal(startingDragPos,GetMousePos()-startingDragPos,{255,255,0,128});
|
||||
game.FillRectDecal(startingDragPos,GetWorldMousePos()-startingDragPos,{255,255,0,128});
|
||||
}
|
||||
}
|
||||
|
||||
@ -64,7 +75,7 @@ void VirusAttack::HandleRightClickMove(){
|
||||
for(auto&u:units){
|
||||
if(!u->IsFriendly()){
|
||||
geom2d::rect<float> unitRegion(u->GetPos()-u->GetUnitSize()/2,u->GetUnitSize());
|
||||
if(geom2d::overlaps(unitRegion,GetMousePos())){
|
||||
if(geom2d::overlaps(unitRegion,GetWorldMousePos())){
|
||||
for(auto&u2:units){
|
||||
if(u2->IsFriendly()&&u2->IsSelected()){
|
||||
u2->SetTargetUnit(u);
|
||||
@ -78,7 +89,7 @@ void VirusAttack::HandleRightClickMove(){
|
||||
if(!selectedTarget){
|
||||
for(auto&u:units){
|
||||
if(u->IsFriendly()&&u->IsSelected()){
|
||||
u->SetTargetLocation(GetMousePos());
|
||||
u->SetTargetLocation(GetWorldMousePos());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -110,6 +121,8 @@ bool VirusAttack::OnUserUpdate(float fElapsedTime){
|
||||
HandleDraggingSelection();
|
||||
HandleRightClickMove();
|
||||
|
||||
game.HandlePanAndZoom();
|
||||
|
||||
for(auto&u:units){
|
||||
Unit*closestUnit=nullptr;
|
||||
float closestDist=999999;
|
||||
@ -120,9 +133,13 @@ bool VirusAttack::OnUserUpdate(float fElapsedTime){
|
||||
u->AttemptAttack(closestUnit);
|
||||
u->Update(fElapsedTime);
|
||||
}
|
||||
game.DrawPartialDecal({0,0},CONSTANT::WORLD_SIZE*CONSTANT::TILE_SIZE,TILE.Decal(),{0,0},CONSTANT::WORLD_SIZE*CONSTANT::TILE_SIZE,DARK_GREEN);
|
||||
|
||||
for(auto&u:units){
|
||||
u->Draw(this);
|
||||
u->Draw(game);
|
||||
}
|
||||
for(auto&u:units){
|
||||
u->DrawHud(game);
|
||||
}
|
||||
|
||||
DrawSelectionRectangle();
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include "olcPixelGameEngine.h"
|
||||
#include "olcSoundWaveEngine.h"
|
||||
#include "olcPGEX_TransformedView.h"
|
||||
#include "Unit.h"
|
||||
#include "Constant.h"
|
||||
class VirusAttack : public olc::PixelGameEngine
|
||||
@ -7,12 +8,19 @@ class VirusAttack : public olc::PixelGameEngine
|
||||
private:
|
||||
std::vector<std::shared_ptr<Unit>>units;
|
||||
|
||||
Renderable TILE;
|
||||
|
||||
vf2d camera={213,160};
|
||||
|
||||
TileTransformedView game;
|
||||
|
||||
vf2d startingDragPos=CONSTANT::UNSELECTED;
|
||||
void HandleDraggingSelection();
|
||||
void DrawSelectionRectangle();
|
||||
void HandleRightClickMove();
|
||||
void CollisionChecking(std::shared_ptr<Unit>u,std::shared_ptr<Unit>u2);
|
||||
void IdentifyClosestTarget(Unit*&closestUnit,float&closestDist,std::shared_ptr<Unit>u,std::shared_ptr<Unit>u2);
|
||||
vf2d GetWorldMousePos();
|
||||
|
||||
public:
|
||||
VirusAttack();
|
||||
|
BIN
olcCodeJam2023Entry/assets/tile.png
Normal file
BIN
olcCodeJam2023Entry/assets/tile.png
Normal file
Binary file not shown.
After ![]() (image error) Size: 1.3 KiB |
@ -82,8 +82,6 @@
|
||||
|
||||
#include "olcPixelGameEngine.h"
|
||||
|
||||
|
||||
|
||||
namespace olc
|
||||
{
|
||||
class TransformedView : public olc::PGEX
|
||||
|
Loading…
x
Reference in New Issue
Block a user