I started to look at the aum83 2d workshop but when i was done with the code it didnt really work as expected.
I try to keep the code clean and separated into several files. Thats where it gets weird here. I separated it into main, functions and player. The code is almost exactly like in the workshop with few exceptions but it just wont work.
The function that reads the txt file and draws the tiles work perfectly. But the player panel never shows up on the screen. I have tried comparing the files with each other and I cant find whats wrong, its probably something small I overlooked or I have gotten it all wrong in the big picture. Either way I could really use some advice on what to do here. I dont want to collect all the code in one big file, it just gets messy when the code grows bigger later.
Main.C
#include <acknex.h>
#include <default.c>
#include "functions.c"
#include "player.c"
function main()
{
fps_max = 60;
video_mode = 11;
video_depth = 32;
video_screen = 1;
vec_set(screen_color, vector(178,153,128));
level_load(NULL);
read_level_data();
player_startup();
}
Functions.C
#define init_x 376
#define init_y 360
#define tile_width 64
#define tile_height 52
STRING* data_str = "#20";
STRING* temp_str = "#20";
PANEL* temp_pan;
function read_level_data()
{
var level_handle, string_size, index, layer_value;
VECTOR tile_pos;
layer_value = 10;
tile_pos.x = init_x;
tile_pos.y = init_y;
level_handle = file_open_read("level.txt");
wait (3);
while (file_str_read(level_handle, data_str) != -1)
{
index = 0;
string_size = str_len(data_str);
while (index < string_size)
{
str_cpy (temp_str, data_str);
str_clip(temp_str, index);
str_trunc(temp_str, string_size - index - 1);
if(str_cmp(temp_str, "d") == 1)
{
temp_pan = pan_create("bmap = dirt.png;", layer_value);
temp_pan.pos_x =tile_pos.x;
temp_pan.pos_y =tile_pos.y;
temp_pan.flags |= VISIBLE;
}
if(str_cmp(temp_str, "g") == 1)
{
temp_pan = pan_create("bmap = grass.png;", layer_value);
temp_pan.pos_x = tile_pos.x;
temp_pan.pos_y = tile_pos.y;
temp_pan.flags |= VISIBLE;
}
if(str_cmp(temp_str, "p")==1)
{
temp_pan = pan_create("bmap = plain.png;", layer_value);
temp_pan.pos_x = tile_pos.x;
temp_pan.pos_y = tile_pos.y;
temp_pan.flags |= VISIBLE;
}
if(str_cmp(temp_str, "s")==1)
{
temp_pan = pan_create("bmap = stone.png;", layer_value);
temp_pan.pos_x = tile_pos.x;
temp_pan.pos_y = tile_pos.y;
temp_pan.flags |= VISIBLE;
}
if(str_cmp(temp_str, "t")==1)
{
temp_pan = pan_create("bmap = terrain.png;", layer_value);
temp_pan.pos_x = tile_pos.x;
temp_pan.pos_y = tile_pos.y;
temp_pan.flags |= VISIBLE;
}
if(str_cmp(temp_str, "w")==1)
{
temp_pan = pan_create("bmap = water.png;", layer_value);
temp_pan.pos_x = tile_pos.x;
temp_pan.pos_y = tile_pos.y;
temp_pan.flags |= VISIBLE;
}
tile_pos.x += tile_width;
index += 1;
}
layer_value += 1;
tile_pos.x = init_x;
tile_pos.y += tile_height;
}
file_close(level_handle);
}
Player.C
PANEL* player_pan;
function player_startup()
{
VECTOR player_speed;
var horizontal_speed = 0;
var vertical_speed = 0;
player_pan = pan_create("bmap = player.png;", 150);
player_pan.pos_x = 383;
player_pan.pos_y = 225;
player_pan.flags |= VISIBLE;
player_pan.center_x = player_pan.size_x * 0.5;
player_pan.center_y = player_pan.size_y;
while(1)
{
vec_set(player_speed.x, accelerate(horizontal_speed, 2 * (key_cur - key_cul), 0.3));
player_pan.pos_x += player_speed.x;
vec_set(player_speed.x, accelerate(horizontal_speed, 2 *(key_cud - key_cuu),0.3));
player_pan.pos_y += player_speed.y;
if (key_cul + key_cur + key_cuu + key_cud)
{
player_pan.angle += 0.3 * sin(40 * total_ticks);
}
else
{
player_pan.angle = 0;
}
wait(1);
}
}
edit:
Since the workshops code works when I copy & paste it I dont think this matters, but Im using the free version of A8.
edit2:
Now it gets even weirder. I added the gem code as well and the gem shows up no problem, but still no playercharacter. I put it at the bottom in the player.c file.
PANEL* gem_pan;
SOUND* gem_wav = "gem.wav";
var game_score;
function gem_startup()
{
VECTOR gem_pos;
while(1)
{
gem_pan = pan_create("bmap = gem.png;",150);
gem_pan.pos_x = 200 + random(560);
gem_pan.pos_y = 150 + random(400);
gem_pan.flags |= VISIBLE;
while ((abs(player_pan.pos_x - gem_pan.pos_x) > 30) || (abs(player_pan.pos_y - gem_pan.pos_y) > 30))
{
wait(1);
}
snd_play(gem_wav,100,0);
game_score += 5;
ptr_remove(gem_pan);
wait(1);
}
}
Last edited by jakk_zeven; 01/02/11 15:05.