Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- canvasId="gameCanvas";
- //System Events
- function eventStart()
- {
- backgroundColor = "black";
- setGameSpeed(30);
- spriteAdd("player", "assets/img/player.png");
- objectAdd("player", "player", 17, 17, 0);
- objectAdd("block1", "none", 0, 0, 0);
- objectAdd("block2", "none", 0, 0, 0);
- keyAdd("up", 38);
- keyAdd("down", 40);
- keyAdd("left", 37);
- keyAdd("right", 39);
- instanceAdd(320, 240, "player");
- instanceAdd(96, 96, "block1");
- instanceAdd(128, 96, "block1");
- instanceAdd(96, 128, "block1");
- instanceAdd(512, 96, "block2");
- instanceAdd(480, 96, "block2");
- instanceAdd(512, 128, "block2");
- }
- function eventStep()
- {
- }
- function eventDraw()
- {
- }
- //Object Events
- function objectEventCreate(instance)
- {
- var objectType=instances[instance].name;
- var i=instance;
- var inst=instances[i];
- if (objectType == "player")
- {
- hitboxSet(i, 31, 31, 16, 16, "player");
- }
- if (objectType == "block1" || objectType == "block2")
- {
- hitboxSet(i, 32, 32, 16, 16, "block");
- }
- }
- function objectEventStep(instance)
- {
- var objectType=instances[instance].name;
- var i=instance;
- var inst=instances[i];
- if (objectType == "player")
- {
- var xx = keyCheck("right")-keyCheck("left");
- var yy = keyCheck("down")-keyCheck("up");
- var speed = 12;
- var dir = pointDirection(0, 0, xx, yy, -1);
- if (dir != -1)
- {
- xx = lengthDirX(speed, dir);
- yy = lengthDirY(speed, dir);
- }
- if (xx != 0)
- {
- inst.xprevious = inst.x;
- inst.x += xx;
- var col = hitboxCollide(i, "block");
- if (col != -1)
- {
- if (xx < 0)
- {
- inst.x = instances[col].x + 49;
- }
- else
- {
- inst.x = instances[col].x - 16;
- }
- }
- }
- if (yy != 0)
- {
- inst.yprevious = inst.y;
- inst.y += yy;
- var col = hitboxCollide(i, "block");
- if (col != -1)
- {
- if (yy < 0)
- {
- inst.y = instances[col].y + 49;
- }
- else
- {
- inst.y = instances[col].y - 16;
- }
- }
- }
- if (inst.x < inst.xoffset)
- {
- inst.x = inst.xoffset;
- }
- if (inst.x > c.width - inst.xoffset)
- {
- inst.x = c.width - inst.xoffset;
- }
- if (inst.y < inst.yoffset)
- {
- inst.y = inst.yoffset;
- }
- if (inst.y > c.height - inst.yoffset)
- {
- inst.y = c.height - inst.yoffset;
- }
- }
- }
- function objectEventDraw(instance)
- {
- var objectType=instances[instance].name;
- var i=instance;
- var inst=instances[i];
- if (objectType == "block1")
- {
- cxt.fillStyle = "white";
- fillRect(inst.x, inst.y, inst.x + 32, inst.y + 32);
- }
- if (objectType == "block2")
- {
- cxt.strokeStyle = "white";
- strokeRect(inst.x, inst.y, inst.x + 32, inst.y + 32);
- }
- }
- //Particles Events
- function particleEventDraw(particle)
- {
- var particleType=particles[particle].type;
- var i=particle;
- var part=particles[i];
- }
- //Custom Functions
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement