Keen: Modding Forum Index Keen: Modding
All the modding info you'll ever need
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Sprite Behaviours in C

 
Post new topic   Reply to topic    Keen: Modding Forum Index -> Keen Community Mod
View previous topic :: View next topic  
Author Message
lemm



Joined: 05 Jul 2009
Posts: 419

PostPosted: Sun Feb 21, 2010 3:50 am    Post subject: Sprite Behaviours in C Reply with quote

Hello,

It is now possible to write sprite behaviours in C. No more going through the trouble assembly to program our sprites. For this mod at least, I hope that some people with C knowledge will use this, because I sure as hell don't want to write 15 sprites worth of behaviours in assembly =).


Anyways, here is a slightly less sloppy example of the default garg movement code in C:

Code:

#include "keen1.h";


extern Sprite temp_sprite;
extern long int tick_count;
extern int sprite_sync;

extern int compute_sprite_delta(void);
extern void do_fall(void);
extern int get_random(void);
extern void think_4_garg_look(void);


void garg_move() {

   if (temp_sprite.vel_y == 0 && temp_sprite.vel_x > -220 && temp_sprite.vel_x < 220) {
      if (get_random() < sprite_sync) {
         temp_sprite.think_ptr = think_4_garg_look;
         temp_sprite.var_c = 0;
      }
   }
   
   if (temp_sprite.vel_x > 0)
      temp_sprite.frame = 0x40;
   else
      temp_sprite.frame = 0x42;

   temp_sprite.frame += (int)(tick_count >> 4 & 1);
   
   do_fall();
   int csd = compute_sprite_delta();
   
   if (csd & 4)
      temp_sprite.vel_x = 0xffc4;
      
   if (csd & 1)
      temp_sprite.vel_x = 0x3C;
   
   if (csd & 2)
      temp_sprite.var_c = 0;
   else {
      int l = temp_sprite.vel_x;
      int m = (l & 0xFFFF) ^ (l >> 16);
      m -= (l >> 16);
      
      if (m == 0xDC && temp_sprite.var_c == 0) {
      
         temp_sprite.var_c = 1;
         temp_sprite.vel_y = 0xFF38;   
         
      }
   }

   return;
}


EDIT:

Here is a bare bones package if you want to try out writing stuff in C. It's still missing a few header files and the help is incomplete, but it contains a walkthrough to guide you through the process of making the garg code. You don't need any other patches to do the walkthrough.

There is one .zip; just dump all the contents into a keen v1.31 directory with ck1patch and follow the instructions. You need winXP.

http://www.mediafire.com/?tnimtdzk1mt

EDIT 2:

Slightly more user friendly. There is no need for hex-editing of object files anymore. Instead, run fixobj <object.obj> 0x#### , where 0x#### is the starting offset of your function, and then link. (It's in the instructions.)

http://www.mediafire.com/?ancwbdgyyym


Last edited by lemm on Thu Mar 04, 2010 11:24 am; edited 4 times in total
Back to top
View user's profile Send private message
Fleexy



Joined: 12 Dec 2008
Posts: 216
Location: Blogham Tower

PostPosted: Sun Feb 21, 2010 4:00 am    Post subject: Reply with quote

Nice! However I don't know one character about C/C#/C++. Do you think you could rig up something like this for QuickBASIC, GML, or VBScript? Of these I am most experienced at QB. Of course I understand if it's impossible or too hard.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Draik



Joined: 26 Jul 2008
Posts: 71

PostPosted: Sun Feb 21, 2010 8:52 am    Post subject: Reply with quote

Those other languages I would put at unlikely at best.

On another note, woo! C is much more manageable than assembly for me, so I might pitch in here.
Back to top
View user's profile Send private message
lemm



Joined: 05 Jul 2009
Posts: 419

PostPosted: Sun Feb 21, 2010 3:43 pm    Post subject: Reply with quote

I couldn't do it for basic, but there are basic to c translators out there which might work if you are adamantly opposed to C syntax =)

Here's one: http://www.bcxgurus.com/
Back to top
View user's profile Send private message
Mink



Joined: 03 Nov 2007
Posts: 173

PostPosted: Mon Feb 22, 2010 1:39 am    Post subject: Reply with quote

Amazing, Lemm! The extent to which you've improved modding is just astounding. I'm looking forward to writing some enemy behaviors.
Back to top
View user's profile Send private message
levellass



Joined: 11 Oct 2006
Posts: 1404
Location: Ngaruawahia New Zealand

PostPosted: Mon Feb 22, 2010 5:14 am    Post subject: Reply with quote

I can do QB or a limited amount of Assembly, those are the only two languages I understand well enough.
Back to top
View user's profile Send private message
lemm



Joined: 05 Jul 2009
Posts: 419

PostPosted: Wed Feb 24, 2010 6:27 pm    Post subject: Reply with quote

Bamp.


Check out the new link. You can start fooling around with stuff now. Let me know if you are successful.
Back to top
View user's profile Send private message
pizza2004



Joined: 07 Jul 2009
Posts: 15

PostPosted: Mon Mar 01, 2010 12:19 am    Post subject: Reply with quote

This is awesome, I'm going to look into using this in Commander Genius. How hard would it be to do this with the physics?
Back to top
View user's profile Send private message
gerstrong



Joined: 25 Jan 2009
Posts: 51

PostPosted: Sat Jul 31, 2010 4:23 pm    Post subject: Reply with quote

This code seems to me quite similar in Commander Genius. Well it has to be... Interesting in fact
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Keen: Modding Forum Index -> Keen Community Mod All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group