Извините, ничего не найдено.

Не расстраивайся! Лучше выпей чайку!
Регистрация
Справка
Календарь

Вернуться   forum.boolean.name > Программирование игр для мобильных телефонов > MidletPascal

Ответ
 
Опции темы
Старый 14.11.2010, 03:01   #1
NastyKhan
Оператор ЭВМ
 
Регистрация: 26.09.2010
Сообщений: 29
Написано 0 полезных сообщений
(для 0 пользователей)
Keypressing

Hello,

I'd like to make simple game, when an Object (starship, car, rocket etc.) is controlled by LEFT and RIGHT buttons. When you hold LEFT it strafe left, when you hold RIGHT, it strafe right, when you release buttons - it stops moving. Like any common shooter.


<------ /[]\ ------>


I tried something like this:


repeat;
drawimage(ship,x,0);
repaint;
delay(10);
key:=getkeypressed;
if (keyToAction(key)=GA_LEFT) then x:=x-10;
if (keyToAction(key)=GA_RIGHT) then x:=x+10;

until false;

It WORKS when I'm pressing ONE button only. But doesn't when I press both at same time. I'll try to explain this:

1. When I press (and hold) LEFT: CPU thinks i'm holding LEFT, and is doing his job.

[left]
<----/[]\

2. Then, when I press (and hold) RIGHT, while still holding LEFT pressed: CPU now thinks i'm holding RIGHT.

[left][right]
/[]\---->

3a. When I release RIGHT button, while still holding LEFT pressed: CPU thinks RIGHT has been released, so in his opinion all buttons has been released and so he does nothing.

[left]
/[]\

3b. Also when I release LEFT button, while still holding RIGHT pressed: CPU thinks that all buttons has been released and so he does nothing.

[right]
/[]\


I hope i made myself clear


My questions:
1. How to fix it?
2. Does anybody could give me working "spacecraft movement" procedure, please?

Thanks
(Offline)
 
Ответить с цитированием
Старый 14.11.2010, 03:19   #2
ViNT
Модератор
 
Регистрация: 03.04.2007
Сообщений: 2,252
Написано 597 полезных сообщений
(для 817 пользователей)
Ответ: Keypressing

This action can't be handled by standard MP functions, because they can't determine current button state, they only handle press/release events.

You should try to use get_key_states function from Lib_game, this possible can handle multiple key pressing.
(Offline)
 
Ответить с цитированием
Старый 14.11.2010, 03:35   #3
NastyKhan
Оператор ЭВМ
 
Регистрация: 26.09.2010
Сообщений: 29
Написано 0 полезных сообщений
(для 0 пользователей)
Ответ: Keypressing

Hmm.. i was also thinking about it. However I don't know how to use lib_game, and other 'non-standard things'.. any clues with that?

edit:

I downloaded and installed 'game' library into my "..\MidletPascal 3.1\Libs\" folder. Then i added "uses game;" line to my game. Finally i changed the code:


repeat;
drawimage(ship,x,0);
repaint;
delay(10);
key := game.get_key_states;
if (game.get_bit(key, 4)<>0) then x:=x-10;
if (game.get_bit(key, 32)<>0) then x:=x+10;

until false;

Compliation and buliding worked fine. The '*.jar' works. However nothing happens. I think the games freezes from some reason.. But dont know why.

edit2:
I realised than i'm missing "game.init", and "game.show" thingies. However when i put them, i get white blank screen. What are they for anyway?

Please help..

Последний раз редактировалось NastyKhan, 14.11.2010 в 04:51.
(Offline)
 
Ответить с цитированием
Старый 14.11.2010, 05:02   #4
NastyKhan
Оператор ЭВМ
 
Регистрация: 26.09.2010
Сообщений: 29
Написано 0 полезных сообщений
(для 0 пользователей)
Ответ: Keypressing

I searched the forum, and i found this:


Program test;

uses
game;

const
UP_PRESSED = 2;
DOWN_PRESSED = 64;
LEFT_PRESSED = 4;
RIGHT_PRESSED = 32;
FIRE_PRESSED = 256;
GAME_A_PRESSED = 512;
GAME_B_PRESSED = 1024;
GAME_C_PRESSED = 2048;
GAME_D_PRESSED = 4096;

