Something went wrong. Try again.
A very rough prototype kag tutorial rework
Something went wrong. Try again.
kag_tutorial TutorialMain.as
4.0 kB · 187 lines
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187////////////////////////////////////////// Tutorial main
/// This is mostly a TEST script/// This just lets us load in and some other stuff/// Will revisit when it comes time to actually making a tutorial
// TEMPbool wasClicking = false;Vec2f lastMousePos = Vec2f(0,0);bool mousePressed = false;// END
void onInit(CRules@ this){ if (!this.exists("default class")) { this.set_string("default class", "knight"); }
onRestart(this);
// TEMP, PUT IN DIFFERENT FILE AddColorToken("$T_D$", color_white); AddColorToken("$T_0$", SColor(255, 25, 140, 255)); AddColorToken("$green$", SColor(255, 100, 255, 100));
GUI::LoadFont("pixeled", CFileMatcher("uni0553.ttf").getFirst(), 26, true);}
void onRestart(CRules@ this){ getMap().RemoveAllSectors();
RegisterFileExtensionScript("Scripts/MapLoaders/LoadPNGMap.as", "png"); AddMapScripts();
RespawnAll(this);}
void RespawnAll(CRules@ this){ for (int a = 0; a < getPlayerCount(); a++) { CPlayer@ player = getPlayer(a); if (player !is null) onPlayerRequestSpawn(this, player); }}
void AddMapScripts(){ string[] name = getMap().getMapName().split('/'); string mapName = name[name.length() - 1]; mapName = mapName.substr(0,mapName.length() - 4);
if (CFileMatcher(mapName).hasMatch()) getMap().AddScript(mapName);
if (CFileMatcher(mapName + "_rules").hasMatch()) getRules().AddScript(mapName + "_rules");}
void onNewPlayerJoin( CRules@ this, CPlayer@ player ){ player.server_setTeamNum(0);}
void onPlayerRequestSpawn(CRules@ this, CPlayer@ player){ Respawn(this, player);}
CBlob@ Respawn(CRules@ this, CPlayer@ player){ if (player !is null) { // remove previous players blob CBlob @blob = player.getBlob();
if (blob !is null) { CBlob @blob = player.getBlob(); blob.server_SetPlayer(null); blob.server_Die(); }
CBlob @newBlob = server_CreateBlob(this.get_string("default class"), 0, getSpawnLocation(player)); newBlob.server_SetPlayer(player); return newBlob; }
return null;}
Vec2f getSpawnLocation(CPlayer@ player){ CMap@ map = getMap(); if (player is null || map is null) { return Vec2f(0,0); } Vec2f[] spawns;
switch (player.getTeamNum()) { case 0: { if (!map.getMarkers("blue spawn", spawns) && !map.getMarkers("blue main spawn", spawns)) { return Vec2f_zero; }
return spawns[XORRandom(spawns.length)]; } }
return Vec2f(0, 0);}
void onTick(CRules@ this){ // TODO: DISABLE BOXES AND OTHER JUNK THAT WE DONT NEED FOR NOW if (g_debug != 0) { }}
void onRender(CRules@ this){ CBlob@ b = getLocalPlayerBlob(); CControls@ c = getControls(); if (g_debug == 0 || b is null || c is null) { return; } GUI::DrawText(getDriver().getWorldPosFromScreenPos(c.getInterpMouseScreenPos()) + "", Vec2f(20,25), SColor(255,255,255,255));
mousePressed = c.mousePressed1; Vec2f currentPos = getDriver().getWorldPosFromScreenPos(c.getInterpMouseScreenPos()); if (mousePressed && !wasClicking) { lastMousePos = currentPos; }
RenderSquare(currentPos);
wasClicking = mousePressed;}
void RenderSquare(Vec2f currentPos){ Vec2f topLeft = lastMousePos; Vec2f botRight = currentPos;
if (botRight.x < topLeft.x) { float temp = botRight.x; botRight.x = topLeft.x; topLeft.x = temp;
if (botRight.y < topLeft.y) { temp = botRight.y; botRight.y = topLeft.y; topLeft.y = temp; } } else if (topLeft.y > botRight.y) { float temp = topLeft.y; topLeft.y = botRight.y; botRight.y = temp; } if (mousePressed) { GUI::DrawPane(getDriver().getScreenPosFromWorldPos(topLeft), getDriver().getScreenPosFromWorldPos(botRight), SColor(150, 0, 0, 0)); }
if (wasClicking && !mousePressed) { print("\nSector pos:\nVec2f" + topLeft +"\nVec2f" + botRight, SColor(255, 255, 100, 255)); }}