Gamestudio Links
Zorro Links
Newest Posts
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (degenerate_762, AbrahamR, AndrewAMD, ozgur), 667 guests, and 8 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
2d platform game. Moving a character #245993
01/12/09 22:15
01/12/09 22:15
Joined: Jul 2008
Posts: 26
Norway
H
Harstad Offline OP
Newbie
Harstad  Offline OP
Newbie
H

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 Offline
Senior Member
Ralph  Offline
Senior Member

Joined: Feb 2006
Posts: 385
Oldenburg,Germany
Hi,
Replace this:
Code:
on_d = move_right;

With this:
Code:
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
H
Harstad Offline OP
Newbie
Harstad  Offline OP
Newbie
H

Joined: Jul 2008
Posts: 26
Norway
thanks^^

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
H
Harstad Offline OP
Newbie
Harstad  Offline OP
Newbie
H

Joined: Jul 2008
Posts: 26
Norway
Deleted.


Last edited by Harstad; 01/16/09 23:32.
Re: 2d platform game. Moving a character [Re: Harstad] #246752
01/16/09 23:30
01/16/09 23:30
Joined: Jul 2008
Posts: 26
Norway
H
Harstad Offline OP
Newbie
Harstad  Offline OP
Newbie
H

Joined: Jul 2008
Posts: 26
Norway
ok, I got this moving, and stuff...

But I need some more help...

I've added code for a jump:
if (key_w)
{
Player_2.pos_y -=30*time_step;
}
else
{
Player_2.pos_y +=30*time_step;
}
I get him to move up and down, but here lies the problem, how can I get him to move to pos_y = 400, and then fall back to 450? As it is now, he goes further up as long as I hold the button.

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 Offline
Junior Member
pewpew  Offline
Junior Member

Joined: Oct 2008
Posts: 67
Originally Posted By: Ralph
Hi,
Replace this:
Code:
on_d = move_right;

With this:
Code:
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
H
Harstad Offline OP
Newbie
Harstad  Offline OP
Newbie
H

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 Offline
Senior Expert
Quad  Offline
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 Offline
Junior Member
pewpew  Offline
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
H
Harstad Offline OP
Newbie
Harstad  Offline OP
Newbie
H

Joined: Jul 2008
Posts: 26
Norway
Originally Posted By: Quadraxas
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

Page 1 of 2 1 2

Gamestudio download | chip programmers | 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