Directional facing movement

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
master
sigonasr2 2 years ago
parent c830002446
commit bf5b85951c
  1. BIN
      MeercaChase
  2. 32
      MeercaChase.cpp
  3. 2
      MeercaChase.js
  4. BIN
      MeercaChase.wasm

Binary file not shown.

@ -1,5 +1,6 @@
#define OLC_PGE_APPLICATION
#include "pixelGameEngine.h"
#include <math.h>
using namespace std;
@ -12,6 +13,7 @@ public:
float accumulatedTime = 0.0f;
int frameCount=0;
int moveSpd=4;
float meercaSpd[2] = {0,0};
float meercaPos[2] = {240,240};
MeercaChase()
{
@ -34,13 +36,41 @@ public:
accumulatedTime+=fElapsedTime;
while (accumulatedTime>=UPDATE_RATE) {
accumulatedTime-=UPDATE_RATE;
meercaPos[0]+=meercaSpd[0];
meercaPos[1]+=meercaSpd[1];
updateGame();
}
if (GetKey(olc::F1).bPressed) {
ConsoleShow(olc::F1,false);
}
if (GetKey(olc::W).bPressed) {
meercaSpd[0]=0;
meercaSpd[1]=-moveSpd;
}
if (GetKey(olc::A).bPressed) {
meercaSpd[0]=-moveSpd;
meercaSpd[1]=0;
}
if (GetKey(olc::D).bPressed) {
meercaSpd[0]=moveSpd;
meercaSpd[1]=0;
}
if (GetKey(olc::S).bPressed) {
meercaSpd[0]=0;
meercaSpd[1]=moveSpd;
}
// called once per frame
DrawDecal({meercaPos[0]-16,meercaPos[1]-16},meerca);
if (meercaSpd[0]==moveSpd) {
DrawRotatedDecal({meercaPos[0]-16,meercaPos[1]-16},meerca,M_PI_2,{16,16});
} else
if (meercaSpd[0]==-moveSpd) {
DrawRotatedDecal({meercaPos[0]-16,meercaPos[1]-16},meerca,M_PI_2*3,{16,16});
} else
if (meercaSpd[1]==moveSpd) {
DrawRotatedDecal({meercaPos[0]-16,meercaPos[1]-16},meerca,M_PI,{16,16});
} else {
DrawRotatedDecal({meercaPos[0]-16,meercaPos[1]-16},meerca,0,{16,16});
}
DrawDecal({32,64},negg,{1,1},olc::YELLOW);
return true;
}

File diff suppressed because one or more lines are too long

Binary file not shown.
Loading…
Cancel
Save