Umm... serverside code for this Sid? Terrible, and CBK might be complicating things too much.
Logical steps people
Things we need to do:
- Init things
- timeout start
- Spawn a spike?
--- Random check for spike
--- Check to see if the spawning rate should change
- update spike positions
- check for player collisions
--- do what happens when player collides.
- timeout
PHP Code:
//#CLIENTSIDE
// ================ Events ===================
function onCreated() {
init();
onTimeout();
}
//====================
function onTimeout() {
if(checkSpawnSpike(this.spawnRate)) {
this.spikes.add(spawnSpike());
}
for (temp.s: this.spikes) {
temp.s.updateSpikePos();
if(temp.s.checkPlayerCollision()) {
doPlayerDamage();
}
}
setTimer(.05);
}
// ============= ! End Events ====================
// ========== User Defined Functions ===============
function init() {
// init values here
// for example: the starting rate of spikes
}
//=====================
function checkSpawnRate() {
// return true if should spawn a spike
// false is not
// (maybe use random? :D)
}
//=======================
function spawnSpike() {
// Return an object with the spike's properties & functions
// Functions include
// updateSpikePos()
// - change the spike's coordinates
// - change where the spike visually is.
// checkPlayerCollision()
// - most likely a check to see if an isosceles triangle (spike)
// is colliding with a rectangle (player)
// return true if is and false otherwise
}
//====================
function doPlayerDamage() {
// What happens when a player actually gets hit.
}
// ========== ! User Defined Functions =============