C++
#include <iostream> #include <vector> using namespace std; class BaseClass { public: BaseClass() {} ~BaseClass() {} virtual const string func() { return "Base class\n"; } }; class DerivedClass : public BaseClass { public: DerivedClass() {} ~DerivedClass() {} const string func() override { string s = BaseClass::func(); s += "Derived class\n"; return s; } }; int main(int argc, char** argv) { // For polymorphism to work, we need to store pointers vector<BaseClass*> objects; DerivedClass obj; objects.push_back(&obj); for (auto &o : objects) { cout << o->func().c_str(); } char in; cin >> in; return 0; }
2D Math snippets
public function MoveTowards(angle:Number):void { nx = x + Math.cos(angle * FP.RAD) * movespeed * FP.elapsed; ny = y + Math.sin(angle * FP.RAD) * movespeed * FP.elapsed; if (!CheckCollision(nx, ny)) { x = nx; y = ny; } }
public function GetAngleTo(x2:int, y2:int):Number { var deltaY:Number = y - y2; var deltaX:Number = x2 - x; return Math.atan2(deltaY, deltaX) * 180 / Math.PI; }
public function update():void { if(mouseover) { image.scale += (1.2 - image.scale) / 2; } else { image.scale += (1 - image.scale) / 2; } }
function updatePosition() { HXP.clampInRect(this, HXP.camera.x, HXP.camera.y, HXP.screen.width, HXP.screen.height, (width+height)); }