Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
0 registered members (), 16,643 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Screen size / slow down - problems #296858
11/03/09 15:27
11/03/09 15:27
Joined: Aug 2009
Posts: 26
Goiânia - Brazil
D
dmBlack Offline OP
Newbie
dmBlack  Offline OP
Newbie
D

Joined: Aug 2009
Posts: 26
Goiânia - Brazil
Hi there,

I´ve done a little space-invaders clone as well as a pong clone. I am facing to problems here.

I´ve tested both of the games on the same pc I´ve programmed them. It´s a Pentium 4 HT 3.6GHz, 1.5 GB RAM, Windows vista. They work fine, fast and the game screen has the size it should has.

I´ve sent the games to some friends and some of them reported that the game screen looks strange, like it´s smaller than it should be. Besides the games are very slow.

I have tested the games on my notebook (Turion X2-64 2.0 GHZ, 2 GB RAM, windows vista) and I got the same problems... the game screen is smaller than the video_mode I´ve set (800X600 runs like 640x480 and the game makes no sense)

What should I try?
I can email the published games for you guys to take a look at the codes...

Re: Screen size / slow down - problems [Re: dmBlack] #296859
11/03/09 15:30
11/03/09 15:30
Joined: Nov 2007
Posts: 1,143
United Kingdom
DJBMASTER Offline
Serious User
DJBMASTER  Offline
Serious User

Joined: Nov 2007
Posts: 1,143
United Kingdom
You should use a function that determines the screen resolution and changes the size/layout of panels/etc accordingly. You can use the variables 'screen_size.x/y' to check the resolution.

You should run the function when the game starts.

Re: Screen size / slow down - problems [Re: DJBMASTER] #296865
11/03/09 15:42
11/03/09 15:42
Joined: Aug 2009
Posts: 26
Goiânia - Brazil
D
dmBlack Offline OP
Newbie
dmBlack  Offline OP
Newbie
D

Joined: Aug 2009
Posts: 26
Goiânia - Brazil
Thanks for the fast reply djbmaster

But I use the "video_mode = 7" before entering the game loop. Isn´t all the pcs suposed to run on 800x600 since I declared "video_mode = 7" ?

Re: Screen size / slow down - problems [Re: dmBlack] #296871
11/03/09 16:31
11/03/09 16:31
Joined: Oct 2004
Posts: 900
Lgh
rojart Offline
User
rojart  Offline
User

Joined: Oct 2004
Posts: 900
Lgh
Try this one video_set(sys_metrics(0), sys_metrics(1), 32, 1); instead of video_mode = 7;


Regards, Robert

Quote
Everything should be made as simple as possible, but not one bit simpler.
by Albert Einstein

PhysX Preview of Cloth, Fluid and Soft Body

A8.47.1P
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
D
dmBlack Offline OP
Newbie
dmBlack  Offline OP
Newbie
D

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 Offline
User
rojart  Offline
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.

Code:
//////////////////////////////////////////////////////////////////////////////
// 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);
	}
}




Regards, Robert

Quote
Everything should be made as simple as possible, but not one bit simpler.
by Albert Einstein

PhysX Preview of Cloth, Fluid and Soft Body

A8.47.1P
Re: Screen size / slow down - problems [Re: rojart] #297037
11/04/09 15:46
11/04/09 15:46
Joined: Aug 2009
Posts: 26
Goiânia - Brazil
D
dmBlack Offline OP
Newbie
dmBlack  Offline OP
Newbie
D

Joined: Aug 2009
Posts: 26
Goiânia - Brazil
Rojart,

The code is pretty much the same thing, except the way I made things move around... and that is exactly what I do in all my games and I think that´s why all my games are slow in other pcs.

I changed to movement functions. Now I am using the time_step variable to control my panel´s position change. This way the pong game as well as all my other 2d games are working ok. I wouldn´t say "working great" because they still look weird... but that may be because the computer performance itself is just ok, I guess...

I don´t know if I understood the hole idea of this time_step variable. Is that because different PCs can do a different amount of stuff in their clock cycle and than the game runs according to that PC clock cycle?

By the way, thanks!

Re: Screen size / slow down - problems [Re: dmBlack] #297045
11/04/09 17:19
11/04/09 17:19
Joined: Jan 2007
Posts: 1,619
Germany
Scorpion Offline
Serious User
Happy Birthday Scorpion  Offline
Serious User

Joined: Jan 2007
Posts: 1,619
Germany
hey dmBlack,
on slower pcs time_step is bigger, because there will be rendered fewer frames, so the objects have to move a larger amount. If the pc is fast, the the frame duration is shorter, so they have to move less => time_step is small


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1