From 1fcb480ed59b6a1646b7fa5170b33b9bcaa47a0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Gia=20Phong?= Date: Sat, 24 Jul 2021 16:41:17 +0700 Subject: Refactor parts gdb points to when crashed Zig and gdb don't seem to play well with each other. --- src/GameTick.cpp | 83 ++++++++++++++++++++------------------------------------ 1 file changed, 29 insertions(+), 54 deletions(-) (limited to 'src/GameTick.cpp') diff --git a/src/GameTick.cpp b/src/GameTick.cpp index f3ca51a..b7d0d64 100644 --- a/src/GameTick.cpp +++ b/src/GameTick.cpp @@ -25,8 +25,6 @@ extern int psychicaimkey; extern int psychickey; extern Decals decals; -/********************> Tick() <*****/ - #define maxfallvel 40 void Game::Splat(int k){ @@ -59,43 +57,25 @@ void Game::Splat(int k){ } } -void Game::Tick(){ - if(mainmenu){ - - unsigned char theKeyMap[16]; - - GetKeys( ( unsigned long * )theKeyMap ); - - if(IsKeyDown(theKeyMap, MAC_SPACE_KEY)){ - - mainmenu=0; - - } +void Game::Tick() +{ + if (mainmenu) { + unsigned char theKeyMap[16]; + GetKeys((unsigned long*) theKeyMap); + if (IsKeyDown(theKeyMap, MAC_SPACE_KEY)) + mainmenu = 0; GetMouse(&mouseloc); - - float mousex=mouseloc.h; - - float mousey=mouseloc.v; - - mousex=(float)mouseloc.h*640/screenwidth; - - mousey=480-(float)mouseloc.v*480/screenheight; - - oldmouseoverbutton=mouseoverbutton; - - mouseoverbutton=0; - - if(mousex>120&&mousex<560&&mousey>235&&mousey<305){ - - mouseoverbutton=1; - - } - - if(mousex>120&&mousex<560&&mousey>112&&mousey<182){ - - mouseoverbutton=2; - + float mousex = (float) mouseloc.h * 640 / screenwidth; + float mousey = 480 - (float) mouseloc.v * 480 / screenheight; + + oldmouseoverbutton = mouseoverbutton; + mouseoverbutton = 0; + if (mousex > 120 && mousex < 560) { + if (mousey > 235 && mousey < 305) + mouseoverbutton = 1; + else if (mousey > 112 && mousey < 182) + mouseoverbutton = 2; } if((Button()&&mouseoverbutton==1&&!gameinprogress&&!oldbutton)||!mainmenuness){ @@ -878,25 +858,20 @@ void Game::Tick(){ camera.targetoffset=0; camera.targetoffset.z=-5; - //Spawn people - spawndelay-=multiplier; - int blockspawnx,blockspawny; - blockspawnx=0; - blockspawny=0; - - int cyclenum; - cyclenum=0; - - while((citypeoplenum[blockspawnx][blockspawny]>=max_people_block&&cyclenum<10)||blockspawnx==0){ - - blockspawnx=((person[0].playercoords.x+block_spacing/2)/block_spacing)+Random()%2; + // Spawn people + int cyclenum = 0; + int blockspawnx = 0, blockspawny = 0; + do { + auto block = person[0].playercoords / block_spacing; + blockspawnx = block.x + 0.5f + Random() % 2; + blockspawny = block.z + 0.5f + Random() % 2; - blockspawny=((person[0].playercoords.z+block_spacing/2)/block_spacing)+Random()%2; - - cyclenum++; - - } + auto& people = citypeoplenum[blockspawnx][blockspawny]; + if (people < max_people_block) + break; + } while (++cyclenum < 10); + spawndelay -= multiplier; if(cyclenum<10){ if(spawndelay<0&&numpeople