var
img: image;
key: integer;
x,y: integer;

procedure cls;
begin
setcolor(255,255,255);
fillrect(0,0,getwidth,getheight);
end;

procedure init;
begin
img:=loadimage('/icon.png');
x:=20;
y:=20;
game.init;
game.show;
end;

Begin
init;
repeat
key:=game.get_key_states;
if game.get_bit(key, LEFT_PRESSED)<>0 then
x:=x-5;
if game.get_bit(key, RIGHT_PRESSED)<>0 then
x:=x+5;
if game.get_bit(key, UP_PRESSED)<>0 then
y:=y-5;
if game.get_bit(key, DOWN_PRESSED)<>0 then
y:=y+5;
cls;
drawimage(img,x,y);
game.refresh;
delay(50);
until game.get_bit(key, FIRE_PRESSED)<>0;
End.



That's exactly what i need. I compiled it, but i when i run *.jar, i get blank white screen again!

Please help..
(Offline)
 
Ответить с цитированием
Старый 14.11.2010, 07:29   #5
Trazzy
Разработчик
 
Аватар для Trazzy
 
Регистрация: 24.11.2008
Адрес: UA
Сообщений: 504
Написано 110 полезных сообщений
(для 225 пользователей)
Ответ: Keypressing

u can try to change game.init; -> game.init(1);
__________________
Уважай собеседника, а лучше подари ему +
(Offline)
 
Ответить с цитированием
Старый 14.11.2010, 08:30   #6
ViNT
Модератор
 
Регистрация: 03.04.2007
Сообщений: 2,252
Написано 597 полезных сообщений
(для 817 пользователей)
Ответ: Keypressing

Try to compile this in MP 2.0.2 version.
(Offline)
 
Ответить с цитированием
Старый 14.11.2010, 16:53   #7
NastyKhan
Оператор ЭВМ
 
Регистрация: 26.09.2010
Сообщений: 29
Написано 0 полезных сообщений
(для 0 пользователей)
Ответ: Keypressing

Using MP 2.0 and changing game.init; to game.init(1); didn't work.

In fact, when i keep game.init; it doesn't compile at all.


Still need help : (


edit:
Maybe i have the library wrongly installed. All i have to do is to copy it into "..\MidletPascal 3.1\Libs\" folder?

Also what [lib_name].init and [lib_name].show commands do?
(Offline)
 
Ответить с цитированием
Старый 14.11.2010, 21:29   #8
ViNT
Модератор
 
Регистрация: 03.04.2007
Сообщений: 2,252
Написано 597 полезных сообщений
(для 817 пользователей)
Ответ: Keypressing

Use MP 2.0.2 version, not MP 2.0.
I compile example from post #4 and it perfectly works.
(Offline)
 
Ответить с цитированием
Старый 15.11.2010, 00:28   #9
Trazzy
Разработчик
 
Аватар для Trazzy
 
Регистрация: 24.11.2008
Адрес: UA
Сообщений: 504
Написано 110 полезных сообщений
(для 225 пользователей)
Ответ: Keypressing

Use Midlet Pascal 2.02
Copy Lib_game.class into "..\MIDletPascal\Libs\"
It works!.
Вложения
Тип файла: zip Lib_game.zip (1.5 Кб, 469 просмотров)
Тип файла: zip Keypressing_sample.zip (7.4 Кб, 462 просмотров)
__________________
Уважай собеседника, а лучше подари ему +
(Offline)
 
Ответить с цитированием
Старый 17.11.2010, 20:02   #10
NastyKhan
Оператор ЭВМ
 
Регистрация: 26.09.2010
Сообщений: 29
Написано 0 полезных сообщений
(для 0 пользователей)
Ответ: Keypressing

Thanks It works now.
(Offline)
 
Ответить с цитированием
Ответ


Опции темы

Ваши права в разделе
Вы не можете создавать темы
Вы не можете отвечать на сообщения
Вы не можете прикреплять файлы
Вы не можете редактировать сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.


Часовой пояс GMT +4, время: 15:41.


vBulletin® Version 3.6.5.
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Перевод: zCarot
Style crйe par Allan - vBulletin-Ressources.com