acetinski
05-04-2009, 12:19 AM
Hey guys, I'm new here and I'm making a zombie game for a school assessment. I look very forward to speaking with you guys regarding some issues and ideas for this game.
The game is a top down shooter, you move your player with the arrow keys, and zombies approach you, and when you meet them, you cannot run through them.
Eventually, I aim for the zombies to not be able to pass through eachother, so you eventually get swarmed (and it'll look much better if they haven't all merged into one super zombie...).
I have coded the Player movement system, the Zombie's movement system, and the Player's Hittests (see below) - yet I have come across some issues.
The player, depending on the order of the if statement (in the collision), has varied effectiveness with collisions - if I put the X-Axis detections first, it only works properly on this axis. Similar to if the Y-Axis is first.
The Zombies, when hitting the player, make him teleport away - due to the Player hit detections, and the way the Zombies moves - making them push him around.
Player Movement (in Player movie clip)
if (Key.isDown(Key.LEFT)){
this._x -= speed
_global.posq = {x: _x, y: _y}}
// _global.posq is used to allow the zombies to know the player's position
if (Key.isDown(Key.RIGHT)){
this._x += speed
_global.posq = {x: _x, y: _y}}
if (Key.isDown(Key.UP)){
this._y -= speed
_global.posq = {x: _x, y: _y}}
if (Key.isDown(Key.DOWN)){
this._y += speed
_global.posq = {x: _x, y: _y}}
Player Collision Detection (in Player movie clip)
for (i in _root.ZombieList){
if (this.hitTest(_root.ZombieList[i])){
PZomb = _root.ZombieList[i]
trace(PZomb)
if ((this._y + this._height >= PZomb._y) && (this._y <= PZomb._y)){
trace("Hit from top!")
this._y -= speed
_global.posq = {x: _x, y: _y}}
if ((this._y <= PZomb._y + PZomb._height) && (this._y >= PZomb._y)){
trace("Hit from bottom!")
this._y += speed
_global.posq = {x: _x, y: _y}}
if ((this._x <= PZomb._x + PZomb._width) && (this._x >= PZomb._x)) {
trace("Hit from right!")
this._x += speed
_global.posq = {x: _x, y: _y}}
if ((this._x + this._width >= PZomb._x) && (this._x <= PZomb._x )) {
trace("Hit from left!")
this._x -= speed
_global.posq = {x: _x, y: _y}}
Zombie Movement (in a movie clip, inside the main Zombie movie clip)
// Get distance.
var xdist:Number = Math.pow((_parent._x - posq.x), 2)
var ydist:Number = Math.pow((_parent._y - posq.y), 2)
var todist:Number = this.xdist + this.ydist
var totdist:Number = Math.sqrt(todist)
// Testing.
if (totdist > 12){
//Up + Right
var nuxdist:Number = Math.pow((_parent._x + 4 - posq.x), 2)
var nuydist:Number = Math.pow((_parent._y - 3 - posq.y), 2)
var nutodist:Number = this.nuxdist + this.nuydist
var nutotdist:Number = Math.sqrt(nutodist)
if (nutotdist < totdist){
_parent._x += 2
_parent._y -= 1.5}
// Up + Left
var nuxdist:Number = Math.pow((_parent._x - 4 - posq.x), 2)
var nuydist:Number = Math.pow((_parent._y - 3 - posq.y), 2)
var nutodist:Number = this.nuxdist + this.nuydist
var nutotdist:Number = Math.sqrt(nutodist)
if (nutotdist < totdist){
_parent._x -= 2
_parent._y -= 1.5}
// Down + Right
var nuxdist:Number = Math.pow((_parent._x + 4 - posq.x), 2)
var nuydist:Number = Math.pow((_parent._y + 3 - posq.y), 2)
var nutodist:Number = this.nuxdist + this.nuydist
var nutotdist:Number = Math.sqrt(nutodist)
if (nutotdist < totdist){
_parent._x += 2
_parent._y += 1.5}
// Down + Left
var nuxdist:Number = Math.pow((_parent._x - 4 - posq.x), 2)
var nuydist:Number = Math.pow((_parent._y + 3 - posq.y), 2)
var nutodist:Number = this.nuxdist + this.nuydist
var nutotdist:Number = Math.sqrt(nutodist)
if (nutotdist < totdist){
_parent._x -= 2
_parent._y += 1.5}
}
(I think I could really improve on the Zombie movement)
Thanks for the help, and tell me if you need anything else from me. I will upload the main swf soon.
The game is a top down shooter, you move your player with the arrow keys, and zombies approach you, and when you meet them, you cannot run through them.
Eventually, I aim for the zombies to not be able to pass through eachother, so you eventually get swarmed (and it'll look much better if they haven't all merged into one super zombie...).
I have coded the Player movement system, the Zombie's movement system, and the Player's Hittests (see below) - yet I have come across some issues.
The player, depending on the order of the if statement (in the collision), has varied effectiveness with collisions - if I put the X-Axis detections first, it only works properly on this axis. Similar to if the Y-Axis is first.
The Zombies, when hitting the player, make him teleport away - due to the Player hit detections, and the way the Zombies moves - making them push him around.
Player Movement (in Player movie clip)
if (Key.isDown(Key.LEFT)){
this._x -= speed
_global.posq = {x: _x, y: _y}}
// _global.posq is used to allow the zombies to know the player's position
if (Key.isDown(Key.RIGHT)){
this._x += speed
_global.posq = {x: _x, y: _y}}
if (Key.isDown(Key.UP)){
this._y -= speed
_global.posq = {x: _x, y: _y}}
if (Key.isDown(Key.DOWN)){
this._y += speed
_global.posq = {x: _x, y: _y}}
Player Collision Detection (in Player movie clip)
for (i in _root.ZombieList){
if (this.hitTest(_root.ZombieList[i])){
PZomb = _root.ZombieList[i]
trace(PZomb)
if ((this._y + this._height >= PZomb._y) && (this._y <= PZomb._y)){
trace("Hit from top!")
this._y -= speed
_global.posq = {x: _x, y: _y}}
if ((this._y <= PZomb._y + PZomb._height) && (this._y >= PZomb._y)){
trace("Hit from bottom!")
this._y += speed
_global.posq = {x: _x, y: _y}}
if ((this._x <= PZomb._x + PZomb._width) && (this._x >= PZomb._x)) {
trace("Hit from right!")
this._x += speed
_global.posq = {x: _x, y: _y}}
if ((this._x + this._width >= PZomb._x) && (this._x <= PZomb._x )) {
trace("Hit from left!")
this._x -= speed
_global.posq = {x: _x, y: _y}}
Zombie Movement (in a movie clip, inside the main Zombie movie clip)
// Get distance.
var xdist:Number = Math.pow((_parent._x - posq.x), 2)
var ydist:Number = Math.pow((_parent._y - posq.y), 2)
var todist:Number = this.xdist + this.ydist
var totdist:Number = Math.sqrt(todist)
// Testing.
if (totdist > 12){
//Up + Right
var nuxdist:Number = Math.pow((_parent._x + 4 - posq.x), 2)
var nuydist:Number = Math.pow((_parent._y - 3 - posq.y), 2)
var nutodist:Number = this.nuxdist + this.nuydist
var nutotdist:Number = Math.sqrt(nutodist)
if (nutotdist < totdist){
_parent._x += 2
_parent._y -= 1.5}
// Up + Left
var nuxdist:Number = Math.pow((_parent._x - 4 - posq.x), 2)
var nuydist:Number = Math.pow((_parent._y - 3 - posq.y), 2)
var nutodist:Number = this.nuxdist + this.nuydist
var nutotdist:Number = Math.sqrt(nutodist)
if (nutotdist < totdist){
_parent._x -= 2
_parent._y -= 1.5}
// Down + Right
var nuxdist:Number = Math.pow((_parent._x + 4 - posq.x), 2)
var nuydist:Number = Math.pow((_parent._y + 3 - posq.y), 2)
var nutodist:Number = this.nuxdist + this.nuydist
var nutotdist:Number = Math.sqrt(nutodist)
if (nutotdist < totdist){
_parent._x += 2
_parent._y += 1.5}
// Down + Left
var nuxdist:Number = Math.pow((_parent._x - 4 - posq.x), 2)
var nuydist:Number = Math.pow((_parent._y + 3 - posq.y), 2)
var nutodist:Number = this.nuxdist + this.nuydist
var nutotdist:Number = Math.sqrt(nutodist)
if (nutotdist < totdist){
_parent._x -= 2
_parent._y += 1.5}
}
(I think I could really improve on the Zombie movement)
Thanks for the help, and tell me if you need anything else from me. I will upload the main swf soon.