0 registered members (),
677
guests, and 5
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
2d platform game. Moving a character
#245993
01/12/09 22:15
01/12/09 22:15
|
Joined: Jul 2008
Posts: 26 Norway
Harstad
OP
Newbie
|
OP
Newbie
Joined: Jul 2008
Posts: 26
Norway
|
Ok, so I'm trying to make a simple 2d Platform game, just to get started.
this is what I got so far:
#include <acknex.h> #include <default.c>
BMAP* background = "second.bmp"; BMAP* gras = "gress.bmp"; BMAP* person = "player.bmp";
PANEL* new_background = //this is the background. { pos_x = 0; pos_y = 0; bmap = background; layer = 1; flags = VISIBLE; }
PANEL* new_ground = //this is the ground for the player to walk on. { pos_x = 0; pos_y = 0; bmap = gras; layer = 3; flags = OVERLAY | VISIBLE; }
PANEL* Player_2 = //this is the player. { pos_x = 250; pos_y = 450; layer = 2; bmap = person; flags = VISIBLE | OVERLAY; }
PANEL* Player_1 = { pos_x = 250; pos_y = 425; Layer = 2; bmap = "player.bmp"; flags = VISIBLE | OVERLAY; }
function move_right() { new_background.pos_x += 5; wait (1); }
function quit_program() { sys_exit (NULL); }
function main () { video_mode = 10; video_screen = 1; screen_color.blue = 150; handle = media_loop ("123.mp3",NULL,50); on_q = quit_program; while(1) { new_background.pos_x -=15*(key_d-key_a)*time_step; //this enables the player to walk forwards and backwards new_ground.pos_x -=15*(key_d-key_a)*time_step; if (key_w) { Player_2.pos_y -=30*time_step; } else { Player_2.pos_y +=30*time_step; } if (Player_2.pos_y > 450) { Player_2.pos_y = 450; } wait(1); } }
Last edited by Harstad; 01/16/09 23:31.
|
|
|
Re: 2d platform game. Moving a character
[Re: Harstad]
#245997
01/12/09 22:39
01/12/09 22:39
|
Joined: Feb 2006
Posts: 385 Oldenburg,Germany
Ralph
Senior Member
|
Senior Member
Joined: Feb 2006
Posts: 385
Oldenburg,Germany
|
Hi, Replace this: With this:
while(1){
Player_2.pos_x +=5*(key_d-key_a)*time_step;
wait(1);
}
|
|
|
Re: 2d platform game. Moving a character
[Re: Ralph]
#246035
01/13/09 10:50
01/13/09 10:50
|
Joined: Jul 2008
Posts: 26 Norway
Harstad
OP
Newbie
|
OP
Newbie
Joined: Jul 2008
Posts: 26
Norway
|
|
|
|
Re: 2d platform game. Moving a character
[Re: Harstad]
#246041
01/13/09 11:09
01/13/09 11:09
|
Joined: Jul 2008
Posts: 26 Norway
Harstad
OP
Newbie
|
OP
Newbie
Joined: Jul 2008
Posts: 26
Norway
|
Deleted.
Last edited by Harstad; 01/16/09 23:32.
|
|
|
Re: 2d platform game. Moving a character
[Re: Ralph]
#246766
01/17/09 01:07
01/17/09 01:07
|
Joined: Oct 2008
Posts: 67
pewpew
Junior Member
|
Junior Member
Joined: Oct 2008
Posts: 67
|
Hi, Replace this: With this:
while(1){
Player_2.pos_x +=5*(key_d-key_a)*time_step;
wait(1);
}
i dont understand - why do you do the (key_d - key_a) thing? how does that work..?
HURRR DERP DERP DEERRPP HURR
|
|
|
Re: 2d platform game. Moving a character
[Re: pewpew]
#246790
01/17/09 09:23
01/17/09 09:23
|
Joined: Jul 2008
Posts: 26 Norway
Harstad
OP
Newbie
|
OP
Newbie
Joined: Jul 2008
Posts: 26
Norway
|
because, you then dont have to make two functions for moving left and right, with that code you can simply use a and d to move left and right with one line;)
Last edited by Harstad; 01/17/09 09:24.
|
|
|
Re: 2d platform game. Moving a character
[Re: Harstad]
#246793
01/17/09 09:29
01/17/09 09:29
|
Joined: Oct 2007
Posts: 5,210 İstanbul, Turkey
Quad
Senior Expert
|
Senior Expert
Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
|
yeah if user presses a itll -5*time_step. if presses d it'll be 5*time_step.
but moving player by directly changin it's dimensions is not good. If you want collisions and stuff, you need to use c_move or physical functions.
3333333333
|
|
|
Re: 2d platform game. Moving a character
[Re: Quad]
#246804
01/17/09 11:22
01/17/09 11:22
|
Joined: Oct 2008
Posts: 67
pewpew
Junior Member
|
Junior Member
Joined: Oct 2008
Posts: 67
|
ohh.. i see now. key_a and key_d are 1 or 0. i was assuming that it converted the key into an ascii code and subtracted. heh i have a horrible tendency to look straight past little tricks like that.
HURRR DERP DERP DEERRPP HURR
|
|
|
Re: 2d platform game. Moving a character
[Re: Quad]
#246805
01/17/09 11:34
01/17/09 11:34
|
Joined: Jul 2008
Posts: 26 Norway
Harstad
OP
Newbie
|
OP
Newbie
Joined: Jul 2008
Posts: 26
Norway
|
yeah if user presses a itll -5*time_step. if presses d it'll be 5*time_step.
but moving player by directly changin it's dimensions is not good. If you want collisions and stuff, you need to use c_move or physical functions. I'm not yet that technical, and I try to make just a simple game of sidescrolling:P though, I was hoping for something to add collision, making like a rock you have to jump, a door and stuff like that:P
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|