Legacy GM Help with infinite driving game please?

E

Evilperson

Guest
My game is like a typical infinite runner, except the player drives a car and the view is top-down.
To do this, I made a car object in the middle of the screen and tried to create the illusion of the car moving by making everything except the car itself move.

The tire tracks object works perfectly, like this:
direction = obj_player_car.image_angle + 180
speed = global.car_speed[global.current_car] + global.current_gear

The Problem:
I am trying to add enemy cars driving in all sorts of directions, while still maintaining the illusion.
Firstly, I tried adding a small car that drives 'south'. I wanted it to turn left and right.
I successfully made it drive 'south' while maintaining the illusion, like this:
speed = 10
image_angle = 270
direction = 270
motion_add(obj_player_car.image_angle + 180,global.car_speed[global.current_car]+ global.current_gear)

BUT when I tried adding the turning a few different ways, anomalies occured.
This is my latest attempt, which doesn't work.
if clockwise = false {
turn_value += 1
// motion_add(0,4)
} else {
turn_value -= 1
//motion_add(180,4)
}
if turn_value > 315 {
clockwise = true
}
if turn_value < 235 {
clockwise = false
}
turn_speed += sin(turn_value/2)*2;
motion_add(0,turn_speed)

Is there a better solution, or have I just made a stupid mistake?
Any help is appreciated, if more info is needed it will be provided.
 

obscene

Member
Personally I'd code the enemy car's movement without consideration of the player's movement. Just make it drive in whatever direction you want it to as if you were coding a normal top down game.

Separately, I'd run another code from your player car that moves everything in relation to it.

Personally I'd code the enemy car's movement without consideration of the player's movement. Just make it drive in whatever direction you want it to as if you were coding a normal top down game.

Separately, I'd run another code from your player car that moves everything in relation to it.

Code:
x+=hsp // your car's supposed horizontal speed
y+=vsp // you car's suppsosed vertical speed
with all
{
// Move everything in the opposite direction (including the car which will be moved back to the previous position)
x-=hsp
y-=vsp
}

This might be a drastic change from what people normally do for an endless runner... but it's what I'd do if I were ever doing one. When you create objects that need to move down the screen, you don't have to give them their own code this way. The car moves every object every step and all you have to do is create more objects at the top of the screen.

Actually I'd use a parent object instead of all but that's up to you.
 
E

Evilperson

Guest
Personally I'd code the enemy car's movement without consideration of the player's movement. Just make it drive in whatever direction you want it to as if you were coding a normal top down game.

Separately, I'd run another code from your player car that moves everything in relation to it.

Personally I'd code the enemy car's movement without consideration of the player's movement. Just make it drive in whatever direction you want it to as if you were coding a normal top down game.

Separately, I'd run another code from your player car that moves everything in relation to it.

Code:
x+=hsp // your car's supposed horizontal speed
y+=vsp // you car's suppsosed vertical speed
with all
{
// Move everything in the opposite direction (including the car which will be moved back to the previous position)
x-=hsp
y-=vsp
}

This might be a drastic change from what people normally do for an endless runner... but it's what I'd do if I were ever doing one. When you create objects that need to move down the screen, you don't have to give them their own code this way. The car moves every object every step and all you have to do is create more objects at the top of the screen.

Actually I'd use a parent object instead of all but that's up to you.
Thanks for help. It seems to work fine now, I haven't noticed anything wrong so far.

I give the car a speed and a direction rather than horizontal and vertical speeds, so I did this:
x += lengthdir_x(global.car_speed[global.current_car]+ global.current_gear,obj_player_car.image_angle + 180)
y += lengthdir_y(global.car_speed[global.current_car]+ global.current_gear,obj_player_car.image_angle + 180)
 
Top