Collecting neggs is possible and random spawn positions.

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
master
sigonasr2 2 years ago
parent bf5b85951c
commit 431e7d89ca
  1. 2
      C++/scripts/md5
  2. 3
      C++/scripts/web.sh
  3. BIN
      MeercaChase
  4. 30
      MeercaChase.cpp
  5. 76
      MeercaChase.html
  6. BIN
      MeercaChase.wasm
  7. 75
      buildtemplate.html

@ -1,3 +1,3 @@
build.sh:530634457ea9041267c05d4ced95eee1 - build.sh:530634457ea9041267c05d4ced95eee1 -
commit.sh:d03a46e721060c22ccb146e19d27e70a - commit.sh:d03a46e721060c22ccb146e19d27e70a -
web.sh:3229cb0053cd0ca4ea08cc90e0d50ad0 - web.sh:241ce74055952325f82f009b494df250 -

@ -6,6 +6,9 @@ else
em++ -std=c++17 -O2 -s ALLOW_MEMORY_GROWTH=1 -s MAX_WEBGL_VERSION=2 -s MIN_WEBGL_VERSION=2 -s USE_LIBPNG=1 $(find . -type f -name "*.cpp") -o ${PROJECT_NAME}.html -I pixelGameEngine.h em++ -std=c++17 -O2 -s ALLOW_MEMORY_GROWTH=1 -s MAX_WEBGL_VERSION=2 -s MIN_WEBGL_VERSION=2 -s USE_LIBPNG=1 $(find . -type f -name "*.cpp") -o ${PROJECT_NAME}.html -I pixelGameEngine.h
fi fi
cp buildtemplate.html ${PROJECT_NAME}.html
sed -i "s/_REPLACEME_/$PROJECT_NAME.js/" ${PROJECT_NAME}.html
if [ "$1" == "headless" ]; then if [ "$1" == "headless" ]; then
echo "Running as headless web server" echo "Running as headless web server"
emrun --no_browser ${PROJECT_NAME}.html emrun --no_browser ${PROJECT_NAME}.html

Binary file not shown.

@ -10,14 +10,23 @@ public:
olc::Decal*meerca; olc::Decal*meerca;
olc::Decal*negg; olc::Decal*negg;
const float UPDATE_RATE = 0.016666667f; const float UPDATE_RATE = 0.016666667f;
const int NEGG_BOUNDARY=16;
float accumulatedTime = 0.0f; float accumulatedTime = 0.0f;
int frameCount=0; int frameCount=0;
int moveSpd=4; int moveSpd=4;
float meercaSpd[2] = {0,0}; float meercaSpd[2] = {0,0};
float meercaPos[2] = {240,240}; float meercaPos[2] = {0,0};
float neggPos[2] = {};
void assignNeggRandomPos() {
neggPos[0]=(float)rand()/RAND_MAX*(480-NEGG_BOUNDARY*2)+NEGG_BOUNDARY;
neggPos[1]=(float)rand()/RAND_MAX*(480-NEGG_BOUNDARY*2)+NEGG_BOUNDARY;
}
MeercaChase() MeercaChase()
{ {
sAppName = "Meerca Chase"; sAppName = "Meerca Chase";
srand(432189);
assignNeggRandomPos();
} }
bool OnUserCreate() override bool OnUserCreate() override
{ {
@ -36,9 +45,7 @@ public:
accumulatedTime+=fElapsedTime; accumulatedTime+=fElapsedTime;
while (accumulatedTime>=UPDATE_RATE) { while (accumulatedTime>=UPDATE_RATE) {
accumulatedTime-=UPDATE_RATE; accumulatedTime-=UPDATE_RATE;
meercaPos[0]+=meercaSpd[0]; updateGame(); //DO NOT ADD THINGS HERE. USE updateGame()!
meercaPos[1]+=meercaSpd[1];
updateGame();
} }
if (GetKey(olc::F1).bPressed) { if (GetKey(olc::F1).bPressed) {
ConsoleShow(olc::F1,false); ConsoleShow(olc::F1,false);
@ -61,22 +68,27 @@ public:
} }
// called once per frame // called once per frame
if (meercaSpd[0]==moveSpd) { if (meercaSpd[0]==moveSpd) {
DrawRotatedDecal({meercaPos[0]-16,meercaPos[1]-16},meerca,M_PI_2,{16,16}); DrawRotatedDecal({meercaPos[0],meercaPos[1]},meerca,M_PI_2,{16,16});
} else } else
if (meercaSpd[0]==-moveSpd) { if (meercaSpd[0]==-moveSpd) {
DrawRotatedDecal({meercaPos[0]-16,meercaPos[1]-16},meerca,M_PI_2*3,{16,16}); DrawRotatedDecal({meercaPos[0],meercaPos[1]},meerca,M_PI_2*3,{16,16});
} else } else
if (meercaSpd[1]==moveSpd) { if (meercaSpd[1]==moveSpd) {
DrawRotatedDecal({meercaPos[0]-16,meercaPos[1]-16},meerca,M_PI,{16,16}); DrawRotatedDecal({meercaPos[0],meercaPos[1]},meerca,M_PI,{16,16});
} else { } else {
DrawRotatedDecal({meercaPos[0]-16,meercaPos[1]-16},meerca,0,{16,16}); DrawRotatedDecal({meercaPos[0],meercaPos[1]},meerca,0,{16,16});
} }
DrawDecal({32,64},negg,{1,1},olc::YELLOW); DrawRotatedDecal({neggPos[0],neggPos[1]},negg,0,{16,16},{1.5,1.5},olc::YELLOW);
return true; return true;
} }
void updateGame() { void updateGame() {
meercaPos[0]+=meercaSpd[0];
meercaPos[1]+=meercaSpd[1];
if (abs(meercaPos[0]-neggPos[0])<8&&abs(meercaPos[1]-neggPos[1])<8) {
assignNeggRandomPos();
}
} }
}; };

