1 registered members (TipmyPip),
18,633
guests, and 5
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: Screen size / slow down - problems
[Re: rojart]
#296997
11/04/09 09:58
11/04/09 09:58
|
Joined: Aug 2009
Posts: 26 Goiânia - Brazil
dmBlack
OP
Newbie
|
OP
Newbie
Joined: Aug 2009
Posts: 26
Goiânia - Brazil
|
Rojart,
I´ve used your suggestion and it works perfectly now... thank you! But my games still run very slow... I don´t know if it´s me doing something wrong or maybe something else... My games are all panel based...
Here is the code for my pong clone... it´s very easy so I don´t mind if somebody reading it use it... it should be very fast because it is a simple game...
/////////////////////////////// #include <acknex.h> #include <default.c> /////////////////////////////// BMAP* campo_bmp = "campo.png"; BMAP* puck_bmp = "puck.bmp"; BMAP* raquete_bmp = "raquete.bmp"; BMAP* vitoria_bmp = "vitoria.bmp";
#define PRAGMA_BIND "campo.png"; #define PRAGMA_BIND "puck.bmp"; #define PRAGMA_BIND "raquete.bmp"; #define PRAGMA_BIND "vitoria.bmp";
PANEL* vitoria_pan = { pos_x = 260; pos_y = 100; layer = 5; bmap = vitoria_bmp; }
PANEL* puck_pan = { pos_x = 385; pos_y = 285; layer = 2; bmap = puck_bmp; flags = OVERLAY | VISIBLE; }
PANEL* r1_pan = { pos_x = 60; pos_y = 270; layer = 1; bmap = raquete_bmp; flags = OVERLAY | VISIBLE; }
PANEL* r2_pan = { pos_x = 715; pos_y = 270; layer = 1; bmap = raquete_bmp; flags = OVERLAY | VISIBLE; }
PANEL* campo_pan = { pos_x = 0; pos_y = 0; layer = 0; bmap = campo_bmp; flags = VISIBLE; }
STRING* jogoL = "SUPERPONG"; STRING* golsjogador1L = "JOGADOR 1 "; STRING* golsjogador2L = "JOGADOR 2 "; STRING* jogo = "PLACAR"; STRING* golsjogador1 = " "; STRING* golsjogador2 = " "; STRING* vitoria1 = "PARABENS!"; STRING* vitoria2 = "VOCE VENCEU,";
TEXT* vitoria1_txt = { pos_x = 270; pos_y = 370; layer = 6; string (vitoria1, vitoria2, golsjogador1L); }
TEXT* vitoria2_txt = { pos_x = 270; pos_y = 370; layer = 6; string (vitoria1, vitoria2, golsjogador2L); }
TEXT* placarlabel_txt = { pos_x = 240; pos_y = 570; layer = 3; string (jogoL, golsjogador1L, golsjogador2L); flags = VISIBLE; }
TEXT* placar_txt = { pos_x = 340; pos_y = 570; layer = 3; string (jogo, golsjogador1, golsjogador2); flags = VISIBLE; }
///////////////////// //VARIAVEIS GLOBAIS// ///////////////////// var direcao_puck = 6; //puck orientation var velocidade_puck = 1; //puck speed var gols_jogador1 = 0; //player 1 points var gols_jogador2 = 0; //player 2 points var posicao_relativa; //relative position
function atualizaPosicaoRelativa() //update relative position { if (puck_pan.pos_x < r1_pan.pos_x) posicao_relativa = 1; else if (puck_pan.pos_x > r2_pan.pos_x) posicao_relativa = 2; else posicao_relativa = 0; }
function verificaLimites() //check boundaries { //raquete 1 if (r1_pan.pos_x <= 1) r1_pan.pos_x = 1; if (r1_pan.pos_x >= 374) r1_pan.pos_x = 374; if (r1_pan.pos_y <= 1) r1_pan.pos_y = 1; if (r1_pan.pos_y >= 539) r1_pan.pos_y = 539; //raquete 2 if (r2_pan.pos_x >= 774) r2_pan.pos_x = 774; if (r2_pan.pos_x <= 400) r2_pan.pos_x = 400; if (r2_pan.pos_y <= 1) r2_pan.pos_y = 1; if (r2_pan.pos_y >= 539) r2_pan.pos_y = 539; }
function mudarDirecao(var direx) //change direction { direcao_puck = direx; }
function movePuck() //move puck { if (direcao_puck == 1) puck_pan.pos_x -= velocidade_puck; //esquerda - left if (direcao_puck == 2) puck_pan.pos_x += velocidade_puck; //direita - right if (direcao_puck == 3) puck_pan.pos_y -= velocidade_puck; //norte - north if (direcao_puck == 4) puck_pan.pos_y += velocidade_puck; //sul - south if (direcao_puck == 5) //nordeste - northeast { puck_pan.pos_x += (velocidade_puck/2); puck_pan.pos_y -= (velocidade_puck/2); } if (direcao_puck == 6) //sudeste - southeast { puck_pan.pos_x += (velocidade_puck/2); puck_pan.pos_y += (velocidade_puck/2); } if (direcao_puck == 7) //sudoeste - southwest { puck_pan.pos_x -= (velocidade_puck/2); puck_pan.pos_y += (velocidade_puck/2); } if (direcao_puck == 8) //noroeste - northwest { puck_pan.pos_x -= (velocidade_puck/2); puck_pan.pos_y -= (velocidade_puck/2); } if (direcao_puck == 0) { } //sem movimento - no movement }
function controlaPontos() //update points { if (puck_pan.pos_x == 0 && (puck_pan.pos_y >= 200 && puck_pan.pos_y < 370)) { gols_jogador2 += 1; media_play("alarm1.wav", NULL, 100); str_for_num(golsjogador2, gols_jogador2); } if (puck_pan.pos_x == 770 && (puck_pan.pos_y >= 200 && puck_pan.pos_y < 370)) { gols_jogador1 += 1; media_play("alarm1.wav", NULL, 100); str_for_num(golsjogador1, gols_jogador1); } }
function colisaoPuck() //puck colision detection { var temp_dir; if (puck_pan.pos_x <= r1_pan.pos_x + 20 && puck_pan.pos_x + 30 >= r1_pan.pos_x && (puck_pan.pos_y >= r1_pan.pos_y - 20 && puck_pan.pos_y <= r1_pan.pos_y + 80)) { if (posicao_relativa == 0) { if (direcao_puck == 1) mudarDirecao(2); if (direcao_puck == 7) mudarDirecao(6); if (direcao_puck == 8) mudarDirecao(5); media_play("ploop.wav", NULL, 100); } if (posicao_relativa == 1) { if (direcao_puck == 2) mudarDirecao(1); if (direcao_puck == 6) mudarDirecao(7); if (direcao_puck == 5) mudarDirecao(8); media_play("ploop.wav", NULL, 100); } } if (puck_pan.pos_x + 30 >= r2_pan.pos_x && puck_pan.pos_x <= r2_pan.pos_x + 20 && (puck_pan.pos_y >= r2_pan.pos_y - 20 && puck_pan.pos_y <= r2_pan.pos_y + 80)) { if (posicao_relativa == 0) { if (direcao_puck == 2) mudarDirecao(1); if (direcao_puck == 6) mudarDirecao(7); if (direcao_puck == 5) mudarDirecao(8); media_play("ploop.wav", NULL, 100); } if (posicao_relativa == 2) { if (direcao_puck == 1) mudarDirecao(2); if (direcao_puck == 7) mudarDirecao(6); if (direcao_puck == 8) mudarDirecao(5); media_play("ploop.wav", NULL, 100); } } if (puck_pan.pos_x <= 0) { if (direcao_puck == 1) mudarDirecao(2); if (direcao_puck == 7) mudarDirecao(6); if (direcao_puck == 8) mudarDirecao(5); media_play("ploop.wav", NULL, 100); } if (puck_pan.pos_y <= 0) { if (direcao_puck == 3) mudarDirecao(4); if (direcao_puck == 5) mudarDirecao(6); if (direcao_puck == 8) mudarDirecao(7); media_play("ploop.wav", NULL, 100); } if (puck_pan.pos_y >= 570) { if (direcao_puck == 4) mudarDirecao(3); if (direcao_puck == 6) mudarDirecao(5); if (direcao_puck == 7) mudarDirecao(8); media_play("ploop.wav", NULL, 100); } if (puck_pan.pos_x >= 770) { if (direcao_puck == 2) mudarDirecao(1); if (direcao_puck == 6) mudarDirecao(7); if (direcao_puck == 5) mudarDirecao(8); media_play("ploop.wav", NULL, 100); } }
function moveRaquete() //move players { if (key_w) r1_pan.pos_y -= 0.3; if (key_s) r1_pan.pos_y += 0.3; if (key_a) r1_pan.pos_x -= 0.3; if (key_d) r1_pan.pos_x += 0.3; if (key_cuu) r2_pan.pos_y -= 0.3; if (key_cud) r2_pan.pos_y += 0.3; if (key_cul) r2_pan.pos_x -= 0.3; if (key_cur) r2_pan.pos_x += 0.3; }
function verificaFinal() //check for a winner { if (gols_jogador1 == 5) { direcao_puck = 0; media_play("crowdcheer.wav", NULL, 100); vitoria_pan.flags = OVERLAY | VISIBLE; vitoria1_txt.flags = OVERLAY | VISIBLE; } if (gols_jogador2 == 5) { direcao_puck = 0; media_play("crowdcheer.wav", NULL, 100); vitoria_pan.flags = OVERLAY | VISIBLE; vitoria2_txt.flags = OVERLAY | VISIBLE; } }
function main() { video_mode = 7; random_seed(1); while(1) { verificaFinal(); atualizaPosicaoRelativa(); colisaoPuck(); controlaPontos(); movePuck(); moveRaquete(); verificaLimites(); wait(1); } }
|
|
|
Re: Screen size / slow down - problems
[Re: dmBlack]
#297004
11/04/09 12:16
11/04/09 12:16
|
Joined: Oct 2004
Posts: 900 Lgh
rojart
User
|
User
Joined: Oct 2004
Posts: 900
Lgh
|
Try this code video_set(800, 600, 32, 2); video_window(NULL,NULL,2,NULL); instead of video_set(sys_metrics(0), sys_metrics(1), 32, 1); or video_mode = 7; maybe it works a bit faster. But for better understanding, why your code is very slow, please compare your code with pong.c code from 3dgs sample folder.
//////////////////////////////////////////////////////////////////////////////
// Pong demo from AUM magazine #26
// Control the right paddle with [Up] / [Down]
// Control the left paddle with [W] / [S]
//////////////////////////////////////////////////////////////////////////////
#include <acknex.h>
FONT* digital_font = "digital.pcx";
var left_score = 0;
var right_score = 0;
PANEL* main_pan = // the main panel
{
bmap = "main.pcx";
layer = 10;
digits(330, 40, 2, digital_font, 1, left_score);
digits(395, 40, 2, digital_font, 1, right_score);
flags = SHOW;
}
PANEL* left_pan = {
bmap = "paddle.pcx";
layer = 11;
pos_x = 60;
pos_y = 250;
flags = SHOW;
}
PANEL* right_pan = {
bmap = "paddle.pcx";
layer = 11;
pos_x = 715;
pos_y = 250;
flags = SHOW;
}
PANEL* ball_pan = {
bmap = "ball.pcx";
layer = 11;
pos_x = 504;
pos_y = 344;
flags = SHOW;
}
SOUND* beep1_wav = "beep1.wav";
SOUND* beep2_wav = "beep2.wav";
SOUND* goal_wav = "goal.ogg";
//////////////////////////////////////////////////////////////////////////////
#define COMPUTER 0
#define USER 1
VECTOR ball_speed;
var mode_left = COMPUTER;
var mode_right = COMPUTER;
TEXT* tName = { string("Computer","User"); }
STRING* sTitle = ""; // the window title
//////////////////////////////////////////////////////////////////////////////
function update_ball()
{
ball_pan.pos_x += 7*ball_speed.x*time_step;
ball_pan.pos_y += 7*ball_speed.y*time_step;
// check if hit a border or a paddle
if (ball_pan.pos_y > 555) // lower border
{
ball_speed.y = -3 - random(3);
snd_play (beep1_wav, 50, 0);
}
else if (ball_pan.pos_y < 32) // upper border
{
ball_speed.y = 3 + random(3);
snd_play (beep1_wav, 50, 0);
}
if (ball_pan.pos_x > 740) // left player scores!
{
snd_play (goal_wav, 70, 0);
ball_speed.x = -3 - random(3);
left_score += 1; // register a goal
ball_pan.pos_x = 740; // prevent registering twice
}
else if (ball_pan.pos_x < 40) // right player scores!
{
snd_play (goal_wav, 70, 0);
ball_speed.x = 3 + random(3);
right_score += 1;
ball_pan.pos_x = 40;
}
if ((ball_pan.pos_y > left_pan.pos_y - 12) && (ball_pan.pos_y < left_pan.pos_y + 96) && (ball_pan.pos_x > 60) && (ball_pan.pos_x < 72))
{
// the left player has blocked the ball
snd_play (beep2_wav, 70, 0);
ball_speed.x = 3 + random(3);
ball_speed.y = 3 - random(3);
}
else if ((ball_pan.pos_y > right_pan.pos_y - 12) && (ball_pan.pos_y < right_pan.pos_y + 96) && (ball_pan.pos_x > 703) && (ball_pan.pos_x < 715))
{
// the right player has blocked the ball
snd_play (beep2_wav, 70, 0);
ball_speed.x = -3 - random(3);
ball_speed.y = 3 - random(3);
}
}
function update_paddle(var *paddle_pos,var paddle_mode,var key)
{
if (COMPUTER == paddle_mode) {
if ((ball_pan.pos_y > 100) && (ball_pan.pos_y < 490)) // the computer makes mistakes too
*paddle_pos = ball_pan.pos_y - 42;
}
else if (USER == paddle_mode) {
*paddle_pos += 30*time_step*key;
*paddle_pos = clamp(*paddle_pos,35,470);
}
}
function main()
{
//video_set(sys_metrics(0), sys_metrics(1), 32, 1);
//video_mode = 7; // 800x600
video_set(800, 600, 32, 2);
video_window(NULL,NULL,2,NULL);
wait (1);
randomize();
ball_speed.x = 3 - 6 * (random(6) % 2); // -3 or 3, random ball direction at game start
ball_speed.y = 3 - random(6); // -3...3, random vertical speed at game start
while ((right_score != 15) && (left_score != 15))
{
if (key_esc) { sys_exit(NULL); }
// switch to user mode if a paddle key is pressed
if (key_w || key_s) mode_left = USER;
if (key_cuu || key_cud) mode_right = USER;
// update paddles and ball, and count scores
update_ball();
update_paddle(left_pan.pos_y,mode_left,key_s-key_w);
update_paddle(right_pan.pos_y,mode_right,key_cud-key_cuu);
// compose the sTitle string
str_cpy(sTitle,"Pong Demo - ");
str_cat(sTitle,(tName.pstring)[mode_left]);
str_cat(sTitle," vs. ");
str_cat(sTitle,(tName.pstring)[mode_right]);
video_window(NULL,NULL,0,sTitle);
wait (1);
}
}
|
|
|
|