# legobear154

Member Since 09 Aug 2010
Offline Last Active May 24 2013 03:29 PM

### Need Help With TDS Tile Collision

02 September 2012 - 11:15 PM

I am working on adding tile collision to my Top down shooter project, but I have run into a problem. My sprite is 31 x 28 and the origin of my sprite is x=7 and y=13 and the players hands go into the wall. Is there any way to fix this? My code is listed below. It is free movement and not grid based movement. The direction the player moves is independent of the mouse look position.

```if(right){
if(tile_layer_find(1000000,x+16,y-14) == -1 && tile_layer_find(1000000,x+16,y+14) == -1){
x += movespeed*(room_speed/fps);
}
}
if(up){
if(tile_layer_find(1000000,x-14,y-16) == -1 && tile_layer_find(1000000,x+14,y-16) == -1){
y -= movespeed*(room_speed/fps);
}
}
if(left){
if(tile_layer_find(1000000,x-16,y-14) == -1 && tile_layer_find(1000000,x-16,y+14) == -1){
x -= movespeed*(room_speed/fps);
}
}
if(down){
if(tile_layer_find(1000000,x-14,y+16) == -1 && tile_layer_find(1000000,x+14,y+16) == -1){
y += movespeed*(room_speed/fps);
}
}```

Thanks,
Legobear154

### Need help with collisions

06 June 2012 - 04:59 PM

I am trying to create tile collisions for my top down shooter game. I am using a modified version of Rixeno's move_step() script found here http://gmc.yoyogames...howtopic=367659.
I have modified it slightly to work with tiles, but I have encountered a problem.
First, here is my code:

```var i,move_check;
for (i = abs(xspeed); i > 0; i -= 1){
if (i < 0) {
i = 0;
}
move_check = sign(xspeed)*i;
if !(check_tile_collision(x+move_check,y,direction)){
x += move_check;
break;
}
if !(check_tile_collision(x+move_check,y-i,direction)){
y -= i/2;
}
if !(check_tile_collision(x+move_check,y+i,direction)){
y += i/2;
}
}
for (i = abs(yspeed); i > 0; i -= 1){
if (i < 0) {
i = 0;
}
move_check = sign(yspeed)*i;
if !(check_tile_collision(x,y+move_check,direction)){
y += move_check;
break;
}
if !(check_tile_collision(x-i,y+move_check,direction)){
x -= i/2;
}
if !(check_tile_collision(x+i,y+move_check,direction)){
x += i/2;
}
}```
xspeed is the speed your player travels in the x direction. yspeed is the speed your player travels in the y direction.

check_tile_collision:
```tile_x = x + lengthdir_x(argument0,argument2);
tile_y = y + lengthdir_y(argument1,argument2);
return(tile_layer_find(1000000,tile_x,tile_y));```

The problem is that the tile_x and tile_y values go to above 100 when I check for collisions. I am not sure why that is though.

Thanks,
Legobear154

### Need Help with HTTP Post Request

07 May 2012 - 03:31 PM

I am using Faucet Networking to do an HTTP Post request to my webserver. I fixed the problem so here is the correct code:

```host = argument0;  //Host to connect to
file = argument1;  //File to access
query = argument2;  //Post query

newLine = chr(13) + chr(10);
socket = tcp_connect(argument0,80);
str = "";
size = 0;

if (socket_has_error(socket)){
show_message("Socket error: " + socket_error(socket));
exit;
}

write_string(socket,"POST " + file + " HTTP/1.1" + newLine);
write_string(socket,"Host: " + host +newLine);
write_string(socket,"Connection: close"+newLine);
write_string(socket,"User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.168 Safari/535.19" + newLine);
write_string(socket,"Accept-Encoding: gzip"+newLine);
write_string(socket,"Accept-Charset: ISO-8859-1,UTF-8;q=0.7,*;q=0.7"+newLine);
write_string(socket,"Cache-Control: no-cache"+newLine);
write_string(socket,"Accept-Language: de,en;q=0.7,en-us;q=0.3"+newLine);
write_string(socket,"Content-type: application/x-www-form-urlencoded"+newLine);
write_string(socket,"Content-length: " + string(string_length(query)) + string_repeat(newLine,2));
write_string(socket,query);
socket_send(socket);

while(!tcp_eof(socket)){
}

return(str);```

### Help with HTTP Request

15 April 2012 - 02:10 AM

I am trying to do an HTTP request to my website using faucet networking. Here is my code right now but I get a size of 0 and no content.

```newLine = chr(13) + chr(10);
socket = tcp_connect("legobear154productions.byethost33.com",80);
str = "";
size = 0;

if (socket_has_error(socket)){
show_message("Socket error: " + socket_error(socket));
exit;
}

write_string(socket,"POST / HTTP/1.0" + newLine);
write_string(socket,"Host: legobear154productions.byethost33.com"+newLine);
write_string(socket,"Connection: close"+newLine);
write_string(socket,"Accept-Charset: ISO-8859-1,UTF-8;q=0.7,*;q=0.7"+newLine);
write_string(socket,"Cache-Control: no-cache"+newLine);
write_string(socket,"Accept-Language: de,en;q=0.7,en-us;q=0.3"+newLine);
socket_send(socket);

while(tcp_eof(socket)){
}

show_message("Size: " + string(size) + "#" + "Content: " + str);```

Thanks,
Legobear154

### Need help with AI

14 April 2012 - 07:37 PM

I am trying to create an AI for my top down shooter. I have the movement done. Here is the code:
Alarm0:
```if (obj_level.__load == false){
if (target = false){
if (path_index == -1){
xto = random(global.rwidth);
yto = random(global.rheight);
mp_grid_path(global.mpgrid,pathfinding_path,x,y,xto,yto,false);
path_start(pathfinding_path,2,0,true);
}
player_collision = collision_rectangle(x-320,y-240,x+320,y+240,obj_player,false,true);

if (player_collision > 0){
target = true;
}
}
if (target = true){
if (collision_rectangle(x-320,y-240,x+320,y+240,player_collision,false,true)){
mp_grid_path(global.mpgrid,pathfinding_path,x,y,player_collision.x,player_collision.y,false);
path_start(pathfinding_path,2,0,true);
}
else{
target = false;
}
}
}

alarm[0] = 2;```

It allows the AI to roam the map looking for players and when it finds a player attacks it. I don't have attacking added yet. What I don't know how to do is to make the AI rotate his sprite so he is facing the way he is moving. How can I go about doing this?

Also, the way the movement works now is the AI goes right over top the player. What would be a good way to make it stay a short distance away and attack? Also, how should I go about adding in a way for the AI to take cover behind a wall when being shot at? I want to make the AI smart enough for it to act like a real player.

Thanks,
Legobear154