File diff suppressed because one or more lines are too long

Binary file not shown.

@ -0,0 +1,75 @@
<!doctype html>
<html lang="en-us">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Emscripten-Generated Code</title>
<style>
html,body { width: 100%; height: 100%; }
body { font-family: arial; margin: 0; padding: 0; background: #000; }
.emscripten { padding-right: 0; margin-left: auto; margin-right: auto; display: block; }
div.emscripten_border { border: none; }
/* the canvas *must not* have any border or padding, or mouse coords will be wrong */
canvas.emscripten { border: 0px none; background-color: black; }
</style>
</head>
<body>
<canvas class="emscripten" id="canvas" oncontextmenu="event.preventDefault()" tabindex=-1></canvas>
<script type='text/javascript'>
var Module = {
preRun: [],
postRun: [],
canvas: (function() {
var canvas = document.getElementById('canvas');
// As a default initial behavior, pop up an alert when webgl context is lost. To make your
// application robust, you may want to override this behavior before shipping!
// See http://www.khronos.org/registry/webgl/specs/latest/1.0/#5.15.2
canvas.addEventListener("webglcontextlost", function(e) { alert('WebGL context lost. You will need to reload the page.'); e.preventDefault(); }, false);
return canvas;
})(),
};
</script>
<script async type="text/javascript" src="_REPLACEME_"></script>
<script type="text/javascript">
Module.canvas.addEventListener("resize", (e) => {
var viewWidth = e.detail.width;
var viewHeight = e.detail.width / Module._olc_WindowAspectRatio;
if(viewHeight > e.detail.height)
{
viewHeight = e.detail.height;
viewWidth = e.detail.height * Module._olc_WindowAspectRatio;
}
// update dom attributes
Module.canvas.setAttribute("width", viewWidth);
Module.canvas.setAttribute("height", viewHeight);
var top = (e.detail.height - viewHeight) / 2;
var left = (e.detail.width - viewWidth) / 2;
// update styles
Module.canvas.style.position = "fixed";
Module.canvas.style.top = top.toString() + "px";
Module.canvas.style.left = left.toString() + "px";
Module.canvas.style.width = "";
Module.canvas.style.height = "";
// trigger PGE update
Module._olc_PGE_UpdateWindowSize(viewWidth, viewHeight);
// ensure canvas has focus
Module.canvas.focus();
e.preventDefault();
});
</script>
</body>
</html>
Loading…
Cancel
Save